This commit is contained in:
shoopea 2019-05-03 19:34:53 +08:00
parent 20c88eed24
commit c8df84a00f
2 changed files with 8 additions and 17 deletions

18
main.go
View File

@ -37,20 +37,12 @@ type Config struct {
} }
} }
type MsgDirection string
const (
Incoming MsgDirection = `incoming`
Outgoing MsgDirection = `outgoing`
)
type ChatWarsMessage struct { type ChatWarsMessage struct {
MsgID64 int64 `json:"msg_id"` MsgID64 int64 `json:"msg_id"`
ChatID64 int64 `json:"chat_id"` ChatID64 int64 `json:"chat_id"`
UserID64 int64 `json:"user_id"` UserID64 int64 `json:"user_id"`
Direction MsgDirection `json:"direction"` MsgText string `json:"msg"`
MsgText string `json:"msg"` MsgDate int32 `json:"date"`
MsgDate int32 `json:"date"`
} }
var ( var (

7
sql.go
View File

@ -68,7 +68,6 @@ func initDB() {
id BIGINT UNSIGNED NOT NULL id BIGINT UNSIGNED NOT NULL
,chat_id BIGINT UNSIGNED NOT NULL ,chat_id BIGINT UNSIGNED NOT NULL
,user_id BIGINT UNSIGNED NOT NULL ,user_id BIGINT UNSIGNED NOT NULL
,direction ENUM('incoming', 'outgoing')
,date TIMESTAMP NOT NULL ,date TIMESTAMP NOT NULL
,text VARCHAR(4096) NOT NULL ,text VARCHAR(4096) NOT NULL
,PRIMARY KEY (id, chat_id) ,PRIMARY KEY (id, chat_id)
@ -81,13 +80,13 @@ func initDB() {
} }
func putMsg(m ChatWarsMessage) { func putMsg(m ChatWarsMessage) {
stmt, err := db.Prepare(`INSERT INTO msg (id, chat_id, user_id, direction, date , text) stmt, err := db.Prepare(`INSERT INTO msg (id, chat_id, user_id, date , text)
VALUES (?, ?, ?, ?, FROM_UNIXTIME(?), ?);`) VALUES (?, ?, ?, FROM_UNIXTIME(?), ?);`)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
_, err = stmt.Exec(m.MsgID64, m.ChatID64, m.UserID64, m.Direction, m.MsgDate, m.MsgText) _, err = stmt.Exec(m.MsgID64, m.ChatID64, m.UserID64, m.MsgDate, m.MsgText)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }