This commit is contained in:
2025-09-29 11:05:52 +03:00
parent e15d56196d
commit 7dc3eeae9d
5 changed files with 99 additions and 2 deletions

View File

@@ -3,9 +3,27 @@ package mdb
import (
"context"
"kurumibot/laniakea"
"os"
"time"
)
type ConsoleLogEntry struct {
Level string `bson:"level"`
Prefix string `bson:"prefix"`
Traceback string `bson:"traceback"`
Message string `bson:"message"`
Time time.Time `bson:"time"`
TimeStamp int64 `bson:"time_stamp"`
}
func WriteConsoleLog(db *laniakea.DatabaseContext, e *ConsoleLogEntry) error {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
col := db.MongoDB.Database(os.Getenv("MONGO_NAME")).Collection("logs")
_, err := col.InsertOne(ctx, e)
return err
}
type MessageLogEntry struct {
MessageID int `bson:"messageId"`
SenderID int `bson:"senderId"`
@@ -17,7 +35,7 @@ type MessageLogEntry struct {
func WriteMessageLog(db *laniakea.DatabaseContext, e *MessageLogEntry) error {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
collection := db.MongoDB.Database("kurumi").Collection("msg_logs")
collection := db.MongoDB.Database(os.Getenv("MONGO_NAME")).Collection("msg_logs")
_, err := collection.InsertOne(ctx, e)
return err
}