chiark / gitweb /
blame: Allow `~blame #last 2' etc. master
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 30 May 2019 11:03:31 +0000 (12:03 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 19 Jun 2019 11:40:01 +0000 (12:40 +0100)
Ie,
  ~blame #last 1   =  ~blame #last
  ~blame #last 2   =  the last-but-one fish
  ~blame #last 3   =  the last-but-two fish
etc.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
---
v2: Fixed off-by-one error in commit message.

commands.py

index d6ba530..721089d 100755 (executable)
@@ -333,7 +333,14 @@ def blameq(bot,cmd,nick,conn,public,fishpond,cfgs):
     cwhat=' '.join(clist[2:])
     kindsfile = "fish?"
     if clist[1]=="#last":
-        try: lmsg, lcfg = fishpond.last[0]
+        try:
+            n = abs(int(clist[2]))-1
+            if n < 0: raise ValueError
+        except IndexError: n = 0
+        except ValueError:
+            bot.automsg(public,nick,"Huh?")
+            return
+        try: lmsg, lcfg = fishpond.last[n]
         except IndexError:
            bot.automsg(public,nick,"Nothing")
            return