Add !latest command

This commit is contained in:
Alexis Marie Wright 2018-12-07 00:06:10 -05:00
parent 4b2b2a1157
commit 43a0a83f0e
1 changed files with 10 additions and 0 deletions

10
bot.py
View File

@ -13,6 +13,7 @@ class CosmicBot(teambot.Handler):
self.commands = dict()
self.register_command("botlist",self.on_botlist)
self.register_command("roster",self.on_roster)
self.register_command("latest",self.on_latest)
self.register_command("admin",self.on_admin,True)
def register_command(self,name,action,is_admin=False):
self.commands[name] = dict(action=action,is_admin=is_admin)
@ -56,6 +57,15 @@ class CosmicBot(teambot.Handler):
for line in output:
line = re.sub("\s+"," ",line).split(" ",1)
self.say(channel,"{}: {} (by {})".format(nick,line[1],unhighlight_nick(line[0])))
def on_latest(self,channel,nick,count=5):
loglist = subprocess.check_output(["cat", "/var/gopher/listing.gophermap"]).decode("ascii").split("\n");
capped = False
count = int(count)
if count > 5:
count = 5 # don't spam the channel
self.say(channel, "{}: Latest {} entries...".format(nick, count))
for logline in loglist[:count]:
self.say(channel, "{}: {}".format(nick, logline.split("\t")[0][1:]))
if __name__=="__main__":
channels = "#cosmic".split()