This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Return User's Level

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
V
ViciousPiranha
Voice
Posts: 36
Joined: Mon Dec 17, 2012 5:21 am

Return User's Level

Post by ViciousPiranha »

I have a text file with all the users' levels.. it looks like this

[VIP]
Manga
splattoy
rammingor

[Voice]
Alex
Ronny
Battlefield3


and so on..

I really want that a user can check for his level by using a public or private command and also make sure they dont flood the bot with too many requests (only 1 for each 10 seconds)

command would:

!level

this will return this nickname's level:

BOT: Hey <nickname>, your level is: level-here

or !level <nickname>

will return that nickname's level

please help
thanks
L
LoKii
Voice
Posts: 34
Joined: Wed Oct 21, 2009 3:59 am

Post by LoKii »

I made something similar for my bot some time ago.

While it does work as intented, im sure that there may be a more sufficient way of doing this, however it does get the job done.

The bot takes the user levels based on flags.


This one is if a user asks about himself (!whoami):

Code: Select all

bind pub - !whoami proc_whoami
##
proc proc_whoami {nick host hand channel text} {
    global botnick
    if {[matchattr $nick +n]} {
        putserv "NOTICE $nick :$nick, you are my Lord. How may I serve you?"
        return 1
    }
    if {[matchattr $nick +qd]} {
        putserv "NOTICE $nick :$nick, you are on a Global Blacklist for either NO-OPs, NO-VOICE, or both for any channel that I am on!"
        putserv "NOTICE $nick :If you think that this is a mistake, please contact my owner."
        return 1
    }
    if {[matchattr $nick |+qd $channel]} {
        putserv "NOTICE $nick :$nick, you are on my Blacklist for either NO-OPs, NO-VOICE, or both for channel $channel!"
        putserv "NOTICE $nick :If you think that this is a mistake, please contact the channel owner."
        return 1
    }
    if {[matchattr $nick |+n $channel]} {
        putserv "NOTICE $nick :$nick, you are a channel OWNER on $channel."
        return 1
    }
    if {[matchattr $nick |+m $channel]} {
        putserv "NOTICE $nick :$nick, you are a channel MASTER on $channel."
        return 1
    }
    if {[matchattr $nick |+o $channel]} {
        putserv "NOTICE $nick :$nick, you are a channel OPs on $channel."
        return 1
    }
    if {[matchattr $nick |+l $channel]} {
        putserv "NOTICE $nick :$nick, you are a channel HALFOPs on $channel."
        return 1
    }
    if {[matchattr $nick |+f $channel]} {
        putserv "NOTICE $nick :$nick, you are a channel FRIEND on $channel."
        return 1
    }
    if {[matchattr $nick |+v $channel]} {
        putserv "NOTICE $nick :$nick, you are a channel VOICE-USER on $channel."
        return 1
    } else {
        putserv "NOTICE $nick :$nick, you are \002NOT\002 on my Channel-List for channel $channel."
        putserv "NOTICE $nick :If you think that this is an error and that I should recognize you, then please \002/msg $botnick ident <your-password>\002."
        putserv "NOTICE $nick :In case you are using a nickname other than the one I normally recognize you under, then please \002/msg $botnick <your-password> <your-normal-nickname>\002."
        putserv "NOTICE $nick :If non of the above solutions worked for you, then please contact the channel admin for $channel."
        return 1
    }
}
This one is if you want to check a user based on his handle (!checkuser <name>):

Code: Select all

