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.

Changing Text Based on Time of Day

Old posts that have not been replied to for several years.
Locked
W
WarpKat

Changing Text Based on Time of Day

Post by WarpKat »

I'd like to be able to send a message via the bot based on the time of day to a user or channel...basically what I have is a customer service bot that assumes oper status on an IRC server and I need it to send a message to customers that join the server and tell them that customer service is "closed" between certain times.

Any help would be greatly appreciated!

^_^
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Re: Changing Text Based on Time of Day

Post by user »

Here's one way to do it

Code: Select all

# get the number of seconds since midnight...
set timeOfDay [expr {[clock seconds]%86400}]
# now, just convert your opening/closing times to seconds past midnight and compare them to that value
if {$timeOfDay>=$open && $timeOfDay<$close} {you're supposed to be avaliable :P}
Have you ever read "The Manual"?
W
WarpKat

Post by WarpKat »

Thank you thank you! I'll assimilate it and see how it works out...
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

I forgot to mention...here's an easy way to convert times to seconds past midnight:

Code: Select all

set open [expr {[clock scan "9 am"]%86400}]
set close [expr {[clock scan "16:00"]%86400}]
...or you could of course just multiply the decimal hour (0.00-23.98 ) with 3600 to save some cpu. But these calculations should be done only once (when the times are set/changed) and the result should be kept in global variables. (imo)
I did the 'clock scan' examples in 12/24 hour formats just to give you an idea of what kind of input clock scan will accept. :)
Check http://tcl.tk/man/tcl8.4/TclCmd/clock.htm#M43 if you need some more info on this.
Have you ever read "The Manual"?
Locked