1
0
Fork 0

Add check for extension state and error support of disabled extension on help

This commit is contained in:
Ethanell 2020-11-05 14:15:58 +01:00
parent 05237dbe7b
commit 6b6e03a809
2 changed files with 23 additions and 1 deletions

19
administrator/check.py Normal file
View file

@ -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)

View file

@ -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