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 

Run a proc between specific times/days

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


Joined: 30 Nov 2010
Posts: 10

PostPosted: Tue Dec 21, 2010 5:41 am    Post subject: Run a proc between specific times/days Reply with quote

currently i have a proc similar to this:

Code:
proc timer {min args} {
 if {[scan $min %d] % 5 == 0} {
  #Code goes here
   }
}


which runs a proc every 5 min, but i would also like to have it check to see if the system time is between 9am-5pm mon-fri before running.

i think it may be somthing similar to
Code:

proc timer {min args} {
set systemTime [clock seconds]
 if { [clock format $systemTime -format %H] >= 9 && [clock format $systemTime -format %H] <= 17 &&
 [scan $min %d] % 5 == 0} {
  #code goes here
   }
}


which i would think would work but doesnt seem to be, inaddition im not sure how to equate day of the week to a numeric value to check against either. Anyhelp is greatly apreciated.

using this for reference http://www.tcl.tk/man/tcl/tutorial/Tcl41.html
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Tue Dec 21, 2010 1:08 pm    Post subject: Re: Run a proc between specific times/days Reply with quote

adi2247 wrote:

...
im not sure how to equate day of the week to a numeric value to check against either.




How about strftime ?
Try strftime %u

Ref:
http://www.eggheads.org/support/egghtml/1.6.20/tcl-commands.html
and find strftime

Also:
http://linux.about.com/library/cmd/blcmdl3_strftime.htm


Is the .tcl command enabled on your bot? If so, you can do some quick experiments with the strftime command.
Example:
Code:

<mynick> .tcl strftime %u
<botnick> Tcl: 2


(Today is Tuesday, and with strftime Monday =1)
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Tue Dec 21, 2010 3:45 pm    Post subject: Reply with quote

If you've got the 1.6.20 version of eggdrop, then you could use the new "CRON" binding rather than the "TIME" binding. In that case, the code would look like this:
Code:
bind cron - {*/5 * * * 1-5} timer
proc timer {minute hour day month weekday} {
  #code goes here
}


If you'd rather use the "TIME" binding, and parse the various arguments passed to the proc as integers, you'll have to remember that single-digit numbers are zero-prefixed, causing 08 and 09 to be treated as invalid octal numbers. This is fairly easy to solve though, using something like this:
Code:
bind time - * someproc {min hour day month year} {
  set min [string trimleft $min 0]
  set hour [string trimleft $hour 0]
  if {$min % 5 == 0 && $hour >= 9 && $hour <= 17} {
...

This won't solve the issue of weekdays though, so you'll have to resort to strftime for this, as suggested by willyw
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
username
Op


Joined: 06 Oct 2005
Posts: 196
Location: Russian Federation, Podolsk

PostPosted: Wed Dec 22, 2010 4:28 am    Post subject: Reply with quote

nml375, but in http://www.eggheads.org/support/egghtml/1.6.20/tcl-commands.html#binda there is other arguments.

bind cron <flags> <mask> <proc>
proc-name <minute> <hour> <day> <weekday> <year>


And in bind description I read:
Quote:
...It can contain up to five fields: minute, hour, day, month, weekday; delimited by whitespace....


So, this is mistake in this line proc-name <minute> <hour> <day> <weekday> <year>?
_________________
Архив TCL скриптов для ботов Eggdrop/Windrop:
http://egghelp.ru/
Back to top
View user's profile Send private message Send e-mail Visit poster's website
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Wed Dec 22, 2010 2:25 pm    Post subject: Reply with quote

username:
If you instead open the tcl-commands.doc that's included with the source, you'll read <weekday> instead of <year>, so it's my best guess they've made a typo with the html-docs.
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
pseudo
Halfop


Joined: 23 Nov 2009
Posts: 88
Location: Bulgaria

PostPosted: Wed Dec 22, 2010 4:40 pm    Post subject: Reply with quote

Yeah, this was a mistake indeed. It's fixed in 1.8 cvs: http://cvs.eggheads.org/viewvc/eggdrop1.8/doc/html/tcl-commands.html?r1=1.2&r2=1.3
Back to top
View user's profile Send private message Visit poster's website
adi2247
Voice


Joined: 30 Nov 2010
Posts: 10

PostPosted: Thu Dec 23, 2010 3:15 pm    Post subject: Reply with quote

ty all for the sugestions! i will try some of these and report back!
Back to top
View user's profile Send private message
adi2247
Voice


Joined: 30 Nov 2010
Posts: 10

PostPosted: Mon Dec 27, 2010 1:08 am    Post subject: Re: Run a proc between specific times/days Reply with quote

strftime seems to be working great for the most part. Sometimes i have to restart the bot completely vs a .rehash but that may or may not be related to the code below, and more related to numerous mysql connections, not sure yet. But if anyone sees anything glaringly wrong w the below please let me know

the two instances im using for this are:

Code:
if { [strftime %u] >= 1 && [strftime %u] <= 6 && [strftime %H%M] >= 930 && [strftime %H%M] <= 1700 &&
    [scan $min %d] % 5 == 0} {


and

Code:
if { [strftime %u] == 7 && [strftime %H] >= 18 && [scan $min %d] % 15 == 0 ||
     [strftime %u] >= 1 && [strftime %u] <= 5 && [scan $min %d] % 15 == 0} {


also what nml375 posted that strftime %H before noon will report back "01" or "02" for example vs just "1" or "2". However if you try to evaluate:

if { [strftime %H] >= 08 }

the bot will error and say this looks like an octal number just as nml375 mentioned.

** and i just realized that the first block of code i posted was NOT running before 10am today so the times will HAVE to be evaluated in the manner that nml375 posted as tcl/eggdrop aparently does not view 01 to == 1
thats a good finding

but the cron method if probably the the best way to run this proc m-f and ill look at the times seperately as mentioned in his post for simplicity

the second block of code i posted works fine since it only evaluates the hour if its greater than 2 digits anyway. cron may not work for this because it needs to look at different times if its a sunday
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