diff --git a/extensions/__init__.py b/extensions/__init__.py index eb39874..0b1a35f 100644 --- a/extensions/__init__.py +++ b/extensions/__init__.py @@ -4,7 +4,7 @@ bot.load_extension("extensions.help") bot.load_extension("extensions.extension") bot.load_extension("extensions.purge") bot.load_extension("extensions.poll") -bot.load_extension("extensions.reminders") +bot.load_extension("extensions.reminder") bot.load_extension("extensions.greetings") bot.load_extension("extensions.presentation") bot.load_extension("extensions.rorec") diff --git a/extensions/extension.py b/extensions/extension.py index 990b6d7..93e6e83 100644 --- a/extensions/extension.py +++ b/extensions/extension.py @@ -12,6 +12,9 @@ class Extension(commands.Cog): def __init__(self, bot: commands.Bot): self.bot = bot + def description(self): + return "Manage bot's extensions" + @commands.group("extension", pass_context=True) @commands.check(is_owner) async def extension(self, ctx: commands.Context): diff --git a/extensions/greetings.py b/extensions/greetings.py index f8229a8..71e7b92 100644 --- a/extensions/greetings.py +++ b/extensions/greetings.py @@ -19,6 +19,9 @@ class Greetings(commands.Cog): def __init__(self, bot: commands.Bot): self.bot = bot + def description(self): + return "Setup join and leave message" + @commands.group("greetings", pass_context=True) @commands.guild_only() @commands.has_permissions(manage_guild=True) diff --git a/extensions/help.py b/extensions/help.py index 8be14e3..aae3497 100644 --- a/extensions/help.py +++ b/extensions/help.py @@ -1,7 +1,7 @@ from discord import Embed from discord.ext import commands from discord.ext.commands import CommandNotFound, MissingRequiredArgument, BadArgument, MissingPermissions, \ - NoPrivateMessage + NoPrivateMessage, CommandError from administrator import config from administrator.logger import logger @@ -16,30 +16,24 @@ class Help(commands.Cog): def __init__(self, bot: commands.Bot): self.bot = bot + def description(self): + return "Give help and command list" + @commands.command("help", pass_context=True) async def help(self, ctx: commands.Context): embed = Embed(title="Help") - embed.add_field(name="Poll", value="Create poll with a simple command\n" - f"`{config.get('prefix')}poll help` for more information", inline=False) - embed.add_field(name="Reminders", value="Create reminders\n" - f"`{config.get('prefix')}reminder help` for more information", - inline=False) - permissions = ctx.channel.permissions_for(ctx.author) - if permissions.manage_messages: - embed.add_field(name="Purge", value="Purge all messages between the command and the next add reaction\n" - f"`{config.get('prefix')}purge help` for more information", inline=False) - if permissions.manage_guild: - embed.add_field(name="Greetings", value="Setup join and leave message\n" - f"`{config.get('prefix')}greetings help` for more information", - inline=False) - embed.add_field(name="Presentation", value="Give role to user who make a presentation in a dedicated " - "channel\n" - f"`{config.get('prefix')}presentation help` for more information", - inline=False) - if await is_owner(ctx): - embed.add_field(name="Extension", value="Manage bot extensions\n" - f"`{config.get('prefix')}extension help` for more information", - inline=False) + + for c in filter(lambda x: x != "Help", self.bot.cogs): + cog = self.bot.cogs[c] + try: + if await getattr(cog, c.lower()).can_run(ctx): + embed.add_field(name=c, + value=cog.description() + "\n" + + f"`{config.get('prefix')}{c.lower()} help` for more information", + inline=False) + except CommandError: + pass + await ctx.send(embed=embed) @commands.Cog.listener() diff --git a/extensions/poll.py b/extensions/poll.py index d76e42a..d31486a 100644 --- a/extensions/poll.py +++ b/extensions/poll.py @@ -19,6 +19,9 @@ class Poll(commands.Cog): self.bot = bot self.polls = {} + def description(self): + return "Create poll with a simple command" + @commands.group("poll", pass_context=True) @commands.guild_only() async def poll(self, ctx: commands.Context, name: str, *choices): diff --git a/extensions/presentation.py b/extensions/presentation.py index 49a1c01..0f594e1 100644 --- a/extensions/presentation.py +++ b/extensions/presentation.py @@ -14,6 +14,9 @@ class Presentation(commands.Cog): def __init__(self, bot: commands.Bot): self.bot = bot + def description(self): + return "Give role to user who make a presentation in a dedicated channel" + @commands.group("presentation", pass_context=True) @commands.guild_only() @commands.has_permissions(manage_guild=True) diff --git a/extensions/purge.py b/extensions/purge.py index aff896c..38ecc2a 100644 --- a/extensions/purge.py +++ b/extensions/purge.py @@ -15,6 +15,9 @@ class Purge(commands.Cog): self.bot = bot self.purges = {} + def description(self): + return "Purge all messages between the command and the next add reaction" + @commands.group("purge", pass_context=True) @commands.guild_only() @commands.has_permissions(manage_messages=True) diff --git a/extensions/reminders.py b/extensions/reminder.py similarity index 94% rename from extensions/reminders.py rename to extensions/reminder.py index 58e2b67..aef4310 100644 --- a/extensions/reminders.py +++ b/extensions/reminder.py @@ -25,10 +25,13 @@ def time_pars(s: str) -> timedelta: raise BadArgument() -class Reminders(commands.Cog): +class Reminders(commands.Cog, name="Reminder"): def __init__(self, bot: commands.Bot): self.bot = bot + def description(self): + return "Create and manage reminders" + @commands.group("reminder", pass_context=True) async def reminder(self, ctx: commands.Context): if ctx.invoked_subcommand is None: @@ -56,9 +59,9 @@ class Reminders(commands.Cog): hours, seconds = divmod(time.seconds, 3600) minutes, seconds = divmod(seconds, 60) await ctx.send(f"""Remind you in {f"{time.days}d {hours}h {minutes}m {seconds}s" - if time.days > 0 else f"{hours}h {minutes}m {seconds}s" - if hours > 0 else f"{minutes}m {seconds}s" - if minutes > 0 else f"{seconds}s"} !""") + if time.days > 0 else f"{hours}h {minutes}m {seconds}s" + if hours > 0 else f"{minutes}m {seconds}s" + if minutes > 0 else f"{seconds}s"} !""") @reminder.group("list", pass_context=True) async def reminder_list(self, ctx: commands.Context): diff --git a/extensions/rorec.py b/extensions/rorec.py index bf6ef8a..ea4c29e 100644 --- a/extensions/rorec.py +++ b/extensions/rorec.py @@ -21,6 +21,9 @@ class RoRec(commands.Cog): self.bot = bot self.edits = {} + def description(self): + return "Create role-reaction message to give role from a reaction add" + @staticmethod def get_message(session: db.Session, message_id: int, guild_id: int) -> db.RoRec: m = session.query(db.RoRec).filter(db.RoRec.message == message_id and db.RoRec.guild == guild_id).first()