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.

How would I do this? [solved]

Help for those learning Tcl or writing their own scripts.
Post Reply
L
Luminous
Op
Posts: 146
Joined: Fri Feb 12, 2010 1:00 pm

How would I do this? [solved]

Post by Luminous »

I am wanting my bot to kick users if they do something an x number of times. Like an action, slapping the bot, etc. I already have a script that will make the bot slap the user back if they slap it or me, but I want it to kick if they slap the bot(or me) three times. How would a counter like this be added?

Code: Select all

set actReplies {
 "with a board"
 "with his banhammer :P"
 "with a car"
 "with a leather book"
 "with Godzilla"
 "with Chuck Norris"
 "right back"
}
bind ctcp * ACTION slap:back
 proc slap:back {nick host hand chan kw arg} {
  global botnick actReplies owner
     if {![validchan $chan]} {return 0}
     if {[string match -nocase "*slap* $botnick*" $arg]} {
        putserv "PRIVMSG $chan :\001ACTION slaps $nick [lindex $actReplies [rand [llength $actReplies]]]\001"
     if {[string match -nocase "*slap* $owner*" $arg]} {
        putserv "PRIVMSG $chan :\001ACTION slaps $nick in $owner's defense\001"
     }
  }
}
I am guessing I would need to write that action slap data to a file... then make an if statement to check it for the count number?
Last edited by Luminous on Fri Aug 13, 2010 1:34 pm, edited 3 times in total.
User avatar
TCL_no_TK
Owner
Posts: 509
Joined: Fri Aug 25, 2006 7:05 pm
Location: England, Yorkshire

Post by TCL_no_TK »

You can try using something like this,

Code: Select all

if {[info exists ::acount($uhost)]} {
 if {$::acount($uhost) >= $::maxactions} {
  # do somthing...
  unset ::acount($uhost)
 } else {
  set ::acount($uhost) [expr {$::acount($uhost) +1}]
 }
} else {
 set ::acount($uhost) "1"
}
Add it after

Code: Select all

     if {![validchan $chan]} {return 0} 
And add

Code: Select all

set maxactions "3"
above

Code: Select all

bind ctcp * ACTION slap:back 
# do somthing...
Change to

Code: Select all

putserv "KICK $chan $nick :Please don't slap me!"
L
Luminous
Op
Posts: 146
Joined: Fri Feb 12, 2010 1:00 pm

Post by Luminous »

Thanks for the reply! :D I get an error though... if I leave it with 3 closing braces, it complains that its missing one, but if I add one, the bot dies. He did slap a test nick back once, but nothing more after that.

All together:

Code: Select all

set actReplies {
 "with a board"
 "with his banhammer :P"
 "with a car"
 "with a leather book"
 "with Godzilla"
 "with Chuck Norris"
 "right back"
}
set maxactions "3"
bind ctcp * ACTION slap:back
proc slap:back {nick uhost hand chan kw arg} {
  global botnick actReplies owner
    if {![validchan $chan]} {return 0}
    if {[info exists ::acount($uhost)]} {
    if {$::acount($uhost) >= $::maxactions} {
        putserv "KICK $chan $nick :Please don't slap me!"
  unset ::acount($uhost)
    } else {
  set ::acount($uhost) [expr {$::acount($uhost) +1}
}
    } else {
  set ::acount($uhost) "1"
}
    if {[string match -nocase "*slap* $botnick*" $arg]} {
        putserv "PRIVMSG $chan :\001ACTION slaps $nick [lindex $actReplies [rand [llength $actReplies]]]\001"
    if {[string match -nocase "*slap* $owner*" $arg]} {
        putserv "PRIVMSG $chan :\001ACTION slaps $nick in $owner's defense\001"
    }
  }
}
L
Luminous
Op
Posts: 146
Joined: Fri Feb 12, 2010 1:00 pm

Post by Luminous »

Nevermind... I had to make "maxactions" global. :D Thanks for showing me that, that should help me out later on.
L
Luminous
Op
Posts: 146
Joined: Fri Feb 12, 2010 1:00 pm

Post by Luminous »

I've been tinkering with this... it has a few bugs that I can't seem to work out.

I think it needs to be the other way around: as in, it will just slap unless maxactions == 3, then it will kick. Reason is that with it as is, it counts three actions in general as a kick, and so will kick after 3 actions. Not good. I've tried variations of this, but I can't get it to kick:

Code: Select all

set actReplies {
 "with a board"
 "with his banhammer :P"
 "with a car"
 "with a leather book"
 "with Godzilla"
 "with Chuck Norris"
 "right back"
}
set maxactions "3"
bind ctcp * ACTION slap:back
proc slap:back {nick uhost hand chan kw arg} {
  global acount botnick actReplies owner maxactions
    if {![validchan $chan]} {return 0}
    if {[string match -nocase "*slap* $botnick*" $arg] || [string match -nocase "*slap* $owner*" $arg]} {
        putserv "PRIVMSG $chan :\001ACTION slaps $nick [lindex $actReplies [rand [llength $actReplies]]]\001"
        set ::acount($uhost) [expr {$::acount($uhost) +1}]
    } elseif {[info exists $::acount($uhost)] && [$::acount($uhost) == $::maxactions]} {
         putserv "KICK $chan $nick :Its not polite to slap people D\:"
         unset ::acount($uhost)
    }
}
Here's the error it gives: Tcl error [slap:back]: can't read
"::acount(webchat@1b533a89.189efabc.X)": no such variable
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Code: Select all

set slapreplies {
 "around a bit with a large trout. *SMACK SMACK*"
 "with a two by four upside the head. *KONK*"
 "with the mighty banhammer eventually :P"
 "with a slimy wet eel, or something similar :P"
 "then stares back. Don't expect an apology :P"
 "with the holy bible autographed by jesus himself. Repent now!"
 "with Chuck Norris' fist. *BOOM*"
 "right back twice as hard. 2x mode activated! Final battle, Fight!"
} 
set maxslaps "3"
bind ctcp * ACTION slap:back 
proc slap:back {nick uhost hand chan kw arg} {
   global slapped_us botnick slapreplies owner maxslaps
   if {![validchan $chan]} {return 0}
   if {[string match -nocase "*slap* $botnick*" $arg] || [string match -nocase "*slap* $owner*" $arg]} {
      if {[info exists slapped_us($uhost)]} {
         if {[incr slapped_us($uhost)] == $maxslaps} {
            putserv "KICK $chan $nick :Its not polite to slap people D\:"
            unset slapped_us($uhost)
            return 0
         }
      } else {
         set slapped_us($uhost) 1
      }
      putserv "PRIVMSG $chan :\001ACTION slaps $nick [lindex $actReplies [rand [llength $actReplies]]]\001"
   }
}
Edit: fixed problem mentioned below. Solved.
Last edited by speechles on Mon Mar 15, 2010 10:35 pm, edited 2 times in total.
L
Luminous
Op
Posts: 146
Joined: Fri Feb 12, 2010 1:00 pm

Post by Luminous »

Code: Select all

 if {[incr slapped_us($uhost)] == $maxslaps]} { 
causes error about an invalid ] . I assume its supposed to be

