From d6ed860bc34d6e9d758c8994253915e41208a6f1 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Fri, 20 Sep 2024 01:59:54 +0100 Subject: [PATCH] Improve automsc command --- app/modules/msc_getter.py | 47 +++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/app/modules/msc_getter.py b/app/modules/msc_getter.py index a20b95d..2bdf147 100644 --- a/app/modules/msc_getter.py +++ b/app/modules/msc_getter.py @@ -253,37 +253,32 @@ class MSCGetter(niobot.Module): else: return await ctx.respond("Unknown operation.") - @niobot.command("automsc.enable") - async def auto_msc_enable(self, ctx: niobot.Context): - """Automatically enables MSC linking. Requires a power level of at least 50.""" - if (sp := ctx.room.power_levels.users.get(ctx.message.sender, -999)) < 50: - return await ctx.respond( - f"You need to have at least a power level of 50 to use this (you have {sp})." - ) + @niobot.command("automsc", usage='') + async def automsc_manager(self, ctx: niobot.Context, action: str): + """ + Enables or disables automatic MSC linking. + """ + action = action.casefold() key = self.bot.redis_key(ctx.room.room_id, "auto_msc.enabled") - exists = await self.bot.redis.get(key) - if exists: - return await ctx.respond("AutoMSC is already enabled in this room.") - await self.bot.redis.set(key, 1) - await self.bot.redis.save() - return await self.bot.add_reaction( - ctx.room, ctx.message, "\N{WHITE HEAVY CHECK MARK}" - ) - - @niobot.command("automsc.disable") - async def auto_msc_disable(self, ctx: niobot.Context): - """Disables automatic MSC linking. Requires a power level of at least 50.""" - if (sp := ctx.room.power_levels.users.get(ctx.message.sender, -999)) < 50: - return await ctx.respond( - f"You need to have at least a power level of 50 to use this (you have {sp})." + if action == "enable": + exists = await self.bot.redis.get(key) + if exists: + return await ctx.respond("AutoMSC is already enabled in this room.") + await self.bot.redis.set(key, 1) + await self.bot.redis.save() + return await self.bot.add_reaction( + ctx.room, ctx.message, "\N{WHITE HEAVY CHECK MARK}" ) - key = self.bot.redis_key(ctx.room.room_id, "auto_msc.enabled") - exists = await self.bot.redis.get(key) - if exists: + elif action == "status": + enabled = bool(await self.bot.redis.get(key)) + text = "AutoMSC detection & linking is **{}**." + text = text.format({True: "**enabled**", False: "**disabled**"}[enabled]) + return await ctx.respond(text) + elif action == "delete": await self.bot.redis.delete(key) await self.bot.redis.save() await self.bot.add_reaction( ctx.room, ctx.message, "\N{WHITE HEAVY CHECK MARK}" ) else: - return await ctx.respond("AutoMSC is already disabled in this room.") + return await ctx.respond("Unrecognised action.")