!say command functionality, lightly tested
authorjweigele <jweigele@local>
Tue, 9 Aug 2022 23:44:40 +0000 (16:44 -0700)
committerjweigele <jweigele@local>
Tue, 9 Aug 2022 23:44:40 +0000 (16:44 -0700)
grahbot.py

index 47c072e9ae01c841a795551ec5100983b1854d4f..0ca591267ca10d6c645f4bbe1b49982abe03f999 100755 (executable)
@@ -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))