Added command to list watched channels

This commit is contained in:
Elnath 2020-12-26 21:49:09 +01:00
parent 36b31989c4
commit d28aa574c2
1 changed files with 24 additions and 0 deletions

View File

@ -49,6 +49,8 @@ class VocalMaisBot(discord.Client):
return await message.channel.send(":ping_pong:")
elif _check_list_element(contents, 1, "register"):
return await self.register_channel(message)
elif _check_list_element(contents, 1, "list"):
return await self.list_watched_channels(message)
else:
return self.sorry_do_not_understand(message)
@ -60,6 +62,7 @@ class VocalMaisBot(discord.Client):
message = f"""
**·** `@{me}register channel_id` : make me watch the voice channel with id `channel_id`
**·** `@{me} help` : print this help
**·** `@{me} list` : list watched channels
**·** `@{me} ping` : pong
"""
await channel.send(embed = discord.Embed(title = "Available commands", description = textwrap.dedent(message)))
@ -106,6 +109,27 @@ class VocalMaisBot(discord.Client):
self.watched_channels_file.flush()
logger.debug("Written watched channels information to file")
async def list_watched_channels(self, message: discord.Message):
guild_id = str(message.guild.id)
if guild_id in self.watched_channels:
guild_info = self.watched_channels[guild_id]
if "watched_channels" in guild_info:
watched_channels_id = guild_info["watched_channels"]
else:
watched_channels_id = []
else:
watched_channels_id = []
if len(watched_channels_id) > 0:
answer_lines = []
for channel_id in watched_channels_id:
channel = self.get_channel(channel_id)
if channel is not None: # Does the channel still exist?
answer_lines.append(f":eyes: {channel.name} ({channel_id})")
await message.channel.send(embed = discord.Embed(title = "I am watching the following channels", description = "\n".join(answer_lines)))
else:
await message.channel.send(f":see_no_evil: I am not watching any voice channel! Do not hesitate to add some by running `@{self.user.display_name} register channel_id`")
async def on_voice_state_update(self, member: discord.Member, before: discord.VoiceState, after: discord.VoiceState):
if member.bot:
return