def set_voice(self, guild, voice):
- print('Setting voice for guild {} to {}'.format(guild, voice))
+ log.debug('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):
log.debug('Declaring exchange')
exchange = await channel.declare_exchange(self.rabbit_config['exchange'], 'topic', passive=True)
- # we have 10 users. Set up a queue for each of them
- # use different channels to avoid any interference
- # during message consumption, just in case.
self.channel = await connection.open_channel()
log.debug('Declaring queue')
self.queue = await self.channel.declare_queue('horn_listener')
await self.queue.consume(self.process_msg, no_ack=True)
log.debug('Consumed a thing')
- # deliver 10 messages to each user
while (True):
await asyncio.sleep(1)
#msg = asynqp.Message("omg here is the time {}".format(datetime.datetime.now()))
async def msg_join_voice_channel(self, channel_name, guild):
- log.debug('Called join voice channel')
+ log.debug('Called join voice channel, trying to join channel "{}" in guild {}'.format(channel_name, guild))
for vc in self.voice_channels:
if vc.name == channel_name and (not guild or vc.guild == guild):
log.debug('Found a voice channel to join {} {}'.format(vc, type(vc)))
- if self.state.get_voice(guild):
+ if self.state.get_voice(guild) is not None:
if vc != self.state.get_voice(guild).channel:
- self.state.set_voice(guild, await self.state.get_voice(guild).move_to(vc))
+ log.debug('Already have a client {}, awaiting the move to {}'.format(self.state.get_voice(guild), vc))
+ await self.state.get_voice(guild).move_to(vc)
else:
self.state.set_voice(guild, await vc.connect())
log.info('Joined voice channel {} {} (id: {})'.format(guild, vc.name, vc.id))
def member_guild_list(self, member):
+ retval = []
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]
+ log.debug('Guild {} Member {}'.format(x, member))
+ if member.id in [y.id for y in x.members]:
+ retval.append(x)
+ return retval
def contextual_guild(self, message):
channel = message.channel
log.debug('Setting member {} to guild {}'.format(message.channel.recipient, guild.name))
self.member_guilds[message.channel.recipient] = [guild]
self.state.set_user_guild(message.channel.recipient, guild)
- break
+ return
+ else:
+ log.debug('Guild {} does not match {}'.format(guild.name, guild_name))
+ log.debug('No guild found for {}'.format(guild))
async def command_sleep(self, message, guild):
await asyncio.sleep(5)
await message.channel.send('Done sleeping')
async def command_join(self, message, guild):
- log.info('Was instructed to join {} guild {}'.format(message.content.split(' ')[1], str(guild)))
- await self.msg_join_voice_channel(message.content.split(' ')[1], guild=guild)
+ 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_play(self, message, guild):
- log.info('Was instructed to play {}'.format(message.content.split(' ')[1]))
+ log.info('Was instructed to play {}'.format(' '.join(message.content.split(' ')[1:])))
await self.msg_play_sound(name=' '.join(message.content.split(' ')[1:]), guild=guild)
async def command_list(self, message, guild):
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]))
+ log.debug('Guild is {}'.format(guilds[0]))
guild = guilds[0]
func = self.get_command_func(potential_command)
except Exception as e:
await self.oh_no(message.channel, e)
+ async def on_voice_state_update(self, member, before, after):
+ if self.user.id == member.id:
+ log.debug('Something happened to me in voice! Member {} before {} after {}'.format(member, before, after))
+ if before.channel is not None and after.channel is not None and before.channel != after.channel:
+ log.debug('Before != after and channels differ, setting the VC appropriately')
+ # try to get the already established VC and resave
+ self.state.set_voice(after.channel.guild, self.state.get_voice(after.channel.guild))
+
+
if __name__ == '__main__':
config = json.load(open('{}/config.json'.format(PERSISTENT_DIR), 'r'))
intents = discord.Intents.default()
intents.members = True
+ intents.voice_states = True
bot = GrahDiscordBot(config, intents=intents)