Utility functions and decorators

botogram ships with some functions and decorators aimed to simplify the bots development. Feel free to use them when you need them.

botogram.run(*bots[, workers=2])

This function allows you to run multiple bots in the same runner. You just need to provide all the bots you want to run, and the options you would normally provide to the bot’s run method.

Remember this function is blocking, so it prevents the execution of the code after the call until the runner is closed. Use a thread or a process if you want to execute things other than just running the runner.

import botogram
from file1 import bot as bot1
from file2 import bot as bot2

if __name__ == "__main__":
    botogram.run(bot1, bot2)
Parameters:
  • *bots (botogram.Bot) – The bots you want to run.
  • workers (int) – The number of workers you want to use.
botogram.usernames_in(message)

Returns a list of usernames contained in the message you provide. The function automatically excludes commands, email addresses and URLs. Remember that returned usernames aren’t prefixed with a @.

Parameters:message (str) – The message which contains the usernames.
Returns:The list of usernames contained in the message.
Return type:list of str
@botogram.pass_shared

This decorator does nothing currently. If you still use it, just remove all the references to it in your source code. Your bot will still work flawlessly.

Deprecated since version pre-0.1: it will be removed in botogram 1.0

@botogram.pass_bot

This decorator does nothing currently. If you still use it, just remove all the references to it in your source code. Your bot will still work flawlessly.

Deprecated since version pre-0.1: it will be removed in botogram 1.0

@botogram.help_message_for(func)

The return value of the decorated function will be treated as the help message of the function you pass to the decorator. The decorated function is called each time the help message is needed: this way you can create dynamic help messages, but it’s advisable to cache the value if it’s expensive to calculate it.

Parameters:func (callable) – The function which needs the help message.