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 

5 Lines MSG

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


Joined: 19 Mar 2011
Posts: 19

PostPosted: Mon Apr 11, 2011 3:43 pm    Post subject: 5 Lines MSG Reply with quote

Hi Dear Coders..

I need your help..

How can we do 5 lines tcl..

when person says 5 lines in my channels, my eggdrop bot will send a message to person.

Example:

<Jackie> Hi
<Jackie> How are u ?
<Jackie> I'm so good.
<Jackie> Imm..
<Jackie> Where are u from ?
<Eggdrop> Jackie Thank You!!! You're chatting so good. Wink
<Jackie> Imm
<Jackie> My Pleasure
<Jackie> Im so happy now
<Jackie> Smile
<Jackie> ..
<Eggdrop> Jackie Thank You!! You're chatting so good. Wink
Back to top
View user's profile Send private message
Nimos
Halfop


Joined: 20 Apr 2008
Posts: 80

PostPosted: Sat Apr 23, 2011 8:13 pm    Post subject: Reply with quote

Code:
###
#   5lines.tcl
##
#
# OUTDATED VERSION, USE THE SCRIPT BELOW!
#
##
#    Settings
#
# The channels the script should be active in, seperated by spaces
# (leave empty for all channels)
set fivelines(channels) ""
#
# How many lines to write, to get an answer
set fivelines(count) 5
#
#
# A list with things the bot can answer
#
# (possible "variables" are %c (channel) %n (nick) %b (botnick))
#
set fivelines(answers) {
   "%n Thank You!!! You're chatting so good. ;)"
   "Hello %n, could you stop spamming now? :>"
   "Hurr durr, I am %b the mighty ruler of %c"
}
##
#
#   End of settings
#
###


bind pubm - * pubm_fivelines_counter

set fivelines(channels) [split $fivelines(channels)]
set fivelines(counter) 0

foreach chan $fivelines(channels) {
   set fivelines(counter|$chan) 0
   set fivelines(nick|$chan) ""
}
putlog [join [array get fivelines] \n]
   
proc pubm_fivelines_counter {nick host hand chan text} {
global fivelines


   if {[lsearch $fivelines(channels) $chan] != -1} {
      
      if {$fivelines(nick|$chan) == $nick} {
         incr fivelines(counter|$chan)
         
         if {$fivelines(counter|$chan) >= $fivelines(count)} {
            set answer [lindex $fivelines(answers) [expr round(rand() * ([llength $fivelines(answers)] - 1))]]
            regsub -all "%c" $answer $chan answer
            regsub -all "%n" $answer $nick answer
            regsub -all "%b" $answer $::botnick answer
            
            putserv "PRIVMSG $chan :$answer"
            
            set fivelines(counter|$chan) 0
         }
      } else {
         set fivelines(counter|$chan) 1
         set fivelines(nick|$chan) $nick
      }
   }
}


Last edited by Nimos on Sun Apr 24, 2011 6:18 am; edited 1 time in total
Back to top
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Sat Apr 23, 2011 11:55 pm    Post subject: Reply with quote

Nimos wrote:
*snipped long code*


Nimos, when new users join the channel, after any rehash/restart/etc .. (ones that were not previously in that channel before the rehash) rejoins your channel that script will cause errors for those nicknames.

Code:
foreach chan $fivelines(channels) {
   set fivelines(counter|$chan) 0
   set fivelines(nick|$chan) ""
}

You use this code to intialize a huge array in global space for some reason. Rather than, using [info exists] command and using this to tell an initialized (aka, empty) array.

You then make this call to your procedure:
Code:
      if {$fivelines(nick|$chan) == $nick} {

This will cause an error for any nickname that wasn't present when you previously initialized the array. It should be based around [info exists] imo. Using a series of sets does not work dynamically how you have done it. Just words of advice. Wink

As people chat, you add them to the array, only then do they eat memory. Until then we use [info exist] to tell if each nick is, or is not, already added to our array. If it's not then "set fivelines($nick|$chan) 1". If it is, then [incr] it ever after based on that until we hit the magic number 5.

Also...

Code:
[expr round(rand() * ([llength $fivelines(answers)] - 1))]]


Might want to brace that [expr {}] to speed it up 1000% and to keep any issues with $fivelines variable from containing any exploits or substitution errors... and just do...
Code:
[rand [llength $fivelines(answers)]]

which is same thing as your long code above in proper form without that nasty expr and needless round required because of that -1 you do to llength. Otherwise your code would never use the last element in the $fiveline(answers) list, which it will do rarely, not evenly like your rand suggest it would. In your list of three you can test this yourself, and do 3 queries. Multiple times. So 3 queries 20x. So 60x total. In those, the most ever the last element can appear as the result of those 60. Is 10 times. One sixth. 1/6. Half of what true random would be for 3 items, and making 60 queries. It should be 1/3rd, or 20/60th's. This is because of reasons having to do with your code versus mine and as I said only affects the last element in the list. My code above works correctly showing each of the 3 items 20 times if 60 requests were made and the list was only 3 lines long.
_________________
speechles' eggdrop tcl archive
Back to top
View user's profile Send private message
Nimos
Halfop


Joined: 20 Apr 2008
Posts: 80

PostPosted: Sun Apr 24, 2011 6:17 am    Post subject: Reply with quote

Thanks for your comment, speechless.

You pointed out some flaws in my script, but it isn't as bad as you understood it.

My script only answers, if someone writes 5 lines in a row, without being interrupted by another person (I think thats what OP wanted.).
Notice, that my array is fivelines(nick|$chan), not fivelines($nick|$chan), so it wont create an entry for every user in the channel, nor would it require every user of the channel to be in it. (So it wont error on rehash/etc)

Still my array wasn't optimal, and I used an info exists line in exchange.


And thanks for the rand function! I didn't know it before.


New script:

Code:
###
#   5lines.tcl
##
#    Settings
#
# The channels the script should be active in, seperated by spaces
# (leave empty for all channels)
set fivelines(channels) ""
#
# How many lines to write, to get an answer
set fivelines(count) 5
#
#
# A list with things the bot can answer
#
# (possible "variables" are %c (channel) %n (nick) %b (botnick))
#
set fivelines(answers) {
   "%n Thank You!!! You're chatting so good. ;)"
   "Hello %n, could you stop spamming now? :>"
   "Hurr durr, I am %b the mighty ruler of %c"
}
##
#
#   End of settings
#
###


bind pubm - * pubm_fivelines_counter

set fivelines(channels) [split $fivelines(channels)]

   
proc pubm_fivelines_counter {nick host hand chan text} {
global fivelines


   if {[lsearch $fivelines(channels) $chan] != -1} {
      
      if {[info exists fivelines(nick|$chan)]} {
      
         if {$fivelines(nick|$chan) == $nick} {
            incr fivelines(counter|$chan)
            
            if {$fivelines(counter|$chan) >= $fivelines(count)} {
               set answer [lindex $fivelines(answers) [rand [llength $fivelines(answers)]]]
               regsub -all "%c" $answer $chan answer
               regsub -all "%n" $answer $nick answer
               regsub -all "%b" $answer $::botnick answer
               
               putserv "PRIVMSG $chan :$answer"
               
               set fivelines(counter|$chan) 0
            }
            
         } else {
            set fivelines(counter|$chan) 1
            set fivelines(nick|$chan) $nick
         }
      } else {
         set fivelines(counter|$chan) 1
         set fiveliens(nick|$chan) $nick
      }
   }[
}


edit: added missing last close brace
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