idletime = multiprocessing.Value('i', 7200)
rsstime = multiprocessing.Value('i', 600)
+playing = multiprocessing.Value('b', False)
feeds = [
{ 'channel': 230340587474255872, 'description': 'GalNet', 'url': 'http://proxy.gonegeeky.com/edproxy/', 'date': False },
{ 'channel': 230340639458459649, 'description': 'Dev tracker', 'url': 'https://miggy.org/games/elite-dangerous/devtracker/ed-dev-posts.rss', 'summary': True },
]
greetings = [
- { 'channel': 222685317885329408, 'message': 'Welcome to Delta Squadron, take a look at #delta_rules and make yourself at home in the public lobby. If interested in joining please PM a member of the High Command or Council for assistance' },
- { 'channel': 225217541922881538, 'message': 'Welcome to Delta Squadron, take a look at #delta_rules and make yourself at home in the public lobby. If interested in joining please PM a member of the High Command or Council for assistance' }
+ { 'channel': 222685317885329408, 'message': 'Welcome to Catbot' },
+ { 'channel': 225217541922881538, 'message': 'Welcome to Delta Squadron, take a look at #delta_rules and make yourself at home in the public lobby. If interested in joining please PM a member of the High Command or Council for assistance', 'voice': 222103336483028993, 'sound': 'meow.wav' }
]
def open_url(url):
@asyncio.coroutine
def set_idle(idle):
yield from client.change_status(idle = idle)
+ for voice in list(client.voice_clients):
+ yield from voice.disconnect()
@asyncio.coroutine
def wake_up(force = False):
for response in ['om nom nom', '^-^', 'meow!', 'lick']:
said = yield from maybe_say(message.channel, response)
if said:
+ yield from maybe_play_sound(voice_channel_for_channel(message.channel), 'purr.wav', join = False)
return
yield from maybe_say(message.channel, 'purr', wake = False)
+ yield from maybe_play_sound(voice_channel_for_channel(message.channel), 'purr.wav', join = False)
@asyncio.coroutine
def do_edi(message, command, raw, p):
yield from set_role(member, 'Unassigned')
@asyncio.coroutine
-def greet(channel, member):
+def greet(channel, member, sound = True):
for greeting in greetings:
if greeting['channel'] != int(channel.id):
continue
log.info('Not sending greeting {}'.format(message))
else:
yield from say(channel, message)
+ if sound:
+ yield from play_greeting(greeting)
@asyncio.coroutine
def set_rss_permissions(feed):
return False
return True
+def voice_channel_for_channel(channel):
+ for voice in client.voice_clients:
+ if voice.server != channel.server:
+ continue
+ if not voice.is_connected:
+ continue
+ return voice.channel
+
+@asyncio.coroutine
+def maybe_play_sound(channel, filename, *, probability = 0.05, join = True):
+ if not channel or not filename:
+ log.warning('Missing channel and/or filename for play_sound()')
+ return False
+
+ if random.random() > probability:
+ log.debug("Didn't bother to play {}".format(filename))
+ return False
+
+ while playing.value:
+ yield from asyncio.sleep(1)
+
+ playing.value = True
+ voice = client.voice_client_in(channel.server)
+ if voice is None or voice.channel != channel:
+ if not join:
+ log.info('Not joining voice channel {} just to play {}'.format(channel, filename))
+ return False
+ log.debug('Moving to voice channel {}'.format(channel))
+ if voice is not None:
+ yield from client.move_to(channel)
+ else:
+ yield from client.join_voice_channel(channel)
+ voice = client.voice_client_in(channel.server)
+ if voice.channel != channel:
+ log.error("Can't move to voice channel {}".format(channel))
+ playing.value = False
+ return False
+ try:
+ log.info('Playing {} in channel {}'.format(filename, channel))
+ player = voice.create_ffmpeg_player(filename)
+ player.start()
+ while not player.is_done():
+ yield from asyncio.sleep(1)
+ playing.value = False
+ except:
+ log.error("Error creating ffpmeg player for {}".format(filename))
+ playing.value = False
+ return False
+
+@asyncio.coroutine
+def play_sound(channel, filename, *, join = True):
+ result = yield from maybe_play_sound(channel, filename, probability = 1.0, join = join)
+ return result
+
+@asyncio.coroutine
+def play_greeting(greeting):
+ if 'voice' not in greeting:
+ return
+ yield from play_sound(client.get_channel(str(greeting['voice'])), greeting['sound'])
+
+
@client.event
@asyncio.coroutine
def on_ready():
print('Greeting in {}'.format([channel.name for channel in channels]))
for channel in channels:
log.debug('Greeting in {}'.format(channel.name))
+ sound = True
for member in channel.server.members:
result = should_greet_member_in(channel, member)
if not result:
continue
- yield from greet(channel, member)
+ yield from greet(channel, member, sound)
+ sound = False
for member in client.get_all_members():
log.debug('Maybe unassigning {}'.format(member.name))
yield from set_unassigned(member)