This commit is contained in:
2026-01-13 13:27:42 +03:00
parent 5e69454678
commit 4925283ede
27 changed files with 6236 additions and 260 deletions

44
database/red/rp_chats.go Normal file
View File

@@ -0,0 +1,44 @@
package red
import (
"context"
"errors"
"fmt"
"kurumibot/laniakea"
)
var ctx = context.Background()
func RPSetSelectedWaifu(db *laniakea.DatabaseContext, userId, waifuId uint) error {
key := fmt.Sprintf("ai.chats.rp.%d", userId)
return db.Redis.Set(ctx, key, waifuId, 0).Err()
}
func RPGetSelectedWaifu(db *laniakea.DatabaseContext, userId uint) uint {
key := fmt.Sprintf("ai.chats.rp.%d", userId)
res := db.Redis.Get(ctx, key)
if res.Err() != nil {
return 0
}
i, _ := res.Int()
return uint(i)
}
func GetChatId(db *laniakea.DatabaseContext, userId uint) string {
waifuId := RPGetSelectedWaifu(db, userId)
if waifuId == 0 {
return "0"
}
key := fmt.Sprintf("ai.chats.rp.%d.%d", userId, waifuId)
res := db.Redis.Get(ctx, key)
if res.Err() != nil {
return ""
}
return res.Val()
}
func SaveChatId(db *laniakea.DatabaseContext, userId uint, chatId string) error {
waifuId := RPGetSelectedWaifu(db, userId)
if waifuId == 0 {
return errors.New("no chat found")
}
key := fmt.Sprintf("ai.chats.rp.%d.%d", userId, waifuId)
return db.Redis.Set(context.Background(), key, chatId, 0).Err()
}