|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"gitea.russia9.dev/russia9/muskrat/storage"
|
|
|
|
"gitea.russia9.dev/russia9/muskrat/types"
|
|
|
|
"gitea.russia9.dev/russia9/muskrat/userbot"
|
|
|
|
"github.com/rs/zerolog/log"
|
|
|
|
"gopkg.in/telebot.v3"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Delete(ctx telebot.Context) error {
|
|
|
|
accounts := make([]types.Account, 0)
|
|
|
|
storage.DB.Find(&accounts, "\"user\" = ?", strconv.FormatInt(ctx.Sender().ID, 10))
|
|
|
|
|
|
|
|
if len(accounts) == 0 {
|
|
|
|
return ctx.Send("Чтобы добавить аккаунт, /add")
|
|
|
|
}
|
|
|
|
|
|
|
|
markup := &telebot.ReplyMarkup{}
|
|
|
|
rows := make([]telebot.Row, 0)
|
|
|
|
|
|
|
|
for _, account := range accounts {
|
|
|
|
rows = append(rows, markup.Row(markup.Data(fmt.Sprintf("%s %s %d", account.Corp, account.Name, account.Level), "delete", strconv.FormatInt(account.ID, 10))))
|
|
|
|
}
|
|
|
|
|
|
|
|
markup.Inline(rows...)
|
|
|
|
|
|
|
|
return ctx.Send("Удалить аккаунт:", markup)
|
|
|
|
}
|
|
|
|
|
|
|
|
func AdminDelete(ctx telebot.Context) error {
|
|
|
|
if ctx.Sender().ID != 784726544 && ctx.Sender().ID != 709800052 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
params := strings.Split(ctx.Text(), " ")
|
|
|
|
if len(params) != 2 {
|
|
|
|
return ctx.Send("Неправильный формат")
|
|
|
|
}
|
|
|
|
|
|
|
|
id, err := strconv.ParseInt(params[1], 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if userbot.Userbots[id].Account == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
account := userbot.Userbots[id].Account
|
|
|
|
|
|
|
|
err = userbot.Userbots[id].Stop()
|
|
|
|
if err != nil {
|
|
|
|
log.Warn().Err(err).Send()
|
|
|
|
}
|
|
|
|
|
|
|
|
delete(userbot.Userbots, id)
|
|
|
|
storage.DB.Unscoped().Delete(&account)
|
|
|
|
|
|
|
|
return ctx.Send("Успешно удалено")
|
|
|
|
}
|
|
|
|
|
|
|
|
func DeleteButton(ctx telebot.Context) error {
|
|
|
|
data := strings.Split(ctx.Data(), "|")
|
|
|
|
if len(data) != 1 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
id, err := strconv.ParseInt(data[0], 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if userbot.Userbots[id].Account == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
account := userbot.Userbots[id].Account
|
|
|
|
|
|
|
|
err = userbot.Userbots[id].Stop()
|
|
|
|
if err != nil {
|
|
|
|
log.Warn().Err(err).Send()
|
|
|
|
}
|
|
|
|
|
|
|
|
delete(userbot.Userbots, id)
|
|
|
|
storage.DB.Unscoped().Delete(&account)
|
|
|
|
|
|
|
|
return ctx.Send("Успешно удалено")
|
|
|
|
}
|