bind pub n|m !checkuser proc_checkuser
##
proc proc_checkuser {nick host hand channel text} {
    global botnick
    set who [lindex [split $text] 0]
    if {($who == $botnick)} {
        putserv "NOTICE $nick :I am a \002bot\002 $nick."
        return 1
    }
    if {$who == ""} {
        putserv "NOTICE $nick :Usage: !checkuser <nick>"
        return 1
    }
    if {![onchan $who $channel]} {
        putserv "NOTICE $nick :I dont see $who on $channel"
        putserv "NOTICE $nick :The user you wish to check \002must\002 be in $channel when issuing the command."
        return 1
    }
    if {[matchattr $who +n]} {
        putserv "NOTICE $nick :$nick, $who is my OWNER."
        return 1
    }
    if {[matchattr $who +qd]} {
        putserv "NOTICE $nick :$nick, the user \002$who\002 is for some reason \002NOT\002 allowed to get OPs or VOICE on \002ANY\002 channel where I am on!"
        putserv "NOTICE $nick :This action has been issued due to either an abuse towards the bot, or as a security pre-caution."
        putserv "NOTICE $nick :If you think that this is an error, please contact my owner."
        return 1
    }
    if {[matchattr $who |+qd $channel]} {
        putserv "NOTICE $nick :$nick, the user \002$who\002 is for some reason \002NOT\002 allowed to get OPS or VOICE on channel $channel!"
        putserv "NOTICE $nick :This action has been issued due to either an abuse towards the bot, or as a security pre-caution."
        putserv "NOTICE $nick :If you think that this is an error, please contact the owner of channel $channel."
        return 1
    }
    if {[matchattr $who |+n $channel]} {
        putserv "NOTICE $nick :$who is a channel OWNER on $channel."
        return 1
    }
    if {[matchattr $who |+m $channel]} {
        putserv "NOTICE $nick :$who is a channel MASTER on $channel."
        return 1
    }
    if {[matchattr $who |+o $channel]} {
        putserv "NOTICE $nick :$who is a channel OPs on $channel."
        return 1
    }
    if {[matchattr $who |+l $channel]} {
        putserv "NOTICE $nick :$who is a channel HALFOPs on $channel."
        return 1
    }
    if {[matchattr $who |+f $channel]} {
        putserv "NOTICE $nick :$who is a channel FRIEND on $channel."
        return 1
    }
    if {[matchattr $who |+v $channel]} {
        putserv "NOTICE $nick :$who is a channel VOICE-USER on $channel."
        return 1
    } else {
        putserv "NOTICE $nick :$who is \002NOT\002 on my Channel-List for $channel $nick."
        return 1
    }
}
Let us know if it is what you needed.

As you can see, most of the 'levels' are channel based, with the exception of the blacklisted levels and the global owner. It shouldn't be hard to add any other global levels in to this script if you need them. In my case, i just added the levels that are available for requests by normal users. I do have some other scripts with more detailed info for global owners, where i can search users in the botlist based on different criteria, but i believe that the ones posted are more what you are looking for.

Cheers.
V
ViciousPiranha
Voice
Posts: 36
Joined: Mon Dec 17, 2012 5:21 am

Post by ViciousPiranha »

Hello LoKii -- thank you for the reply

I think I confused you a bit with my request, although I talked about users' level I did not mean levels on the eggdrop..

I meant for a file in the form as I provided or in any similiar form, such as:

[Friends]
Aaron
Tony

[Strangers]
LoKii
Morgan

So that if Morgan types !level it will return Strangers

If Aaron types !level it will return Friends

if Aaron types: !level LoKii it will return 'Strangers'

So those are actually topics I can define in a file and add/remove users from it
w
willyw
Revered One
Posts: 1203
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

Would you be willing to organize and label your users not by sections in a text file, but with an identifying number in your text file?

Aaron 1
Tony 1
LoKii 2
Moran 2
Bill 3
Tom 3
John 4
George 4
Jim 5
Jeff 5
Charles 5


I'm not promising to work on it yet. I'm just thinking about how I would do it. :)


Edit:
How many names to you expect to be ever be in your file? ... just curious.
V
ViciousPiranha
Voice
Posts: 36
Joined: Mon Dec 17, 2012 5:21 am

Post by ViciousPiranha »

Honestly I do not mind how the file would look like as long as it would be easy to set for each user his 'level' and the bot will will be able to retrieve it too

Posted: Fri Apr 19, 2013 8:32 am Post subject:
Vicious Piranha wrote:

...
I meant for a file in the form as I provided or in any similiar form, such as:

[Friends]
Aaron
Tony

[Strangers]
LoKii
Morgan
...


Would you be willing to organize and label your users not by sections in a text file, but with an identifying number in your text file?

Aaron 1
Tony 1
LoKii 2
Moran 2
Bill 3
Tom 3
John 4
George 4
Jim 5
Jeff 5
Charles 5


