Inserting message on handleMessage

This commit is contained in:
2023-09-11 17:32:11 -05:00
parent 22a9faa3ca
commit d9fc3014b4
2 changed files with 21 additions and 1 deletions

View File

@ -19,6 +19,7 @@ package database
import (
"database/sql"
"errors"
"fmt"
"go.mau.fi/util/dbutil"
"time"
@ -143,3 +144,22 @@ func (msg *Message) Scan(row dbutil.Scannable) *Message {
}
return msg
}
func (msg *Message) Insert() {
query := fmt.Sprintf(`
INSERT INTO message (chat_gmid, chat_receiver, gmid, mxid, sender, timestamp, sent)
VALUES ('%s', '%s', '%s', '%s', '%s', '%d', '%t')
`, msg.Chat.GMID, msg.Chat.Receiver, msg.GMID, msg.MXID, msg.Sender, msg.Timestamp.Unix(), msg.Sent)
_, err := msg.db.Exec(query)
if err != nil {
msg.log.Warnfln("Failed to insert %s: %v", msg.MXID, err)
}
}
//func (msg *Message) Delete() {
// ans := msg.db.Delete(&msg)
// if ans.Error != nil {
// msg.log.Warnfln("Failed to delete %s@%s: %v", msg.Chat, msg.JID, ans.Error)
// }
//}