You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
1.9 KiB
92 lines
1.9 KiB
package handlers |
|
|
|
import ( |
|
"fmt" |
|
"github.com/rs/zerolog/log" |
|
"gopkg.in/tucnak/telebot.v3" |
|
"muskrat/storage" |
|
"muskrat/types" |
|
"muskrat/userbot" |
|
"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("Успешно удалено") |
|
}
|
|
|