Sorry if this is a dumb question, but please bear with me ;-)
I have over the last week put together bits and pieces to create my own bot, which works rather great if I may say so. One thing I cannot work out is the timer. What I want to do is have a timer which simply outputs the total users to a separate log file for web stats. I just cannot get it to work. In my bot.pl, I have at the top:
$ALARM_TIME = "1m";
and all the way down (not in any other subfunction, I have used the example from the docs:
sub hub_timer()
{
odch::data_to_all("<$botname> Hub timer test.|");
}
If I understand this correctly, it should, every minute send a message to all (main chat) of "Hub timer test", but I get nothing, and then suddenly, some 8 minutes after reloading the script I get the message.... but this isn't every 8 minutes... really wierd.
Am I missing something here? Do I have to add an &sub_timer(); somewhere?
Any help would be appreciated.
Thanks
Ralph
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sorry if this is a dumb question, but please bear with me ;-)
I have over the last week put together bits and pieces to create my own bot, which works rather great if I may say so. One thing I cannot work out is the timer. What I want to do is have a timer which simply outputs the total users to a separate log file for web stats. I just cannot get it to work. In my bot.pl, I have at the top:
$ALARM_TIME = "1m";
and all the way down (not in any other subfunction, I have used the example from the docs:
sub hub_timer()
{
odch::data_to_all("<$botname> Hub timer test.|");
}
If I understand this correctly, it should, every minute send a message to all (main chat) of "Hub timer test", but I get nothing, and then suddenly, some 8 minutes after reloading the script I get the message.... but this isn't every 8 minutes... really wierd.
Am I missing something here? Do I have to add an &sub_timer(); somewhere?
Any help would be appreciated.
Thanks
Ralph
the alarm is 900 seconds
Is there a way to set this to a lower/higher time, and if so, how exactly?
You can edit main.h
#define ALARM_TIME 900 /* Seconds between alarm calls */
I'd watch out changing this as there's a lot of processing done in the hub at each alarm call, so reducing this time could produce other problems.
You can use perl's alarm function as so (the scripts are separate processes so the alarm signal won't interfere with the hubs alarm):
$TimerInterval = 60;
$SIG{ALRM} = \&ScriptTimer;
alarm($TimerInterval);
sub ScriptTimer {
# Code goes in here
alarm($TimerInterval);
}
Thanks, works like a charm with the perl timer ;-)
Many thanks
Ralph