I'm not promising to work on it yet. I'm just thinking about how I would do it.
Edit:
How many names to you expect to be ever be in your file? ... just curious.
No more than 1,000, more like 800
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Why not using a sqlite database? It's by far easier to manage whatever you wish rather than a flat file.
Once the game is over, the king and the pawn go back in the same box.
w
willyw
Revered One
Posts: 1203
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

ViciousPiranha wrote:Honestly I do not mind how the file would look like as long as it would be easy to set for each user his 'level' and the bot will will be able to retrieve it too
...

Code: Select all


# April 19, 2013

# http://forum.egghelp.org/viewtopic.php?p=101413#101413


# Usage:
# !level
# or 
# !level <name>




#########################

## set path/filename of user nick/level file here
set userlevelfile "scripts/added/forum_requests/userlevelfile.txt"




bind pub - "!level" say_level


proc say_level {nick uhost handle chan text} {
global userlevelfile

        if {![file exists $userlevelfile]} {
                putserv "privmsg $chan :$nick: Sorry,  $userlevelfile not found"
                return 0
            }


#reference    http://forum.egghelp.org/viewtopic.php?t=6885
        set fname $userlevelfile
        set fp [open $fname "r"]
        set data [read -nonewline $fp]
        close $fp

        set lines [split $data "\n"]



       if {![llength [split $text]]} {
                if {[lsearch -nocase -index 0 $lines $nick] == -1} {
                        putserv "privmsg $chan :Sorry, $nick is not in list"
                        return 0
                   }

                putserv "privmsg $chan :Hey $nick, your level is: [lindex $lines [lsearch -nocase -index 0 $lines $nick] 1]"

           } else {

                if {[lsearch -nocase -index 0 $lines [lindex [split $text] 0] ] == -1} {
                        putserv "privmsg $chan :Sorry, [lindex [split $text] 0] is not in list"
                        return 0
                   }

                putserv "privmsg $chan :User: [lindex $lines [lsearch -nocase -index 0 $lines [lindex [split $text] 0] ] 0] Level: [lindex $lines [lsearch -nocase -index 0 $lines [lindex [split $text] 0] ] 1] "

# Beware of line wrapping when copy-n-pasting. The immediate above is all on one line.

             }

}



Experiment with the above. (I have tested it, but only briefly)
I have no idea how well it will handle a list with 800+ pairs.
Perhaps you will need someone else to help with a database, as mentioned by caesar.


Here is an example of the corresponding userlevelfile.txt:

Code: Select all

Aaron VIP
Tony Stranger
LoKii voice
Moran whatever
Bill nobody
Tom regular
John VIP
George voice
Jim Op
Jeff banned
Charles novice
jaCK_test bozo
herman 2
boo 0
foo 1

I hope this helps.
Last edited by willyw on Fri Apr 19, 2013 11:02 am, edited 1 time in total.
w
willyw
Revered One
Posts: 1203
Joined: Thu Jan 15, 2009 12:55 am

Re: Return User's Level

Post by willyw »

ViciousPiranha wrote: ...
and also make sure they dont flood the bot with too many requests (only 1 for each 10 seconds)
...

Can this be handled satisfactorily by Eggdrop's built in flood protection?
V
ViciousPiranha
Voice
Posts: 36
Joined: Mon Dec 17, 2012 5:21 am

Post by ViciousPiranha »

hey willyw,

Thanks for that - that is almost perfect.. the only problem is if the users 'level' is more than a single word.. in that case it truncates it..
w
willyw
Revered One
Posts: 1203
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

ViciousPiranha wrote:hey willyw,

Thanks for that - that is almost perfect.. the only problem is if the users 'level' is more than a single word.. in that case it truncates it..
Exactly.

Isn't that what you showed in your examples above?
w
willyw
Revered One
Posts: 1203
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

Code: Select all


# April 19, 2013

# http://forum.egghelp.org/viewtopic.php?p=101413#101413



#########################

## set path/filename of user nick/level file here
set userlevelfile "scripts/added/forum_requests/userlevelfile.txt"




bind pub - "!level" say_level


