iNFERiON Voice
Joined: 13 Nov 2004 Posts: 7
|
Posted: Tue Nov 08, 2005 12:47 pm Post subject: [SOLVED] Determining the time |
|
|
This problem has been solved on IRC, see the bottom of this post for the final WORKING code.
I am writing a greet script that will determine the time first and then will respond "Good Morning/Afternoon/Evening/Night" depending on the time.
I got this code and this works:
| Code: | proc gen_test {nick host handle chan text} {
putmsg $chan "Botmaster requested a channel test, nothing to worry about, probably just maintenance ;)"
putmsg $nick "Channel report for: $chan"
if {[botisop $chan]} {
putmsg $nick "I \002\0033AM\003\002 an operator on $chan"
} else {
putmsg $nick "I \002\0034AM NOT\003\002 an operator on $chan"
}
set timetest [clock format [clock seconds] -format "%H:%M"]
putmsg $nick "The time is: $timetest"
} |
This sends me the time in a PM. The time shown is correct. However, when I want the bot to say hi upon someone joining, I got this code:
| Code: | bind join - * gen_greet
bind pub - "hi Bot" gen_greet
(...)
proc gen_greet {nick host handle chan text} {
set time [clock format [clock seconds] -format "%H:%M"]
if {$time >= 00:00 AND < 06:00} {
putmsg $chan "Goedenacht $nick"
} elseif {$time >= 06:00 AND < 12:00} {
putmsg $chan "Goedemorgen $nick"
} elseif {$time >= 12:00 AND < 18:00} {
putmsg $chan "Goedemiddag $nick"
} elseif {$time >= 18:00 AND < 00:00} {
putmsg $chan "Goedeavond $nick"
} else {
putmsg $chan "Hallo $nick"
}
} |
Whenever someone joins the channel or types "hi bot" the bot says nothing. I get this from the console:
| Code: | | [17:46] Tcl error [gen_greet]: syntax error in expression "$time >= 00:00 AND < 06:00": extra tokens at end of expression |
What am I doing wrong ?
---
Edit: After some help on the IRC Channel, the code is now this, but it just spits out the else { message "Hello $nick"...
| Code: | set time [clock format [clock seconds] -format "%H"]
if {$time < 06} {
putmsg $chan "Good night $nick"
} elseif {$time < 12} {
putmsg $chan "Good morning $nick"
} elseif {$time < 18} {
putmsg $chan "Good afternoon $nick"
} elseif {$time > 18} {
putmsg $chan "Good evening $nick"
} else {
putmsg $chan "Hello $nick"
} |
----
Last edit: Problem has been solved, this is the final WORKING code:
| Code: | bind join - * gen_greet
(...)
proc gen_greet {nick host handle chan} {
# Store the current hour (e.g. at 17:15, the hour is 17) as $time
set time [clock format [clock seconds] -format "%H"]
# If it's earlier then 06:00, greet with good night
if {$time < 06} {
putmsg $chan "Good night $nick"
# If it is somewhere in 11:00 or earlier, greet with good morning
} elseif {$time <= 11} {
putmsg $chan "Good morning $nick"
# If it is somewhere in 17:00 or earlier, greet with good afternoon
} elseif {$time <= 17} {
putmsg $chan "Good afternoon $nick"
# If it is 18:00 or later, greet with good evening
} elseif {$time >= 18} {
putmsg $chan "Good evening $nick"
# If for some reason unable to determine time, greet with a general hello.
} else {
putmsg $chan "Hello $nick, welcome to $chan"
}
} |
|
|