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.

[SOLVED] Determining the time

Help for those learning Tcl or writing their own scripts.
Post Reply
i
iNFERiON
Voice
Posts: 7
Joined: Sat Nov 13, 2004 4:23 pm

[SOLVED] Determining the time

Post by iNFERiON »

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: Select all

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: Select all

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: Select all

[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: Select all

	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: Select all

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"
	}
}
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

I'm glad at least one person read the sticky topics.
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
Post Reply