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.

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

Help for those learning Tcl or writing their own scripts.
Post Reply
a
aliby
Voice
Posts: 5
Joined: Thu Jun 22, 2006 12:56 pm

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

Post by aliby »

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: Select all

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
G
Garp
Voice
Posts: 29
Joined: Mon Sep 15, 2003 7:58 pm

Post by Garp »

set a lock. For example like this here:

Code: Select all

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 :)
a
aliby
Voice
Posts: 5
Joined: Thu Jun 22, 2006 12:56 pm

Post by aliby »

Grim,

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

Code: Select all

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]
G
Garp
Voice
Posts: 29
Joined: Mon Sep 15, 2003 7:58 pm

Post by Garp »

just move the flock setting to the portion of the code you want to protect.
a
aliby
Voice
Posts: 5
Joined: Thu Jun 22, 2006 12:56 pm

Post by aliby »

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
G
Garp
Voice
Posts: 29
Joined: Mon Sep 15, 2003 7:58 pm

Post by Garp »

You would need to timestamp the handled nicks.

Code: Select all

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: Select all


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 :o) sorry for being uncondensated.
a
aliby
Voice
Posts: 5
Joined: Thu Jun 22, 2006 12:56 pm

Post by aliby »

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
G
Garp
Voice
Posts: 29
Joined: Mon Sep 15, 2003 7:58 pm

Post by Garp »

Code: Select all

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.
a
aliby
Voice
Posts: 5
Joined: Thu Jun 22, 2006 12:56 pm

Post by aliby »

Garp,

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

Code: Select all

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
Post Reply