some changes
This commit is contained in:
@@ -4,17 +4,27 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"kurumibot/laniakea"
|
||||
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
var ctx = context.Background()
|
||||
|
||||
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()
|
||||
type RPRepository struct {
|
||||
client *redis.Client
|
||||
}
|
||||
func RPGetSelectedWaifu(db *laniakea.DatabaseContext, userId int) int {
|
||||
|
||||
func NewRPRepository(db *laniakea.DatabaseContext) *RPRepository {
|
||||
return &RPRepository{client: db.Redis}
|
||||
}
|
||||
|
||||
func (rep *RPRepository) SetSelectedWaifu(userId, waifuId int) error {
|
||||
key := fmt.Sprintf("ai.chats.rp.%d", userId)
|
||||
res := db.Redis.Get(ctx, key)
|
||||
return rep.client.Set(ctx, key, waifuId, 0).Err()
|
||||
}
|
||||
func (rep *RPRepository) GetSelectedWaifu(userId int) int {
|
||||
key := fmt.Sprintf("ai.chats.rp.%d", userId)
|
||||
res := rep.client.Get(ctx, key)
|
||||
if res.Err() != nil {
|
||||
return 0
|
||||
}
|
||||
@@ -22,39 +32,39 @@ func RPGetSelectedWaifu(db *laniakea.DatabaseContext, userId int) int {
|
||||
return i
|
||||
}
|
||||
|
||||
func RPSetChatId(db *laniakea.DatabaseContext, userId, waifuId int, chatId string) error {
|
||||
func (rep *RPRepository) SetChatId(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()
|
||||
return rep.client.Set(context.Background(), key, chatId, 0).Err()
|
||||
}
|
||||
func RPGetChatId(db *laniakea.DatabaseContext, userId, waifuId int) string {
|
||||
func (rep *RPRepository) GetChatId(userId, waifuId int) string {
|
||||
key := fmt.Sprintf("ai.chats.rp.%d.%d.chat", userId, waifuId)
|
||||
res := db.Redis.Get(ctx, key)
|
||||
res := rep.client.Get(ctx, key)
|
||||
if res.Err() != nil {
|
||||
return ""
|
||||
}
|
||||
return res.Val()
|
||||
}
|
||||
|
||||
func RPSetChatPrompt(db *laniakea.DatabaseContext, userId, waifuId int, prompt string) error {
|
||||
func (rep *RPRepository) SetChatPrompt(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()
|
||||
return rep.client.Set(context.Background(), key, prompt, 0).Err()
|
||||
}
|
||||
func RPGetChatPrompt(db *laniakea.DatabaseContext, userId, waifuId int) string {
|
||||
func (rep *RPRepository) GetChatPrompt(userId, waifuId int) string {
|
||||
key := fmt.Sprintf("ai.chats.rp.%d.%d.prompt", userId, waifuId)
|
||||
res := db.Redis.Get(ctx, key)
|
||||
res := rep.client.Get(ctx, key)
|
||||
if res.Err() != nil {
|
||||
return ""
|
||||
}
|
||||
return res.Val()
|
||||
}
|
||||
|
||||
func RPSetCounter(db *laniakea.DatabaseContext, userId, waifuId, counter int) error {
|
||||
func (rep *RPRepository) SetCounter(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()
|
||||
return rep.client.Set(ctx, key, counter, 0).Err()
|
||||
}
|
||||
func RPGetCounter(db *laniakea.DatabaseContext, userId, waifuId int) int {
|
||||
func (rep *RPRepository) GetCounter(userId, waifuId int) int {
|
||||
key := fmt.Sprintf("ai.chats.rp.%d.%d.counter", userId, waifuId)
|
||||
res := db.Redis.Get(ctx, key)
|
||||
res := rep.client.Get(ctx, key)
|
||||
if res.Err() != nil {
|
||||
return 0
|
||||
}
|
||||
@@ -62,20 +72,16 @@ func RPGetCounter(db *laniakea.DatabaseContext, userId, waifuId int) int {
|
||||
return i
|
||||
}
|
||||
|
||||
func RPSetIndex(db *laniakea.DatabaseContext, userId, waifuId, index int) error {
|
||||
key := fmt.Sprintf("ai.chats.rp.%d.%d.index", userId, waifuId)
|
||||
return db.Redis.Set(ctx, key, index, 0).Err()
|
||||
func (rep *RPRepository) SetChatTokens(userId, waifuId, tokens int) error {
|
||||
key := fmt.Sprintf("ai.chats.rp.%d.%d.tokens", userId, waifuId)
|
||||
return rep.client.Set(ctx, key, tokens, 0).Err()
|
||||
}
|
||||
func RPGetIndex(db *laniakea.DatabaseContext, userId, waifuId int) int {
|
||||
key := fmt.Sprintf("ai.chats.rp.%d.%d.index", userId, waifuId)
|
||||
res := db.Redis.Get(ctx, key)
|
||||
func (rep *RPRepository) GetChatTokens(userId, waifuId int) int {
|
||||
key := fmt.Sprintf("ai.chats.rp.%d.%d.tokens", userId, waifuId)
|
||||
res := rep.client.Get(ctx, key)
|
||||
if res.Err() != nil {
|
||||
return 0
|
||||
}
|
||||
i, err := res.Int()
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
i, _ := res.Int()
|
||||
return i
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user