glados package¶
-
class
glados.
Glados
[source]¶ Bases:
object
Glados is the core of the GLaDOS package.
-
add_bot
(bot)[source]¶ Add a new bot to GLaDOS.
- Parameters
bot (GladosBot) – the bot to be added to GLaDOS
-
add_plugin
(plugin)[source]¶ Add a plugin to GLaDOS
- Parameters
plugin (GladosPlugin) – the plugin to be added to GLaDOS
-
request
(request)[source]¶ Send a request to GLaDOS.
- Parameters
request (GladosRequest) – the request to be sent to GLaDOS
-
-
class
glados.
GladosBot
(token, name, signing_secret=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) – The bot token
client (WebClient) – A Slack client generated for that bot
-
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
-
delete_message
(channel, ts)[source]¶ Deletes a message that was sent by a bot
- Parameters
channel (
str
) –ts (
str
) –
- Return type
SlackResponse
-
send_message
(channel, message)[source]¶ Send a message as the bot
- Parameters
channel (str) – channel to send the message to
message (Message) – message object to send
- Return type
SlackResponse
-
update_message
(channel, ts, message)[source]¶ Updates a message that was sent by the bot
- Parameters
channel (
str
) –ts (
str
) –message (
Message
) –
- Return type
SlackResponse
-
validate_slack_signature
(request)[source]¶ - Parameters
request (
GladosRequest
) –
-
class
glados.
GladosRequest
(route_type, route, slack_verify=None, bot_name=None, json=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 (
Union
[str
,dict
,None
]) – the json paylod of the requestkwargs –
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
- Return type
str
-
class
glados.
RouteType
(*args, **kwds)[source]¶ Bases:
aenum.Enum
-
Callback
= 3¶
-
Events
= 5¶
-
Interaction
= 6¶
-
Menu
= 7¶
-
Response
= 2¶
-
SendMessage
= 1¶
-
Slash
= 4¶
-
-
class
glados.
EventRoutes
(*args, **kwds)[source]¶ Bases:
aenum.Enum
-
app_home_opened
= 1¶
-
message
= 2¶
-
-
class
glados.
GladosPlugin
(name, bot, **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
kwargs –
Examples
>>> def mock_function(request): ... print("Mock Function") >>> plugin = GladosPlugin("mock", None) >>> plugin.add_route(RouteType.SendMessage, "send_message", mock_function) >>> from glados import GladosRoute >>> plugin.routes[0].__dict__ == GladosRoute(RouteType.SendMessage, "send_message", mock_function).__dict__ True >>> try: ... plugin.add_route(RouteType.SendMessage, "send_message", mock_function) ... except GladosPathExistsError: ... print("Got Error") Got Error
-
add_route
(route_type, route, function)[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
-
property
routes
¶ List all routes for the plugin.
Examples
>>> from plugin import GladosPlugin >>> from router import RouteType, GladosRoute >>> plugin = GladosPlugin("mockPlugin", None) >>> plugin.routes [] >>> plugin.add_route(RouteType.SendMessage, "send_message", (lambda x: 1)) >>> r = plugin.routes[0] # type: GladosRoute >>> r.route == "send_message" True >>> r.function("NULL") 1
-
send_request
(request, **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 –