setting and scenario in chat stat
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"kurumibot/laniakea"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
@@ -44,6 +45,14 @@ func (rep *RPRepository) GetChatId(userId, waifuId int) string {
|
||||
}
|
||||
return res.Val()
|
||||
}
|
||||
func (rep *RPRepository) GetOrCreateChatId(userId, waifuId int) (string, error) {
|
||||
chatId := rep.GetChatId(userId, waifuId)
|
||||
if chatId == "" {
|
||||
chatId = uuid.New().String()
|
||||
}
|
||||
err := rep.SetChatId(userId, waifuId, chatId)
|
||||
return chatId, err
|
||||
}
|
||||
|
||||
func (rep *RPRepository) SetChatPrompt(userId, waifuId int, prompt string) error {
|
||||
key := fmt.Sprintf("ai.chats.rp.%d.%d.prompt", userId, waifuId)
|
||||
@@ -85,3 +94,31 @@ func (rep *RPRepository) GetChatTokens(userId, waifuId int) int {
|
||||
i, _ := res.Int()
|
||||
return i
|
||||
}
|
||||
|
||||
func (rep *RPRepository) SetChatSettingID(userId, waifuId, settingId int) error {
|
||||
key := fmt.Sprintf("ai.chats.rp.%d.%d.setting_id", userId, waifuId)
|
||||
return rep.client.Set(ctx, key, settingId, 0).Err()
|
||||
}
|
||||
func (rep *RPRepository) GetChatSettingID(userId, waifuId int) int {
|
||||
key := fmt.Sprintf("ai.chats.rp.%d.%d.setting_id", userId, waifuId)
|
||||
res := rep.client.Get(ctx, key)
|
||||
if res.Err() != nil {
|
||||
return 0
|
||||
}
|
||||
i, _ := res.Int()
|
||||
return i
|
||||
}
|
||||
|
||||
func (rep *RPRepository) SetChatScenarioID(userId, waifuId, scenarioId int) error {
|
||||
key := fmt.Sprintf("ai.chats.rp.%d.%d.scenario_id", userId, waifuId)
|
||||
return rep.client.Set(ctx, key, scenarioId, 0).Err()
|
||||
}
|
||||
func (rep *RPRepository) GetChatScenarioID(userId, waifuId int) int {
|
||||
key := fmt.Sprintf("ai.chats.rp.%d.%d.scenario_id", userId, waifuId)
|
||||
res := rep.client.Get(ctx, key)
|
||||
if res.Err() != nil {
|
||||
return 0
|
||||
}
|
||||
i, _ := res.Int()
|
||||
return i
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user