2018-11-26 20:05:36 +00:00
|
|
|
import teambot, sys, tasks, json
|
2018-11-25 22:52:38 +00:00
|
|
|
import os.path as fs
|
|
|
|
|
|
|
|
class RadioBot(teambot.Handler):
|
2018-11-26 01:19:43 +00:00
|
|
|
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))
|
2018-11-26 20:05:36 +00:00
|
|
|
self.channels = [x.split()[0] for x in self._bot.chanlist]
|
2018-11-26 01:19:43 +00:00
|
|
|
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
|
2018-11-25 22:52:38 +00:00
|
|
|
def on_pubmsg(self,channel,nick,text):
|
2018-11-26 01:19:43 +00:00
|
|
|
if nick.startswith("khuxkm") and text.rstrip()=="!down":
|
|
|
|
self.tasks.stop()
|
|
|
|
self._bot.die("Stopping...")
|
2018-11-26 20:05:36 +00:00
|
|
|
else:
|
|
|
|
self.say(channel,json.dumps(self.channels))
|
2018-11-25 22:52:38 +00:00
|
|
|
|
|
|
|
if __name__=="__main__":
|
|
|
|
if not fs.exists("channels.txt"):
|
|
|
|
print("ERROR: No channels.txt. Use channels.txt.example as an example.")
|
|
|
|
sys.exit(1)
|
|
|
|
with open("channels.txt") as f:
|
|
|
|
channels = [l.rstrip() for l in f if l.rstrip()]
|
|
|
|
bot = teambot.TeamBot(channels,"radiobot2","localhost",chandler=RadioBot)
|
|
|
|
bot.start()
|