ai work
This commit is contained in:
@@ -2,43 +2,48 @@ package red
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"kurumibot/laniakea"
|
||||
)
|
||||
|
||||
var ctx = context.Background()
|
||||
|
||||
func RPSetSelectedWaifu(db *laniakea.DatabaseContext, userId, waifuId uint) error {
|
||||
func RPSetSelectedWaifu(db *laniakea.DatabaseContext, userId, waifuId int) 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 {
|
||||
func RPGetSelectedWaifu(db *laniakea.DatabaseContext, userId int) int {
|
||||
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)
|
||||
return 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)
|
||||
|
||||
func RPSetChatId(db *laniakea.DatabaseContext, userId, waifuId int, chatId string) error {
|
||||
key := fmt.Sprintf("ai.chats.rp.%d.%d.chat", userId, waifuId)
|
||||
return db.Redis.Set(context.Background(), key, chatId, 0).Err()
|
||||
}
|
||||
func RPGetChatId(db *laniakea.DatabaseContext, userId, waifuId int) string {
|
||||
key := fmt.Sprintf("ai.chats.rp.%d.%d.chat", 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()
|
||||
|
||||
func RPSetChatPrompt(db *laniakea.DatabaseContext, userId, waifuId int, prompt string) error {
|
||||
key := fmt.Sprintf("ai.chats.rp.%d.%d.prompt", userId, waifuId)
|
||||
return db.Redis.Set(context.Background(), key, prompt, 0).Err()
|
||||
}
|
||||
func RPGetChatPrompt(db *laniakea.DatabaseContext, userId, waifuId int) string {
|
||||
key := fmt.Sprintf("ai.chats.rp.%d.%d.prompt", userId, waifuId)
|
||||
res := db.Redis.Get(ctx, key)
|
||||
if res.Err() != nil {
|
||||
return ""
|
||||
}
|
||||
return res.Val()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user