csbot.events module

class csbot.events.ImmediateEventRunner(handle_event)[source]

Bases: object

A very simple blocking event runner for immediate chains of events.

This class is only responsible for making sure chains of events get handled before the next root event happens. The handle_event method should be a callable that expects a single argument - it will receive whatever is passed to post_event().

The context manager technique is used to ensure the event runner is left in a usable state if an exception propagates out of it in response to running an event.

post_event(event)[source]

Post event to be handled soon.

If this is a root event, i.e. this method hasn’t been called while handling another event, then the event queue will run immediately and block until the event and all child events have been handled.

If this is a child event, i.e. this method has been called from another event handler, then it will be added to the queue and will be processed before the post_event() for the root event exits.

If a chain of events forms a tree, the handling order is equivalent to a breadth-first traversal of the event tree.

class csbot.events.AsyncEventRunner(handle_event, loop=None)[source]

Bases: object

An asynchronous event runner.

Runs on loop, and events are passed to handle_event which should return an iterable of awaitables (coroutine objects, tasks, etc.).

Parameters:
  • handle_event – Function to turn an event into awaitables
  • loop – asyncio event loop to use (default: None, use current loop)
post_event(event)[source]

Post event to be handled soon.

All tasks resulting from calling handle_event() on event are created and a future that completes only when those tasks are complete is returned.

The returned future may depend on more than just the tasks resulting from event, because new tasks are aggregated into an existing future if there are still outstanding tasks.

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.