From eb2785ebf2815e20f76f0e9f73ff78f39dd29263 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Wed, 18 Sep 2024 21:03:25 +0100 Subject: [PATCH] Implement botbans --- app/main.py | 9 +++++++++ app/modules/evaluation.py | 25 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/app/main.py b/app/main.py index e093756..a44b688 100644 --- a/app/main.py +++ b/app/main.py @@ -66,6 +66,15 @@ class NonsenseBot(niobot.NioBot): 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( homeserver=config["bot"]["homeserver"], diff --git a/app/modules/evaluation.py b/app/modules/evaluation.py index fc27d0a..3e1cdb7 100644 --- a/app/modules/evaluation.py +++ b/app/modules/evaluation.py @@ -265,3 +265,28 @@ class EvalModule(niobot.Module): return await ctx.respond(repr(response)) case _: 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")