Some debug prints, update discord API section for intents, fix bug in setting voice...
authorjweigele <jweigele@local>
Sun, 13 Jun 2021 22:14:24 +0000 (15:14 -0700)
committerjweigele <jweigele@local>
Sun, 13 Jun 2021 22:14:24 +0000 (15:14 -0700)
grahbot.py

index 173adb37ab45657c6538ef12c758802eb2b49bb9..1b7d9387cba3cd8745ed06974ec76ea83e356f15 100755 (executable)
@@ -47,12 +47,19 @@ class GrahState(object):
 
 
     def set_voice(self, guild, voice):
+        print('Setting voice for guild {} to {}'.format(guild, voice))
         self.set_voice_by_id(guild.id, voice)
 
     def set_voice_by_id(self, guild_id, voice):
-        self.data['guild'][str(guild_id)] = voice.channel.id
-        if not self.voice[str(guild_id)]:
-            self.voice[str(guild_id)] = voice
+        if voice is None:
+            if str(guild_id) in self.data['guild']:
+                del self.data['guild'][str(guild_id)]
+            if str(guild_id) in self.voice:
+                del self.voice[str(guild_id)]
+        else:
+            self.data['guild'][str(guild_id)] = voice.channel.id
+            if not self.voice[str(guild_id)]:
+                self.voice[str(guild_id)] = voice
         self.save()
 
 
@@ -151,7 +158,7 @@ class GrahDiscordBot(discord.Client, HornClient):
         else:
             log.debug('Received a horn not for us: {}'.format(msg.body))
 
-    def __init__(self, config):
+    def __init__(self, config, intents=None):
         self.config = config
         self.player = None
         self.used = []
@@ -161,7 +168,7 @@ class GrahDiscordBot(discord.Client, HornClient):
         #self.horn_client = HornClient('config-piege.json')
         HornClient.__init__(self, config)
         self.rabbit = self.loop.create_task(self.rabbit_connect())
-        discord.Client.__init__(self, loop=self.loop)
+        discord.Client.__init__(self, loop=self.loop, intents=intents)
         self.loop_forever()
 
     def terminate_all(self, guild):
@@ -287,7 +294,7 @@ class GrahDiscordBot(discord.Client, HornClient):
         guild = discord.utils.get(self.guilds, id=guild_id)
         if self.state.get_voice(guild):
             self.terminate_all(guild=guild)
-            self.state.get_voice(guild).play(discord.FFmpegPCMAudio(filename))
+            self.state.get_voice(guild).play(discord.FFmpegOpusAudio(filename))
             #self.player.start()
         else:
             log.debug('Was asked to play {} but no voice channel'.format(filename))
@@ -352,6 +359,10 @@ class GrahDiscordBot(discord.Client, HornClient):
 
 
     def member_guild_list(self, member):
+        for x in self.guilds:
+            for member in x.members:
+                print('Guild {} Member {}'.format(x, member))
+            #print(x.members)
         return [x for x in self.guilds if member in x.members]
 
     def contextual_guild(self, message):
@@ -449,6 +460,7 @@ class GrahDiscordBot(discord.Client, HornClient):
             await message.channel.send('Too many guilds!!!\n{}'.format('\n'.join([str(x) for x in guilds])))
             return
         elif len(guilds) == 1:
+            print('Guild is {}'.format(guilds[0]))
             guild = guilds[0]
 
         func = self.get_command_func(potential_command)
@@ -465,4 +477,6 @@ class GrahDiscordBot(discord.Client, HornClient):
 
 if __name__ == '__main__':
     config = json.load(open('{}/config.json'.format(PERSISTENT_DIR), 'r'))
-    bot = GrahDiscordBot(config)
+    intents = discord.Intents.default()
+    intents.members = True
+    bot = GrahDiscordBot(config, intents=intents)