Added command to list watched channels
This commit is contained in:
parent
36b31989c4
commit
d28aa574c2
|
|
@ -49,6 +49,8 @@ class VocalMaisBot(discord.Client):
|
||||||
return await message.channel.send(":ping_pong:")
|
return await message.channel.send(":ping_pong:")
|
||||||
elif _check_list_element(contents, 1, "register"):
|
elif _check_list_element(contents, 1, "register"):
|
||||||
return await self.register_channel(message)
|
return await self.register_channel(message)
|
||||||
|
elif _check_list_element(contents, 1, "list"):
|
||||||
|
return await self.list_watched_channels(message)
|
||||||
else:
|
else:
|
||||||
return self.sorry_do_not_understand(message)
|
return self.sorry_do_not_understand(message)
|
||||||
|
|
||||||
|
|
@ -60,6 +62,7 @@ class VocalMaisBot(discord.Client):
|
||||||
message = f"""
|
message = f"""
|
||||||
**·** `@{me}register channel_id` : make me watch the voice channel with id `channel_id`
|
**·** `@{me}register channel_id` : make me watch the voice channel with id `channel_id`
|
||||||
**·** `@{me} help` : print this help
|
**·** `@{me} help` : print this help
|
||||||
|
**·** `@{me} list` : list watched channels
|
||||||
**·** `@{me} ping` : pong
|
**·** `@{me} ping` : pong
|
||||||
"""
|
"""
|
||||||
await channel.send(embed = discord.Embed(title = "Available commands", description = textwrap.dedent(message)))
|
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()
|
self.watched_channels_file.flush()
|
||||||
logger.debug("Written watched channels information to file")
|
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):
|
async def on_voice_state_update(self, member: discord.Member, before: discord.VoiceState, after: discord.VoiceState):
|
||||||
if member.bot:
|
if member.bot:
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue