Anope IRC Services

Anope Development => Modules => Topic started by: CuttingEdge on August 09, 2007, 12:25:08 PM

Title: Help with Callbacks
Post by: CuttingEdge on August 09, 2007, 12:25:08 PM
Hi all.  I'm pretty much new to the whole Anope coding scene, and would like to find out the following:

How would one trigger a callback function at a specific time of the day (daily) almost like a cron job of sorts.

I'd like to code up a module that triggers once in the evening (lets say at 20:00), and once in the morning (lets say at 08:00) everyday at specific times.

Help on this matter would be grately appreciated! :)
Title:
Post by: Trystan Scott Lee on August 09, 2007, 02:33:43 PM
Well Anopes callbacks are not really cron like, they get set off in x seconds, as the core loop goes around..  so to figure out how to execute at a given time you gotta do some math on the modules load

1. Find the current time let say that is 14:00
2. Take the current time and find the start points of the call backs
    8:00 -> 18 hours
    20:00 -> 6 hours
3. Set the first call back timer to be for 6 hours and 18 hours
4. In the call back function themselves set a 24 hour call back so that they are on a regular time after that, if they were evenly spaced then you could use one function

Note that since anope's main loop may not reach back to the top quickly or may idle, that any timed event will execute when the main loop is completed.