all repos — paprika @ 5d2368994a7887c962696739070e16398fc2e8ac

go rewrite of taigabot

fix seen... again
Anthony DeDominic adedomin@gmail.com
Tue, 18 Jan 2022 08:33:02 -0500
commit

5d2368994a7887c962696739070e16398fc2e8ac

parent

db1b9b0a0c4855bc2946ef41aa87ce019a33c73e

1 files changed, 35 insertions(+), 35 deletions(-)

jump to
M plugins/seen.goplugins/seen.go

@@ -37,48 +37,48 @@ var reply string

if m.Command == "PRIVMSG" && strings.HasPrefix(m.Trailing(), ".seen") { params := strings.SplitN(m.Trailing(), " ", 3) if len(params) != 2 { - return "Usage: .seen <nickname>", nil - } + reply = "Usage: .seen <nickname>" + } else { + nameKey := database.ToKey("seen", params[1]) + lastS, err := database.DB.Get(nameKey) + if err == badger.ErrKeyNotFound { + reply = fmt.Sprintf("I have not seen %s", params[1]) + } else if err != nil { + return "", err + } else { + var lastSeen LastSeenInfo + err = gob.NewDecoder(bytes.NewReader(lastS)).Decode(&lastSeen) + if err != nil { + return "", err + } - nameKey := database.ToKey("seen", params[1]) - lastS, err := database.DB.Get(nameKey) - if err == badger.ErrKeyNotFound { - return fmt.Sprintf("I have not seen %s", params[1]), nil - } else if err != nil { - return "", err - } + humanized := humanize.Time(lastSeen.Time) - var lastSeen LastSeenInfo - err = gob.NewDecoder(bytes.NewReader(lastS)).Decode(&lastSeen) - if err != nil { - return "", err - } - - humanized := humanize.Time(lastSeen.Time) - - // Don't want "now ago". - if humanized != "now" { - humanized = humanized + " ago" - } + // Don't want "now ago". + if humanized != "now" { + humanized = humanized + " ago" + } - if lastSeen.Doing == "PRIVMSG" { - reply = fmt.Sprintf( - "\x02%s\x02 was last seen %s, saying: %s", - params[1], humanized, - lastSeen.Message, - ) - } else { - reply = fmt.Sprintf( - "\x02%s\x02 was last seen %s, doing: %s", - params[1], humanized, - lastSeen.Doing, - ) + if lastSeen.Doing == "PRIVMSG" { + reply = fmt.Sprintf( + "\x02%s\x02 was last seen %s, saying: %s", + params[1], humanized, + lastSeen.Message, + ) + } else { + reply = fmt.Sprintf( + "\x02%s\x02 was last seen %s, doing: %s", + params[1], humanized, + lastSeen.Doing, + ) + } + } } } seenDoing := LastSeenInfo{ Message: m.Trailing(), - Doing: m.Command, + Doing: m.Command, // We just saw the user, so. Time: time.Now(), }

@@ -88,7 +88,7 @@ err := gob.NewEncoder(&enc).Encode(seenDoing)

if err != nil { return "", err } - + nameKey := database.ToKey("seen", m.Name) database.DB.Set(nameKey, enc.Bytes())