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 

Send message to a channel with a delay (it's complex)

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


Joined: 22 Jun 2006
Posts: 5

PostPosted: Thu Jun 22, 2006 1:06 pm    Post subject: Send message to a channel with a delay (it's complex) Reply with quote

Hello,

I want to have my tcl script post a message to the channel if a user's text matches my regexp.

Here is the script i have so far:

Code:

bind pubm - * helptext
proc helptext {nick uhost hand chan text} {
set response default
set helptext [string tolower $text]
      if [regexp {(admin|op|pm).*(admin|op|pm)} $helptext] {
              set response "Please ask your question in the channel before asking an admin/op to PM you."
           }
      if [regexp {(\dv\d|\d v \d).*(our|your)} $helptext] {
            set response "Please use #findscrim to find scrims"   
      }
if ![regexp -nocase {default} $response] {
putmsg $chan "\002\037$nick:\037\002 $response"
}
}


How can I make it so that the second response, "Please use #findscrim to find scrims" is only displayed once every five seconds.

For example - Say a user posts this:
5v5 | east | yours | cal o | dust 2

I want it to say "Please use #findscrim to find scrims"

But if they say this:
5v5 | east | yours | cal o | dust 2
5v5 | east | yours | cal o | dust 2
5v5 | east | yours | cal o | dust 2
5v5 | east | yours | cal o | dust 2
5v5 | east | yours | cal o | dust 2
5v5 | east | yours | cal o | dust 2

I want it to say "Please use #findscrim to find scrims" once then wait five seconds then if they repeat the line 5v5 | east | yours | cal o | dust 2 again (after 5 seconds), I want the eggdrop bot to say it again (and possibly kick them out of the channel giving them the reason again: "Didn't I tell you to use #findscrim?")

Sorry if this is confusing, I hope someone can give me a hand with this.

Thanks,

-Noah
Back to top
View user's profile Send private message
Garp
Voice


Joined: 15 Sep 2003
Posts: 29

PostPosted: Thu Jun 22, 2006 7:32 pm    Post subject: Reply with quote

set a lock. For example like this here:

Code:

bind pubm - * helptext
set helpflock 0

proc helptext {nick uhost hand chan text} {
global helpflock

set response default

if [string match $helpflock 1] { return }
set helpflock 1

set notagain 4;# change this to a value in secounds that fits your need

set helptext [string tolower $text]

    if [regexp {(admin|op|pm).*(admin|op|pm)} $helptext] {
       set response "Please ask your question in the channel before asking an admin/op to PM you."
    }
    if {[regexp {(\dv\d|\d v \d).*(our|your)} $helptext]  {
       set response "Please use #findscrim to find scrims"   
    }
    if ![regexp -nocase {default} $response] {
       putmsg $chan "\002\037$nick:\037\002 $response"
    }

utimer $notagain "set helpflock 0"
}


Untested Smile
Back to top
View user's profile Send private message
aliby
Voice


Joined: 22 Jun 2006
Posts: 5

PostPosted: Fri Jun 23, 2006 1:13 am    Post subject: Reply with quote

Grim,

I only want that to work for the one output statement though... Not the other one. I have also updated the code:

Code:

bind pubm - * helptext
proc helptext {nick uhost hand chan text} {
global botnick
set response default
set admin 0
set helptext [string tolower $text]

if {[isop $nick $chan] == 0} {
      if [regexp {((admin|op).*(\ypm|\yaround|\yneed|\yhere))|((\ypm|\yaround|\yneed|\yhere).*(admin|op))} $helptext] {
              set response "Please ask your question in the channel."
           }
      if [regexp {(\dv\d|\d v \d).*(\your|\yyour)} $helptext] {
            set response "Please use #findscrim to find scrims"   
      }

#there is more that goes here, but i'll skip that


   if {![regexp {default} $response]} {
   putmsg $chan "$response"
   }
}




Any thoughts?

-Noah[/code]
Back to top
View user's profile Send private message
Garp
Voice


Joined: 15 Sep 2003
Posts: 29

PostPosted: Fri Jun 23, 2006 8:32 am    Post subject: Reply with quote

just move the flock setting to the portion of the code you want to protect.
Back to top
View user's profile Send private message
aliby
Voice


Joined: 22 Jun 2006
Posts: 5

PostPosted: Fri Jun 23, 2006 9:49 am    Post subject: Reply with quote

Garp,

Thanks! That worked beautifully.

Now I have another question. If the bot has to tell the same person ($nick) to use #findscrim more than 3 times, I would like the bot to kick the person.

And by 3 times I mean 3 times in one day.

How would I go about doing that?

-Noah
Back to top
View user's profile Send private message
Garp
Voice


Joined: 15 Sep 2003
Posts: 29

PostPosted: Fri Jun 23, 2006 10:21 am    Post subject: Reply with quote

You would need to timestamp the handled nicks.

Code:

array set requestcache {}

proc helptext {nick uhost hand chan text} {
global botnick requestcache

...

if [regexp {(\dv\d|\d v \d).*(\your|\yyour)} $helptext] {
    if {![info exists requestcache($nick)]} {
        set response "Please use #findscrim to find scrims"
        set requestcache($nick) [unixtime]        
    } else {
        putserv "KICK $chan $nick :We already had that"             
        set requestcache($nick) [unixtime]
        return
    }
      
}



And you need a function that cleans the timestamped nicks all hours

Code:


bind time - "00 *" clean:requestcache

proc clean:requestcache {{args ""}} {
global requestcache
set limit [expr [unixtime] - (3600 * 24)]
 foreach {x y} [array get requestcache] {
  if { $y <= $limit } {
   unset talkusers($x)
  }
 }
}



Oh damn, you want to kick on the 3th request? This here kicks within the 2nd Surprised) sorry for being uncondensated.
Back to top
View user's profile Send private message
aliby
Voice


Joined: 22 Jun 2006
Posts: 5

PostPosted: Fri Jun 23, 2006 7:16 pm    Post subject: Reply with quote

Garp

How would you make it so that if you repeated 3 or 4 or 5 times in 24 hours, it would kick the person?

What about 3 or 4 or 5 in 1 hour?

Basically I'd just like to have an explanation of how the code works so that I can understand it and use it again sometime.

Thanks,

-Noah
Back to top
View user's profile Send private message
Garp
Voice


Joined: 15 Sep 2003
Posts: 29

PostPosted: Fri Jun 23, 2006 7:32 pm    Post subject: Reply with quote

Code:
if {![info exists requestcache($nick)]} {
        set response "Please use #findscrim to find scrims"
        set requestcache($nick) "[unixtime] 0"
} else {
      set requests [lindex [split $requestcache($nick)] 1]
      
      if { ($requests >= 3) } {
         #kick ban ... whatever
      }

      incr requests
      set requestcache($nick) "[unixtime] $requests"
}


On cleanup you need to check for [lindex [split $requestcache($nick)] 0] where you have the timestamp.
Back to top
View user's profile Send private message
aliby
Voice


Joined: 22 Jun 2006
Posts: 5

PostPosted: Fri Jun 23, 2006 7:46 pm    Post subject: Reply with quote

Garp,

When talking about the checking in cleanup, is this what you mean?

Code:

bind time - "00 *" clean:requestcache
proc clean:requestcache {{args ""}} {
set limit [expr [lindex [split $requestcache($nick)] 0] - (3600 * 24)]
   foreach {x y} [array get requestcache] {
      if {$y <= $limit } {
        unset talkusers($x)       
      }
   }
}


Or am I way off?

Thanks,

-Noah
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