laniakea v1.0.0 rc1

This commit is contained in:
2026-03-17 16:54:18 +03:00
parent 9a34d05572
commit 7943c860ab
12 changed files with 84 additions and 68 deletions

View File

@@ -23,8 +23,8 @@ type RPRepository struct {
type RPChat struct {
ID uuid.UUID
UserID int
WaifuID int
UserID int64
WaifuID int64
Prompt string
Counter int
ChatTokens int64
@@ -39,25 +39,25 @@ func NewRPRepository(db *database.Context) RPRepository {
return RPRepository{db.Redis, db}
}
func (rep RPRepository) SetSelectedWaifu(userId, waifuId int) error {
func (rep RPRepository) SetSelectedWaifu(userId, waifuId int64) error {
key := fmt.Sprintf("ai.chats.rp.%d", userId)
return rep.client.Set(ctx, key, waifuId, 0).Err()
}
func (rep RPRepository) GetSelectedWaifu(userId int) int {
func (rep RPRepository) GetSelectedWaifu(userId int64) int64 {
key := fmt.Sprintf("ai.chats.rp.%d", userId)
res := rep.client.Get(ctx, key)
if res.Err() != nil {
return 0
}
i, _ := res.Int()
return i
return int64(i)
}
func (rep RPRepository) SetChatId(userId, waifuId int, chatId string) error {
func (rep RPRepository) SetChatId(userId, waifuId int64, chatId string) error {
key := fmt.Sprintf("ai.chats.rp.%d.%d.chat", userId, waifuId)
return rep.client.Set(context.Background(), key, chatId, 0).Err()
}
func (rep RPRepository) GetChatId(userId, waifuId int) string {
func (rep RPRepository) GetChatId(userId, waifuId int64) string {
key := fmt.Sprintf("ai.chats.rp.%d.%d.chat", userId, waifuId)
res := rep.client.Get(ctx, key)
if res.Err() != nil {
@@ -65,7 +65,7 @@ func (rep RPRepository) GetChatId(userId, waifuId int) string {
}
return res.Val()
}
func (rep RPRepository) GetOrCreateChatId(userId, waifuId int) (string, error) {
func (rep RPRepository) GetOrCreateChatId(userId, waifuId int64) (string, error) {
chatId := rep.GetChatId(userId, waifuId)
if chatId == "" {
chatId = uuid.New().String()
@@ -73,7 +73,7 @@ func (rep RPRepository) GetOrCreateChatId(userId, waifuId int) (string, error) {
err := rep.SetChatId(userId, waifuId, chatId)
return chatId, err
}
func (rep RPRepository) GetChat(userId int) (RPChat, error) {
func (rep RPRepository) GetChat(userId int64) (RPChat, error) {
var chat RPChat
waifuId := rep.GetSelectedWaifu(userId)
if waifuId == 0 {
@@ -133,7 +133,7 @@ func (rep RPRepository) SaveChat(chat RPChat) error {
if err = rep.SetCounter(userId, waifuId, chat.Counter); err != nil {
return err
}
if err = rep.SetChatTokens(userId, waifuId, int(chat.ChatTokens)); err != nil {
if err = rep.SetChatTokens(userId, waifuId, chat.ChatTokens); err != nil {
return err
}
@@ -161,11 +161,11 @@ func (rep RPRepository) SaveChat(chat RPChat) error {
return nil
}
func (rep RPRepository) SetChatPrompt(userId, waifuId int, prompt string) error {
func (rep RPRepository) SetChatPrompt(userId, waifuId int64, prompt string) error {
key := fmt.Sprintf("ai.chats.rp.%d.%d.prompt", userId, waifuId)
return rep.client.Set(context.Background(), key, prompt, 0).Err()
}
func (rep RPRepository) GetChatPrompt(userId, waifuId int) string {
func (rep RPRepository) GetChatPrompt(userId, waifuId int64) string {
key := fmt.Sprintf("ai.chats.rp.%d.%d.prompt", userId, waifuId)
res := rep.client.Get(ctx, key)
if res.Err() != nil {
@@ -174,11 +174,11 @@ func (rep RPRepository) GetChatPrompt(userId, waifuId int) string {
return res.Val()
}
func (rep RPRepository) SetCounter(userId, waifuId, counter int) error {
func (rep RPRepository) SetCounter(userId, waifuId int64, counter int) error {
key := fmt.Sprintf("ai.chats.rp.%d.%d.counter", userId, waifuId)
return rep.client.Set(ctx, key, counter, 0).Err()
}
func (rep RPRepository) GetCounter(userId, waifuId int) int {
func (rep RPRepository) GetCounter(userId, waifuId int64) int {
key := fmt.Sprintf("ai.chats.rp.%d.%d.counter", userId, waifuId)
res := rep.client.Get(ctx, key)
if res.Err() != nil {
@@ -188,25 +188,25 @@ func (rep RPRepository) GetCounter(userId, waifuId int) int {
return i
}
func (rep RPRepository) SetChatTokens(userId, waifuId, tokens int) error {
func (rep RPRepository) SetChatTokens(userId, waifuId, tokens int64) error {
key := fmt.Sprintf("ai.chats.rp.%d.%d.tokens", userId, waifuId)
return rep.client.Set(ctx, key, tokens, 0).Err()
}
func (rep RPRepository) GetChatTokens(userId, waifuId int) int {
func (rep RPRepository) GetChatTokens(userId, waifuId int64) int64 {
key := fmt.Sprintf("ai.chats.rp.%d.%d.tokens", userId, waifuId)
res := rep.client.Get(ctx, key)
if res.Err() != nil {
return 0
}
i, _ := res.Int()
return i
return int64(i)
}
func (rep RPRepository) SetChatSettingID(userId, waifuId, settingId int) error {
func (rep RPRepository) SetChatSettingID(userId, waifuId int64, 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 {
func (rep RPRepository) GetChatSettingID(userId, waifuId int64) int {
key := fmt.Sprintf("ai.chats.rp.%d.%d.setting_id", userId, waifuId)
res := rep.client.Get(ctx, key)
if res.Err() != nil {
@@ -216,12 +216,12 @@ func (rep RPRepository) GetChatSettingID(userId, waifuId int) int {
return i
}
func (rep RPRepository) SetChatScenariosIDs(userId, waifuId int, scenarioIds []int) error {
func (rep RPRepository) SetChatScenariosIDs(userId, waifuId int64, scenarioIds []int) error {
key := fmt.Sprintf("ai.chats.rp.%d.%d.scenario_id", userId, waifuId)
ids := strings.Join(utils.Map(scenarioIds, utils.AnyToString), ",")
return rep.client.Set(ctx, key, ids, 0).Err()
}
func (rep RPRepository) GetChatScenariosIDs(userId, waifuId int) []int {
func (rep RPRepository) GetChatScenariosIDs(userId, waifuId int64) []int {
key := fmt.Sprintf("ai.chats.rp.%d.%d.scenario_id", userId, waifuId)
res := rep.client.Get(ctx, key)
if res.Err() != nil {