Implement botbans

This commit is contained in:
Nexus 2024-09-18 21:03:25 +01:00
parent 034e8cef66
commit eb2785ebf2
2 changed files with 34 additions and 0 deletions

View file

@ -66,6 +66,15 @@ class NonsenseBot(niobot.NioBot):
await super().start(**kwargs) await super().start(**kwargs)
async def process_message(self, room, message):
if self.redis:
room_banned = await self.redis.get(self.redis_key("botban", room.room_id))
user_banned = await self.redis.get(self.redis_key("botban", message.sender))
if room_banned or user_banned:
self.log.debug("Ignoring banned room/user: %r - %r", room, message)
return
return await super().process_message(room, message)
bot = NonsenseBot( bot = NonsenseBot(
homeserver=config["bot"]["homeserver"], homeserver=config["bot"]["homeserver"],

View file

@ -265,3 +265,28 @@ class EvalModule(niobot.Module):
return await ctx.respond(repr(response)) return await ctx.respond(repr(response))
case _: case _:
return await ctx.respond("Unknown operation.") return await ctx.respond("Unknown operation.")
@niobot.command()
@niobot.is_owner()
async def botban(self, ctx: niobot.Context, target: str):
"""Bans someone from the bot."""
key = self.bot.redis_key("botban", target)
if await self.bot.redis.get(key) is not None:
return await ctx.respond("User/room is already banned.")
await self.bot.redis.set(key, 1)
return await ctx.respond("ok")
@niobot.command()
@niobot.is_owner()
async def botbanlist(self, ctx: niobot.Context):
return await ctx.respond("idk, keys are hashed lol")
@niobot.command()
@niobot.is_owner()
async def botunban(self, ctx: niobot.Context, target: str):
"""Unbans someone from the bot."""
key = self.bot.redis_key("botban", target)
if await self.bot.redis.get(key) is None:
return await ctx.respond("User/room is not banned.")
await self.bot.redis.delete(key)
return await ctx.respond("ok")