updates
This commit is contained in:
@@ -5,6 +5,8 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"git.nix13.pw/scuroneko/laniakea"
|
||||
"git.nix13.pw/scuroneko/laniakea/tgapi"
|
||||
"git.nix13.pw/scuroneko/laniakea/utils"
|
||||
)
|
||||
|
||||
func RegisterAdmin(b *laniakea.Bot) {
|
||||
@@ -13,7 +15,7 @@ func RegisterAdmin(b *laniakea.Bot) {
|
||||
p.Command(emojiId, "emojiId")
|
||||
p.Command(test, "test")
|
||||
|
||||
p.Middleware(AdminMiddleware())
|
||||
p.AddMiddleware(AdminMiddleware())
|
||||
b.AddPlugins(p.Build())
|
||||
}
|
||||
|
||||
@@ -35,7 +37,7 @@ func test(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext) {
|
||||
func emojiId(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext) {
|
||||
var id string
|
||||
for _, e := range ctx.Msg.Entities {
|
||||
if e.Type != laniakea.MessageEntityCustomEmoji {
|
||||
if e.Type != tgapi.MessageEntityCustomEmoji {
|
||||
continue
|
||||
}
|
||||
id = e.CustomEmojiID
|
||||
@@ -44,14 +46,14 @@ func emojiId(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext) {
|
||||
ctx.Answer(id)
|
||||
}
|
||||
func uploadPhoto(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext) {
|
||||
ctx.SendAction(laniakea.ChatActionUploadPhoto)
|
||||
ctx.SendAction(tgapi.ChatActionUploadPhoto)
|
||||
photoId := ctx.Msg.Photo.Last().FileID
|
||||
f, err := ctx.Api.GetFile(&laniakea.GetFileP{FileId: photoId})
|
||||
f, err := ctx.Api.GetFile(tgapi.GetFileP{FileId: photoId})
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
return
|
||||
}
|
||||
u := laniakea.NewUploader(ctx.Api)
|
||||
u := tgapi.NewUploader(ctx.Api)
|
||||
defer u.Close()
|
||||
content, err := ctx.Bot.GetFileByLink(f.FilePath)
|
||||
if err != nil {
|
||||
@@ -59,13 +61,13 @@ func uploadPhoto(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext) {
|
||||
return
|
||||
}
|
||||
filename := filepath.Base(f.FilePath)
|
||||
msg, err := u.UploadPhoto(laniakea.NewUploaderFile(filename, content), laniakea.SendPhotoBaseP{
|
||||
msg, err := u.UploadPhoto(tgapi.UploadPhotoP{
|
||||
ChatID: ctx.Msg.Chat.ID,
|
||||
Caption: ctx.Msg.Caption,
|
||||
})
|
||||
}, tgapi.NewUploaderFile(filename, content))
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
return
|
||||
}
|
||||
ctx.Answer(laniakea.EscapeMarkdown(msg.Photo.Last().FileID))
|
||||
ctx.Answer(utils.EscapeMarkdown(msg.Photo.Last().FileID))
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"kurumibot/database/mdb"
|
||||
"kurumibot/utils"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -17,7 +18,7 @@ func RegisterLogs(bot *laniakea.Bot) {
|
||||
p := laniakea.NewPlugin("Logs")
|
||||
p.Command(getLogs, "logs")
|
||||
p.Command(getMsgLogs, "msglogs")
|
||||
p.Middleware(AdminMiddleware())
|
||||
p.AddMiddleware(AdminMiddleware())
|
||||
bot.AddPlugins(p.Build())
|
||||
}
|
||||
func InitLogMiddleware() laniakea.Middleware {
|
||||
@@ -91,7 +92,7 @@ func (w *DatabaseWriter) Print(level slog.LogLevel, prefix string, traceback []*
|
||||
Level: level.GetName(),
|
||||
Prefix: prefix,
|
||||
Traceback: slog.FormatFullTraceback(traceback),
|
||||
Message: strings.Join(laniakea.Map(messages, func(el any) string {
|
||||
Message: strings.Join(utils.Map(messages, func(el any) string {
|
||||
return fmt.Sprintf("%v", el)
|
||||
}), "\n"),
|
||||
Time: t,
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
|
||||
"git.nix13.pw/scuroneko/extypes"
|
||||
"git.nix13.pw/scuroneko/laniakea"
|
||||
"git.nix13.pw/scuroneko/laniakea/tgapi"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
@@ -415,7 +416,7 @@ func newChatStage2(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
|
||||
selectedScenariosIds := make(extypes.Slice[int], 0)
|
||||
if len(ctx.Args) > 1 {
|
||||
selectedScenariosIds = utils.Map(utils.StringToInt, ctx.Args[1:])
|
||||
selectedScenariosIds = utils.Map(ctx.Args[1:], utils.StringToInt)
|
||||
}
|
||||
|
||||
out := []string{
|
||||
@@ -489,7 +490,7 @@ func newChat(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
chatPrompt = "Вот краткое описание мира(сеттинг): " + scenario.Prompt + "."
|
||||
}
|
||||
|
||||
scenariosIds := utils.Map(utils.StringToInt, ctx.Args[1:])
|
||||
scenariosIds := utils.Map(ctx.Args[1:], utils.StringToInt)
|
||||
if len(scenariosIds) > 0 && scenariosIds[0] > 0 {
|
||||
rep := psql.NewRPRepository(db)
|
||||
var scenariosPrompt []string
|
||||
@@ -522,7 +523,7 @@ func newChat(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
}
|
||||
err = redisRpRep.SetChatScenariosIDs(ctx.FromID, waifuId, strings.Join(utils.Map(utils.AnyToString, scenariosIds), ","))
|
||||
err = redisRpRep.SetChatScenariosIDs(ctx.FromID, waifuId, strings.Join(utils.Map(scenariosIds, utils.AnyToString), ","))
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
}
|
||||
@@ -650,7 +651,7 @@ func generate(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
kb := laniakea.NewInlineKeyboard(1)
|
||||
kb.AddCallbackButtonStyle("Отменить", laniakea.ButtonStyleDanger, "rp.cancel")
|
||||
m := ctx.Keyboard("Генерация запущена...", kb)
|
||||
ctx.SendAction(laniakea.ChatActionTyping)
|
||||
ctx.SendAction(tgapi.ChatActionTyping)
|
||||
api := ai.NewOpenAIAPI(ai.GPTBaseUrl, "", rpUser.Model.Key)
|
||||
defer api.Close()
|
||||
res, err := api.CreateCompletion(messages, userMessage, 1.0)
|
||||
@@ -718,6 +719,7 @@ func generate(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
|
||||
func regenerateResponse(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
ctx.AnswerCbQueryText("Запущена повторная генерация…")
|
||||
ctx.EditCallback("Генерация запущена...", nil)
|
||||
|
||||
redRep := red.NewRPRepository(db)
|
||||
waifuId := redRep.GetSelectedWaifu(ctx.FromID)
|
||||
@@ -780,7 +782,7 @@ func regenerateResponse(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext)
|
||||
}
|
||||
|
||||
kb := laniakea.NewInlineKeyboard(1)
|
||||
kb.AddCallbackButton("🔄Перегенерировать", "rp.regenerate", count)
|
||||
kb.AddCallbackButtonStyle("🔄 Перегенерировать 🔄", laniakea.ButtonStyleDanger, "rp.regenerate", count)
|
||||
ctx.EditCallback(laniakea.EscapeMarkdown(res.Choices[0].Message.Content), kb)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user