Make task state accessible to the handler, fix up task some, and add commands
This commit is contained in:
parent
cc9ce6041b
commit
df35d00b5d
23
bot.py
23
bot.py
|
@ -16,18 +16,31 @@ class RadioBot(teambot.Handler):
|
||||||
resp = json.loads(f.read().rstrip())
|
resp = json.loads(f.read().rstrip())
|
||||||
if resp["dj"] is not None and not state.get("dj_live",False):
|
if resp["dj"] is not None and not state.get("dj_live",False):
|
||||||
bot.say(bot.channels[0],"{} is now live!".format(resp["dj"]))
|
bot.say(bot.channels[0],"{} is now live!".format(resp["dj"]))
|
||||||
|
state["dj"] = resp["dj"]
|
||||||
state["dj_live"]=True
|
state["dj_live"]=True
|
||||||
|
if resp["dj"] is None and state.get("dj_live",True):
|
||||||
|
state["dj_live"]=False
|
||||||
if resp["song"]!=state.get("song") or resp["listeners"]!=state.get("listeners"):
|
if resp["song"]!=state.get("song") or resp["listeners"]!=state.get("listeners"):
|
||||||
bot.say(bot.channels[0],"now playing: {} ({!s} listeners{})".format(resp["song"],resp["listeners"],(", played by "+resp["dj"] if resp["dj"] is not None else "")))
|
bot.say(bot.channels[0],"now playing: {} ({!s} listeners{})".format(resp["song"],resp["listeners"],(", played by "+resp["dj"] if resp["dj"] is not None else "")))
|
||||||
state["song"]=resp["song"]
|
state["song"]=resp["song"]
|
||||||
state["listeners"]=resp["listeners"]
|
state["listeners"]=resp["listeners"]
|
||||||
|
basestate["handler"].task_state = state
|
||||||
return state
|
return state
|
||||||
def on_pubmsg(self,channel,nick,text):
|
def on_pubmsg(self,channel,nick,text):
|
||||||
if nick.startswith("khuxkm") and text.rstrip()=="!down":
|
if text.startswith(self._bot.bot_nick+": "):
|
||||||
self.tasks.stop()
|
cmd = text[len(self._bot.bot_nick+": "):].strip()
|
||||||
self._bot.die("Stopping...")
|
if self.event.source.userhost=="khuxkm@oper.tilde.chat" and cmd=="down":
|
||||||
else:
|
self.tasks.stop()
|
||||||
self.say(channel,json.dumps(self.channels))
|
self._bot.die("Stopping...")
|
||||||
|
elif cmd=="dj":
|
||||||
|
if self.task_state["dj_live"]:
|
||||||
|
self.say(channel,nick+": {} is the current dj!".format(self.task_state["dj"]))
|
||||||
|
else:
|
||||||
|
self.say(channel,nick+": nobody is live right now.")
|
||||||
|
elif cmd=="nowplaying":
|
||||||
|
self.say(channel,nick+": now playing: {} ({!s} listeners{})".format(self.task_state["song"],self.task_state["listeners"],(", played by "+self.task_state["dj"] if self.task_state["dj_live"] else "")))
|
||||||
|
elif text.strip()=="!botlist":
|
||||||
|
self.say(channel,"Maintainer: khuxkm@tilde.team | your friendly neighborhood radio bot | https://tildegit.org/khuxkm/radiobot")
|
||||||
|
|
||||||
if __name__=="__main__":
|
if __name__=="__main__":
|
||||||
if not fs.exists("channels.txt"):
|
if not fs.exists("channels.txt"):
|
||||||
|
|
Loading…
Reference in New Issue