cosmicbot/commands/latest.py

18 lines
718 B
Python

import plugin, re, subprocess
@plugin.command("latest","<count/filter>")
def on_latest(self,channel,nick,count="5"):
if re.match(r"\d+",count):
count = int(count)
if count < 1:
count = 1 # ...nice try, smartass
if count > 5:
count = 5 # don't spam the channel
self.say(channel, "{}: Latest {} {}. (See cosmic.voyage for more!)".format(nick, count, (count == 1 and "entry" or "entries")))
else:
self.say(channel, "{}: Latest entries matching '{}'. (See cosmic.voyage for more!)".format(nick, count))
output = subprocess.check_output(["/usr/local/bin/latest",str(count)]).decode("utf-8").split("\n")
output = filter(None,output)
for line in output:
self.say(channel,"{}: {}".format(nick,line))