From 94299e03367d5e124bf51cffc3ca93dce113f912 Mon Sep 17 00:00:00 2001 From: voXrey <72698969+voXrey@users.noreply.github.com> Date: Wed, 19 Jun 2024 16:28:31 +0200 Subject: [PATCH] "Je suis" feature --- main.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 8177789..4df020d 100644 --- a/main.py +++ b/main.py @@ -42,12 +42,28 @@ class MyClient(commands.Bot): print(f"Admins : {', '.join([m.name for m in team.members])}") print('------') - async def on_message(self, msg): - p = re.compile("[qQ]uoi[ \\.!?;\"»]*$") - print(f"{msg!r}") - if p.search(msg.content) is not None: + async def on_message(self, msg: discord.Message): + # quoicoubot + quoi = re.compile("[qQ]uoi[ \\.!?;\"»]*$") + if quoi.search(msg.content) is not None: await msg.reply("Quoicoubeh !") + # je suis + je_suis = "je suis " + if msg.content.lower().startswith(je_suis): # détection + words = msg.content[len(je_suis):].split(' ') + new_pseudo = "" # pseudo creation (do not split a word) + for word in words: + if (len(new_pseudo) + len(word) + 1) > 32: + break + new_pseudo += " " + word + if new_pseudo != "": + member = msg.author + try: + await member.edit(nick=new_pseudo, reason="Il est " + new_pseudo) + except discord.Forbidden: + pass + if __name__ == "__main__": client = MyClient()