glados package

class glados.Glados(config_file=None, plugins_folder=None, bots_config_dir=None, plugins_config_dir=None)[source]

Bases: object

Glados is the core of the GLaDOS package.

add_bot(bot: glados.bot.GladosBot)[source]

Add a new bot to GLaDOS.

Parameters

bot (GladosBot) – the bot to be added to GLaDOS

add_plugin(plugin: glados.plugin.GladosPlugin)[source]

Add a plugin to GLaDOS

Parameters

plugin (GladosPlugin) – the plugin to be added to GLaDOS

import_bots()[source]

Import all discovered bots

import_plugins(bot_name=None)[source]

Import all discovered plugins and add them to the plugin list.

read_config(bot_name=None)[source]
request(request: glados.request.GladosRequest)[source]

Send a request to GLaDOS.

Parameters

request (GladosRequest) – the request to be sent to GLaDOS

class glados.GladosBot(token: Union[str, Dict[str, str]], name, signing_secret: Union[str, Dict[str, str]] = None, **kwargs)[source]

Bases: object

GLaDOS Bot represents all the required data and functions for a Slack bot.

Notes

All Slack Web API functions can be called from MyBot.client.*

Parameters
  • name (str) – The name of the bot (URL Safe)

  • token (str, Dict[str, str]) – The bot token

  • signing_secret (str, Dict[str, str]) – The bot signing secret.

name

The name of the bot (URL Safe)

Type

str

token

The bot token

Type

str

client

A Slack client generated for that bot

Type

WebClient

signing_secret

The bots signing secret.

Type

str

check_for_env_vars(value)[source]

Check an input value to see if it is an env_var or enc_env_var and get the value.

Parameters

value (input to check.) –

Returns

Returns the value of the var from either the passed in value, or the env var value.

Return type

Any

delete_message(channel: str, ts: str) → slack.web.slack_response.SlackResponse[source]

Deletes a message that was sent by a bot

Parameters
  • channel

  • ts

send_message(channel: str, message: slack.web.classes.messages.Message) → slack.web.slack_response.SlackResponse[source]

Send a message as the bot

Parameters
  • channel (str) – channel to send the message to

  • message (Message) – message object to send

update_message(channel: str, ts: str, message: slack.web.classes.messages.Message) → slack.web.slack_response.SlackResponse[source]

Updates a message that was sent by the bot

Parameters
  • channel

  • ts

  • message

validate_slack_signature(request: glados.request.GladosRequest)[source]
class glados.GladosRequest(route_type: glados.route_type.RouteType, route: str = None, slack_verify: glados.request.SlackVerification = None, bot_name: str = None, json: Union[str, dict] = None, **kwargs)[source]

Bases: object

GLaDOS Request Object. This holds all the data required to process the request.

Parameters
  • route_type (RouteType) – what type of route is this

  • route (str) – what is the route to be called

  • slack_verify (SlackVerification) – slack data used for verifying the request came from Slack

  • bot_name (str) – The name of the bot to send the request to. This is used for select RouteTypes

  • json – the json paylod of the request

  • kwargs

Examples

>>> request = GladosRequest(RouteType.SendMessage, "send_mock", json={"message":"my message"})
>>> print(request.json.message)
my message
>>> try:
...    print(request.json.other_param)
... except AttributeError:
...     print("ERROR")
ERROR
property route

the actual route

If the route automatically prefixed the route with the bot name, it will return the route with the prefix

class glados.RouteType[source]

Bases: enum.Enum

An enumeration.

Callback = 3
Events = 5
Interaction = 6
Menu = 7
Response = 2
Slash = 4
Webhook = 1
class glados.EventRoutes[source]

Bases: enum.Enum

An enumeration.

app_home_opened = 1
message = 2
class glados.GladosPlugin(config: glados.plugin.PluginConfig, bot: glados.bot.GladosBot, **kwargs)[source]

Bases: object

Parent class for a GLaDOS Plugin

Parameters
  • name (str) – the name of the plugin

  • bot (GladosBot) – the GLaDOS bot that this plugin will use

add_route(route_type: glados.route_type.RouteType, route: Union[glados.route_type.EventRoutes, str], function: Callable)[source]

Add a new route to the plugin

Parameters
  • route_type (RouteType) – what type of route this is this

  • route (Union[EventRoutes, str]) – what is the route to be added

  • function (Callable) – the function to be executed when this route runs

respond_to_url(request: glados.request.GladosRequest, text: str, **kwargs)[source]
property routes

List all routes for the plugin.

send_request(request: glados.request.GladosRequest, **kwargs)[source]

This is the function to be called when sending a request to a plugin.

This function is responsible for validating the slack signature if needed. It also returns and empty string if the function called returns None.

Parameters
  • request (GladosRequest) – the request object to be sent

  • kwargs

class glados.GladosConfig(config_file: str)[source]

Bases: object

read_config()[source]

Read the config file into a config object

property sections

what sections are there in the config file

Returns

sorted list of sections in the yaml file

Return type

List[str]

glados.read_config(config_file: str)[source]