some fixes
This commit is contained in:
@@ -2,8 +2,8 @@ package mdb
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"kurumibot/database"
|
||||||
"kurumibot/laniakea"
|
"kurumibot/laniakea"
|
||||||
"os"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ type ConsoleLogEntry struct {
|
|||||||
func WriteConsoleLog(db *laniakea.DatabaseContext, e *ConsoleLogEntry) error {
|
func WriteConsoleLog(db *laniakea.DatabaseContext, e *ConsoleLogEntry) error {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
col := db.MongoDB.Database(os.Getenv("MONGO_NAME")).Collection("logs")
|
col := database.GetMongoCollection(db, "logs")
|
||||||
_, err := col.InsertOne(ctx, e)
|
_, err := col.InsertOne(ctx, e)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -35,7 +35,7 @@ type MessageLogEntry struct {
|
|||||||
func WriteMessageLog(db *laniakea.DatabaseContext, e *MessageLogEntry) error {
|
func WriteMessageLog(db *laniakea.DatabaseContext, e *MessageLogEntry) error {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
collection := db.MongoDB.Database(os.Getenv("MONGO_NAME")).Collection("msg_logs")
|
col := database.GetMongoCollection(db, "msg_logs")
|
||||||
_, err := collection.InsertOne(ctx, e)
|
_, err := col.InsertOne(ctx, e)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,12 +22,12 @@ func NewFractionRepository(db *sqlx.DB) *FractionRepository {
|
|||||||
return &FractionRepository{db: db}
|
return &FractionRepository{db: db}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rep *FractionRepository) GetAllFractions() ([]*Fraction, error) {
|
func (rep *FractionRepository) GetAll() ([]*Fraction, error) {
|
||||||
fractions := make([]*Fraction, 0)
|
fractions := make([]*Fraction, 0)
|
||||||
err := rep.db.Select(&fractions, "SELECT * FROM fractions ORDER BY id DESC;")
|
err := rep.db.Select(&fractions, "SELECT * FROM fractions ORDER BY id DESC;")
|
||||||
return fractions, err
|
return fractions, err
|
||||||
}
|
}
|
||||||
func (rep *FractionRepository) GetFraction(id int32) (*Fraction, error) {
|
func (rep *FractionRepository) GetById(id int32) (*Fraction, error) {
|
||||||
fraction := new(Fraction)
|
fraction := new(Fraction)
|
||||||
err := rep.db.Get(fraction, "SELECT * FROM fractions WHERE id = $1", id)
|
err := rep.db.Get(fraction, "SELECT * FROM fractions WHERE id = $1", id)
|
||||||
return fraction, err
|
return fraction, err
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ func GetUser(telegramId int) (*User, error) {
|
|||||||
}
|
}
|
||||||
if user.FractionID.Valid {
|
if user.FractionID.Valid {
|
||||||
fractionRep := NewFractionRepository(database.PostgresDatabase)
|
fractionRep := NewFractionRepository(database.PostgresDatabase)
|
||||||
user.Fraction, err = fractionRep.GetFraction(user.FractionID.Int32)
|
user.Fraction, err = fractionRep.GetById(user.FractionID.Int32)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ func RegisterRP(bot *laniakea.Bot) {
|
|||||||
rp = rp.Command(rpPresetsList, "rpplist")
|
rp = rp.Command(rpPresetsList, "rpplist")
|
||||||
rp = rp.Command(rpPresetSet, "rppset")
|
rp = rp.Command(rpPresetSet, "rppset")
|
||||||
rp = rp.Command(newChat, "newchat")
|
rp = rp.Command(newChat, "newchat")
|
||||||
|
rp = rp.Command(rpUserPromptGet, "rpuserpget")
|
||||||
|
rp = rp.Command(rpUserPromptSet, "rpuserpset")
|
||||||
rp = rp.Command(generate, "g", "gen", "г")
|
rp = rp.Command(generate, "g", "gen", "г")
|
||||||
|
|
||||||
bot.AddPlugins(rp.Build())
|
bot.AddPlugins(rp.Build())
|
||||||
@@ -50,7 +52,10 @@ func rpPresetsList(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
|||||||
}
|
}
|
||||||
out := make([]string, len(presets))
|
out := make([]string, len(presets))
|
||||||
for i, preset := range 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"))
|
ctx.Answer(strings.Join(out, "\n"))
|
||||||
}
|
}
|
||||||
@@ -102,6 +107,38 @@ func newChat(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
|||||||
}
|
}
|
||||||
ctx.Answer("Был создан новый чат.")
|
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) {
|
func generate(ctx *laniakea.MsgContext, db *laniakea.DatabaseContext) {
|
||||||
waifuId := red.RPGetSelectedWaifu(db, ctx.FromID)
|
waifuId := red.RPGetSelectedWaifu(db, ctx.FromID)
|
||||||
|
|||||||
Reference in New Issue
Block a user