refactoring, fixes and laniakea v0.8

This commit is contained in:
2026-02-19 14:02:25 +03:00
parent 0804398b6c
commit c9a5a81643
30 changed files with 219 additions and 190 deletions

View File

@@ -2,14 +2,13 @@ package mdb
import (
"context"
"kurumibot/database"
"time"
"ymgb/database"
"git.nix13.pw/scuroneko/laniakea"
"go.mongodb.org/mongo-driver/v2/bson"
)
func GetGptChatHistory(db *laniakea.DatabaseContext, chatId string) ([]AiChatMessage, error) {
func GetGptChatHistory(db *database.Context, chatId string) ([]AiChatMessage, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
col := database.GetMongoCollection(db, "gpt_chat_messages")
@@ -21,7 +20,7 @@ func GetGptChatHistory(db *laniakea.DatabaseContext, chatId string) ([]AiChatMes
err = cursor.All(ctx, &result)
return result, err
}
func UpdateGptChatHistory(db *laniakea.DatabaseContext, chatId, role, message string) error {
func UpdateGptChatHistory(db *database.Context, chatId, role, message string) error {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
col := database.GetMongoCollection(db, "gpt_chat_messages")

View File

@@ -2,10 +2,9 @@ package mdb
import (
"context"
"kurumibot/database"
"time"
"ymgb/database"
"git.nix13.pw/scuroneko/laniakea"
"go.mongodb.org/mongo-driver/v2/bson"
)
@@ -22,7 +21,7 @@ type CodeEntry struct {
TotalUsages uint `bson:"totalUsages"`
}
func FindCode(db *laniakea.DatabaseContext, code string) (CodeEntry, error) {
func FindCode(db *database.Context, code string) (CodeEntry, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
collection := database.GetMongoCollection(db, "codes")

View File

@@ -2,11 +2,10 @@ package mdb
import (
"context"
"kurumibot/database"
"time"
"ymgb/database"
"git.nix13.pw/scuroneko/extypes"
"git.nix13.pw/scuroneko/laniakea"
"go.mongodb.org/mongo-driver/v2/bson"
"go.mongodb.org/mongo-driver/v2/mongo/options"
)
@@ -20,14 +19,14 @@ type ConsoleLogEntry struct {
TimeStamp int64 `bson:"timeStamp" json:"time_stamp"`
}
func WriteConsoleLog(db *laniakea.DatabaseContext, e ConsoleLogEntry) error {
func WriteConsoleLog(db *database.Context, e ConsoleLogEntry) error {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
col := database.GetMongoCollection(db, "logs")
_, err := col.InsertOne(ctx, e)
return err
}
func GetConsoleLogs(db *laniakea.DatabaseContext) ([]ConsoleLogEntry, error) {
func GetConsoleLogs(db *database.Context) ([]ConsoleLogEntry, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
col := database.GetMongoCollection(db, "logs")
@@ -52,14 +51,14 @@ type MessageLogEntry struct {
TimeStamp int64 `bson:"timestamp" json:"timestamp"`
}
func WriteMessageLog(db *laniakea.DatabaseContext, e *MessageLogEntry) error {
func WriteMessageLog(db *database.Context, e *MessageLogEntry) error {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
col := database.GetMongoCollection(db, "msg_logs")
_, err := col.InsertOne(ctx, e)
return err
}
func GetMessageLogs(db *laniakea.DatabaseContext) (extypes.Slice[*MessageLogEntry], error) {
func GetMessageLogs(db *database.Context) (extypes.Slice[*MessageLogEntry], error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
col := database.GetMongoCollection(db, "msg_logs")

View File

@@ -2,10 +2,9 @@ package mdb
import (
"context"
"kurumibot/database"
"time"
"ymgb/database"
"git.nix13.pw/scuroneko/laniakea"
"go.mongodb.org/mongo-driver/v2/bson"
)
@@ -17,7 +16,7 @@ type AiChatMessage struct {
Index int `bson:"index"`
}
func GetRPChatHistory(db *laniakea.DatabaseContext, chatId string) ([]AiChatMessage, error) {
func GetRPChatHistory(db *database.Context, chatId string) ([]AiChatMessage, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
col := database.GetMongoCollection(db, "rp_chat_messages")
@@ -29,7 +28,7 @@ func GetRPChatHistory(db *laniakea.DatabaseContext, chatId string) ([]AiChatMess
err = cursor.All(ctx, &result)
return result, err
}
func UpdateRPChatHistory(db *laniakea.DatabaseContext, chatId, role, message string, index int) error {
func UpdateRPChatHistory(db *database.Context, chatId, role, message string, index int) error {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
col := database.GetMongoCollection(db, "rp_chat_messages")
@@ -41,13 +40,13 @@ func UpdateRPChatHistory(db *laniakea.DatabaseContext, chatId, role, message str
})
return err
}
func GetRPChatHistorySize(db *laniakea.DatabaseContext, chatId string) (int64, error) {
func GetRPChatHistorySize(db *database.Context, chatId string) (int64, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
col := database.GetMongoCollection(db, "rp_chat_messages")
return col.CountDocuments(ctx, bson.M{"chatId": chatId})
}
func DeleteRPChatEntry(db *laniakea.DatabaseContext, entry AiChatMessage) error {
func DeleteRPChatEntry(db *database.Context, entry AiChatMessage) error {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
col := database.GetMongoCollection(db, "rp_chat_messages")