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.

Avoid dupplication of timer

Help for those learning Tcl or writing their own scripts.
Post Reply
n
neoclust
Halfop
Posts: 55
Joined: Fri Aug 14, 2009 11:03 am

Avoid dupplication of timer

Post by neoclust »

I want to apply a method to avoid duplication of timers, thanks

Code: Select all

proc Channel:check {from kw text} {
	global botnick
	set chan [lindex $text 1]
	set host [lindex $text 2]@[lindex $text 3]
	set nick [lindex $text 5]
	set flag [lindex $text 6]
	if {[string index $flag 1] == ""} {
		if {![channel get $chan autovoice]} { return 0 }
		if {![botisop $chan]} { return 0 }
		if {$nick != $botnick} {
			if {[string length [set t [utimerexists procname]]]} { killutimer $t }
			if {![string match ~* $host ]} {
				puthelp "NOTICE $nick :Welcome."
				utimer 10 "pushmode $chan +v $nick"
			}
			switch -glob -- $host {*.dynamic.jazztel.es 
				{puthelp "NOTICE $nick :Welcome."; utimer 10 "pushmode $chan +v $nick" }
				~*@* { puthelp "NOTICE $nick :Welcome."; utimer 30 "pushmode $chan +v $nick" }
			}
			return 0                                                                                                                                                                                                     }
	}
}
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Code: Select all

proc Channel:check {from kw text} {
   global botnick vtimers
   set chan [lindex $text 1]
   set host [lindex $text 2]@[lindex $text 3]
   set nick [lindex $text 5]
   set flag [lindex $text 6]
   if {[string index $flag 1] == ""} {
      if {![channel get $chan autovoice]} { return 0 }
      if {![botisop $chan]} { return 0 }
      if {$nick != $botnick} {
         if {[string length [set t [utimerexists procname]]]} { killutimer $t }
         if {![string match ~* $host ] && ![info exists vtimers($nick:$chan)} {
            puthelp "NOTICE $nick :Welcome."
            set vtimers($nick:$chan) [utimer 10 [list voice:nick $chan $nick]]
         }
         switch -glob -- $host {*.dynamic.jazztel.es
            {puthelp "NOTICE $nick :Welcome."; utimer 10 "pushmode $chan +v $nick" }
            ~*@* { puthelp "NOTICE $nick :Welcome."; utimer 30 "pushmode $chan +v $nick" }
         }
         return 0                                                                                                                                                                                                     }
   }
}

proc voice:nick {chan nick} {
 global vtimers
 pushmode $chan +v $nick
 unset vtimers($nick:$chan)
}
n
neoclust
Halfop
Posts: 55
Joined: Fri Aug 14, 2009 11:03 am

Post by neoclust »

There is an ']' missing in this line:
if {![string match ~* $host ] && ![info exists vtimers($nick:$chan)]} {
and it must also apply this line
set vtimers($nick:$chan) [utimer 10 [list voice:nick $chan $nick]]
in switch

Code: Select all

proc Channel:check {from kw text} {
   global botnick vtimers
   set chan [lindex $text 1]
   set host [lindex $text 2]@[lindex $text 3]
   set nick [lindex $text 5]
   set flag [lindex $text 6]
   if {[string index $flag 1] == ""} {
      if {![channel get $chan autovoice]} { return 0 }
      if {![botisop $chan]} { return 0 }
      if {$nick != $botnick} {
         if {[string length [set t [utimerexists Channel:check]]]} { killutimer $t }
         if {![string match ~* $host ] && ![info exists vtimers($nick:$chan)]} {
            puthelp "NOTICE $nick :Welcome."
            set vtimers($nick:$chan) [utimer 10 [list voice:nick $chan $nick]]
         }
         switch -glob -- $host {*.dynamic.jazztel.es
            {puthelp "NOTICE $nick :Welcome."; set vtimers($nick:$chan) [utimer 10 [list voice:nick $chan $nick]] }
            ~*@* { puthelp "NOTICE $nick :Welcome."; set vtimers($nick:$chan) [utimer 30 [list voice:nick $chan $nick]] }
         }
         return 0                                                                                                                                                                                                     }
   }
}

proc voice:nick {chan nick} {
 global vtimers
 pushmode $chan +v $nick
 unset vtimers($nick:$chan)
}

Last edited by neoclust on Sun Aug 16, 2009 2:57 pm, edited 1 time in total.
n
neoclust
Halfop
Posts: 55
Joined: Fri Aug 14, 2009 11:03 am

Post by neoclust »

the bot sends several notice before voice, there is a way to limit this set, for example at the beginning if the nick is already handled by the timer it must pass a return 0
and i have this error :
can't unset "vtimers(neoclust:#chan)": no such variable
[19:40:00] -Egg- Welcome.
[19:40:12] -Egg- Welcome.
[19:40:26] *** Egg sets mode: +v neoclust
[19:40:29] -Egg- Welcome.
[/quote]
User avatar
TCL_no_TK
Owner
Posts: 509
Joined: Fri Aug 25, 2006 7:05 pm
Location: England, Yorkshire

Post by TCL_no_TK »

sud only allow the bot to send out the "Welcome" message to a nickname once a day.

:arrow: it looks like this is a raw event, in which case i doubt you'd be wanting to return 1

Code: Select all

 proc Channel:check {from kw text} { 
  global botnick 
   set chan [lindex $text 1] 
   set host [lindex $text 2]@[lindex $text 3] 
   set nick [lindex $text 5] 
   set flag [lindex $text 6] 
    if {[string index $flag 1] == ""} { 
      if {![channel get $chan autovoice]} {
       return
      } 
       if {![botisop $chan]} {
        return
       } 
        if {$nick != $botnick} { 
         if {[string length [set t [utimerexists procname]]]} { killutimer $t }
          switch -glob -- $host {
           *.dynamic.jazztel.es {
            Channel:check:welcome $nick
            utimer 10 [list pushmode $chan +v $nick]
           }
           ~*@* {
            Channel:check:welcome $nick
            utimer 30 [list pushmode $chan +v $nick]
           }
           default {
            Channel:check:welcome $nick
            utimer 10 [list pushmode $chan +v $nick]
           } 
         }
     return                                                                                                                                                                                                } 
    }
 }

 proc Channel:check:welcome {nick} {
  global cc_tmp
   if {![info exists cc_tmp($nick)]} {
    set cc_tmp($nick) [clock seconds]
    puthelp "NOTICE $nick :Welcome"
    return
   } elseif {[string equal [clock scan "yesterday"] $cc_tmp($nick)]} {
    set cc_tmp($nick) [clock seconds]
    puthelp "NOTICE $nick :Welcome"
    return
   } else {
    return
   }
 }
n
neoclust
Halfop
Posts: 55
Joined: Fri Aug 14, 2009 11:03 am

Post by neoclust »

Thank TCL_no_TK & Sir_Fz it work
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

You might want to [split $text] before applying [lindex] on it.
Post Reply