-
Notifications
You must be signed in to change notification settings - Fork 0
/
logging.go
32 lines (27 loc) · 838 Bytes
/
logging.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
package main
import (
"github.com/osm/irc"
)
// loggingHandler implements basic logging of all the received messages. This
// functionality can be toggled by setting enableLogging to false in the
// configuration file. The bot is written to support one and only one
// channel, so the channel information is NOT stored in the database.
func (b *bot) loggingHandler(m *irc.Message) {
a := b.parseAction(m).(*privmsgAction)
if !a.validChannel {
return
}
stmt, err := b.prepare(`INSERT INTO log (id, timestamp, nick, message) VALUES($1, $2, $3, $4);`)
if err != nil {
b.logger.Printf("loggingHandler: %v", err)
b.privmsg(b.DB.Err)
return
}
defer stmt.Close()
_, err = stmt.Exec(newUUID(), newTimestamp(), a.nick, a.msg)
if err != nil {
b.logger.Printf("loggingHandler: %v", err)
b.privmsg(b.DB.Err)
return
}
}