summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Perry <nathan@meta.sc>2016-04-14 21:41:08 -0400
committerNathan Perry <nathan@meta.sc>2016-04-14 21:41:08 -0400
commitd9ed9e568a9ad245d621712bb1a35b285df16561 (patch)
treed2acde4f67396ac03e2836a62a3076c9213ff78f
parent10d5d032a652585edf788d663ecc51758829ffb6 (diff)
ugly SIGINT handling and clean up enqueue_video
-rw-r--r--bot.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/bot.py b/bot.py
index c6cceed..c571b7d 100644
--- a/bot.py
+++ b/bot.py
@@ -2,6 +2,7 @@ import discord
import logging
import re
import yaml
+from signal import signal, SIGINT
from asyncio import Queue, QueueEmpty, sleep
from urllib.parse import urlsplit
from functools import partial
@@ -81,7 +82,7 @@ async def on_message(message):
url = url.geturl()
logger.debug('playing video from url \'{}\''.format(url))
- enqueue_video((url, message))
+ enqueue_video(url, message)
async def pause():
@@ -119,18 +120,18 @@ async def stop_client():
await stop_player()
-async def enqueue_video(pair):
+async def enqueue_video(url, message):
await connect_voice()
if not client.is_voice_connected():
- client.send_message(pair[1].channel, 'go fuck yourself. voice isn\'t working.', tts=True)
+ client.send_message(message.channel, 'go fuck yourself. voice isn\'t working.', tts=True)
return
if queue.full():
- client.send_message(pair[1].channel, 'fuck you. wait for the other videos.', tts=True)
+ client.send_message(message.channel, 'fuck you. wait for the other videos.', tts=True)
return
- queue.put(pair)
+ queue.put((url, message))
async def connect_voice():
@@ -229,6 +230,8 @@ async def run_video():
run_video()
+## this is a harsh exit, but I don't want to deal with closing out the task waiting in run_video or C-c C-c
+signal(SIGINT, lambda _, __: exit(0))
run_video()
client.run(config['username'], config['password'])