From c854d2c2ba2b7678b407a2b3ec19f80c24d65328 Mon Sep 17 00:00:00 2001 From: Zevaryx Date: Sat, 30 Apr 2022 20:12:43 -0600 Subject: [PATCH] Add scale-level check instead of per-command check --- jarvis/cogs/botutil.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/jarvis/cogs/botutil.py b/jarvis/cogs/botutil.py index 1497dc2..aeb6fc3 100644 --- a/jarvis/cogs/botutil.py +++ b/jarvis/cogs/botutil.py @@ -14,11 +14,14 @@ class BotutilCog(Scale): def __init__(self, bot: Snake): self.bot = bot self.logger = logging.getLogger(__name__) + self.add_scale_check(self.is_owner) + + async def is_owner(self, ctx: MessageContext) -> bool: + """Checks if author is bot owner.""" + return ctx.author.id == self.bot.owner.id @msg_command(name="tail") async def _tail(self, ctx: MessageContext, count: int = 10) -> None: - if ctx.author.id != self.bot.owner.id: - return lines = [] async with AIOFile("jarvis.log", "r") as af: async for line in LineReader(af): @@ -37,9 +40,6 @@ class BotutilCog(Scale): @msg_command(name="log") async def _log(self, ctx: MessageContext) -> None: - if ctx.author.id != self.bot.owner.id: - return - async with AIOFile("jarvis.log", "r") as af: with BytesIO() as file_bytes: raw = await af.read_bytes() @@ -50,9 +50,6 @@ class BotutilCog(Scale): @msg_command(name="crash") async def _crash(self, ctx: MessageContext) -> None: - if ctx.author.id != self.bot.owner.id: - return - raise Exception("As you wish")