proc say_level {nick uhost handle chan text} {
global userlevelfile

        if {![file exists $userlevelfile]} {
                putserv "privmsg $chan :$nick: Sorry,  $userlevelfile not found"
                return 0
            }
#reference    http://forum.egghelp.org/viewtopic.php?t=6885
        set fname $userlevelfile
        set fp [open $fname "r"]
        set data [read -nonewline $fp]
        close $fp

        set lines [split $data "\n"]


        if {![llength [split $text]]} {
                if {[lsearch -nocase -index 0 $lines $nick] == -1} {
                        putserv "privmsg $chan :Sorry, $nick is not in list"
                        return 0
                   }


                #putserv "privmsg $chan :Hey $nick, your level is: [lindex $lines [lsearch -nocase -index 0 $lines $nick] 1]"
                putserv "privmsg $chan :Hey $nick, your level is: [lrange [lsearch -nocase -inline -index 0 $lines $nick] 1 end]"

           } else {

                if {[lsearch -nocase -index 0 $lines [lindex [split $text] 0] ] == -1} {
                        putserv "privmsg $chan :Sorry, [lindex [split $text] 0] is not in list"
                        return 0
                   }

               ###putserv "privmsg $chan :User: [lindex $lines [lsearch -nocase -index 0 $lines [lindex [split $text] 0] ] 0]  Level: [lindex $lines [lsearch -nocase -index 0 $lines [lindex [split $text] 0] ] 1] "
                putserv "privmsg $chan :User: [lindex $lines [lsearch -nocase -index 0 $lines [lindex [split $text] 0] ] 0]  Level:  [lrange [lsearch -nocase -inline -index 0 $lines [lindex [split $text] 0]] 1 end] "

## Again, beware of line wrapping when copy-n-pasting

             }

}


Code: Select all

Aaron VIP one something whatever
Tony Stranger
LoKii voice
Moran whatever
Bill nobody
Tom regular yak yak blah blah
John VIP
George voice
Jim Op
Jeff banned
Charles novice
jaCK_test bozo
herman 2
boo 0
foo 1
V
ViciousPiranha
Voice
Posts: 36
Joined: Mon Dec 17, 2012 5:21 am

Post by ViciousPiranha »

thank you willyw, its perfect, I love you!
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

If you insist in keeping things into a plain text file, then at least choose a better approach like reading line by line, rather than reading the entire file into buffer:

Code: Select all

set fh [open "file" r]
while {[gets $fh line] >= 0} {
# work with $line here
}
close $fh
What's even worse is that since there's no flood protection into this, so the execution of the code multiple times in a short period of time will just make the script crash the bot with core dump as the buffer is overflowed.

Our dear user (a valuable member and moderator of this forum) created a simple throttled function that can be used quite easy without much fuss.
Once the game is over, the king and the pawn go back in the same box.
w
willyw
Revered One
Posts: 1203
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

caesar wrote:If you insist in keeping things into a plain text file,
You forgot to clarify who the "you" is that you are speaking to.

If it is me: I don't "insist" on anything. :)
I replied to his request.

I suspect that using a database, as you mentioned, would be "better". Especially for larger numbers of pairs. I am not studied in it, so it is just a gut feeling for me.

I was hoping that you would follow through and produce another version, using a database, and explain why it is better too.

then at least choose a better approach like reading line by line,
You forgot to say WHY it is better.
rather than reading the entire file into buffer:

Code: Select all

set fh [open "file" r]
while {[gets $fh line] >= 0} {
# work with $line here
}
close $fh
What's even worse is that since there's no flood protection into this,
Perhaps you overlooked it. This is still under discussion. See my post containing a question, above.
so the execution of the code multiple times in a short period of time will just make the script crash the bot with core dump as the buffer is overflowed.
Why will the buffer overflow?
Our dear user (a valuable member and moderator of this forum) created a simple throttled function that can be used quite easy without much fuss.
Thanks for the info and the link.

Feel free to show the original poster - here - how to modify/add it to the code above. I don't mind at all. It could be useful learning for him, or for anybody else that ever comes along and finds this thread. :)

Thanks
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

I've been busy lately and didn't have a eggdrop to test on, but will return tomorrow hopefully with my version. :)
Once the game is over, the king and the pawn go back in the same box.
Post Reply