Menu

Using the timer, how?

Scripting
2003-02-23
2003-02-24
  • Ralph Slooten

    Ralph Slooten - 2003-02-23

    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

     
    • AzaToth

      AzaToth - 2003-02-23

      the alarm is 900 seconds

       
    • Ralph Slooten

      Ralph Slooten - 2003-02-23

      Is there a way to set this to a lower/higher time, and if so, how exactly?

       
    • AzaToth

      AzaToth - 2003-02-23

      You can edit main.h

      #define ALARM_TIME         900             /* Seconds between alarm calls */

       
      • Robin Hill

        Robin Hill - 2003-02-23

        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.

         
    • Robin Hill

      Robin Hill - 2003-02-23

      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);
      }

       
    • Ralph Slooten

      Ralph Slooten - 2003-02-24

      Thanks, works like a charm with the perl timer ;-)

      Many thanks
      Ralph

       

Log in to post a comment.