refactoring, fixes and laniakea v0.8
This commit is contained in:
@@ -2,9 +2,10 @@ package plugins
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"kurumibot/database/psql"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"ymgb/database"
|
||||
"ymgb/database/psql"
|
||||
|
||||
"git.nix13.pw/scuroneko/laniakea"
|
||||
"git.nix13.pw/scuroneko/laniakea/tgapi"
|
||||
@@ -12,18 +13,18 @@ import (
|
||||
"github.com/vinovest/sqlx"
|
||||
)
|
||||
|
||||
func RegisterAdmin(b *laniakea.Bot) {
|
||||
p := laniakea.NewPlugin("Admin")
|
||||
func RegisterAdmin() *laniakea.Plugin[database.Context] {
|
||||
p := laniakea.NewPlugin[database.Context]("Admin")
|
||||
p.AddCommand(laniakea.NewCommand(uploadPhoto, "uploadPhoto").SkipCommandAutoGen())
|
||||
p.AddCommand(laniakea.NewCommand(emojiId, "emojiId").SkipCommandAutoGen())
|
||||
p.AddCommand(laniakea.NewCommand(getProxy, "proxy").SkipCommandAutoGen())
|
||||
p.AddCommand(laniakea.NewCommand(execSql, "sql").SkipCommandAutoGen())
|
||||
|
||||
p.AddMiddleware(AdminMiddleware())
|
||||
b.AddPlugins(p)
|
||||
return p
|
||||
}
|
||||
func AdminMiddleware() laniakea.Middleware {
|
||||
m := laniakea.NewMiddleware("AdminMiddleware", func(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) bool {
|
||||
func AdminMiddleware() laniakea.Middleware[database.Context] {
|
||||
m := laniakea.NewMiddleware("AdminMiddleware", func(ctx *laniakea.MsgContext, db *database.Context) bool {
|
||||
rep := psql.NewUserRepository(db)
|
||||
u, err := rep.GetById(ctx.FromID)
|
||||
if err != nil {
|
||||
@@ -34,12 +35,12 @@ func AdminMiddleware() laniakea.Middleware {
|
||||
return *m
|
||||
}
|
||||
|
||||
func execSql(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
func execSql(ctx *laniakea.MsgContext, db *database.Context) {
|
||||
stmt := strings.Join(ctx.Args, " ")
|
||||
stmt = db.PostgresSQL.Rebind(stmt)
|
||||
stmt = db.Postgres.Rebind(stmt)
|
||||
|
||||
var res []map[string]any
|
||||
r, err := db.PostgresSQL.Query(stmt)
|
||||
r, err := db.Postgres.Query(stmt)
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
return
|
||||
@@ -61,7 +62,7 @@ func execSql(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
}
|
||||
ctx.Answerf("`%s`", data)
|
||||
}
|
||||
func getProxy(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext) {
|
||||
func getProxy(ctx *laniakea.MsgContext, _ *database.Context) {
|
||||
ruProxy := "tg://proxy?port=3128&secret=7qaZyfQN-IQ7ZMwrR_zWnHBvem9uLnJ1&server=185.231.245.25"
|
||||
fiProxy := "tg://proxy?port=3128&secret=7vmNtw_233xvIRFvImm2PLtvem9uLnJ1&server=46.243.6.125"
|
||||
kb := laniakea.NewInlineKeyboard(1)
|
||||
@@ -69,7 +70,7 @@ func getProxy(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext) {
|
||||
kb.AddUrlButtonStyle("🇫🇮Finland", laniakea.ButtonStylePrimary, fiProxy)
|
||||
ctx.Keyboard("Доступные прокси", kb)
|
||||
}
|
||||
func emojiId(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext) {
|
||||
func emojiId(ctx *laniakea.MsgContext, _ *database.Context) {
|
||||
var id string
|
||||
for _, e := range ctx.Msg.Entities {
|
||||
if e.Type != tgapi.MessageEntityCustomEmoji {
|
||||
@@ -80,7 +81,7 @@ func emojiId(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext) {
|
||||
}
|
||||
ctx.Answer(id)
|
||||
}
|
||||
func uploadPhoto(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext) {
|
||||
func uploadPhoto(ctx *laniakea.MsgContext, _ *database.Context) {
|
||||
ctx.SendAction(tgapi.ChatActionUploadPhoto)
|
||||
photoId := ctx.Msg.Photo.Last().FileID
|
||||
f, err := ctx.Api.GetFile(tgapi.GetFileP{FileId: photoId})
|
||||
@@ -90,7 +91,7 @@ func uploadPhoto(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext) {
|
||||
}
|
||||
u := tgapi.NewUploader(ctx.Api)
|
||||
defer u.Close()
|
||||
content, err := ctx.Bot.GetFileByLink(f.FilePath)
|
||||
content, err := ctx.Api.GetFileByLink(f.FilePath)
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
return
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
package plugins
|
||||
|
||||
import (
|
||||
"kurumibot/database/mdb"
|
||||
"kurumibot/database/red"
|
||||
"kurumibot/utils/ai"
|
||||
"strings"
|
||||
"ymgb/database"
|
||||
"ymgb/database/mdb"
|
||||
"ymgb/database/red"
|
||||
"ymgb/utils/ai"
|
||||
|
||||
"git.nix13.pw/scuroneko/laniakea"
|
||||
)
|
||||
|
||||
func RegisterAi(bot *laniakea.Bot) {
|
||||
p := laniakea.NewPlugin("AI")
|
||||
func RegisterAi() *laniakea.Plugin[database.Context] {
|
||||
p := laniakea.NewPlugin[database.Context]("AI")
|
||||
p.AddCommand(p.NewCommand(gpt, "gpt").SkipCommandAutoGen())
|
||||
bot.AddPlugins(p)
|
||||
return p
|
||||
}
|
||||
|
||||
func gpt(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
func gpt(ctx *laniakea.MsgContext, db *database.Context) {
|
||||
q := strings.Join(ctx.Args, " ")
|
||||
api := ai.NewOpenAIAPI(ai.GPTBaseUrl, "", "anthropic/claude-sonnet-4")
|
||||
defer api.Close()
|
||||
|
||||
@@ -2,20 +2,21 @@ package plugins
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"kurumibot/database/psql"
|
||||
"kurumibot/utils"
|
||||
"math"
|
||||
"math/rand/v2"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"ymgb/database"
|
||||
"ymgb/database/psql"
|
||||
"ymgb/utils"
|
||||
|
||||
"git.nix13.pw/scuroneko/laniakea"
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
func RegisterEconomy(bot *laniakea.Bot) {
|
||||
p := laniakea.NewPlugin("Economy")
|
||||
func RegisterEconomy(bot *laniakea.Bot[database.Context]) *laniakea.Plugin[database.Context] {
|
||||
p := laniakea.NewPlugin[database.Context]("Economy")
|
||||
p.AddCommand(p.NewCommand(profile, "profile"))
|
||||
p.AddCommand(p.NewCommand(profile, "профиль").SkipCommandAutoGen())
|
||||
p.AddCommand(p.NewCommand(work, "work"))
|
||||
@@ -33,14 +34,13 @@ func RegisterEconomy(bot *laniakea.Bot) {
|
||||
p.AddCommand(p.NewCommand(aboutGroup, "group"))
|
||||
p.AddCommand(p.NewCommand(aboutGroup, "о группе").SkipCommandAutoGen())
|
||||
|
||||
bot.AddRunner(laniakea.NewRunner(
|
||||
bot.AddRunner(*laniakea.NewRunner[database.Context](
|
||||
"economy.PassiveIncome", passiveIncome,
|
||||
).Timeout(time.Minute).Build())
|
||||
|
||||
bot.AddPlugins(p)
|
||||
).Timeout(time.Minute))
|
||||
return p
|
||||
}
|
||||
|
||||
func passiveIncome(b *laniakea.Bot) error {
|
||||
func passiveIncome(b *laniakea.Bot[database.Context]) error {
|
||||
ctx := b.GetDBContext()
|
||||
waifuRep := psql.NewWaifuRepository(ctx)
|
||||
userRep := psql.NewUserRepository(ctx)
|
||||
@@ -49,7 +49,7 @@ func passiveIncome(b *laniakea.Bot) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
b.Logger().Debugf("Loaded %d users\n", len(users))
|
||||
b.GetLogger().Debugf("Loaded %d users\n", len(users))
|
||||
|
||||
for _, user := range users {
|
||||
if user.Business == nil && user.Maid == nil && user.Miner == nil {
|
||||
@@ -76,7 +76,7 @@ func passiveIncome(b *laniakea.Bot) error {
|
||||
|
||||
waifus, err := waifuRep.GetByUserId(user.ID)
|
||||
if err != nil {
|
||||
b.Logger().Error(err)
|
||||
b.GetLogger().Errorln(err)
|
||||
continue
|
||||
}
|
||||
for _, waifu := range waifus {
|
||||
@@ -96,16 +96,16 @@ func passiveIncome(b *laniakea.Bot) error {
|
||||
|
||||
_, err = userRep.Update(&user)
|
||||
if err != nil {
|
||||
b.Logger().Error(err)
|
||||
b.GetLogger().Errorln(err)
|
||||
continue
|
||||
}
|
||||
|
||||
b.Logger().Debug(fmt.Sprintf("У %d было пассивно собрано. След. сбор через час\n", user.ID))
|
||||
b.GetLogger().Debugln(fmt.Sprintf("У %d было пассивно собрано. След. сбор через час\n", user.ID))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func profile(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
func profile(ctx *laniakea.MsgContext, db *database.Context) {
|
||||
rep := psql.NewUserRepository(db)
|
||||
user, err := rep.GetOrCreate(ctx.FromID, ctx.Msg.From.FirstName)
|
||||
if err != nil {
|
||||
@@ -158,7 +158,7 @@ func profile(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
ctx.Answer(strings.Join(out, "\n"))
|
||||
}
|
||||
|
||||
func work(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
func work(ctx *laniakea.MsgContext, db *database.Context) {
|
||||
rep := psql.NewUserRepository(db)
|
||||
user, err := rep.GetOrCreate(ctx.FromID, ctx.Update.Message.From.FirstName)
|
||||
if err != nil {
|
||||
@@ -207,7 +207,7 @@ func work(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
))
|
||||
}
|
||||
|
||||
func collect(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
func collect(ctx *laniakea.MsgContext, db *database.Context) {
|
||||
rep := psql.NewUserRepository(db)
|
||||
user, err := rep.GetOrCreate(ctx.FromID, ctx.Update.Message.From.FirstName)
|
||||
if err != nil {
|
||||
@@ -312,11 +312,11 @@ func collect(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
ctx.Answer(strings.Join(out, "\n"))
|
||||
}
|
||||
|
||||
func code(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext) {
|
||||
func code(ctx *laniakea.MsgContext, _ *database.Context) {
|
||||
// user, err := database.Get
|
||||
}
|
||||
|
||||
func vacancies(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
func vacancies(ctx *laniakea.MsgContext, db *database.Context) {
|
||||
worksRep := psql.NewWorkRepository(db)
|
||||
works, err := worksRep.GetAll()
|
||||
|
||||
@@ -336,7 +336,7 @@ func vacancies(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
ctx.Answer(strings.Join(out, "\n"))
|
||||
}
|
||||
|
||||
func getAJob(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
func getAJob(ctx *laniakea.MsgContext, db *database.Context) {
|
||||
if len(ctx.Args) == 0 {
|
||||
ctx.Answer("Недостаточно аргументов")
|
||||
return
|
||||
@@ -372,7 +372,7 @@ func getAJob(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
ctx.Answer("Ты успешно устроился на работу!")
|
||||
}
|
||||
|
||||
func aboutGroup(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
func aboutGroup(ctx *laniakea.MsgContext, db *database.Context) {
|
||||
userRep := psql.NewUserRepository(db)
|
||||
user, err := userRep.GetOrCreate(ctx.FromID, ctx.Msg.From.FirstName)
|
||||
if err != nil {
|
||||
|
||||
@@ -2,15 +2,16 @@ package plugins
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"ymgb/database"
|
||||
|
||||
"git.nix13.pw/scuroneko/laniakea"
|
||||
)
|
||||
|
||||
func RegisterFun(bot *laniakea.Bot) {
|
||||
p := laniakea.NewPlugin("Fun")
|
||||
func RegisterFun() *laniakea.Plugin[database.Context] {
|
||||
p := laniakea.NewPlugin[database.Context]("Fun")
|
||||
p.AddCommand(p.NewCommand(beautyFont, "bf"))
|
||||
p.AddCommand(p.NewCommand(beautyFontHeart, "bfh"))
|
||||
bot.AddPlugins(p)
|
||||
return p
|
||||
}
|
||||
|
||||
var ligatures = map[string]string{
|
||||
@@ -22,7 +23,7 @@ var ligatures = map[string]string{
|
||||
"v": "𝑣", "w": "𝑤", "x": "𝑥", "y": "𝑦", "z": "𝑧",
|
||||
}
|
||||
|
||||
func beautyFont(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
func beautyFont(ctx *laniakea.MsgContext, _ *database.Context) {
|
||||
m := strings.Join(ctx.Args, " ")
|
||||
out := ""
|
||||
for _, r := range m {
|
||||
@@ -36,7 +37,7 @@ func beautyFont(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
ctx.Answer(out)
|
||||
}
|
||||
|
||||
func beautyFontHeart(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
func beautyFontHeart(ctx *laniakea.MsgContext, _ *database.Context) {
|
||||
m := strings.Join(ctx.Args, " ")
|
||||
out := ""
|
||||
for _, r := range m {
|
||||
|
||||
@@ -4,28 +4,29 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"kurumibot/database/mdb"
|
||||
"kurumibot/utils"
|
||||
"strings"
|
||||
"time"
|
||||
"ymgb/database"
|
||||
"ymgb/database/mdb"
|
||||
"ymgb/utils"
|
||||
|
||||
"git.nix13.pw/scuroneko/extypes"
|
||||
"git.nix13.pw/scuroneko/laniakea"
|
||||
"git.nix13.pw/scuroneko/slog"
|
||||
)
|
||||
|
||||
func RegisterLogs(bot *laniakea.Bot) {
|
||||
p := laniakea.NewPlugin("Logs")
|
||||
func RegisterLogs() *laniakea.Plugin[database.Context] {
|
||||
p := laniakea.NewPlugin[database.Context]("Logs")
|
||||
p.AddCommand(p.NewCommand(getLogs, "logs").SkipCommandAutoGen())
|
||||
p.AddCommand(p.NewCommand(getMsgLogs, "msglogs").SkipCommandAutoGen())
|
||||
p.AddMiddleware(AdminMiddleware())
|
||||
bot.AddPlugins(p)
|
||||
return p
|
||||
}
|
||||
func InitLogMiddleware() laniakea.Middleware {
|
||||
func InitLogMiddleware() laniakea.Middleware[database.Context] {
|
||||
return *laniakea.NewMiddleware("LogMiddleware", logMiddleware).SetAsync(true)
|
||||
}
|
||||
|
||||
func getLogs(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
func getLogs(ctx *laniakea.MsgContext, db *database.Context) {
|
||||
logs, err := mdb.GetConsoleLogs(db)
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
@@ -34,7 +35,7 @@ func getLogs(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
out := encodeLogs(logs)
|
||||
ctx.Answer(strings.Join(out, ""))
|
||||
}
|
||||
func getMsgLogs(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
func getMsgLogs(ctx *laniakea.MsgContext, db *database.Context) {
|
||||
logs, err := mdb.GetMessageLogs(db)
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
@@ -61,7 +62,7 @@ func encodeLogs[T comparable](logs extypes.Slice[T]) extypes.Slice[string] {
|
||||
return out
|
||||
}
|
||||
|
||||
func logMiddleware(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) bool {
|
||||
func logMiddleware(ctx *laniakea.MsgContext, db *database.Context) bool {
|
||||
if ctx.Msg == nil {
|
||||
return true
|
||||
}
|
||||
@@ -70,18 +71,18 @@ func logMiddleware(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) bool
|
||||
SenderID: ctx.FromID,
|
||||
ChatID: ctx.Msg.Chat.ID,
|
||||
Text: ctx.Msg.Text,
|
||||
TimeStamp: time.Now().Unix(),
|
||||
TimeStamp: int64(ctx.Msg.Date),
|
||||
}
|
||||
err := mdb.WriteMessageLog(db, entry)
|
||||
if err != nil {
|
||||
ctx.Bot.Logger().Errorln(err)
|
||||
ctx.Error(err)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
type DatabaseWriter struct {
|
||||
slog.LoggerWriter
|
||||
db *laniakea.DatabaseContext
|
||||
db *database.Context
|
||||
}
|
||||
|
||||
func (w *DatabaseWriter) Print(level slog.LogLevel, prefix string, traceback []*slog.MethodTraceback, messages ...any) error {
|
||||
@@ -102,6 +103,6 @@ func (w *DatabaseWriter) Print(level slog.LogLevel, prefix string, traceback []*
|
||||
err := mdb.WriteConsoleLog(w.db, entry)
|
||||
return err
|
||||
}
|
||||
func DatabaseLogger(db *laniakea.DatabaseContext) slog.LoggerWriter {
|
||||
func DatabaseLogger(db *database.Context) slog.LoggerWriter {
|
||||
return &DatabaseWriter{db: db}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
package plugins
|
||||
|
||||
import "git.nix13.pw/scuroneko/laniakea"
|
||||
import (
|
||||
"ymgb/database"
|
||||
|
||||
func RegisterRelations(b *laniakea.Bot) {
|
||||
p := laniakea.NewPlugin("Relations")
|
||||
b.AddPlugins(p)
|
||||
"git.nix13.pw/scuroneko/laniakea"
|
||||
)
|
||||
|
||||
func RegisterRelations() *laniakea.Plugin[database.Context] {
|
||||
p := laniakea.NewPlugin[database.Context]("Relations")
|
||||
return p
|
||||
}
|
||||
|
||||
@@ -4,14 +4,15 @@ import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"kurumibot/database/mdb"
|
||||
"kurumibot/database/psql"
|
||||
"kurumibot/database/red"
|
||||
"kurumibot/utils"
|
||||
"kurumibot/utils/ai"
|
||||
"log"
|
||||
"strconv"
|
||||
"strings"
|
||||
"ymgb/database"
|
||||
"ymgb/database/mdb"
|
||||
"ymgb/database/psql"
|
||||
"ymgb/database/red"
|
||||
"ymgb/utils"
|
||||
"ymgb/utils/ai"
|
||||
|
||||
"git.nix13.pw/scuroneko/extypes"
|
||||
"git.nix13.pw/scuroneko/laniakea"
|
||||
@@ -19,8 +20,8 @@ import (
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func RegisterRP(bot *laniakea.Bot) {
|
||||
rp := laniakea.NewPlugin("RP")
|
||||
func RegisterRP() *laniakea.Plugin[database.Context] {
|
||||
rp := laniakea.NewPlugin[database.Context]("RP")
|
||||
rp.AddCommand(rp.NewCommand(rpUserPromptSet, "rpuserpset"))
|
||||
rp.AddCommand(rp.NewCommand(rpInfo, "rp").SetDescription("РП профиль пользователя"))
|
||||
rp.AddCommand(rp.NewCommand(rpInfo, "рп").SkipCommandAutoGen())
|
||||
@@ -50,10 +51,10 @@ func RegisterRP(bot *laniakea.Bot) {
|
||||
rp.AddPayload(rp.NewCommand(compressSettingStage2, "rp.compress_setting_s2"))
|
||||
rp.AddPayload(rp.NewCommand(compressSetting, "rp.compress_setting"))
|
||||
|
||||
bot.AddPlugins(rp)
|
||||
return rp
|
||||
}
|
||||
|
||||
func rpInfo(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
func rpInfo(ctx *laniakea.MsgContext, db *database.Context) {
|
||||
userRep := psql.NewUserRepository(db)
|
||||
_, err := userRep.GetOrCreate(ctx.FromID, ctx.From.FirstName)
|
||||
if err != nil {
|
||||
@@ -135,7 +136,7 @@ func rpInfo(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
}
|
||||
}
|
||||
|
||||
func rpWaifuList(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
func rpWaifuList(ctx *laniakea.MsgContext, db *database.Context) {
|
||||
waifuRep := psql.NewWaifuRepository(db)
|
||||
var waifus extypes.Slice[*psql.Waifu]
|
||||
|
||||
@@ -176,7 +177,7 @@ func rpWaifuList(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
ctx.EditCallback(strings.Join(out, "\n"), kb)
|
||||
ctx.AnswerCbQuery()
|
||||
}
|
||||
func rpWaifuSet(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
func rpWaifuSet(ctx *laniakea.MsgContext, db *database.Context) {
|
||||
waifuId, err := strconv.Atoi(ctx.Args[0])
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
@@ -201,7 +202,7 @@ func rpWaifuSet(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
ctx.AnswerCbQuery()
|
||||
}
|
||||
|
||||
func rpPresetsList(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
func rpPresetsList(ctx *laniakea.MsgContext, db *database.Context) {
|
||||
rep := psql.NewRPRepository(db)
|
||||
presets, err := rep.GetAllPresets()
|
||||
if err != nil {
|
||||
@@ -222,7 +223,7 @@ func rpPresetsList(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
ctx.EditCallback(strings.Join(out, "\n"), kb)
|
||||
ctx.AnswerCbQuery()
|
||||
}
|
||||
func rpPresetSet(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
func rpPresetSet(ctx *laniakea.MsgContext, db *database.Context) {
|
||||
if len(ctx.Args) == 0 || ctx.Args[0] == "" {
|
||||
return
|
||||
}
|
||||
@@ -249,7 +250,7 @@ func rpPresetSet(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
ctx.AnswerCbQuery()
|
||||
}
|
||||
|
||||
func rpModelList(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
func rpModelList(ctx *laniakea.MsgContext, db *database.Context) {
|
||||
rep := psql.NewAIRepository(db)
|
||||
models, err := rep.GetAllModels()
|
||||
if err != nil {
|
||||
@@ -268,7 +269,7 @@ func rpModelList(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
ctx.EditCallback(strings.Join(out, "\n"), kb)
|
||||
ctx.AnswerCbQuery()
|
||||
}
|
||||
func rpModelSet(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
func rpModelSet(ctx *laniakea.MsgContext, db *database.Context) {
|
||||
rep := psql.NewRPRepository(db)
|
||||
user, err := rep.GetOrCreateUser(int64(ctx.FromID))
|
||||
if err != nil {
|
||||
@@ -293,7 +294,7 @@ func rpModelSet(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
ctx.AnswerCbQuery()
|
||||
}
|
||||
|
||||
func rpScenarioList(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
func rpScenarioList(ctx *laniakea.MsgContext, db *database.Context) {
|
||||
rep := psql.NewRPRepository(db)
|
||||
scenarios, err := rep.GetAllScenarios()
|
||||
if err != nil {
|
||||
@@ -309,7 +310,7 @@ func rpScenarioList(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
ctx.EditCallback("Список сценариев\n"+strings.Join(out, "\n"), kb)
|
||||
ctx.AnswerCbQuery()
|
||||
}
|
||||
func rpSettingList(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
func rpSettingList(ctx *laniakea.MsgContext, db *database.Context) {
|
||||
rep := psql.NewRPRepository(db)
|
||||
settings, err := rep.GetAllSettings()
|
||||
if err != nil {
|
||||
@@ -327,7 +328,7 @@ func rpSettingList(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
ctx.AnswerCbQuery()
|
||||
}
|
||||
|
||||
func chatStat(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
func chatStat(ctx *laniakea.MsgContext, db *database.Context) {
|
||||
redisRpRep := red.NewRPRepository(db)
|
||||
chat, err := redisRpRep.GetChat(ctx.FromID)
|
||||
if err != nil {
|
||||
@@ -368,7 +369,7 @@ func chatStat(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
ctx.AnswerCbQuery()
|
||||
}
|
||||
|
||||
func newChatStage1(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
func newChatStage1(ctx *laniakea.MsgContext, db *database.Context) {
|
||||
// Выбор сеттинга
|
||||
rep := psql.NewRPRepository(db)
|
||||
settings, err := rep.GetAllSettings()
|
||||
@@ -391,7 +392,7 @@ func newChatStage1(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
ctx.EditCallback(strings.Join(out, "\n"), kb)
|
||||
ctx.AnswerCbQuery()
|
||||
}
|
||||
func newChatStage2(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
func newChatStage2(ctx *laniakea.MsgContext, db *database.Context) {
|
||||
// Выбор сценария
|
||||
if len(ctx.Args) == 0 {
|
||||
ctx.Error(fmt.Errorf("zero args len"))
|
||||
@@ -455,7 +456,7 @@ func newChatStage2(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
//ctx.AnswerCbQueryText(fmt.Sprintf("Ты выбрал сеттинг %s", setting.Name))
|
||||
ctx.AnswerCbQuery()
|
||||
}
|
||||
func newChat(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
func newChat(ctx *laniakea.MsgContext, db *database.Context) {
|
||||
redisRpRep := red.NewRPRepository(db)
|
||||
psqlRpRep := psql.NewRPRepository(db)
|
||||
waifuId := redisRpRep.GetSelectedWaifu(ctx.FromID)
|
||||
@@ -536,7 +537,7 @@ func newChat(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
ctx.AnswerCbQuery()
|
||||
}
|
||||
|
||||
func rpUserPromptSet(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
func rpUserPromptSet(ctx *laniakea.MsgContext, db *database.Context) {
|
||||
if len(ctx.Args) == 0 || ctx.Args[0] == "" {
|
||||
return
|
||||
}
|
||||
@@ -556,7 +557,7 @@ func rpUserPromptSet(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
ctx.Answer("Описание пользователя было обновлено")
|
||||
}
|
||||
|
||||
func _getChatHistory(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) ([]ai.Message, error) {
|
||||
func _getChatHistory(ctx *laniakea.MsgContext, db *database.Context) ([]ai.Message, error) {
|
||||
redRep := red.NewRPRepository(db)
|
||||
psqlRep := psql.NewRPRepository(db)
|
||||
waifuRep := psql.NewWaifuRepository(db)
|
||||
@@ -620,7 +621,7 @@ func _getChatHistory(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) ([]
|
||||
return messages, nil
|
||||
}
|
||||
|
||||
func generate(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
func generate(ctx *laniakea.MsgContext, db *database.Context) {
|
||||
redisRpRep := red.NewRPRepository(db)
|
||||
rpRep := psql.NewRPRepository(db)
|
||||
waifuId := redisRpRep.GetSelectedWaifu(ctx.FromID)
|
||||
@@ -717,7 +718,7 @@ func generate(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
}
|
||||
}
|
||||
|
||||
func regenerateResponse(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
func regenerateResponse(ctx *laniakea.MsgContext, db *database.Context) {
|
||||
ctx.AnswerCbQueryText("Запущена повторная генерация…")
|
||||
|
||||
redRep := red.NewRPRepository(db)
|
||||
@@ -789,7 +790,7 @@ func regenerateResponse(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext)
|
||||
ctx.EditCallback(laniakea.EscapeMarkdown(res.Choices[0].Message.Content), kb)
|
||||
}
|
||||
|
||||
func compress(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
func compress(ctx *laniakea.MsgContext, db *database.Context) {
|
||||
ctx.AnswerCbQueryText("Запущено сжатие чата…")
|
||||
_compress(ctx, db)
|
||||
kb := laniakea.NewInlineKeyboard(1)
|
||||
@@ -797,7 +798,7 @@ func compress(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
kb.AddCallbackButtonStyle("На главную", laniakea.ButtonStyleDanger, "rp.info")
|
||||
}
|
||||
|
||||
func _compress(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
func _compress(ctx *laniakea.MsgContext, db *database.Context) {
|
||||
redisRpRep := red.NewRPRepository(db)
|
||||
waifuId := redisRpRep.GetSelectedWaifu(ctx.FromID)
|
||||
if waifuId == 0 {
|
||||
@@ -902,7 +903,7 @@ var tokenMethodCount = []int{
|
||||
16, 32, 64, 128, 256,
|
||||
}
|
||||
|
||||
func compressSettingStage1(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext) {
|
||||
func compressSettingStage1(ctx *laniakea.MsgContext, _ *database.Context) {
|
||||
kb := laniakea.NewInlineKeyboard(2)
|
||||
kb.AddCallbackButton("По сообщениям", "rp.compress_setting_s2", "messages")
|
||||
kb.AddCallbackButton("По токенам", "rp.compress_setting_s2", "tokens")
|
||||
@@ -917,7 +918,7 @@ func compressSettingStage1(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext
|
||||
|
||||
ctx.EditCallback(strings.Join(out, "\n"), kb)
|
||||
}
|
||||
func compressSettingStage2(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext) {
|
||||
func compressSettingStage2(ctx *laniakea.MsgContext, _ *database.Context) {
|
||||
if len(ctx.Args) == 0 {
|
||||
return
|
||||
}
|
||||
@@ -942,7 +943,7 @@ func compressSettingStage2(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext
|
||||
kb.AddCallbackButtonStyle("На главную", laniakea.ButtonStyleDanger, "rp.info")
|
||||
ctx.EditCallback(strings.Join(out, "\n"), kb)
|
||||
}
|
||||
func compressSetting(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
func compressSetting(ctx *laniakea.MsgContext, db *database.Context) {
|
||||
rep := psql.NewRPRepository(db)
|
||||
user, err := rep.GetUser(int64(ctx.FromID))
|
||||
if err != nil {
|
||||
|
||||
@@ -2,23 +2,24 @@ package plugins
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"kurumibot/utils"
|
||||
"runtime"
|
||||
"strings"
|
||||
"ymgb/database"
|
||||
"ymgb/utils"
|
||||
|
||||
"git.nix13.pw/scuroneko/laniakea"
|
||||
)
|
||||
|
||||
func RegisterService(bot *laniakea.Bot) {
|
||||
p := laniakea.NewPlugin("service")
|
||||
func RegisterService() *laniakea.Plugin[database.Context] {
|
||||
p := laniakea.NewPlugin[database.Context]("service")
|
||||
p.AddPayload(p.NewCommand(generalClose, "general.close"))
|
||||
|
||||
p.AddCommand(p.NewCommand(about, "about"))
|
||||
p.AddCommand(p.NewCommand(about, "о боте").SkipCommandAutoGen())
|
||||
bot.AddPlugins(p)
|
||||
return p
|
||||
}
|
||||
|
||||
func about(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext) {
|
||||
func about(ctx *laniakea.MsgContext, _ *database.Context) {
|
||||
out := []string{
|
||||
fmt.Sprintf("Версия Go: %s", runtime.Version()[2:]),
|
||||
fmt.Sprintf("Версия Laniakea: %s", laniakea.VersionString),
|
||||
@@ -32,7 +33,7 @@ func about(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext) {
|
||||
ctx.Keyboard(strings.Join(out, "\n"), kb)
|
||||
}
|
||||
|
||||
func generalClose(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext) {
|
||||
func generalClose(ctx *laniakea.MsgContext, _ *database.Context) {
|
||||
ctx.CallbackDelete()
|
||||
ctx.AnswerCbQuery()
|
||||
}
|
||||
|
||||
@@ -2,19 +2,20 @@ package plugins
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"kurumibot/database/psql"
|
||||
"kurumibot/utils"
|
||||
"log"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"ymgb/database"
|
||||
"ymgb/database/psql"
|
||||
"ymgb/utils"
|
||||
|
||||
"git.nix13.pw/scuroneko/extypes"
|
||||
"git.nix13.pw/scuroneko/laniakea"
|
||||
)
|
||||
|
||||
func RegisterWaifus(bot *laniakea.Bot) {
|
||||
p := laniakea.NewPlugin("Waifus")
|
||||
func RegisterWaifus() *laniakea.Plugin[database.Context] {
|
||||
p := laniakea.NewPlugin[database.Context]("Waifus")
|
||||
|
||||
p.AddCommand(p.NewCommand(myWaifu, "mywaifu"))
|
||||
p.AddCommand(p.NewCommand(myWaifu, "моивайфу").SkipCommandAutoGen())
|
||||
@@ -33,10 +34,10 @@ func RegisterWaifus(bot *laniakea.Bot) {
|
||||
p.AddPayload(p.NewCommand(waifuNotImplemented, "waifu.confirm_buy"))
|
||||
p.AddPayload(p.NewCommand(waifuNotImplemented, "waifu.confirm_sell"))
|
||||
|
||||
bot.AddPlugins(p)
|
||||
return p
|
||||
}
|
||||
|
||||
func myWaifu(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
func myWaifu(ctx *laniakea.MsgContext, db *database.Context) {
|
||||
userRep := psql.NewUserRepository(db)
|
||||
user, err := userRep.GetOrCreate(ctx.FromID, ctx.From.FirstName)
|
||||
if err != nil {
|
||||
@@ -73,7 +74,7 @@ func myWaifu(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
}
|
||||
}
|
||||
|
||||
func waifuList(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
func waifuList(ctx *laniakea.MsgContext, db *database.Context) {
|
||||
rep := psql.NewWaifuRepository(db)
|
||||
waifus, err := rep.GetAll()
|
||||
if err != nil {
|
||||
@@ -108,7 +109,7 @@ func waifuList(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
}
|
||||
}
|
||||
|
||||
func waifuSell(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
func waifuSell(ctx *laniakea.MsgContext, db *database.Context) {
|
||||
const CantSellWaifu = "Не удалось продать вайфу"
|
||||
|
||||
waifuId, err := strconv.Atoi(ctx.Args[0])
|
||||
@@ -147,11 +148,11 @@ func waifuSell(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
ctx.Keyboard(strings.Join(out, "\n"), kb)
|
||||
}
|
||||
|
||||
func buyWaifu(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
func buyWaifu(ctx *laniakea.MsgContext, db *database.Context) {
|
||||
|
||||
}
|
||||
|
||||
func waifuInfo(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
func waifuInfo(ctx *laniakea.MsgContext, db *database.Context) {
|
||||
if len(ctx.Args) != 1 {
|
||||
ctx.Answer("Не указан ID вайфу!")
|
||||
return
|
||||
@@ -198,7 +199,7 @@ func waifuInfo(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
ctx.AnswerCbQuery()
|
||||
}
|
||||
|
||||
func waifuSearch(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
func waifuSearch(ctx *laniakea.MsgContext, db *database.Context) {
|
||||
userRep := psql.NewUserRepository(db)
|
||||
user, err := userRep.GetOrCreate(ctx.FromID, ctx.Msg.From.FirstName)
|
||||
if err != nil {
|
||||
@@ -265,7 +266,7 @@ func waifuSearch(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
}
|
||||
}
|
||||
|
||||
func waifuNotImplemented(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext) {
|
||||
func waifuNotImplemented(ctx *laniakea.MsgContext, _ *database.Context) {
|
||||
kb := laniakea.NewInlineKeyboard(2).AddCallbackButton("Мои вайфу", "waifu.my").AddCallbackButton("Все вайфу", "waifu.list")
|
||||
ctx.EditCallback("Данная функция ещё не реализована", kb)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user