| View previous topic :: View next topic |
| Author |
Message |
Torrevado Op
Joined: 02 Aug 2006 Posts: 101
|
Posted: Sat Jan 03, 2009 6:14 pm Post subject: bind time proc |
|
|
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: | 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: | bind pub - !testing testing
proc testing {nick host handle chan text} {
putserv "PRIVMSG $chan :\002Message goes here!!\002"
} |
Why doesn't the other one? |
|
| Back to top |
|
 |
arfer Master

Joined: 26 Nov 2004 Posts: 436 Location: Manchester, UK
|
Posted: Sat Jan 03, 2009 6:54 pm Post subject: |
|
|
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
} |
|
| Back to top |
|
 |
arfer Master

Joined: 26 Nov 2004 Posts: 436 Location: Manchester, UK
|
Posted: Sat Jan 03, 2009 7:14 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
Torrevado Op
Joined: 02 Aug 2006 Posts: 101
|
Posted: Sun Jan 04, 2009 4:52 am Post subject: |
|
|
Thanks for your great explanation, arfer  |
|
| Back to top |
|
 |
|