some fixes

This commit is contained in:
2026-01-20 10:06:37 +03:00
parent fec89b5305
commit 02437946ed
4 changed files with 45 additions and 8 deletions

View File

@@ -2,8 +2,8 @@ package mdb
import (
"context"
"kurumibot/database"
"kurumibot/laniakea"
"os"
"time"
)
@@ -19,7 +19,7 @@ type ConsoleLogEntry struct {
func WriteConsoleLog(db *laniakea.DatabaseContext, e *ConsoleLogEntry) error {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
col := db.MongoDB.Database(os.Getenv("MONGO_NAME")).Collection("logs")
col := database.GetMongoCollection(db, "logs")
_, err := col.InsertOne(ctx, e)
return err
}
@@ -35,7 +35,7 @@ type MessageLogEntry struct {
func WriteMessageLog(db *laniakea.DatabaseContext, e *MessageLogEntry) error {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
collection := db.MongoDB.Database(os.Getenv("MONGO_NAME")).Collection("msg_logs")
_, err := collection.InsertOne(ctx, e)
col := database.GetMongoCollection(db, "msg_logs")
_, err := col.InsertOne(ctx, e)
return err
}

View File

@@ -22,12 +22,12 @@ func NewFractionRepository(db *sqlx.DB) *FractionRepository {
return &FractionRepository{db: db}
}
func (rep *FractionRepository) GetAllFractions() ([]*Fraction, error) {
func (rep *FractionRepository) GetAll() ([]*Fraction, error) {
fractions := make([]*Fraction, 0)
err := rep.db.Select(&fractions, "SELECT * FROM fractions ORDER BY id DESC;")
return fractions, err
}
func (rep *FractionRepository) GetFraction(id int32) (*Fraction, error) {
func (rep *FractionRepository) GetById(id int32) (*Fraction, error) {
fraction := new(Fraction)
err := rep.db.Get(fraction, "SELECT * FROM fractions WHERE id = $1", id)
return fraction, err

View File

@@ -119,7 +119,7 @@ func GetUser(telegramId int) (*User, error) {
}
if user.FractionID.Valid {
fractionRep := NewFractionRepository(database.PostgresDatabase)
user.Fraction, err = fractionRep.GetFraction(user.FractionID.Int32)
user.Fraction, err = fractionRep.GetById(user.FractionID.Int32)
if err != nil {
return err
}

View File

@@ -22,6 +22,8 @@ func RegisterRP(bot *laniakea.Bot) {
rp = rp.Command(rpPresetsList, "rpplist")
rp = rp.Command(rpPresetSet, "rppset")
rp = rp.Command(newChat, "newchat")
rp = rp.Command(rpUserPromptGet, "rpuserpget")
rp = rp.Command(rpUserPromptSet, "rpuserpset")
rp = rp.Command(generate, "g", "gen", "г")
bot.AddPlugins(rp.Build())
@@ -50,7 +52,10 @@ func rpPresetsList(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
}
out := make([]string, len(presets))
for i, preset := range presets {
out[i] = fmt.Sprintf("%s) *%s*\n%s", preset.ID, preset.Name, preset.Description)
out[i] = fmt.Sprintf(
"%s) *%s*\n%s",
preset.ID, laniakea.EscapeMarkdown(preset.Name), preset.Description,
)
}
ctx.Answer(strings.Join(out, "\n"))
}
@@ -102,6 +107,38 @@ func newChat(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
}
ctx.Answer("Был создан новый чат.")
}
func rpUserPromptGet(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
rep := psql.NewRPRepository(db.PostgresSQL)
user, err := rep.GetOrCreateUser(int64(ctx.FromID))
if err != nil {
ctx.Error(err)
return
}
if user.UserPrompt == "" {
ctx.Answer("У тебя нет описания")
return
}
ctx.Answerf("Вот твое РП описание пользователя\n%s", user.UserPrompt)
}
func rpUserPromptSet(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
if len(ctx.Args) == 0 || ctx.Args[0] == "" {
return
}
prompt := strings.Join(ctx.Args[1:], " ")
rep := psql.NewRPRepository(db.PostgresSQL)
user, err := rep.GetOrCreateUser(int64(ctx.FromID))
if err != nil {
ctx.Error(err)
return
}
user.UserPrompt = prompt
err = rep.UpdateUser(user)
if err != nil {
ctx.Error(err)
return
}
ctx.Answer("Описание пользователя было обновлено.")
}
func generate(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
waifuId := red.RPGetSelectedWaifu(db, ctx.FromID)