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 

How would I do this? [solved]

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
Luminous
Op


Joined: 12 Feb 2010
Posts: 146

PostPosted: Thu Mar 11, 2010 12:10 am    Post subject: How would I do this? [solved] Reply with quote

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
View user's profile Send private message
TCL_no_TK
Owner


Joined: 25 Aug 2006
Posts: 509
Location: England, Yorkshire

PostPosted: Thu Mar 11, 2010 11:15 pm    Post subject: Reply with quote

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
Code:
set maxactions "3"
above
Code:
bind ctcp * ACTION slap:back
Quote:
# do somthing...
Change to
Code:
putserv "KICK $chan $nick :Please don't slap me!"

_________________
TCL the misunderstood
Back to top
View user's profile Send private message Send e-mail
Luminous
Op


Joined: 12 Feb 2010
Posts: 146

PostPosted: Fri Mar 12, 2010 11:41 am    Post subject: Reply with quote

Thanks for the reply! Very Happy 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
View user's profile Send private message
Luminous
Op


Joined: 12 Feb 2010
Posts: 146

PostPosted: Fri Mar 12, 2010 10:56 pm    Post subject: Reply with quote

Nevermind... I had to make "maxactions" global. Very Happy Thanks for showing me that, that should help me out later on.
Back to top
View user's profile Send private message
Luminous
Op


Joined: 12 Feb 2010
Posts: 146

PostPosted: Mon Mar 15, 2010 7:28 pm    Post subject: Reply with quote

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
View user's profile Send private message
speechles
Revered One


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

PostPosted: Mon Mar 15, 2010 7:34 pm    Post subject: Reply with quote

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
View user's profile Send private message
Luminous
Op


Joined: 12 Feb 2010
Posts: 146

PostPosted: Mon Mar 15, 2010 8:47 pm    Post subject: Reply with quote

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
View user's profile Send private message
speechles
Revered One


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

PostPosted: Mon Mar 15, 2010 9:39 pm    Post subject: Reply with quote

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
View user's profile Send private message
Luminous
Op


Joined: 12 Feb 2010
Posts: 146

PostPosted: Mon Mar 15, 2010 10:25 pm    Post subject: Reply with quote

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. Sad
I may just have to stick with slapping the person back.
Back to top
View user's profile Send private message
Ashoq
Voice


Joined: 17 Jul 2010
Posts: 11

PostPosted: Tue Aug 10, 2010 2:36 pm    Post subject: Reply with quote

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
View user's profile Send private message
Luminous
Op


Joined: 12 Feb 2010
Posts: 146

PostPosted: Tue Aug 10, 2010 2:40 pm    Post subject: Reply with quote

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
View user's profile Send private message
Ashoq
Voice


Joined: 17 Jul 2010
Posts: 11

PostPosted: Tue Aug 10, 2010 4:10 pm    Post subject: Reply with quote

cool Smile can u paste it for me please ?
10x Smile
Back to top
View user's profile Send private message
Luminous
Op


Joined: 12 Feb 2010
Posts: 146

PostPosted: Tue Aug 10, 2010 5:28 pm    Post subject: Reply with quote

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
View user's profile Send private message
dj-zath
Op


Joined: 15 Nov 2008
Posts: 134

PostPosted: Thu Aug 19, 2010 10:53 am    Post subject: Reply with quote

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-
Smile Smile
Back to top
View user's profile Send private message Visit poster's website
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Thu Aug 19, 2010 1:18 pm    Post subject: Reply with quote

@dj-zath,
You do know that "incr L 0" is a NoOp (No Operation)?
_________________
NML_375, idling at #eggdrop@IrcNET
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 -> Scripting Help 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