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 

bind time proc

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


Joined: 02 Aug 2006
Posts: 101

PostPosted: Sat Jan 03, 2009 6:14 pm    Post subject: bind time proc Reply with quote

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
View user's profile Send private message
arfer
Master


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Sat Jan 03, 2009 6:54 pm    Post subject: Reply with quote

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
View user's profile Send private message
arfer
Master


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Sat Jan 03, 2009 7:14 pm    Post subject: Reply with quote

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
View user's profile Send private message
Torrevado
Op


Joined: 02 Aug 2006
Posts: 101

PostPosted: Sun Jan 04, 2009 4:52 am    Post subject: Reply with quote

Thanks for your great explanation, arfer Wink
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