egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Return User's Level

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
ViciousPiranha
Voice


Joined: 17 Dec 2012
Posts: 36

PostPosted: Tue Apr 16, 2013 6:07 am    Post subject: Return User's Level Reply with quote

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
Back to top
View user's profile Send private message
LoKii
Voice


Joined: 21 Oct 2009
Posts: 34

PostPosted: Fri Apr 19, 2013 4:14 am    Post subject: Reply with quote

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:

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:

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.
Back to top
View user's profile Send private message
ViciousPiranha
Voice


Joined: 17 Dec 2012
Posts: 36

PostPosted: Fri Apr 19, 2013 5:36 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Fri Apr 19, 2013 8:32 am    Post subject: Reply with quote

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. Smile


Edit:
How many names to you expect to be ever be in your file? ... just curious.
Back to top
View user's profile Send private message
ViciousPiranha
Voice


Joined: 17 Dec 2012
Posts: 36

PostPosted: Fri Apr 19, 2013 8:41 am    Post subject: Reply with quote

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.

Quote:

Edit:
How many names to you expect to be ever be in your file? ... just curious.



No more than 1,000, more like 800
Back to top
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Fri Apr 19, 2013 9:38 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Fri Apr 19, 2013 10:59 am    Post subject: Reply with quote

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:


# 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:

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
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Fri Apr 19, 2013 11:00 am    Post subject: Re: Return User's Level Reply with quote

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?
Back to top
View user's profile Send private message
ViciousPiranha
Voice


Joined: 17 Dec 2012
Posts: 36

PostPosted: Fri Apr 19, 2013 12:29 pm    Post subject: Reply with quote

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..
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Fri Apr 19, 2013 12:42 pm    Post subject: Reply with quote

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?
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Fri Apr 19, 2013 1:30 pm    Post subject: Reply with quote

Code:


# 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:

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
Back to top
View user's profile Send private message
ViciousPiranha
Voice


Joined: 17 Dec 2012
Posts: 36

PostPosted: Sat Apr 20, 2013 5:59 am    Post subject: Reply with quote

thank you willyw, its perfect, I love you!
Back to top
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Sat Apr 20, 2013 7:43 am    Post subject: Reply with quote

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:

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.
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Sat Apr 20, 2013 8:56 am    Post subject: Reply with quote

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. Smile
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.


Quote:

then at least choose a better approach like reading line by line,


You forgot to say WHY it is better.

Quote:

rather than reading the entire file into buffer:
Code:

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.

Quote:

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?

Quote:

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. Smile

Thanks
Back to top
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Thu Apr 25, 2013 2:18 pm    Post subject: Reply with quote

I've been busy lately and didn't have a eggdrop to test on, but will return tomorrow hopefully with my version. Smile
_________________
Once the game is over, the king and the pawn go back in the same box.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber