From 5ebb403479660bddf03ff3c39e1cb45d33486ccc Mon Sep 17 00:00:00 2001 From: CMDR furrycat Date: Wed, 26 Oct 2016 21:12:37 +0100 Subject: [PATCH] Choose a voice channel based on member. --- app.py | 6 +++--- bot.py | 10 ++++++++++ plugins/announcements.py | 4 ++-- plugins/feeds.py | 4 ++-- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app.py b/app.py index fcb6149..18f1b3f 100644 --- a/app.py +++ b/app.py @@ -523,7 +523,7 @@ def do_commands(message, command, raw, non_admin): elif command == 'time': # time yield from bot.say(message.channel, bot.iso8601(int(time.time()))) - yield from bot.maybe_play_sound(bot.voice_channel_for_channel(message.channel), 'purr.wav', join = False) + yield from bot.maybe_play_sound(bot.voice_channel_for_user(message.author), 'purr.wav', join = False) return elif command in ['treat', 'stroke', 'fuss', 'pat']: @@ -535,11 +535,11 @@ def do_commands(message, command, raw, non_admin): for response in responses: said = yield from bot.maybe_say(message.channel, response) if said: - yield from bot.maybe_play_sound(bot.voice_channel_for_channel(message.channel), 'purr.wav', join = False) + yield from bot.maybe_play_sound(bot.voice_channel_for_user(message.author), 'purr.wav', join = False) return yield from bot.maybe_say(message.channel, 'purr', wake = False) - yield from bot.maybe_play_sound(bot.voice_channel_for_channel(message.channel), 'purr.wav', join = False) + yield from bot.maybe_play_sound(bot.voice_channel_for_user(message.author), 'purr.wav', join = False) @asyncio.coroutine def do_edi(message, command, raw, p): diff --git a/bot.py b/bot.py index d6de40e..b0e1fb6 100644 --- a/bot.py +++ b/bot.py @@ -190,6 +190,16 @@ def voice_channel_for_channel(channel): continue return voice.channel +def voice_channel_for_user(user): + for server in client.servers: + member = server.get_member(user.id) + if not member: + continue + voice_channel = member.voice_channel + if voice_channel is None: + if voice_channel.server in client.servers: + return voice_channel + @asyncio.coroutine def maybe_play_sound(channel, filename, *, probability = 0.05, join = True): if not channel or not filename: diff --git a/plugins/announcements.py b/plugins/announcements.py index 48c1842..eb1a00f 100644 --- a/plugins/announcements.py +++ b/plugins/announcements.py @@ -617,7 +617,7 @@ class Announcements(DBConnection): create['id'] = id log.info('Created announcement: {}'.format(create)) yield from bot.say(message.channel, id) - yield from bot.play_sound(bot.voice_channel_for_channel(message.channel), 'purr.wav', join = False) + yield from bot.play_sound(bot.voice_channel_for_user(message.author), 'purr.wav', join = False) else: log.info('Failed to create announcement: {}'.format(create)) yield from bot.say(message.channel, 'yelp!') @@ -641,7 +641,7 @@ class Announcements(DBConnection): if self.update_announcement(client, id, **update): log.info('Edited announcement {}: {}'.format(id, update)) yield from bot.say(message.channel, ', '.join([announcement_key(k) for k in update])) - yield from bot.play_sound(bot.voice_channel_for_channel(message.channel), 'purr.wav', join = False) + yield from bot.play_sound(bot.voice_channel_for_user(message.author), 'purr.wav', join = False) else: log.info('Failed to edit announcement {}: {}'.format(id, update)) yield from bot.say(message.channel, 'yelp!') diff --git a/plugins/feeds.py b/plugins/feeds.py index da5ff63..0a514fd 100644 --- a/plugins/feeds.py +++ b/plugins/feeds.py @@ -442,7 +442,7 @@ class Feeds(DBConnection): create['id'] = id log.info('Created feed: {}'.format(create)) yield from bot.say(message.channel, id) - yield from play_sound(voice_channel_for_channel(message.channel), 'purr.wav', join = False) + yield from play_sound(voice_channel_for_user(message.author), 'purr.wav', join = False) else: log.info('Failed to create feed: {}'.format(create)) yield from bot.say(message.channel, 'yelp!') @@ -466,7 +466,7 @@ class Feeds(DBConnection): if self.update_feed(client, id, **update): log.info('Edited feed {}: {}'.format(id, update)) yield from bot.say(message.channel, ', '.join([self.feed_key(k) for k in update])) - yield from play_sound(voice_channel_for_channel(message.channel), 'purr.wav', join = False) + yield from play_sound(voice_channel_for_user(message.author), 'purr.wav', join = False) else: log.info('Failed to edit feed {}: {}'.format(id, update)) yield from bot.say(message.channel, 'yelp!') -- 2.7.4