From a036397b80093ed46be4674e4f4066e97ba69224 Mon Sep 17 00:00:00 2001 From: flifloo Date: Thu, 4 Feb 2021 10:53:26 +0100 Subject: [PATCH] Switch help to slash commands --- extensions/greetings.py | 14 -------------- extensions/help.py | 40 ++++++++++++++-------------------------- extensions/invite.py | 17 ----------------- 3 files changed, 14 insertions(+), 57 deletions(-) diff --git a/extensions/greetings.py b/extensions/greetings.py index ad59907..08469c4 100644 --- a/extensions/greetings.py +++ b/extensions/greetings.py @@ -21,20 +21,6 @@ class Greetings(commands.Cog): def description(self): return "Setup join and leave message" - @cog_ext.cog_subcommand(base="greetings", name="help", - description="Help about greetings") - @is_enabled() - @guild_only() - @has_permissions(manage_guild=True) - async def greetings_help(self, ctx: SlashContext): - embed = Embed(title="Greetings help") - embed.add_field(name="set ", value="Set the greetings message\n" - "`{}` will be replace by the username", - inline=False) - embed.add_field(name="show ", value="Show the greetings message", inline=False) - embed.add_field(name="toggle ", value="Enable or disable the greetings message", inline=False) - await ctx.send(embeds=[embed]) - @cog_ext.cog_subcommand(base="greetings", name="set", description="Set the greetings message\n`{}` will be replace by the username", options=[ diff --git a/extensions/help.py b/extensions/help.py index 5ffbf43..591e1de 100644 --- a/extensions/help.py +++ b/extensions/help.py @@ -1,10 +1,8 @@ -from discord import Embed from discord.ext import commands from discord.ext.commands import CommandNotFound, MissingRequiredArgument, BadArgument, MissingPermissions, \ - NoPrivateMessage, CommandError, NotOwner + NoPrivateMessage, NotOwner from discord_slash import SlashContext -from administrator import config from administrator.check import ExtensionDisabled from administrator.logger import logger @@ -20,23 +18,6 @@ class Help(commands.Cog): 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") - - 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() async def on_command_error(self, ctx: commands.Context, error): await self.error_handler(ctx, error) @@ -45,21 +26,28 @@ class Help(commands.Cog): async def on_slash_command_error(self, ctx: SlashContext, error: Exception): await self.error_handler(ctx, error) - @staticmethod - async def error_handler(ctx, error: Exception): + async def error_handler(self, ctx, error: Exception): if isinstance(error, CommandNotFound): - await ctx.send(content="\u2753") + await self.reaction(ctx, "\u2753") elif isinstance(error, MissingRequiredArgument) or isinstance(error, BadArgument): - await ctx.send(content="\u274C") + await self.reaction(ctx, "\u274C") elif isinstance(error, NotOwner) or isinstance(error, MissingPermissions) \ or isinstance(error, NoPrivateMessage): - await ctx.send(content="\U000026D4") + await self.reaction(ctx, "\U000026D4") elif isinstance(error, ExtensionDisabled): - await ctx.send(content="\U0001F6AB") + await self.reaction(ctx, "\U0001F6AB") else: await ctx.send(content="An error occurred !") raise error + @staticmethod + async def reaction(ctx, react: str): + m = getattr(ctx, "message", None) + if m: + await m.add_reaction(react) + else: + await ctx.send(content=react) + def setup(bot): logger.info(f"Loading...") diff --git a/extensions/invite.py b/extensions/invite.py index 77dacf3..c64cfe3 100644 --- a/extensions/invite.py +++ b/extensions/invite.py @@ -30,23 +30,6 @@ class Invite(commands.Cog): def description(self): return "Get role from a special invite link" - @cog_ext.cog_subcommand(base="invite", name="help", description="Help about invite") - @is_enabled() - @guild_only() - @has_permissions(administrator=True) - async def invite_help(self, ctx: SlashContext): - embed = Embed(title="Invite help") - embed.add_field(name="invite create <#channel> <@role>", value="Create a invite link to a role", inline=False) - embed.add_field(name="invite delete ", value="Remove a invite", inline=False) - await ctx.send(embeds=[embed]) - - @cog_ext.cog_subcommand(base="invite", name="create", description="Create a invite link to a role", - options=[ - manage_commands.create_option("channel", "The channel to join", - SlashCommandOptionType.CHANNEL, True), - manage_commands.create_option("role", "The role to give", - SlashCommandOptionType.ROLE, True) - ]) @is_enabled() @guild_only() @has_permissions(administrator=True)