45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
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()
|
|
}
|