This repository has been archived by the owner on May 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot_commands.py
53 lines (41 loc) · 1.77 KB
/
bot_commands.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from chat_functions import send_text_to_room
class Command(object):
def __init__(self, client, store, config, command, room, event):
"""A command made by a user
Args:
client (nio.AsyncClient): The client to communicate to matrix with
store (Storage): Bot storage
config (Config): Bot configuration parameters
command (str): The command and arguments
room (nio.rooms.MatrixRoom): The room the command was sent in
event (nio.events.room_events.RoomMessageText): The event describing the command
"""
self.client = client
self.store = store
self.config = config
self.command = command
self.room = room
self.event = event
self.args = self.command.split()[1:]
async def process(self):
"""Process the command"""
if self.command.startswith("list") or self.command.startswith("all"):
await self._episodes()
elif self.command.startswith("help"):
await self._show_help()
else:
await self._unknown_command()
async def _episodes(self):
"""List all episode playlists"""
await send_text_to_room(self.client, self.room.room_id, self.config.all_episode_text)
async def _show_help(self):
"""Show the help text"""
text = ("Mention an episode by name or `SXXEYY`, "
"and I'll post the link to it. See `%s list` to see all episodes.")
await send_text_to_room(self.client, self.room.room_id, text)
async def _unknown_command(self):
await send_text_to_room(
self.client,
self.room.room_id,
f"Unknown command '{self.command}'. Try the 'help' command for more information.",
)