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.

repeating timers

Old posts that have not been replied to for several years.
s
simonbell
Halfop
Posts: 68
Joined: Mon Aug 05, 2002 8:07 pm
Location: Washington, England
Contact:

repeating timers

Post by simonbell »

Hi.

Im writing a script which checks the userfile for entries more than 30 days old an deletes them.

I cant really seem to find it in the docs but i assume from the wording that using timer or utimer will trigger then event once and then stop the timer, so how do i go about making it repeat every x seconds?

an example of the current script is:
bind EVNT - loaded timer_loaded

proc timer_loaded {type} {
global H4exphandcheck H4exphandtime
timer $H4exphandcheck {
putlog "Checking for expired users"
foreach handcheck [userlist] {
if { [getuser $handcheck XTRA lastlogin] < [expr [unixtime]-$H4exphandtime] } {
putlog "Deleted handle $handcheck because it expired"
deluser $handcheck
foreach a [channels] {
if { [matchattr $handcheck -|n $a] == 1 } {
putlog "Deleted channel $a because owner handle expired"
channel remove $a
}
}
}
}
}
}
thanks
Simon
User avatar
stere0
Halfop
Posts: 47
Joined: Sun Sep 23, 2001 8:00 pm
Location: Brazil

8P

Post by stere0 »

# cleanusers.tcl v1.1 (20 February 2000)
# copyright (c) 1999 by slennox <slennox@egghelp.org>
# slennox's eggdrop page - http://www.egghelp.org/
#
# Checks the userlist once a day and removes users who haven't been seen
# for a specified number of days. Can also remove users who don't have a
# password set.
[]s
s
simonbell
Halfop
Posts: 68
Joined: Mon Aug 05, 2002 8:07 pm
Location: Washington, England
Contact:

Post by simonbell »

thanks...but from what i can see in that script it is set to bind at a specific time of day and then unbind itself. I need my script to have user definable settings for how often the bot should check its userlist which id guess would be best done by a timer.

Simon
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

You simply include a timer command, wiht the called proc.

Code: Select all

proc test1 {} {
 call code
 utimer 10 test1
}
timer 10 test1
s
simonbell
Halfop
Posts: 68
Joined: Mon Aug 05, 2002 8:07 pm
Location: Washington, England
Contact:

Post by simonbell »

Hi

im not exactly sure what you mean by this script.

if i have:
proc blah {} {
timer 10 { putnotc $nick "test" }
}

where would i add another timer in order to make it perform that notice every 10 minutes repeatedly?

thanks
Simon
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

You could use my code as, is, by simply changing one line.

Re-read my post, the answer is there. Simply read back the code to yoruself, translating it to some form of text, that you could read to some1 as instructions.

When looking at my code, think how it will operate. Will there be some form of loop (*HINT*)
s
simonbell
Halfop
Posts: 68
Joined: Mon Aug 05, 2002 8:07 pm
Location: Washington, England
Contact:

Post by simonbell »

So.

call code just means run code? so that would be the putnotc part?

then 10 seconds later run the proc again?

then the proc is closed

and there is another timer command outside of the process, that is what i didnt quite get, as in, what is actually going to trigger it and why is it there if utimer 10 test1 calls the script again itself?

Simon
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

You have to "jump start" the loop by setting the first timer yourself. Otherwise, the proc will never be called and therefore it can't create the next timer.

Another method would be to call the proc once, rather than create a timer to call it.
s
simonbell
Halfop
Posts: 68
Joined: Mon Aug 05, 2002 8:07 pm
Location: Washington, England
Contact:

Post by simonbell »

Thats what ive been doing, it was in my script in the first post.
proc timer_test {type} {
utimer 10 {
putnotc bell "test"
}
utimer 1 timer_test
}
The first timer works and outputs the notice 10 seconds after the bot has finished loading. The second timer which i took from the script above doesnt appear to work though

Simon
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

No, you have to call "timer_test" in the timer.

Look it's very simple:

set timer for timer_test
timer_test called by timer: send notice, set timer for timer_test
timer_test called by timer: send notice, set timer for timer_test
timer_test called by timer: send notice, set timer for timer_test
...

see?

The key is you have to call a function, and the function has to create a timer to call itself, not put the command in the utimer.
s
simonbell
Halfop
Posts: 68
Joined: Mon Aug 05, 2002 8:07 pm
Location: Washington, England
Contact:

Post by simonbell »

to be honest, i am now completely confused.
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

Damn - In plain english, you can't get any simpler.

Working with timers, is no different to normal Tcl. There is nothing strange about the command.

Instructions for doing this.

Create your proc as normal, which will call other procs, collect data from files and whatever else. Do not do anything with timers yet.

Next, you need to call the proc once, outside of this proc, so that it get it's first start. Without doing this, you have a proc sitting there doing nothing.

Next, inside the proc, the last line should become a call the the proc again, just like the starting line, but this time, it should be insode the timer command, so it's triggered after time, and not right away.

This being said. You said in a prvious reply "do I replace 'call code' with this". In a way yes. Keeping the same format as I posted, you simply need only change the 'call code' line with your commands.

Beyond codeing it for you, which I have allready done, there is nothing more we can say.
d
darko``
Op
Posts: 121
Joined: Sun Sep 08, 2002 5:33 pm
Location: Malta

Post by darko`` »

One fine day about 8 years ago 'weed' saw the light of the day.

tclsh scripts/weed

and check the options. ( +n - not seen n number of days )

>:> muahahah
Ignorant and lazy people will save 30 minutes by chosing simple config file. Smart ones will save 3000 minutes of *everyone's* time by opting for complete config file.
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

I am guessing he is trying to automate this process.
s
simonbell
Halfop
Posts: 68
Joined: Mon Aug 05, 2002 8:07 pm
Location: Washington, England
Contact:

Post by simonbell »

I have finally got this working, i dont know why i was being so thick before. Anyway, i just wanted to know if this script would need anything in it to stop it creating more timers during a rehash. Ive seen a post about it before but i wasnt sure if it would apply in this case, and if it would, how do i deal with it?

ty

Simon
proc nickbell {} {
if { [onchan bell #InfinitY] == 1 } {
file copy -force irconline.jpg /home/simonbell/www/html/irc/infinity/peopleonline/bellircdisplay.jpg
}
if { [onchan bell #InfinitY] == 0 } {
file copy -force ircoffline.jpg /home/simonbell/www/html/irc/infinity/peopleonline/bellircdisplay.jpg
}
timer 1 nickbell
}
utimer 5 nickbell
Locked