berconpy.dispatch.EventDispatcher

class berconpy.dispatch.EventDispatcher

Bases: ABC

The base class for implementing an event handler system.

Methods

add_listener(event, func, /)

Adds a listener for a given event, e.g.

listen([event])

A decorator shorthand to add a listener for a given event, e.g.

remove_listener(event, func)

Removes a listener from a given event, e.g.

abstract add_listener(event, func, /)

Adds a listener for a given event, e.g. "on_login".

See the Event Reference for a list of supported events.

Parameters:
  • event (str) – The event to listen for.

  • func (Callable) – The function to dispatch when the event is received.

listen(event=None)

A decorator shorthand to add a listener for a given event, e.g. "on_login".

Parameters:

event (Optional[str]) – The event to listen for. If None, the function name is used as the event name.

Return type:

Callable[[TypeVar(T)], TypeVar(T)]

abstract remove_listener(event, func)

Removes a listener from a given event, e.g. "on_login".

This method should be a no-op if the given event and function does not match any registered listener.

Parameters:
  • event (str) – The event used by the listener.

  • func (Callable) – The function used by the listener.