Merge branch 'latest-regex' of tomasino/cosmicbot into master

This commit is contained in:
Robert Miles 2019-02-13 14:18:35 -05:00 committed by Gitea
commit bfe88e2e5e
1 changed files with 9 additions and 6 deletions

15
bot.py
View File

@ -71,12 +71,15 @@ class CosmicBot(teambot.Handler):
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):
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")))
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("ascii").split("\n")
output = filter(None,output)
for line in output: