diff --git a/src/commands.py b/src/commands.py
index 8a49e73..19f2a4e 100644
--- a/src/commands.py
+++ b/src/commands.py
@@ -2,8 +2,9 @@ import discord
def register_all_commands(bot):
bot.register_command("guilds", cmd_guilds)
- bot.register_command("vc", cmd_vc)
+ bot.register_command("listvc", cmd_listvc)
bot.register_command("activevc", cmd_activevc)
+ bot.register_command("vcinfo", cmd_vcinfo)
def cmd_guilds(bot, text, user, arg, argv):
"""
@@ -11,11 +12,11 @@ def cmd_guilds(bot, text, user, arg, argv):
"""
response = ""
for guild in bot.discord.guilds:
- response += f"{guild.id}: {guild.name}\n"
+ response += f"{guild.id}: {guild.name}<br />\n"
user.send_text_message(response)
-def cmd_vc(bot, text, user, arg, argv):
+def cmd_listvc(bot, text, user, arg, argv):
"""
Show voice channels in all guilds,
or in a specific guild if the ID or name of guild has been given
@@ -23,9 +24,9 @@ def cmd_vc(bot, text, user, arg, argv):
if not argv:
response = ""
for guild in bot.discord.guilds:
- response += f"{guild.id}: {guild.name}\n"
+ response += f"{guild.id}: {guild.name}<br />\n"
for vc in guild.voice_channels:
- response += f">{vc.id}: {vc.name}\n"
+ response += f">{vc.id}: {vc.name}<br />\n"
else:
guild = None
try:
@@ -38,9 +39,9 @@ def cmd_vc(bot, text, user, arg, argv):
user.send_text_message("no guild found")
return
- response = f"{guild.name}: \n"
+ response = f"{guild.name}: <br />\n"
for vc in guild.voice_channels:
- response += f">{vc.id}: {vc.name}\n"
+ response += f">{vc.id}: {vc.name}<br />\n"
user.send_text_message(response)
@@ -56,9 +57,57 @@ def cmd_activevc(bot, text, user, arg, argv):
if len(vc.members) > 0:
vcs_with_active_members.append(vc)
if len(vcs_with_active_members) > 0:
- response += f"{guild.id}: {guild.name}\n"
+ response += f"{guild.id}: {guild.name}<br />\n"
for vc in vcs_with_active_members:
- response += f">{vc.id}: {vc.name} ({len(vc.members)})\n"
+ response += f">{vc.id}: {vc.name} ({len(vc.members)})<br />\n"
user.send_text_message(response)
else:
user.send_text_message("no active voice channels found")
+
+def cmd_vcinfo(bot, text, user, arg, argv):
+ try:
+ if len(argv) >= 1:
+ vc_id = int(argv[0])
+ if len(argv) == 2:
+ guild_id = int(argv[1])
+ except TypeError:
+ user.send_text_message("strings are not allowed: please use the ID and not the name")
+
+ if len(argv) == 1:
+ guild_id = None
+
+ vc = get_vc(bot.discord, guild_id, vc_id)
+
+ if not vc:
+ user.send_text_message("no vc found")
+
+ response = f"""Name: {vc.name}<br />\n
+ Guild: {vc.guild.name}<br />\n
+ Members: {len(vc.members)}<br />\n
+ """
+
+ if len(vc.members) > 0:
+ response += "<br />\n"
+
+ for member in vc.members:
+ response += f"{member.name}<br />\n"
+
+ user.send_text_message(response)
+
+def get_vc(ctx, guild, identifier):
+ """
+ Try to get a Discord voice channel by ID
+ ctx: discord.py context
+ identifier: int: ID of the guild
+ """
+ if not guild:
+ for g in ctx.guilds:
+ vc = discord.utils.find(lambda vc: vc.id == identifier, g.voice_channels)
+ if vc is not None:
+ return vc
+ else:
+ g = discord.utils.find(lambda g: g.id == identifier, ctx.guilds)
+ if not g:
+ return None
+ vc = discord.utils.find(lambda vc: vc.id == identifier, g.voice_channels)
+ return vc
|