some fixes and changes
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
package plugins
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"kurumibot/database/psql"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"git.nix13.pw/scuroneko/laniakea"
|
||||
"git.nix13.pw/scuroneko/laniakea/tgapi"
|
||||
"git.nix13.pw/scuroneko/laniakea/utils"
|
||||
"github.com/vinovest/sqlx"
|
||||
)
|
||||
|
||||
func RegisterAdmin(b *laniakea.Bot) {
|
||||
@@ -14,7 +17,7 @@ func RegisterAdmin(b *laniakea.Bot) {
|
||||
p.Command(uploadPhoto, "uploadPhoto")
|
||||
p.Command(emojiId, "emojiId")
|
||||
p.Command(getProxy, "proxy")
|
||||
p.Command(test, "test")
|
||||
p.Command(execSql, "sql")
|
||||
|
||||
p.AddMiddleware(AdminMiddleware())
|
||||
b.AddPlugins(p.Build())
|
||||
@@ -31,8 +34,32 @@ func AdminMiddleware() *laniakea.PluginMiddleware {
|
||||
return m
|
||||
}
|
||||
|
||||
func test(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext) {
|
||||
ctx.Answer("Ok")
|
||||
func execSql(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
stmt := strings.Join(ctx.Args, " ")
|
||||
stmt = db.PostgresSQL.Rebind(stmt)
|
||||
|
||||
var res []map[string]any
|
||||
r, err := db.PostgresSQL.Query(stmt)
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
return
|
||||
}
|
||||
defer r.Close()
|
||||
for r.Next() {
|
||||
a := make(map[string]any)
|
||||
if err = sqlx.MapScan(r, a); err != nil {
|
||||
ctx.Error(err)
|
||||
return
|
||||
}
|
||||
res = append(res, a)
|
||||
}
|
||||
|
||||
data, err := json.MarshalIndent(res, "", " ")
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
return
|
||||
}
|
||||
ctx.Answerf("`%s`", data)
|
||||
}
|
||||
func getProxy(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext) {
|
||||
ruProxy := "tg://proxy?port=3128&secret=7qaZyfQN-IQ7ZMwrR_zWnHBvem9uLnJ1&server=185.231.245.25"
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"kurumibot/utils"
|
||||
"math"
|
||||
"math/rand/v2"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -27,8 +26,6 @@ func RegisterEconomy(bot *laniakea.Bot) {
|
||||
|
||||
economy.Command(aboutGroup, "group", "о группе")
|
||||
|
||||
economy.Command(about, "about", "о боте")
|
||||
|
||||
bot.AddRunner(laniakea.NewRunner(
|
||||
"economy.PassiveIncome", passiveIncome,
|
||||
).Timeout(time.Minute).Build())
|
||||
@@ -36,16 +33,6 @@ func RegisterEconomy(bot *laniakea.Bot) {
|
||||
bot.AddPlugins(economy.Build())
|
||||
}
|
||||
|
||||
func about(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext) {
|
||||
out := []string{
|
||||
fmt.Sprintf("Версия Go: %s", runtime.Version()[2:]),
|
||||
fmt.Sprintf("Версия Laniakea: %s", laniakea.VersionString),
|
||||
fmt.Sprintf("Время сборки: %s", utils.BuildTime),
|
||||
fmt.Sprintf("Git хеш: %s", utils.GitCommit),
|
||||
}
|
||||
ctx.Answer(strings.Join(out, "\n"))
|
||||
}
|
||||
|
||||
func passiveIncome(b *laniakea.Bot) error {
|
||||
ctx := b.GetDBContext()
|
||||
waifuRep := psql.NewWaifuRepository(ctx)
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"kurumibot/database/red"
|
||||
"kurumibot/utils"
|
||||
"kurumibot/utils/ai"
|
||||
"log"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -322,53 +323,40 @@ func rpSettingList(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
|
||||
func chatStat(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
redisRpRep := red.NewRPRepository(db)
|
||||
waifuId := redisRpRep.GetSelectedWaifu(ctx.FromID)
|
||||
if waifuId == 0 {
|
||||
ctx.Answer("Не выбрана вайфу")
|
||||
chat, err := redisRpRep.GetChat(ctx.FromID)
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
return
|
||||
}
|
||||
chatId := redisRpRep.GetChatId(ctx.FromID, waifuId)
|
||||
if chatId == "" {
|
||||
ctx.Answer("Нет активного чата")
|
||||
return
|
||||
}
|
||||
messageCount, err := mdb.GetRPChatHistorySize(db, chatId)
|
||||
messageCount, err := mdb.GetRPChatHistorySize(db, chat.ID.String())
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
tokens := redisRpRep.GetChatTokens(ctx.FromID, waifuId)
|
||||
kb := laniakea.NewInlineKeyboard(1)
|
||||
kb.AddCallbackButtonStyle("Сжать чат", laniakea.ButtonStyleSuccess, "rp.compress_chat")
|
||||
kb.AddCallbackButtonStyle("На главную", laniakea.ButtonStyleDanger, "rp.info")
|
||||
out := []string{
|
||||
"Статистика чата",
|
||||
fmt.Sprintf("*ID*: `%s`", chatId),
|
||||
fmt.Sprintf("*ID*: `%s`", chat.ID.String()),
|
||||
fmt.Sprintf("*Кол-во сообщений*: %d", messageCount),
|
||||
fmt.Sprintf("*Кол-во токенов*: %d", tokens),
|
||||
fmt.Sprintf("*Кол-во токенов*: %d", chat.ChatTokens),
|
||||
}
|
||||
psqlRpRep := psql.NewRPRepository(db)
|
||||
scenarioIds := redisRpRep.GetChatScenariosIDs(ctx.FromID, waifuId)
|
||||
if len(scenarioIds) > 0 && scenarioIds[0] > 0 {
|
||||
scenarioNames := make([]string, len(scenarioIds))
|
||||
for i, id := range scenarioIds {
|
||||
scenario, err := psqlRpRep.GetScenario(id)
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
|
||||
if len(chat.Scenarios) > 0 && chat.Scenarios[0].ID > 0 {
|
||||
scenarioNames := make([]string, len(chat.Scenarios))
|
||||
for i, scenario := range chat.Scenarios {
|
||||
if scenario.ID == 0 {
|
||||
continue
|
||||
}
|
||||
scenarioNames[i] = fmt.Sprintf("%s (ID: %d)", scenario.Name, scenario.ID)
|
||||
}
|
||||
out = append(out, fmt.Sprintf("*Выбранные сценарии*: %s", strings.Join(scenarioNames, ", ")))
|
||||
}
|
||||
|
||||
settingId := redisRpRep.GetChatSettingID(ctx.FromID, waifuId)
|
||||
if settingId > 0 {
|
||||
setting, err := psqlRpRep.GetSetting(settingId)
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
}
|
||||
out = append(out, fmt.Sprintf("*Выбранный сеттинг*: %s (ID: %d)", setting.Name, setting.ID))
|
||||
if chat.Setting != nil {
|
||||
out = append(out, fmt.Sprintf("*Выбранный сеттинг*: %s (ID: %d)", chat.Setting.Name, chat.Setting.ID))
|
||||
}
|
||||
ctx.EditCallback(strings.Join(out, "\n"), kb)
|
||||
ctx.AnswerCbQuery()
|
||||
@@ -449,7 +437,7 @@ func newChatStage2(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
if len(scenariosIds) == 0 {
|
||||
scenariosIds = append(scenariosIds, 0)
|
||||
}
|
||||
kb.AddCallbackButton("Продолжить", "rp.new_chat", utils.AppendToInt(settingId, selectedScenariosIds)...)
|
||||
kb.AddCallbackButtonStyle("Создать", laniakea.ButtonStyleSuccess, "rp.new_chat", utils.AppendToInt(settingId, selectedScenariosIds)...)
|
||||
kb.AddLine()
|
||||
kb.AddCallbackButtonStyle("Назад", laniakea.ButtonStyleDanger, "rp.new_chat_s1")
|
||||
ctx.EditCallback(strings.Join(out, "\n"), kb)
|
||||
@@ -476,6 +464,13 @@ func newChat(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
return
|
||||
}
|
||||
|
||||
chat, err := redisRpRep.GetChat(ctx.FromID)
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Println(ctx.Args)
|
||||
chatPrompt := ""
|
||||
settingId, err := strconv.Atoi(ctx.Args[0])
|
||||
if err != nil {
|
||||
@@ -483,7 +478,7 @@ func newChat(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
return
|
||||
}
|
||||
if settingId > 0 {
|
||||
scenario, err := psqlRpRep.GetSetting(settingId)
|
||||
setting, err := psqlRpRep.GetSetting(settingId)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
ctx.Answerf("Сеттинг №%d не найден", settingId)
|
||||
@@ -492,10 +487,13 @@ func newChat(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
}
|
||||
return
|
||||
}
|
||||
chatPrompt = "Вот краткое описание мира(сеттинг): " + scenario.Prompt + "."
|
||||
chat.Setting = &setting
|
||||
chat.SettingID = settingId
|
||||
chatPrompt = "Вот краткое описание мира(сеттинг): " + setting.Prompt + "."
|
||||
}
|
||||
|
||||
scenariosIds := utils.Map(ctx.Args[1:], utils.StringToInt)
|
||||
chat.Scenarios = make([]psql.RPScenario, 0)
|
||||
if len(scenariosIds) > 0 && scenariosIds[0] > 0 {
|
||||
rep := psql.NewRPRepository(db)
|
||||
var scenariosPrompt []string
|
||||
@@ -510,39 +508,23 @@ func newChat(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
}
|
||||
return
|
||||
}
|
||||
chat.Scenarios = append(chat.Scenarios, scenario)
|
||||
scenariosPrompt = append(scenariosPrompt, scenario.Prompt)
|
||||
}
|
||||
|
||||
chatPrompt += "Вот дополнительная информация: " + strings.Join(scenariosPrompt, ".")
|
||||
}
|
||||
|
||||
if chatPrompt != "" {
|
||||
err = redisRpRep.SetChatPrompt(ctx.FromID, waifuId, chatPrompt)
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
err = redisRpRep.SetChatSettingID(ctx.FromID, waifuId, settingId)
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
}
|
||||
err = redisRpRep.SetChatScenariosIDs(ctx.FromID, waifuId, strings.Join(utils.Map(scenariosIds, utils.AnyToString), ","))
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
}
|
||||
err = redisRpRep.SetCounter(ctx.FromID, waifuId, 0)
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
}
|
||||
err = redisRpRep.SetChatTokens(ctx.FromID, waifuId, 0)
|
||||
chat.Prompt = chatPrompt
|
||||
chat.Counter = 0
|
||||
chat.ChatTokens = 0
|
||||
err = redisRpRep.SaveChat(chat)
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
kb := laniakea.NewInlineKeyboard(2)
|
||||
kb.AddCallbackButton("На главную", "rp.info")
|
||||
kb.AddCallbackButtonStyle("На главную", laniakea.ButtonStyleSuccess, "rp.info")
|
||||
kb.AddCallbackButtonStyle("Закрыть", laniakea.ButtonStyleDanger, "general.close")
|
||||
ctx.EditCallback("Был создан новый чат. Для общения используй `/г промпт`.", kb)
|
||||
ctx.AnswerCbQuery()
|
||||
@@ -666,7 +648,7 @@ func generate(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||
ctx.SendAction(tgapi.ChatActionTyping)
|
||||
api := ai.NewOpenAIAPI(ai.GPTBaseUrl, "", rpUser.Model.Key)
|
||||
defer api.Close()
|
||||
res, err := api.CreateCompletion(messages, userMessage, 1.0)
|
||||
res, err := api.CreateCompletion(messages, userMessage, 0.5)
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
return
|
||||
@@ -784,7 +766,7 @@ func regenerateResponse(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext)
|
||||
messages = messages.Pop(count - 2)
|
||||
|
||||
ctx.EditCallback("Генерация запущена...", nil)
|
||||
res, err := api.CreateCompletion(messages, userReq.Message, 1.0)
|
||||
res, err := api.CreateCompletion(messages, userReq.Message, 0.5)
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
return
|
||||
|
||||
@@ -1,13 +1,36 @@
|
||||
package plugins
|
||||
|
||||
import "git.nix13.pw/scuroneko/laniakea"
|
||||
import (
|
||||
"fmt"
|
||||
"kurumibot/utils"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"git.nix13.pw/scuroneko/laniakea"
|
||||
)
|
||||
|
||||
func RegisterService(bot *laniakea.Bot) {
|
||||
p := laniakea.NewPlugin("service")
|
||||
p.Payload(generalClose, "general.close")
|
||||
|
||||
p.Command(about, "about", "о боте")
|
||||
bot.AddPlugins(p.Build())
|
||||
}
|
||||
|
||||
func about(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext) {
|
||||
out := []string{
|
||||
fmt.Sprintf("Версия Go: %s", runtime.Version()[2:]),
|
||||
fmt.Sprintf("Версия Laniakea: %s", laniakea.VersionString),
|
||||
fmt.Sprintf("Время сборки: %s", utils.BuildTime),
|
||||
fmt.Sprintf("Git хеш: %s", utils.GitCommit),
|
||||
}
|
||||
|
||||
kb := laniakea.NewInlineKeyboard(2)
|
||||
kb.AddUrlButtonStyle("Канал", laniakea.ButtonStylePrimary, "https://t.me/ym_gbot_news")
|
||||
kb.AddUrlButtonStyle("Чат", laniakea.ButtonStylePrimary, "https://t.me/ym_gbot_chat")
|
||||
ctx.Keyboard(strings.Join(out, "\n"), kb)
|
||||
}
|
||||
|
||||
func generalClose(ctx *laniakea.MsgContext, _ *laniakea.DatabaseContext) {
|
||||
ctx.CallbackDelete()
|
||||
ctx.AnswerCbQuery()
|
||||
|
||||
Reference in New Issue
Block a user