csbot.events module

class csbot.events.HybridEventRunner(get_handlers, loop=None)[source]

Bases: object

A hybrid synchronous/asynchronous event runner.

get_handlers is called for each event passed to post_event(), and should return an iterable of callables to handle that event, each of which will be called with the event object.

Events are processed in the order they are received, with all handlers for an event being called before the handlers for the next event. If a handler returns an awaitable, it is added to a set of asynchronous tasks to wait on.

The future returned by post_event() completes only when all events have been processed and all asynchronous tasks have completed.

Parameters:
  • get_handlers – Get functions to call for an event
  • loop – asyncio event loop to use (default: use current loop)
post_event(event)[source]

Post event to be handled soon.

event is added to the queue of events.

Returns a future which resolves when the handlers of event (and all events generated during those handlers) have completed.

class csbot.events.Event(bot, event_type, data=None)[source]

Bases: dict

IRC event information.

Events are dicts of event information, plus some attributes which are applicable for all events.

bot = None

The Bot which triggered the event.

event_type = None

The name of the event.

datetime = None

The value of datetime.datetime.now() when the event was triggered.

classmethod extend(event, event_type=None, data=None)[source]

Create a new event by extending an existing event.

The main purpose of this classmethod is to duplicate an event as a new event type, preserving existing information. For example:

reply(message)[source]

Send a reply.

For messages that have a reply_to key, instruct the bot to send a reply.

class csbot.events.CommandEvent(bot, event_type, data=None)[source]

Bases: csbot.events.Event

classmethod parse_command(event, prefix, nick)[source]

Attempt to create a CommandEvent from a core.message.privmsg event.

A command is signified by event[“message”] starting with the command prefix string followed by one or more non-space characters.

Returns None if event[‘message’] wasn’t recognised as being a command.

arguments()[source]

Parse self[“data”] into a list of arguments using parse_arguments(). This might raise a ValueError if the string cannot be parsed, e.g. if there are unmatched quotes.