diff --git a/bot.py b/bot.py index 1ca9c20..5c808b7 100644 --- a/bot.py +++ b/bot.py @@ -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: