| View previous topic :: View next topic |
| Author |
Message |
Luminous Op
Joined: 12 Feb 2010 Posts: 146
|
Posted: Thu Mar 11, 2010 12:10 am Post subject: How would I do this? [solved] |
|
|
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: | 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 |
|
| Back to top |
|
 |
TCL_no_TK Owner

Joined: 25 Aug 2006 Posts: 509 Location: England, Yorkshire
|
Posted: Thu Mar 11, 2010 11:15 pm Post subject: |
|
|
You can try using something like this, | Code: | 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: | | if {![validchan $chan]} {return 0} | And add above | Code: | | bind ctcp * ACTION slap:back | Change to | Code: | | putserv "KICK $chan $nick :Please don't slap me!" |
_________________ TCL the misunderstood |
|
| Back to top |
|
 |
Luminous Op
Joined: 12 Feb 2010 Posts: 146
|
Posted: Fri Mar 12, 2010 11:41 am Post subject: |
|
|
Thanks for the reply! 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: | 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"
}
}
}
|
|
|
| Back to top |
|
 |
Luminous Op
Joined: 12 Feb 2010 Posts: 146
|
Posted: Fri Mar 12, 2010 10:56 pm Post subject: |
|
|
Nevermind... I had to make "maxactions" global. Thanks for showing me that, that should help me out later on. |
|
| Back to top |
|
 |
Luminous Op
Joined: 12 Feb 2010 Posts: 146
|
Posted: Mon Mar 15, 2010 7:28 pm Post subject: |
|
|
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: | 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 |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Mon Mar 15, 2010 7:34 pm Post subject: |
|
|
| Code: | 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. _________________ speechles' eggdrop tcl archive
Last edited by speechles on Mon Mar 15, 2010 10:35 pm; edited 2 times in total |
|
| Back to top |
|
 |
Luminous Op
Joined: 12 Feb 2010 Posts: 146
|
Posted: Mon Mar 15, 2010 8:47 pm Post subject: |
|
|
| Code: | | if {[incr slapped_us($uhost)] == $maxslaps]} { | causes error about an invalid ] . I assume its supposed to be | Code: | | if {[incr slapped_us($uhost) == $maxslaps]} { | But then that gives the error: Tcl error [slap:back]: wrong # args: should be "incr varName
?increment?" |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Mon Mar 15, 2010 9:39 pm Post subject: |
|
|
| Luminous wrote: | | Code: | | if {[incr slapped_us($uhost)] == $maxslaps]} { |
| My bad. See above, fixed it within that code block. _________________ speechles' eggdrop tcl archive |
|
| Back to top |
|
 |
Luminous Op
Joined: 12 Feb 2010 Posts: 146
|
Posted: Mon Mar 15, 2010 10:25 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
Ashoq Voice

Joined: 17 Jul 2010 Posts: 11
|
Posted: Tue Aug 10, 2010 2:36 pm Post subject: |
|
|
| Code: | 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 ) |
|
| Back to top |
|
 |
Luminous Op
Joined: 12 Feb 2010 Posts: 146
|
Posted: Tue Aug 10, 2010 2:40 pm Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
Ashoq Voice

Joined: 17 Jul 2010 Posts: 11
|
Posted: Tue Aug 10, 2010 4:10 pm Post subject: |
|
|
cool can u paste it for me please ?
10x  |
|
| Back to top |
|
 |
Luminous Op
Joined: 12 Feb 2010 Posts: 146
|
Posted: Tue Aug 10, 2010 5:28 pm Post subject: |
|
|
| 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... |
|
| Back to top |
|
 |
dj-zath Op
Joined: 15 Nov 2008 Posts: 134
|
Posted: Thu Aug 19, 2010 10:53 am Post subject: |
|
|
I'm planning a simular thing.. however I'm going to use a "stepped timer counter" idea..
| Code: |
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-
 |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Thu Aug 19, 2010 1:18 pm Post subject: |
|
|
@dj-zath,
You do know that "incr L 0" is a NoOp (No Operation)? _________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
|