Code: Select all

 if {[incr slapped_us($uhost) == $maxslaps]} { 
But then that gives the error: Tcl error [slap:back]: wrong # args: should be "incr varName
?increment?"
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Luminous wrote:

Code: Select all

 if {[incr slapped_us($uhost)] == $maxslaps]} { 
My bad. See above, fixed it within that code block.
L
Luminous
Op
Posts: 146
Joined: Fri Feb 12, 2010 1:00 pm

Post by Luminous »

Ah, okay... I had tried adding another incr line cause I figured that's what needed to happen...

I am not getting any errors with that script, but the bot is not slapping or kicking at all now. :(
I may just have to stick with slapping the person back.
User avatar
Ashoq
Voice
Posts: 11
Joined: Sat Jul 17, 2010 4:35 pm

Post by Ashoq »

Code: Select all

set slapreplies {
 "around a bit with a large trout. *SMACK SMACK*"
 "with a two by four upside the head. *KONK*"
 "with the mighty banhammer eventually :P"
 "with a slimy wet eel, or something similar :P"
 "then stares back. Don't expect an apology :P"
 "with the holy bible autographed by jesus himself. Repent now!"
 "with Chuck Norris' fist. *BOOM*"
 "right back twice as hard. 2x mode activated! Final battle, Fight!"
}
set maxactions "3"
bind ctcp * ACTION slap:back
proc slap:back {nick uhost hand chan kw arg} {
   global slapped_us botnick slapreplies owner maxslaps
   if {![validchan $chan]} {return 0}
   if {[string match -nocase "*slap* $botnick*" $arg] || [string match -nocase "*slap* $owner*" $arg]} {
      if {[info exists slapped_us($uhost)]} {
         if {[incr slapped_us($uhost)] == $maxslaps} {
            putserv "KICK $chan $nick :Please don't slap me!"
            unset slapped_us($uhost)
            return 0
         }
      } else {
         set slapped_us($uhost) 1
      }
      putserv "PRIVMSG $chan :\001ACTION slaps $nick [lindex $slapreplies [rand [llength $slapreplies]]]\001"
   }
}
try this ( tested by me )
L
Luminous
Op
Posts: 146
Joined: Fri Feb 12, 2010 1:00 pm

Post by Luminous »

Thanks, but I should have mentioned that I have long since solved this. I have it set now so that it kicks on second offense and on the third time it bans for 15 minutes, but it allows those 3 kicks only within an hour before resetting. I am using the comment field to store number of offenses though, rather than a counter like this one. I haven't had any luck running counters like that.
User avatar
Ashoq
Voice
Posts: 11
Joined: Sat Jul 17, 2010 4:35 pm

Post by Ashoq »

cool :) can u paste it for me please ?
10x :)
L
Luminous
Op
Posts: 146
Joined: Fri Feb 12, 2010 1:00 pm

Post by Luminous »

it wouldn't work for you as is. I use a custom proc in it that... I'm not exactly wanting to share, as it required tremendous work to get right... and I use a modified version of an alltools proc for the timer work, etc...
d
dj-zath
Op
Posts: 134
Joined: Sat Nov 15, 2008 6:49 am
Contact:

Post by dj-zath »

I'm planning a simular thing.. however I'm going to use a "stepped timer counter" idea..

Code: Select all


set L "0"
proc    counter {} {
    if {$L < "2"}
        do something
        incr L
        return 1
     } else {
        do something else
        incr L "0"
        return 0
    }
}
just something I threw together for this post hehe

-DjZ-
:) :)
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

@dj-zath,
You do know that "incr L 0" is a NoOp (No Operation)?
NML_375
Post Reply