Add task infrastructure
This commit is contained in:
parent
b0304fee32
commit
1099070b5b
16
bot.py
16
bot.py
|
@ -1,9 +1,21 @@
|
|||
import teambot, sys
|
||||
import teambot, sys, tasks
|
||||
import os.path as fs
|
||||
|
||||
class RadioBot(teambot.Handler):
|
||||
def __init__(self,*args):
|
||||
super(RadioBot,self).__init__(*args)
|
||||
self.tasks = tasks.TaskPool(handler=self)
|
||||
self.tasks.add_coroutine(self.check_nowplaying,1,dict(now_playing="",dj=None))
|
||||
self.channels = [x.split()[0] for x in args[0].channels]
|
||||
self.tasks.run()
|
||||
def check_nowplaying(self,state,basestate):
|
||||
with open(fs.expanduser("~ben/public_html/radio/now_playing.txt")) as f:
|
||||
text = f.read().rstrip()
|
||||
print(text) #TODO: implement parsing
|
||||
def on_pubmsg(self,channel,nick,text):
|
||||
pass # change this
|
||||
if nick.startswith("khuxkm") and text.rstrip()=="!down":
|
||||
self.tasks.stop()
|
||||
self._bot.die("Stopping...")
|
||||
|
||||
if __name__=="__main__":
|
||||
if not fs.exists("channels.txt"):
|
||||
|
|
Loading…
Reference in New Issue