From 6b6e03a809fd188aff334af8c4886baef00a64d6 Mon Sep 17 00:00:00 2001 From: flifloo Date: Thu, 5 Nov 2020 14:15:58 +0100 Subject: [PATCH] Add check for extension state and error support of disabled extension on help --- administrator/check.py | 19 +++++++++++++++++++ extensions/help.py | 5 ++++- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 administrator/check.py diff --git a/administrator/check.py b/administrator/check.py new file mode 100644 index 0000000..3e36548 --- /dev/null +++ b/administrator/check.py @@ -0,0 +1,19 @@ +from discord.ext import commands + +import db + + +class ExtensionDisabled(commands.CheckFailure): + pass + + +def is_enabled(): + async def check(ctx: commands.Context): + if ctx.command.cog: + s = db.Session() + es = s.query(db.ExtensionState).get((ctx.command.cog.qualified_name, ctx.guild.id)) + s.close() + if es and not es.state: + raise ExtensionDisabled() + return True + return commands.check(check) diff --git a/extensions/help.py b/extensions/help.py index 4cca80b..3d958f2 100644 --- a/extensions/help.py +++ b/extensions/help.py @@ -4,6 +4,7 @@ from discord.ext.commands import CommandNotFound, MissingRequiredArgument, BadAr NoPrivateMessage, CommandError, NotOwner from administrator import config +from administrator.check import ExtensionDisabled from administrator.logger import logger @@ -43,7 +44,9 @@ class Help(commands.Cog): await ctx.message.add_reaction("\u274C") elif isinstance(error, NotOwner) or isinstance(error, MissingPermissions)\ or isinstance(error, NoPrivateMessage): - await ctx.message.add_reaction("\u274C") + await ctx.message.add_reaction("\U000026D4") + elif isinstance(error, ExtensionDisabled): + await ctx.message.add_reaction("\U0001F6AB") else: await ctx.send("An error occurred !") raise error