all repos — paprika @ f6eedab26bfdb778c676fd60259b531d25f66ad6

go rewrite of taigabot

Add last message
Anirudh Oppiliappan x@icyphox.sh
Sat, 01 Jan 2022 16:35:11 +0530
commit

f6eedab26bfdb778c676fd60259b531d25f66ad6

parent

59bc10a1b861af4a0035e8909e17995edec13ce2

1 files changed, 22 insertions(+), 4 deletions(-)

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

@@ -22,9 +22,19 @@ }

var LastSeen sync.Map +type LastSeenInfo struct { + // The last message the user sent. + Message string + // The last time this user was seen. + Time time.Time +} + func (Seen) Execute(m *irc.Message) (string, error) { - // we just saw this user so. - LastSeen.Store(m.Name, time.Now()) + LastSeen.Store(m.Name, LastSeenInfo{ + Message: m.Trailing(), + // We just saw the user, so. + Time: time.Now(), + }) if strings.HasPrefix(m.Params[1], ".seen") { params := strings.Split(m.Trailing(), " ")

@@ -33,9 +43,17 @@ return "Usage: .seen <nickname>", nil

} if seen, ok := LastSeen.Load(params[1]); ok { + humanized := humanize.Time(seen.(LastSeenInfo).Time) + + // Don't want "now ago". + if humanized != "now" { + humanized = humanized + " ago" + } + return fmt.Sprintf( - "\x02%s\x02 was last seen: %s", - params[1], humanize.Time(seen.(time.Time)), + "\x02%s\x02 was last seen %s, saying: %s", + params[1], humanized, + seen.(LastSeenInfo).Message, ), nil } else { return "I have not seen " + params[1], nil