Improve automsc command

This commit is contained in:
Nexus 2024-09-20 01:59:54 +01:00
parent 9e659f26bf
commit d6ed860bc3

View file

@ -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='<action: enable|disable|status>')
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.")