Execute independent tasks

Unfortunately, not everything can be executed after a user input, especially if you need periodic execution, or background cleanup. In order to solve this, botogram provides you the tasks system, which allows for the execution of independent tasks.

Repeated execution

There might be the case when you need to execute a specific function periodically. For example if you want to implement alerts, or if you need to do some internal cleanup in your bot. Timers offer an easy and reliable way to implement this, with a resolution of one second. Just use the timer() decorator:

def init(shared):
    shared["subs"] = []

def subscribe_command(shared, chat, message, args):
    """Subscribe to the hourly BONG"""
    subs = shared["subs"]
    shared["subs"] = subs

def BONG(bot, shared):
    for chat in shared["subs"]:

If you’re working with components, you can instead use the add_timer() method of the component instance.