This commit is contained in:
2026-02-12 14:01:43 +03:00
parent e5a3b6253d
commit ee6729e12a
8 changed files with 36 additions and 48 deletions

View File

@@ -46,7 +46,7 @@ type RPRepository struct {
}
func NewRPRepository(db *laniakea.DatabaseContext) *RPRepository {
return &RPRepository{db: db.PostgresSQL}
return &RPRepository{db.PostgresSQL}
}
func (rep *RPRepository) GetOrCreateUser(id int64) (*RPUser, error) {

View File

@@ -122,5 +122,5 @@ func (rep *RPRepository) GetChatScenariosIDs(userId, waifuId int) []int {
return []int{0}
}
ids := strings.Split(res.Val(), ",")
return utils.Map(utils.StringToInt, ids)
return utils.Map(ids, utils.StringToInt)
}

12
go.mod
View File

@@ -3,8 +3,8 @@ module kurumibot
go 1.26.0
require (
git.nix13.pw/scuroneko/extypes v1.1.0
git.nix13.pw/scuroneko/laniakea v0.4.4-1
git.nix13.pw/scuroneko/extypes v1.2.0
git.nix13.pw/scuroneko/laniakea v0.5.0
git.nix13.pw/scuroneko/slog v1.0.2
github.com/google/uuid v1.6.0
github.com/joho/godotenv v1.5.1
@@ -15,11 +15,9 @@ require (
go.mongodb.org/mongo-driver/v2 v2.5.0
)
//replace (
// //git.nix13.pw/scuroneko/extypes v1.1.0 => ../go-extypes
// //git.nix13.pw/scuroneko/laniakea v0.4.4 => ./laniakea
// //git.nix13.pw/scuroneko/slog v1.0.2 => ../slog
//)
//replace git.nix13.pw/scuroneko/laniakea v0.5.0 => ./laniakea
//replace git.nix13.pw/scuroneko/extypes v1.1.0 => ../go-extypes
//replace git.nix13.pw/scuroneko/slog v1.0.2 => ../slog
require (
github.com/cespare/xxhash/v2 v2.3.0 // indirect

8
go.sum
View File

@@ -1,9 +1,9 @@
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
git.nix13.pw/scuroneko/extypes v1.1.0 h1:kdAraybAqQgVhArVkVfrIi7KVEX8HgTr8mzbIZAAAqg=
git.nix13.pw/scuroneko/extypes v1.1.0/go.mod h1:uZVs8Yo3RrYAG9dMad6qR6lsYY67t+459D9c65QAYAw=
git.nix13.pw/scuroneko/laniakea v0.4.4-1 h1:vakfENNCABXj+Rripss1QiwCl1EVIgh4DtdDW41bD5s=
git.nix13.pw/scuroneko/laniakea v0.4.4-1/go.mod h1:lE6WFg6BhAzdjsxV4EAT1ZQMYBkjOkjhiyA9GwaQZ/U=
git.nix13.pw/scuroneko/extypes v1.2.0 h1:2n2hD6KsMAted+6MGhAyeWyli2Qzc9G2y+pQNB7C1dM=
git.nix13.pw/scuroneko/extypes v1.2.0/go.mod h1:uZVs8Yo3RrYAG9dMad6qR6lsYY67t+459D9c65QAYAw=
git.nix13.pw/scuroneko/laniakea v0.5.0 h1:Pi+VWmN5XUiaUFYuOz5BevuUFuwR8qTvnFM7RjMOjBU=
git.nix13.pw/scuroneko/laniakea v0.5.0/go.mod h1:KZNqECXWJQUdDGJDfG2naPC60vWwCMRG0oRKVuhYlBs=
git.nix13.pw/scuroneko/slog v1.0.2 h1:vZyUROygxC2d5FJHUQM/30xFEHY1JT/aweDZXA4rm2g=
git.nix13.pw/scuroneko/slog v1.0.2/go.mod h1:3Qm2wzkR5KjwOponMfG7TcGSDjmYaFqRAmLvSPTuWJI=
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=

View File

@@ -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))
}

View File

@@ -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,

View File

@@ -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)
}

View File

@@ -22,27 +22,12 @@ func Max(a, b int) int {
return b
}
func Map[S, R any](f func(s S) R, s []S) []R {
out := make([]R, len(s))
for i := range s {
out[i] = f(s[i])
func Map[T, V any](ts []T, fn func(T) V) []V {
result := make([]V, len(ts))
for i, t := range ts {
result[i] = fn(t)
}
return out
}
// Deprecated
func PopSlice[S any](s []S, index int) []S {
if index == 0 {
return s[1:]
}
out := make([]S, 0)
for i, e := range s {
if i == index {
continue
}
out = append(out, e)
}
return out
return result
}
// Deprecated