forked from khuxkm/cosmicbot
(sidecar) Mask highlight differently; fix roster
- Instead of using Unicode space magic, with which many clients have trouble, to mask highlights, do it with _underscores_. - Join roster arguments over spaces, so e.g. '!roster dei genetrix' behaves properly.
This commit is contained in:
parent
43a0a83f0e
commit
f07ff9ddbb
19
bot.py
19
bot.py
|
@ -1,15 +1,23 @@
|
|||
import teambot,tasks,rss,time,sys,subprocess,re
|
||||
|
||||
def unhighlight_nick (nick):
|
||||
return nick[0] + "\u200b" + nick[1:]
|
||||
return "_{}_".format(nick)
|
||||
|
||||
def newpost(post):
|
||||
return dict(
|
||||
title = post.title,
|
||||
link = post.link,
|
||||
published = post.published
|
||||
)
|
||||
|
||||
class CosmicBot(teambot.Handler):
|
||||
def __init__(self,bot):
|
||||
super(CosmicBot,self).__init__(bot)
|
||||
self.prefix = "!"
|
||||
self.tasks = tasks.TaskPool()
|
||||
self.tasks.add_coroutine(self.check_rss,60,dict(url="https://cosmic.voyage/rss.xml",known=[],channel="#cosmic"))
|
||||
self.tasks.add_coroutine(self.check_rss,12,dict(url="https://cosmic.voyage/rss.xml",known=[],channel="#cosmic"))
|
||||
self.tasks.load_state(0)
|
||||
self.known_posts = dict() # to be populated by check_rss
|
||||
self.commands = dict()
|
||||
self.register_command("botlist",self.on_botlist)
|
||||
self.register_command("roster",self.on_roster)
|
||||
|
@ -24,6 +32,7 @@ class CosmicBot(teambot.Handler):
|
|||
newtrans = rss.fetchNew(state["url"],memory)
|
||||
if newtrans:
|
||||
memory.extend(x.guid for x in newtrans)
|
||||
self.known_posts.extend(newpost(x) for x in newtrans)
|
||||
for trans in newtrans:
|
||||
self.say(state["channel"],"Transmission received: {transmission.title} ({transmission.link})".format(transmission=trans))
|
||||
time.sleep(1)
|
||||
|
@ -51,8 +60,8 @@ class CosmicBot(teambot.Handler):
|
|||
sys.exit(0)
|
||||
elif subcmd=="check":
|
||||
self.tasks.states[0] = self.check_rss(self.tasks.states[0],self.tasks.base_state)
|
||||
def on_roster(self,channel,nick,namecnt=""):
|
||||
output = subprocess.check_output(["/usr/local/bin/roster",namecnt]).decode("ascii").split("\n")
|
||||
def on_roster(self,channel,nick,*namecnt):
|
||||
output = subprocess.check_output(["/usr/local/bin/roster",' '.join(namecnt)]).decode("ascii").split("\n")
|
||||
output = filter(None,output)
|
||||
for line in output:
|
||||
line = re.sub("\s+"," ",line).split(" ",1)
|
||||
|
@ -63,7 +72,7 @@ class CosmicBot(teambot.Handler):
|
|||
count = int(count)
|
||||
if count > 5:
|
||||
count = 5 # don't spam the channel
|
||||
self.say(channel, "{}: Latest {} entries...".format(nick, count))
|
||||
self.say(channel, "{}: Latest {} entries. (See cosmic.voyage for more!)".format(nick, count))
|
||||
for logline in loglist[:count]:
|
||||
self.say(channel, "{}: {}".format(nick, logline.split("\t")[0][1:]))
|
||||
|
||||
|
|
Loading…
Reference in New Issue