Add scale-level check instead of per-command check

This commit is contained in:
Zeva Rose 2022-04-30 20:12:43 -06:00
parent 4bf7e3785b
commit c854d2c2ba

View file

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