dispatcher module

class dispatcher.Dispatcher(inc_queue, database_connection, consumer, commands, queue_timeout=10, logging=<module 'logging' from '/opt/python/3.6.3/lib/python3.6/logging/__init__.py'>)[source]

Bases: object

A dispatcher to relay the received messages to the appropriate commands.

Parameters:
  • inc_queue – The incoming message queue.
  • database_connection – The datanase interface.
  • consumer – The discord REST API consumer to send messages through.
COMMAND_PREFIX = '!c/'
DELIMITER = '/'
is_command(content)[source]

Indicates whether a message is a command.

Parameters:content – The contents of the message.
Returns:A boolean indicating whether the message is a command.
parse(content)[source]

Parses a message to extract the command and its parameters.

Parameters:content – The contents of the message.
Returns:A tuple containing the command identifier and the parameters.
dispatch(command_id, message, *args)[source]

Calls the appropriate command with the given parameters.

Parameters:
  • command_id – The string identifier of the command.
  • params – The parameters to be passed to the command.
  • message – The full message which contained the command.
Returns:

The results of the command.

process_message(message)[source]

Calls the appropriate command with the given parameters.

Parameters:
  • command_id – The string identifier of the command.
  • params – The parameters to be passed to the command.
  • message – The full message which contained the command.
Returns:

The results of the command.

run()[source]

Listens for new messages in the incoming queue and dispatches them to the appropriate commands and stores them.

start()[source]

Starts listening for incoming messages.

stop()[source]

Stops listening for incoming messages.