-
Notifications
You must be signed in to change notification settings - Fork 0
/
seen.go
62 lines (54 loc) · 1.22 KB
/
seen.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"database/sql"
"github.com/osm/irc"
)
// initSeenHandler initializes the seen handler default messages.
func (b *bot) initSeenHandler() {
if b.IRC.SeenMsgFound == "" {
b.IRC.SeenMsgFound = "<nick> <date> <time>, saying <message>"
}
if b.IRC.SeenMsgNotFound == "" {
b.IRC.SeenMsgNotFound = "<nick> has never been here"
}
}
// seenHandler handle the !seen requests
func (b *bot) seenHandler(m *irc.Message) {
a := b.parseAction(m).(*privmsgAction)
if !a.validChannel {
return
}
if a.cmd != b.IRC.SeenCmd {
return
}
if b.shouldIgnore(m) {
return
}
if len(a.args) < 1 {
return
}
nick := a.args[0]
var timestamp string
var message string
err := b.queryRow(
"SELECT timestamp, message FROM log WHERE nick = $1 ORDER BY timestamp DESC LIMIT 1",
nick,
).Scan(×tamp, &message)
if err != nil && err != sql.ErrNoRows {
b.logger.Printf("seenHandler: %v", err)
b.privmsg(b.DB.Err)
return
}
if len(timestamp) == 0 {
b.privmsgph(b.IRC.SeenMsgNotFound, map[string]string{
"<nick>": nick,
})
} else {
b.privmsgph(b.IRC.SeenMsgFound, map[string]string{
"<nick>": nick,
"<date>": timestamp[0:10],
"<time>": timestamp[11:16],
"<message>": message,
})
}
}