diff --git a/VocalMaisBot.py b/VocalMaisBot.py index 072d7cd..01e0ff8 100755 --- a/VocalMaisBot.py +++ b/VocalMaisBot.py @@ -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