From 2e9142f4f339c08e812be3299adc5f4e9ef7aec9 Mon Sep 17 00:00:00 2001 From: jweigele Date: Tue, 9 Aug 2022 16:44:40 -0700 Subject: [PATCH] !say command functionality, lightly tested --- grahbot.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/grahbot.py b/grahbot.py index 47c072e..0ca5912 100755 --- a/grahbot.py +++ b/grahbot.py @@ -339,6 +339,19 @@ class GrahDiscordBot(discord.Client, HornClient, HornProm): log.debug('Was asked to play {} but no voice channel'.format(filename)) + async def msg_say_channel(self, channel_name, text, guild): + channel = None + log.debug('Called say channel, trying to say "{}" in channel "{}" in guild {}'.format(text, channel_name, guild)) + for c in self.text_channels: + if c.name == channel_name and (not guild or c.guild == guild): + log.debug('Found a text channel matching name {}'.format(c, type(c))) + channel = c + log.debug('Sending text now') + if channel is None: + raise Exception('No such channel found') + await channel.send(text) + + async def msg_join_voice_channel(self, channel_name, guild): log.debug('Called join voice channel, trying to join channel "{}" in guild {}'.format(channel_name, guild)) for vc in self.voice_channels: @@ -452,6 +465,14 @@ class GrahDiscordBot(discord.Client, HornClient, HornProm): log.info('Was instructed to join {} guild {}'.format(' '.join(message.content.split(' ')[1:]), str(guild))) await self.msg_join_voice_channel(' '.join(message.content.split(' ')[1:]), guild=guild) + async def command_say(self, message, guild): + message_split = message.content.split(' ') + channel = message_split[1] + text = ' '.join(message_split[2:]) + log.info('Was instructed to say {} in channel {} guild {}'.format(text, channel, str(guild))) + await self.msg_say_channel(channel, text, guild=guild) + + async def command_play(self, message, guild): horn = ' '.join(message.content.split(' ')[1:]) log.info('Was instructed to play {}'.format(horn)) -- 2.30.2