From f3939b6a5a6f5c86004f0eafad2e0e1e34bbce4f Mon Sep 17 00:00:00 2001 From: ChUrl Date: Fri, 28 Oct 2022 15:38:23 +0200 Subject: [PATCH] transition to slash commands (todo: voicelines) --- bot.py | 193 +++++++++++++++------------------------------------------ 1 file changed, 50 insertions(+), 143 deletions(-) diff --git a/bot.py b/bot.py index 2f5ebc8..84d5a91 100644 --- a/bot.py +++ b/bot.py @@ -14,10 +14,8 @@ from rich.traceback import install install(show_locals=True) # DONE: Migrate back to discord.py -# TODO: Rewrite bot with slash commands (and making actual use of discord.py) +# DONE: Rewrite bot with slash commands (and making actual use of discord.py) # TODO: yt-dlp music support -# TODO: Send messages only to heidispam channel -# TODO: Print status messages to heidispam # TODO: Somehow upload voicelines more easily (from discord voice message?) # TODO: Reenable text/quote generation, allow uploading of training text files, allow switching "personalities" # TODO: Zalgo generator @@ -33,10 +31,6 @@ class HeidiClient(discord.Client): # Separate object that keeps all application command state self.tree = app_commands.CommandTree(self) - # TODO: Replace with slash commands - self.prefix = "Heidi, " - self.prefix_regex = "^" + self.prefix - # self.models = Models() # scraped model list # automatic actions on all messages @@ -47,26 +41,6 @@ class HeidiClient(discord.Client): lambda m: "jeremy" in m.author.nick.lower(): self._autoreact_to_jeremy } - # TODO: Replace these by slash commands - # explicit commands - self.matchers = { - "Hilfe$": self.show_help, - "Heidi!$": self.say_name, - - # GNTM stuff - # "wer ist dabei\\?$": self.list_models_in, - # "wer ist raus\\?$": self.list_models_out, - # "gib Bild von .+$": self.show_model_picture, - "gib Link$": self.show_link, - - # Fun stuff - "welche Farbe .+\\?": self.random_color, - ".+, ja oder nein\\?": self.magic_shell, - "wähle: (.+,?)+$": self.choose, - "sprechen": self.list_voicelines, - "sag .+$": self.say_voiceline - } - # Synchronize commands to guilds async def setup_hook(self): self.tree.copy_global_to(guild=LINUS_GUILD) @@ -75,51 +49,8 @@ class HeidiClient(discord.Client): self.tree.copy_global_to(guild=TEST_GUILD) await self.tree.sync(guild=TEST_GUILD) - # Helpers ------------------------------------------------------------------------------------ - - def _help_text(self): - """ - Generate help-string from docstrings of matchers and triggers - """ - docstrings_triggers = [ - " - " + str(func.__doc__).strip() for func in self.auto_triggers.values() - ] - docstrings_matchers = [ - " - " + str(func.__doc__).strip() for func in self.matchers.values() - ] - - response = 'Präfix: "' + self.prefix + '" (mit Leerzeichen)\n' - response += "--------------------------------------------------\n" - - response += "Automatisch:\n" - response += "\n".join(docstrings_triggers) - - response += "\n\nCommands:\n" - response += "\n".join(docstrings_matchers) - - return response - - def _match(self, matcher, message): - """ - Check if a string matches against prefix + matcher (case-insensitive) - """ - return re.match(self.prefix_regex + matcher, message.content, re.IGNORECASE) - # Commands ----------------------------------------------------------------------------------- - async def show_help(self, message): - """ - Hilfe (Senpai UwU) - """ - await message.channel.send(self._help_text()) - - @staticmethod - async def say_name(message): - """ - Heidi! - """ - await message.channel.send("HEIDI!") - # async def list_models_in(self, message): # """ # wer ist dabei? @@ -142,68 +73,6 @@ class HeidiClient(discord.Client): # picture.set_footer(text=name) # await message.channel.send(embed=picture) - @staticmethod - async def magic_shell(message): - """ - , ja oder nein? - """ - choices = [ - "Ja!", - "Jo.", - "Total!", - "Natürlich.", - "Nein!", - "Nö.", - "Nä.", - "Niemals!", - ] - await message.channel.send(random.choice(choices)) - - # TODO: Accept multi-word inputs: "Heidi, wähle: Ipp ist dumm, ich bin dumm" - @staticmethod - async def choose(message): - """ - wähle: