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.

bind time proc

Help for those learning Tcl or writing their own scripts.
Post Reply
T
Torrevado
Op
Posts: 101
Joined: Wed Aug 02, 2006 6:29 pm

bind time proc

Post by Torrevado »

Hi,
I need a script to make the bot send a message to a channel past 1 minute of each hour (that is 01:01, 02:01, 03:01..etc).

Code: Select all

bind time - "1 * * * *" testing  
proc testing {testing chan text time} { 
  putserv "PRIVMSG $chan :\002Message goes here!!\002" 
}
Of course, it doesn't work
So, if this code works:

Code: Select all

bind pub - !testing testing 
proc testing {nick host handle chan text} {
  putserv "PRIVMSG $chan :\002Message goes here!!\002"
}
Why doesn't the other one?
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

Firstly, the minute mask of a time bind is padded to 2 characters. Therefore you need :-

bind time - "01 * * * *" testing

Secondly, a time bind returns arguments to the corresponding proc as follows :-

proc testing {minute hour day month year} {
# code here
}

You cannot pick and choose what information a bind passes as proc arguments, but you can name the arguments anything you like.

Note that the irc channel is not passed to the proc. This ought to be obvious since a time bind executes independently of IRC channels. It is not an IRC event.

You will have to find some way of storing channel name(s) in a variable and passing the variable globally to the proc OR use something like the following code inside the proc :-

foreach chan [channels] {
# IRC output code here
}
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

As an example, this is a small script that outputs a GMT time message on the hour every hour to all the bot's channels. ie. at 00 minutes

bind TIME - "00 * * * *" prcClock

proc prcClock {minute hour day month year} {
set now [split [regsub {[\s][\s]} [clock format [clock seconds] -format "%A %e %B %G %I:%M%p" -gmt 1] " "]]
switch -- [lindex $now 1] {
1 - 21 - 31 {set now [lreplace $now 1 1 "[lindex $now 1]st"]}
2 - 22 {set now [lreplace $now 1 1 "[lindex $now 1]nd"]}
3 - 23 {set now [lreplace $now 1 1 "[lindex $now 1]rd"]}
default {set now [lreplace $now 1 1 "[lindex $now 1]th"]}
}
set now [lreplace $now end end [string tolower [lindex $now end]]]
foreach chan [channels] {
putserv "PRIVMSG $chan :GMT (UTC) (0\xB0) [join $now]"
}
}

The channel output is typically as follows :-

GMT (UTC) (0°) Saturday 3rd January 2009 11:00pm

I hope this helps
T
Torrevado
Op
Posts: 101
Joined: Wed Aug 02, 2006 6:29 pm

Post by Torrevado »

Thanks for your great explanation, arfer :wink:
Post Reply