Skip to content

Usable functions in modules

nemunaire edited this page Sep 8, 2014 · 3 revisions

When a module is loaded by the nemubot importer, some imports are made to include basic bot features.

Events and hooks

  • add_hook(store, hook): add a hook (Hook class) in the given hook_store (string).
  • del_hook(store, hook): remove a hook (Hook class) from the given hook_store (string).
  • add_event(event): add a new event to the list (give a filled Event class). Return the event id.
  • add_event_eid(event, eid): add an event with a fixed event id. Return the event id.
  • del_event(eid): remove the eid event.

Responses

Instead of returning all response with the return keyword, you can use the send_response function.

For example:

send_response(server, response)

The server argument can be a string or a Server class.

The response argument has to be Response class.

Features

  • save(): force saving the data module.

Debug

  • print(msg): display a message on shell;
  • print_debug(msg): display a message on shell, only if debug-mode is on.

Attributes

  • CONF: the module configuration

Internal use only

  • DEBUG : boolean storing debuging state of this module;
  • DIR : address to the module directory;
  • name : internal name of the module;
  • REGISTERED_HOOKS : list which save hooks register by this module (mainly used for unload);
  • REGISTERED_EVENTS : list which save events register by this module (mainly used for unload).