updates
This commit is contained in:
@@ -46,7 +46,7 @@ type RPRepository struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewRPRepository(db *laniakea.DatabaseContext) *RPRepository {
|
func NewRPRepository(db *laniakea.DatabaseContext) *RPRepository {
|
||||||
return &RPRepository{db: db.PostgresSQL}
|
return &RPRepository{db.PostgresSQL}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rep *RPRepository) GetOrCreateUser(id int64) (*RPUser, error) {
|
func (rep *RPRepository) GetOrCreateUser(id int64) (*RPUser, error) {
|
||||||
|
|||||||
@@ -122,5 +122,5 @@ func (rep *RPRepository) GetChatScenariosIDs(userId, waifuId int) []int {
|
|||||||
return []int{0}
|
return []int{0}
|
||||||
}
|
}
|
||||||
ids := strings.Split(res.Val(), ",")
|
ids := strings.Split(res.Val(), ",")
|
||||||
return utils.Map(utils.StringToInt, ids)
|
return utils.Map(ids, utils.StringToInt)
|
||||||
}
|
}
|
||||||
|
|||||||
12
go.mod
12
go.mod
@@ -3,8 +3,8 @@ module kurumibot
|
|||||||
go 1.26.0
|
go 1.26.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.nix13.pw/scuroneko/extypes v1.1.0
|
git.nix13.pw/scuroneko/extypes v1.2.0
|
||||||
git.nix13.pw/scuroneko/laniakea v0.4.4-1
|
git.nix13.pw/scuroneko/laniakea v0.5.0
|
||||||
git.nix13.pw/scuroneko/slog v1.0.2
|
git.nix13.pw/scuroneko/slog v1.0.2
|
||||||
github.com/google/uuid v1.6.0
|
github.com/google/uuid v1.6.0
|
||||||
github.com/joho/godotenv v1.5.1
|
github.com/joho/godotenv v1.5.1
|
||||||
@@ -15,11 +15,9 @@ require (
|
|||||||
go.mongodb.org/mongo-driver/v2 v2.5.0
|
go.mongodb.org/mongo-driver/v2 v2.5.0
|
||||||
)
|
)
|
||||||
|
|
||||||
//replace (
|
//replace git.nix13.pw/scuroneko/laniakea v0.5.0 => ./laniakea
|
||||||
// //git.nix13.pw/scuroneko/extypes v1.1.0 => ../go-extypes
|
//replace git.nix13.pw/scuroneko/extypes v1.1.0 => ../go-extypes
|
||||||
// //git.nix13.pw/scuroneko/laniakea v0.4.4 => ./laniakea
|
//replace git.nix13.pw/scuroneko/slog v1.0.2 => ../slog
|
||||||
// //git.nix13.pw/scuroneko/slog v1.0.2 => ../slog
|
|
||||||
//)
|
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||||
|
|||||||
8
go.sum
8
go.sum
@@ -1,9 +1,9 @@
|
|||||||
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
||||||
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
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.2.0 h1:2n2hD6KsMAted+6MGhAyeWyli2Qzc9G2y+pQNB7C1dM=
|
||||||
git.nix13.pw/scuroneko/extypes v1.1.0/go.mod h1:uZVs8Yo3RrYAG9dMad6qR6lsYY67t+459D9c65QAYAw=
|
git.nix13.pw/scuroneko/extypes v1.2.0/go.mod h1:uZVs8Yo3RrYAG9dMad6qR6lsYY67t+459D9c65QAYAw=
|
||||||
git.nix13.pw/scuroneko/laniakea v0.4.4-1 h1:vakfENNCABXj+Rripss1QiwCl1EVIgh4DtdDW41bD5s=
|
git.nix13.pw/scuroneko/laniakea v0.5.0 h1:Pi+VWmN5XUiaUFYuOz5BevuUFuwR8qTvnFM7RjMOjBU=
|
||||||
git.nix13.pw/scuroneko/laniakea v0.4.4-1/go.mod h1:lE6WFg6BhAzdjsxV4EAT1ZQMYBkjOkjhiyA9GwaQZ/U=
|
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 h1:vZyUROygxC2d5FJHUQM/30xFEHY1JT/aweDZXA4rm2g=
|
||||||
git.nix13.pw/scuroneko/slog v1.0.2/go.mod h1:3Qm2wzkR5KjwOponMfG7TcGSDjmYaFqRAmLvSPTuWJI=
|
git.nix13.pw/scuroneko/slog v1.0.2/go.mod h1:3Qm2wzkR5KjwOponMfG7TcGSDjmYaFqRAmLvSPTuWJI=
|
||||||
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
|
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"git.nix13.pw/scuroneko/laniakea"
|
"git.nix13.pw/scuroneko/laniakea"
|
||||||
|
"git.nix13.pw/scuroneko/laniakea/tgapi"
|
||||||
|
"git.nix13.pw/scuroneko/laniakea/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RegisterAdmin(b *laniakea.Bot) {
|
func RegisterAdmin(b *laniakea.Bot) {
|
||||||
@@ -13,7 +15,7 @@ func RegisterAdmin(b *laniakea.Bot) {
|
|||||||
p.Command(emojiId, "emojiId")
|
p.Command(emojiId, "emojiId")
|
||||||
p.Command(test, "test")
|
p.Command(test, "test")
|
||||||
|
|
||||||
p.Middleware(AdminMiddleware())
|
p.AddMiddleware(AdminMiddleware())
|
||||||
b.AddPlugins(p.Build())
|
b.AddPlugins(p.Build())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,7 +37,7 @@ func test(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext) {
|
|||||||
func emojiId(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext) {
|
func emojiId(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext) {
|
||||||
var id string
|
var id string
|
||||||
for _, e := range ctx.Msg.Entities {
|
for _, e := range ctx.Msg.Entities {
|
||||||
if e.Type != laniakea.MessageEntityCustomEmoji {
|
if e.Type != tgapi.MessageEntityCustomEmoji {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
id = e.CustomEmojiID
|
id = e.CustomEmojiID
|
||||||
@@ -44,14 +46,14 @@ func emojiId(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext) {
|
|||||||
ctx.Answer(id)
|
ctx.Answer(id)
|
||||||
}
|
}
|
||||||
func uploadPhoto(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext) {
|
func uploadPhoto(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext) {
|
||||||
ctx.SendAction(laniakea.ChatActionUploadPhoto)
|
ctx.SendAction(tgapi.ChatActionUploadPhoto)
|
||||||
photoId := ctx.Msg.Photo.Last().FileID
|
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 {
|
if err != nil {
|
||||||
ctx.Error(err)
|
ctx.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
u := laniakea.NewUploader(ctx.Api)
|
u := tgapi.NewUploader(ctx.Api)
|
||||||
defer u.Close()
|
defer u.Close()
|
||||||
content, err := ctx.Bot.GetFileByLink(f.FilePath)
|
content, err := ctx.Bot.GetFileByLink(f.FilePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -59,13 +61,13 @@ func uploadPhoto(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
filename := filepath.Base(f.FilePath)
|
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,
|
ChatID: ctx.Msg.Chat.ID,
|
||||||
Caption: ctx.Msg.Caption,
|
Caption: ctx.Msg.Caption,
|
||||||
})
|
}, tgapi.NewUploaderFile(filename, content))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(err)
|
ctx.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Answer(laniakea.EscapeMarkdown(msg.Photo.Last().FileID))
|
ctx.Answer(utils.EscapeMarkdown(msg.Photo.Last().FileID))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"kurumibot/database/mdb"
|
"kurumibot/database/mdb"
|
||||||
|
"kurumibot/utils"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -17,7 +18,7 @@ func RegisterLogs(bot *laniakea.Bot) {
|
|||||||
p := laniakea.NewPlugin("Logs")
|
p := laniakea.NewPlugin("Logs")
|
||||||
p.Command(getLogs, "logs")
|
p.Command(getLogs, "logs")
|
||||||
p.Command(getMsgLogs, "msglogs")
|
p.Command(getMsgLogs, "msglogs")
|
||||||
p.Middleware(AdminMiddleware())
|
p.AddMiddleware(AdminMiddleware())
|
||||||
bot.AddPlugins(p.Build())
|
bot.AddPlugins(p.Build())
|
||||||
}
|
}
|
||||||
func InitLogMiddleware() laniakea.Middleware {
|
func InitLogMiddleware() laniakea.Middleware {
|
||||||
@@ -91,7 +92,7 @@ func (w *DatabaseWriter) Print(level slog.LogLevel, prefix string, traceback []*
|
|||||||
Level: level.GetName(),
|
Level: level.GetName(),
|
||||||
Prefix: prefix,
|
Prefix: prefix,
|
||||||
Traceback: slog.FormatFullTraceback(traceback),
|
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)
|
return fmt.Sprintf("%v", el)
|
||||||
}), "\n"),
|
}), "\n"),
|
||||||
Time: t,
|
Time: t,
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import (
|
|||||||
|
|
||||||
"git.nix13.pw/scuroneko/extypes"
|
"git.nix13.pw/scuroneko/extypes"
|
||||||
"git.nix13.pw/scuroneko/laniakea"
|
"git.nix13.pw/scuroneko/laniakea"
|
||||||
|
"git.nix13.pw/scuroneko/laniakea/tgapi"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -415,7 +416,7 @@ func newChatStage2(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
|||||||
|
|
||||||
selectedScenariosIds := make(extypes.Slice[int], 0)
|
selectedScenariosIds := make(extypes.Slice[int], 0)
|
||||||
if len(ctx.Args) > 1 {
|
if len(ctx.Args) > 1 {
|
||||||
selectedScenariosIds = utils.Map(utils.StringToInt, ctx.Args[1:])
|
selectedScenariosIds = utils.Map(ctx.Args[1:], utils.StringToInt)
|
||||||
}
|
}
|
||||||
|
|
||||||
out := []string{
|
out := []string{
|
||||||
@@ -489,7 +490,7 @@ func newChat(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
|||||||
chatPrompt = "Вот краткое описание мира(сеттинг): " + scenario.Prompt + "."
|
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 {
|
if len(scenariosIds) > 0 && scenariosIds[0] > 0 {
|
||||||
rep := psql.NewRPRepository(db)
|
rep := psql.NewRPRepository(db)
|
||||||
var scenariosPrompt []string
|
var scenariosPrompt []string
|
||||||
@@ -522,7 +523,7 @@ func newChat(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(err)
|
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 {
|
if err != nil {
|
||||||
ctx.Error(err)
|
ctx.Error(err)
|
||||||
}
|
}
|
||||||
@@ -650,7 +651,7 @@ func generate(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
|||||||
kb := laniakea.NewInlineKeyboard(1)
|
kb := laniakea.NewInlineKeyboard(1)
|
||||||
kb.AddCallbackButtonStyle("Отменить", laniakea.ButtonStyleDanger, "rp.cancel")
|
kb.AddCallbackButtonStyle("Отменить", laniakea.ButtonStyleDanger, "rp.cancel")
|
||||||
m := ctx.Keyboard("Генерация запущена...", kb)
|
m := ctx.Keyboard("Генерация запущена...", kb)
|
||||||
ctx.SendAction(laniakea.ChatActionTyping)
|
ctx.SendAction(tgapi.ChatActionTyping)
|
||||||
api := ai.NewOpenAIAPI(ai.GPTBaseUrl, "", rpUser.Model.Key)
|
api := ai.NewOpenAIAPI(ai.GPTBaseUrl, "", rpUser.Model.Key)
|
||||||
defer api.Close()
|
defer api.Close()
|
||||||
res, err := api.CreateCompletion(messages, userMessage, 1.0)
|
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) {
|
func regenerateResponse(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||||
ctx.AnswerCbQueryText("Запущена повторная генерация…")
|
ctx.AnswerCbQueryText("Запущена повторная генерация…")
|
||||||
|
ctx.EditCallback("Генерация запущена...", nil)
|
||||||
|
|
||||||
redRep := red.NewRPRepository(db)
|
redRep := red.NewRPRepository(db)
|
||||||
waifuId := redRep.GetSelectedWaifu(ctx.FromID)
|
waifuId := redRep.GetSelectedWaifu(ctx.FromID)
|
||||||
@@ -780,7 +782,7 @@ func regenerateResponse(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext)
|
|||||||
}
|
}
|
||||||
|
|
||||||
kb := laniakea.NewInlineKeyboard(1)
|
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)
|
ctx.EditCallback(laniakea.EscapeMarkdown(res.Choices[0].Message.Content), kb)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,27 +22,12 @@ func Max(a, b int) int {
|
|||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
func Map[S, R any](f func(s S) R, s []S) []R {
|
func Map[T, V any](ts []T, fn func(T) V) []V {
|
||||||
out := make([]R, len(s))
|
result := make([]V, len(ts))
|
||||||
for i := range s {
|
for i, t := range ts {
|
||||||
out[i] = f(s[i])
|
result[i] = fn(t)
|
||||||
}
|
}
|
||||||
return out
|
return result
|
||||||
}
|
|
||||||
|
|
||||||
// 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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated
|
// Deprecated
|
||||||
|
|||||||
Reference in New Issue
Block a user