many changes
This commit is contained in:
@@ -2,7 +2,7 @@ package plugins
|
||||
|
||||
import (
|
||||
"kurumibot/database/psql"
|
||||
"log"
|
||||
"path/filepath"
|
||||
|
||||
"git.nix13.pw/scuroneko/laniakea"
|
||||
)
|
||||
@@ -24,9 +24,7 @@ func uploadPhoto(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
return
|
||||
}
|
||||
|
||||
// https://core.telegram.org/bots/api#getfile
|
||||
log.Println(ctx.Msg.Photo[0])
|
||||
photoId := ctx.Msg.Photo[0].FileID
|
||||
photoId := ctx.Msg.Photo.Last().FileID
|
||||
f, err := ctx.Bot.GetFile(&laniakea.GetFileP{FileId: photoId})
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
@@ -38,11 +36,14 @@ func uploadPhoto(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
ctx.Error(err)
|
||||
return
|
||||
}
|
||||
err = u.UploadPhoto(ctx.Msg.Chat.ID, content)
|
||||
filename := filepath.Base(f.FilePath)
|
||||
msg, err := u.UploadPhoto(laniakea.NewUploaderFile(filename, content), laniakea.SendPhotoBaseP{
|
||||
ChatID: ctx.Msg.Chat.ID,
|
||||
Caption: ctx.Msg.Caption,
|
||||
})
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
return
|
||||
}
|
||||
log.Println(*f)
|
||||
ctx.AnswerPhoto(photoId, laniakea.EscapeMarkdown(photoId))
|
||||
ctx.Answer(laniakea.EscapeMarkdown(msg.Photo.Last().FileID))
|
||||
}
|
||||
|
||||
@@ -9,10 +9,10 @@ import (
|
||||
"kurumibot/database/red"
|
||||
"kurumibot/utils"
|
||||
"kurumibot/utils/ai"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"git.nix13.pw/scuroneko/extypes"
|
||||
"git.nix13.pw/scuroneko/laniakea"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
@@ -96,13 +96,15 @@ func rpInfo(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
compressText = "токенов"
|
||||
}
|
||||
out := []string{
|
||||
fmt.Sprintf("Привет, %s!", ctx.From.FirstName),
|
||||
fmt.Sprintf("Привет, _%s_!", ctx.From.FirstName),
|
||||
fmt.Sprintf("*Выбранная вайфу*: %s", waifu.Name),
|
||||
fmt.Sprintf("*Выбранный пресет*: %s", laniakea.EscapeMarkdown(rpUser.Preset.Name)),
|
||||
fmt.Sprintf("*Выбранная модель*: %s", rpUser.Model.Name),
|
||||
fmt.Sprintf("*Использовано токенов*: %d", rpUser.UsedTokens),
|
||||
fmt.Sprintf("*Настройки сжатия*: %d %s", rpUser.CompressLimit, compressText),
|
||||
fmt.Sprintf("*Твоё описание персонажа*: %s", rpUser.UserPrompt),
|
||||
"",
|
||||
"Что бы установить описание персонажа, используй `/rpuserpset \"описание персонажа\"` без кавычек.",
|
||||
}
|
||||
|
||||
kb := laniakea.NewInlineKeyboard(2)
|
||||
@@ -127,7 +129,7 @@ func rpInfo(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
|
||||
func rpWaifuList(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
waifuRep := psql.NewWaifuRepository(db)
|
||||
waifus := make([]*psql.Waifu, 0)
|
||||
waifus := make(extypes.Slice[*psql.Waifu], 0)
|
||||
var err error
|
||||
|
||||
userRep := psql.NewUserRepository(db)
|
||||
@@ -145,6 +147,9 @@ func rpWaifuList(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
ctx.Error(err)
|
||||
return
|
||||
}
|
||||
waifus = waifus.Filter(func(w *psql.Waifu) bool {
|
||||
return len(w.RpPrompt) > 0
|
||||
})
|
||||
|
||||
out := make([]string, len(waifus))
|
||||
kb := laniakea.NewInlineKeyboard(2)
|
||||
@@ -407,7 +412,7 @@ func newChatStage2(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
return
|
||||
}
|
||||
|
||||
selectedScenariosIds := make([]int, 0)
|
||||
selectedScenariosIds := make(extypes.Slice[int], 0)
|
||||
if len(ctx.Args) > 1 {
|
||||
selectedScenariosIds = utils.Map(utils.StringToInt, ctx.Args[1:])
|
||||
}
|
||||
@@ -416,21 +421,18 @@ func newChatStage2(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
"Выбери сценарий:",
|
||||
}
|
||||
kb := laniakea.NewInlineKeyboard(2)
|
||||
scenariosIds := make([]int, 0)
|
||||
scenariosIds := make(extypes.Slice[int], 0)
|
||||
for _, scenario := range scenarios {
|
||||
isSelected := slices.Index(selectedScenariosIds, scenario.ID) >= 0
|
||||
isSelected := selectedScenariosIds.Index(scenario.ID) >= 0
|
||||
prefix := ""
|
||||
if isSelected {
|
||||
prefix = "✅"
|
||||
}
|
||||
out = append(out, fmt.Sprintf("%s*%s* - %s", prefix, scenario.Name, scenario.Description))
|
||||
if isSelected {
|
||||
scenariosIds = utils.PopSlice(
|
||||
selectedScenariosIds,
|
||||
slices.Index(selectedScenariosIds, scenario.ID),
|
||||
)
|
||||
scenariosIds = selectedScenariosIds.Remove(scenario.ID)
|
||||
} else {
|
||||
scenariosIds = append(selectedScenariosIds, scenario.ID)
|
||||
scenariosIds = selectedScenariosIds.Push(scenario.ID)
|
||||
}
|
||||
kb.AddCallbackButton(
|
||||
fmt.Sprintf("%s%s", prefix, scenario.Name),
|
||||
@@ -542,7 +544,7 @@ func rpUserPromptSet(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
if len(ctx.Args) == 0 || ctx.Args[0] == "" {
|
||||
return
|
||||
}
|
||||
prompt := strings.Join(ctx.Args[1:], " ")
|
||||
prompt := strings.Join(ctx.Args, " ")
|
||||
rep := psql.NewRPRepository(db)
|
||||
user, err := rep.GetOrCreateUser(int64(ctx.FromID))
|
||||
if err != nil {
|
||||
@@ -645,6 +647,7 @@ func generate(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
|
||||
kb := laniakea.NewInlineKeyboard(1).AddCallbackButton("Отменить", "rp.cancel")
|
||||
m := ctx.Keyboard("Генерация запущена...", kb)
|
||||
ctx.SendAction(laniakea.ChatActionTyping)
|
||||
api := ai.NewOpenAIAPI(ai.GPTBaseUrl, "", rpUser.Model.Key)
|
||||
defer api.Close()
|
||||
res, err := api.CreateCompletion(messages, userMessage, 1.0)
|
||||
|
||||
Reference in New Issue
Block a user