PykeBot2.frontend package

Submodules

PykeBot2.frontend.command_interpreter module

Responsible for understanding the raw command in a given Query and setting next step, flags and data accordingly.

author

Jonathan Decker

PykeBot2.frontend.command_interpreter.create_error(query: PykeBot2.models.query.Query, content: str)
Description

Creates an error message from the content and adds it to the query,

further sets query forward to to frontend and next step to format. :param query: The handled query, which encountered an error. :type query: Query :param content: The error message to be displayed, should usually include str(query). :type content: str :return: None :rtype: None

PykeBot2.frontend.command_interpreter.interpret_command(query: PykeBot2.models.query.Query)
Description

Interprets the raw command of the Query and sets next step, flags and data accordingly.

Parameters

query (Query) – The handled Query.

Returns

None

Return type

None

PykeBot2.frontend.console_interface module

PykeBot2.frontend.discord_interface module

author

Jonathan Decker

class PykeBot2.frontend.discord_interface.PykeBot(*args, **kwargs)

Bases: discord.ext.commands.bot.Bot

Description

Overwrites the standard Discord Bot to add fields for the incoming and outgoing Queues as well as

background tasks. The prefix for co

forward_queue: asyncio.queues.Queue
output_queue: asyncio.queues.Queue
async output_queue_listener()
Description

Coroutine that handles the discord output queue and sends messages based on the incoming queries.

The query objects is not further forwarded. :return: None :rtype: None

PykeBot2.frontend.discord_interface.chunk_message(out_raw: str)
PykeBot2.frontend.discord_interface.initiate_query(message: discord.message.Message)
Description

Creates query object from the given message and submits it to the forward query.

Parameters

message (discord.Message) – A valid message, usually captured by the on_message event.

Returns

None

Return type

None

async PykeBot2.frontend.discord_interface.on_message(message: discord.message.Message)
Description

Event triggered when a message is send to a viewed channel.

If the message starts with the prefix (standard: ‘.pb’), a query is created from the message and forwarded. Another exception is {prefix} ping which results in an immediate Pong instead of a Query. :param message: The message object that triggered the event. :type message: discord.Message :return: None :rtype: None

async PykeBot2.frontend.discord_interface.on_ready()
Description

Event triggered when the Discord Bot is ready. Logs the event and sets the presence for the bot.

Returns

None

Return type

None

async PykeBot2.frontend.discord_interface.run_discord_bot_loop(forward_queue: asyncio.queues.Queue, output_queue: asyncio.queues.Queue)
Description

Main Coroutine for the Discord Bot interface.

Handles the final setup steps and starts the main Coroutine for Discord Bot. :param forward_queue: Where queries created from incoming messages are put. :type forward_queue: asyncio.Queue :param output_queue: The message from queries in this Queue will be send back via the interface. :type output_queue: asyncio.Queue :return: None :rtype: None

PykeBot2.frontend.frontend_master module

Main Frontend module, responsible for calling command interpreter on new queries, calling output formatter and checking the context before sending a query to the respective interface.

author

Jonathan Decker

async PykeBot2.frontend.frontend_master.frontend_loop(forward_queue: asyncio.queues.Queue, frontend_queue: asyncio.queues.Queue)
Description

Main Coroutine for the frontend. Responsible for calling command interpreter and output formatter.

Parameters
  • forward_queue (asyncio.Queue) – The Queue which is handled by the forwarder of the main event loop.

  • frontend_queue (asyncio.Queue) – The Queue that is handled by this Coroutine.

Returns

None

Return type

None

async PykeBot2.frontend.frontend_master.loop_back_dummy(forward_queue: asyncio.queues.Queue, frontend_queue: asyncio.queues.Queue)
Description

A dummy Coroutine that sends incoming queries back to the discord interface.

Parameters
  • forward_queue (asyncio.Queue) – The forward_queue which should be handled by the query_forwarder.

  • frontend_queue (asyncio.Queue) – The Queue that is handled by this Coroutine.

Returns

None

Return type

None

PykeBot2.frontend.output_formatter module

Responsible for creating the output message from the payload by calling str messages, respecting flags.

author

Jonathan Decker

PykeBot2.frontend.output_formatter.create_error(query: PykeBot2.models.query.Query, content: str)
Description

Creates an error message from the content and adds it to the query,

further sets query forward to to frontend and next step to format. :param query: The handled query, which encountered an error. :type query: Query :param content: The error message to be displayed, should usually include str(query). :type content: str :return: None :rtype: None

PykeBot2.frontend.output_formatter.format_error(query: PykeBot2.models.query.Query)
Description

Formats error payloads, and sets output message.

Parameters

query (Query) – The handled Query.

Returns

None

Return type

None

PykeBot2.frontend.output_formatter.format_message(query: PykeBot2.models.query.Query)
Description

Formats message payloads, and sets output message.

Parameters

query (Query) – The handled Query.

Returns

None

Return type

None

PykeBot2.frontend.output_formatter.format_payload(query: PykeBot2.models.query.Query)
Description

Takes the Payload from the Query and calls to str based on context and flags and saves it to output message.

Parameters

query (Query) – The handled Query.

Returns

None

Return type

None

Module contents