Improve automsc command
This commit is contained in:
parent
9e659f26bf
commit
d6ed860bc3
1 changed files with 21 additions and 26 deletions
|
@ -253,14 +253,14 @@ class MSCGetter(niobot.Module):
|
||||||
else:
|
else:
|
||||||
return await ctx.respond("Unknown operation.")
|
return await ctx.respond("Unknown operation.")
|
||||||
|
|
||||||
@niobot.command("automsc.enable")
|
@niobot.command("automsc", usage='<action: enable|disable|status>')
|
||||||
async def auto_msc_enable(self, ctx: niobot.Context):
|
async def automsc_manager(self, ctx: niobot.Context, action: str):
|
||||||
"""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:
|
Enables or disables automatic MSC linking.
|
||||||
return await ctx.respond(
|
"""
|
||||||
f"You need to have at least a power level of 50 to use this (you have {sp})."
|
action = action.casefold()
|
||||||
)
|
|
||||||
key = self.bot.redis_key(ctx.room.room_id, "auto_msc.enabled")
|
key = self.bot.redis_key(ctx.room.room_id, "auto_msc.enabled")
|
||||||
|
if action == "enable":
|
||||||
exists = await self.bot.redis.get(key)
|
exists = await self.bot.redis.get(key)
|
||||||
if exists:
|
if exists:
|
||||||
return await ctx.respond("AutoMSC is already enabled in this room.")
|
return await ctx.respond("AutoMSC is already enabled in this room.")
|
||||||
|
@ -269,21 +269,16 @@ class MSCGetter(niobot.Module):
|
||||||
return await self.bot.add_reaction(
|
return await self.bot.add_reaction(
|
||||||
ctx.room, ctx.message, "\N{WHITE HEAVY CHECK MARK}"
|
ctx.room, ctx.message, "\N{WHITE HEAVY CHECK MARK}"
|
||||||
)
|
)
|
||||||
|
elif action == "status":
|
||||||
@niobot.command("automsc.disable")
|
enabled = bool(await self.bot.redis.get(key))
|
||||||
async def auto_msc_disable(self, ctx: niobot.Context):
|
text = "AutoMSC detection & linking is **{}**."
|
||||||
"""Disables automatic MSC linking. Requires a power level of at least 50."""
|
text = text.format({True: "**enabled**", False: "**disabled**"}[enabled])
|
||||||
if (sp := ctx.room.power_levels.users.get(ctx.message.sender, -999)) < 50:
|
return await ctx.respond(text)
|
||||||
return await ctx.respond(
|
elif action == "delete":
|
||||||
f"You need to have at least a power level of 50 to use this (you have {sp})."
|
|
||||||
)
|
|
||||||
key = self.bot.redis_key(ctx.room.room_id, "auto_msc.enabled")
|
|
||||||
exists = await self.bot.redis.get(key)
|
|
||||||
if exists:
|
|
||||||
await self.bot.redis.delete(key)
|
await self.bot.redis.delete(key)
|
||||||
await self.bot.redis.save()
|
await self.bot.redis.save()
|
||||||
await self.bot.add_reaction(
|
await self.bot.add_reaction(
|
||||||
ctx.room, ctx.message, "\N{WHITE HEAVY CHECK MARK}"
|
ctx.room, ctx.message, "\N{WHITE HEAVY CHECK MARK}"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
return await ctx.respond("AutoMSC is already disabled in this room.")
|
return await ctx.respond("Unrecognised action.")
|
||||||
|
|
Loading…
Reference in a new issue