mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
add simple logging
This commit is contained in:
parent
9fd63759fa
commit
e713b78b05
43
pkg/db/log_message.go
Normal file
43
pkg/db/log_message.go
Normal file
|
@ -0,0 +1,43 @@
|
|||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type LogMessage struct {
|
||||
LoginName string `json:"login_name"`
|
||||
Channel string `json:"channel"`
|
||||
UserID string `json:"user_id"`
|
||||
Text string `json:"message"`
|
||||
}
|
||||
|
||||
func (l *LogMessage) Insert(nb *bot.Bot, name, channel, id, text string) error {
|
||||
logrus.Info("logging message")
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
||||
defer cancel()
|
||||
|
||||
collection := nb.MongoClient.Database("nourybot").Collection("logs")
|
||||
|
||||
_, err := collection.InsertOne(ctx, &LogMessage{
|
||||
LoginName: name,
|
||||
Channel: channel,
|
||||
UserID: id,
|
||||
Text: text,
|
||||
})
|
||||
if err != nil {
|
||||
logrus.Info("failed to log message")
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func InsertMessage(nb *bot.Bot, name, channel, id, text string) {
|
||||
err := (&LogMessage{}).Insert(nb, name, channel, id, text)
|
||||
if err != nil {
|
||||
logrus.Info("failed to log message")
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ package handlers
|
|||
import (
|
||||
"github.com/gempir/go-twitch-irc/v2"
|
||||
"github.com/lyx0/nourybot/cmd/bot"
|
||||
"github.com/lyx0/nourybot/pkg/db"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
|
@ -22,6 +23,8 @@ func PrivateMessage(message twitch.PrivateMessage, nb *bot.Bot) {
|
|||
return
|
||||
}
|
||||
|
||||
db.InsertMessage(nb, message.User.Name, message.Channel, message.User.ID, message.Message)
|
||||
|
||||
// Thing for #pajlada
|
||||
if message.Channel == "pajlada" && message.Message == "pajaS 🚨 ALERT" && message.User.Name == "pajbot" && message.Action {
|
||||
// log.Info(message.Message)
|
||||
|
|
Loading…
Reference in a new issue