From a212804b8d161bafa215087a073c7fb8bcb92ef1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20M=C3=A4ki?= Date: Tue, 20 Feb 2024 13:05:29 +0000 Subject: [PATCH] message passing code --- ovos_PHAL_plugin_discord_bot/__init__.py | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/ovos_PHAL_plugin_discord_bot/__init__.py b/ovos_PHAL_plugin_discord_bot/__init__.py index f614520..cefaca9 100644 --- a/ovos_PHAL_plugin_discord_bot/__init__.py +++ b/ovos_PHAL_plugin_discord_bot/__init__.py @@ -48,6 +48,33 @@ class DiscordBotPlugin(PHALPlugin): LOG.info(f"Admin is {admin.name}") await admin.send("I'm now online") + # Discord event: Process incoming messages + @this.bot.event + async def on_message(message): + if message.author == bot.user: + return + + await bot.process_commands(message) + admin = await get_discord_user_by_id(self.config.get("admin_id")) + + if message.author == admin: + if message.content.lower().startswith("tell mycroft"): + # The message starts with "tell mycroft" + # Implement the action you want to take in response to this here. + # For example, you can extract the command from the message and respond accordingly. + command = message.content[len("tell mycroft"):].strip() # Remove "tell mycroft" and strip any leading/trailing spaces. + # Now, you can execute the command or respond accordingly based on the extracted command. + self.bus.emit( + Message( + "recognizer_loop:utterance", + { + 'utterances': [command], + 'lang': 'en-us' + } + ) + ) + await message.channel.send(f"Telling mycroft {command}") + QUEUE_POLL_INTERVAL = 0.2 @tasks.loop(seconds=QUEUE_POLL_INTERVAL) async def myLoop():