From d520b8b87c6d279cd9597767aeee2eb264462ccf Mon Sep 17 00:00:00 2001 From: Paillat Date: Tue, 15 Aug 2023 19:20:12 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(chat.py):=20add=20missing=20?= =?UTF-8?q?import=20statement=20for=20asyncio=20module=20=F0=9F=90=9B=20fi?= =?UTF-8?q?x(chat.py):=20fix=20import=20statement=20for=20banusr=20module?= =?UTF-8?q?=20=E2=9C=A8=20feat(chat.py):=20add=20functionality=20to=20ban?= =?UTF-8?q?=20and=20unban=20users=20with=20botator!ban=20and=20botator!unb?= =?UTF-8?q?an=20commands=20=E2=9C=A8=20feat(chat.py):=20add=20functionalit?= =?UTF-8?q?y=20to=20send=20messages=20from=20banned=20users=20after=20a=20?= =?UTF-8?q?delay=20=E2=9C=A8=20feat(banusr.py):=20create=20banusr=20module?= =?UTF-8?q?=20to=20handle=20banning=20and=20unbanning=20of=20users=20?= =?UTF-8?q?=E2=9C=A8=20feat(banusr.py):=20add=20functionality=20to=20ban?= =?UTF-8?q?=20a=20user=20by=20appending=20their=20ID=20to=20banend=5Fusers?= =?UTF-8?q?=20list=20=E2=9C=A8=20feat(banusr.py):=20add=20functionality=20?= =?UTF-8?q?to=20unban=20a=20user=20by=20removing=20their=20ID=20from=20ban?= =?UTF-8?q?end=5Fusers=20list?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cogs/chat.py | 18 ++++++++++++++++++ src/utils/banusr.py | 22 ++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 src/utils/banusr.py diff --git a/src/cogs/chat.py b/src/cogs/chat.py index 36b8af4..6b69064 100644 --- a/src/cogs/chat.py +++ b/src/cogs/chat.py @@ -4,9 +4,12 @@ from src.config import ( debug, webhook_url, ) +import asyncio import src.makeprompt as mp import aiohttp +from src.utils import banusr + class MyModal(discord.ui.Modal): def __init__(self, message): @@ -95,6 +98,21 @@ class Chat(discord.Cog): @discord.Cog.listener() async def on_message(self, message: discord.Message): + if await self.bot.is_owner(message.author): + if message.content.startswith("botator!ban"): + user2ban = message.content.split(" ")[1] + await banusr.banuser(user2ban) + await message.channel.send(f"User {user2ban} banned !") + return + if message.content.startswith("botator!unban"): + user2ban = message.content.split(" ")[1] + await banusr.unbanuser(user2ban) + await message.channel.send(f"User {user2ban} unbanned !") + return + if str(message.author.id) in banusr.banend_users: + await asyncio.sleep(2) + await message.channel.send(message.content) + return await mp.chat_process(self, message) @discord.slash_command(name="say", description="Say a message") diff --git a/src/utils/banusr.py b/src/utils/banusr.py new file mode 100644 index 0000000..cd82f49 --- /dev/null +++ b/src/utils/banusr.py @@ -0,0 +1,22 @@ +import os +import orjson + +banend_users_path = "./database/banend_users.json" +if not os.path.exists(banend_users_path): + with open(banend_users_path, "w", encoding="utf-8") as file: + file.write("[]") + +with open("./database/banend_users.json", "r", encoding="utf-8") as file: + banend_users = orjson.loads(file.read()) + + +async def banuser(id): + banend_users.append(id) + with open("./database/banend_users.json", "w", encoding="utf-8") as file: + file.write(orjson.dumps(banend_users).decode()) + + +async def unbanuser(id): + banend_users.remove(id) + with open("./database/banend_users.json", "w", encoding="utf-8") as file: + file.write(orjson.dumps(banend_users).decode())