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 

[SOLVED] Determining the time

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


Joined: 13 Nov 2004
Posts: 7

PostPosted: Tue Nov 08, 2005 12:47 pm    Post subject: [SOLVED] Determining the time Reply with quote

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"
   }
}
Back to top
View user's profile Send private message
Alchera
Revered One


Joined: 11 Aug 2003
Posts: 3344
Location: Ballarat Victoria, Australia

PostPosted: Tue Nov 08, 2005 8:53 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website
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