This commit is contained in:
2026-01-13 21:01:10 +03:00
parent cec3a35d83
commit 7d540962a1
6 changed files with 79 additions and 21 deletions

View File

@@ -18,7 +18,7 @@ type RPChatMessage struct {
func GetChatHistory(db *laniakea.DatabaseContext, chatId string) ([]*RPChatMessage, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
col := database.GetMongoCollection(db, "rp_chat_history")
col := database.GetMongoCollection(db, "rp_chat_messages")
cursor, err := col.Find(ctx, bson.M{"chat_id": chatId})
if err != nil {
return nil, err
@@ -30,7 +30,7 @@ func GetChatHistory(db *laniakea.DatabaseContext, chatId string) ([]*RPChatMessa
func UpdateChatHistory(db *laniakea.DatabaseContext, chatId, role, message string) error {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
col := database.GetMongoCollection(db, "rp_chat_history")
col := database.GetMongoCollection(db, "rp_chat_messages")
_, err := col.InsertOne(ctx, RPChatMessage{
chatId,
role,

View File

@@ -47,3 +47,17 @@ func RPGetChatPrompt(db *laniakea.DatabaseContext, userId, waifuId int) string {
}
return res.Val()
}
func RPSetCounter(db *laniakea.DatabaseContext, userId, waifuId, counter int) error {
key := fmt.Sprintf("ai.chats.rp.%d.%d.counter", userId, waifuId)
return db.Redis.Set(ctx, key, counter, 0).Err()
}
func RPGetCounter(db *laniakea.DatabaseContext, userId, waifuId int) int {
key := fmt.Sprintf("ai.chats.rp.%d.%d.counter", userId, waifuId)
res := db.Redis.Get(ctx, key)
if res.Err() != nil {
return 0
}
i, _ := res.Int()
return i
}