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.

245 lines
7.5 KiB

3 years ago
package handlers
import (
"context"
"fmt"
"gitea.russia9.dev/russia9/muskrat/storage"
"gitea.russia9.dev/russia9/muskrat/types"
"gitea.russia9.dev/russia9/muskrat/userbot"
"gitea.russia9.dev/russia9/muskrat/utils"
"gopkg.in/telebot.v3"
3 years ago
"regexp"
"strconv"
"strings"
)
func List(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), "account", strconv.FormatInt(account.ID, 10))))
}
markup.Inline(rows...)
return ctx.Send("Список аккаунтов:", markup)
}
func Account(ctx telebot.Context) error {
if len(ctx.Data()) == 0 {
return ctx.Delete()
}
var account types.Account
storage.DB.First(&account, strings.Split(ctx.Data(), "|")[0])
markup := &telebot.ReplyMarkup{}
id := strconv.FormatInt(account.ID, 10)
markup.Inline(
markup.Row(
3 years ago
markup.Data(fmt.Sprintf("%s Еда", utils.BoolEmoji(account.Eat)), "edit", id, "eat"),
markup.Data(fmt.Sprintf("%s Еда на 200", utils.BoolEmoji(account.Eat200)), "edit", id, "eat_200"),
3 years ago
),
markup.Row(
markup.Data(fmt.Sprintf("Команда еды: %s", account.EatCommand), "edit", id, "eat_command"),
markup.Data(fmt.Sprintf("Шанс на еду: %d", account.EatChance), "edit", id, "eat_chance"),
),
markup.Row(
3 years ago
markup.Data(fmt.Sprintf("%s Лвлап", utils.BoolEmoji(account.Levelup)), "edit", id, "levelup"),
markup.Data(fmt.Sprintf("%s Скилл", utils.BoolLevelup(account.LevelupSkill)), "edit", id, "levelup_skill"),
3 years ago
),
markup.Row(
3 years ago
markup.Data(fmt.Sprintf("%s Пины", utils.BoolEmoji(account.Pin)), "edit", id, "pin"),
3 years ago
markup.Data(fmt.Sprintf("Чат: %d", account.PinChat), "edit", id, "pin_chat"),
markup.Data(fmt.Sprintf("Пауза: %.1f", account.PinDelay), "edit", id, "pin_delay"),
markup.Data(fmt.Sprintf("Шанс: %d", account.PinChance), "edit", id, "pin_chance"),
),
markup.Row(
3 years ago
markup.Data(fmt.Sprintf("%s Репорты", utils.BoolEmoji(account.Report)), "edit", id, "report"),
3 years ago
markup.Data(fmt.Sprintf("Чат: %d", account.ReportChat), "edit", id, "report_chat"),
markup.Data(fmt.Sprintf("Пауза: %.1f", account.ReportDelay), "edit", id, "report_delay"),
markup.Data(fmt.Sprintf("Шанс: %d", account.ReportChance), "edit", id, "report_chance"),
),
markup.Row(
3 years ago
markup.Data(fmt.Sprintf("%s Мобы", utils.BoolEmoji(account.Mob)), "edit", id, "mob"),
3 years ago
markup.Data(fmt.Sprintf("Пауза: %.1f", account.MobDelay), "edit", id, "mob_delay"),
markup.Data(fmt.Sprintf("Шанс: %d", account.MobChance), "edit", id, "mob_chance"),
),
markup.Row(
3 years ago
markup.Data(fmt.Sprintf("%s Акула", utils.BoolEmoji(account.Shark)), "edit", id, "shark"),
3 years ago
markup.Data(fmt.Sprintf("Пауза: %.1f", account.SharkDelay), "edit", id, "shark_delay"),
markup.Data(fmt.Sprintf("Команда: %s", utils.SharkEmoji(account.SharkTeam)), "edit", id, "shark_team"),
),
markup.Row(
3 years ago
markup.Data(fmt.Sprintf("%s Сон", utils.BoolEmoji(account.Sleep)), "edit", id, "sleep"),
markup.Data(fmt.Sprintf("%s Сон в отеле?", utils.BoolEmoji(account.SleepHotel)), "edit", id, "sleep_hotel"),
3 years ago
),
markup.Row(
3 years ago
markup.Data(fmt.Sprintf("%s Слив моты", utils.BoolEmoji(account.Motivation)), "edit", id, "motivation"),
markup.Data(fmt.Sprintf("%s Слив по кд", utils.BoolEmoji(account.MotivationKD)), "edit", id, "motivation_kd"),
3 years ago
),
markup.Row(
markup.Data(fmt.Sprintf("Команда для слива: %s", account.MotivationCommand), "edit", id, "motivation_command"),
),
)
return ctx.EditOrSend(fmt.Sprintf("Аккаунт <b>%s %s</b>:", account.Corp, account.Name), markup)
}
func Edit(ctx telebot.Context) error {
data := strings.Split(ctx.Data(), "|")
if len(data) != 2 {
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
switch data[1] {
case "eat":
account.Eat = !account.Eat
case "eat_200":
account.Eat200 = !account.Eat200
case "levelup":
account.Levelup = !account.Levelup
case "levelup_skill":
account.LevelupSkill = !account.LevelupSkill
case "pin":
account.Pin = !account.Pin
case "report":
account.Report = !account.Report
case "mob":
account.Mob = !account.Mob
case "shark":
account.Shark = !account.Shark
case "shark_team":
account.SharkTeam = !account.SharkTeam
case "sleep":
account.Sleep = !account.Sleep
case "sleep_hotel":
account.SleepHotel = !account.SleepHotel
case "motivation":
account.Motivation = !account.Motivation
case "motivation_kd":
account.MotivationKD = !account.MotivationKD
default:
err = storage.SetState(context.Background(), ctx.Sender().ID, "edit", data...)
if err != nil {
return err
}
return ctx.Send(fmt.Sprintf("Введите значение <b>%s</b>:", data[1]))
}
userbot.Userbots[id].Account = account
storage.DB.Save(&account)
return Account(ctx)
}
func EditInput(ctx telebot.Context, data []string) error {
defer storage.ClearState(context.Background(), ctx.Sender().ID)
if len(data) != 2 {
return nil
}
id, err := strconv.ParseInt(data[0], 10, 64)
if err != nil {
return err
}
if userbot.Userbots[id] == nil {
return nil
}
account := userbot.Userbots[id].Account
switch data[1] {
case "eat_command":
account.EatCommand = ctx.Text()
case "eat_chance":
account.EatChance, err = strconv.Atoi(ctx.Text())
if err != nil {
return ctx.Send("Неправильный формат")
}
case "pin_chat":
account.PinChat, err = strconv.ParseInt(ctx.Text(), 10, 64)
if err != nil {
return ctx.Send("Неправильный формат")
}
case "pin_delay":
account.PinDelay, err = strconv.ParseFloat(ctx.Text(), 64)
if err != nil {
return ctx.Send("Неправильный формат")
}
case "pin_chance":
account.PinChance, err = strconv.Atoi(ctx.Text())
if err != nil {
return ctx.Send("Неправильный формат")
}
case "report_chat":
account.ReportChat, err = strconv.ParseInt(ctx.Text(), 10, 64)
if err != nil {
return ctx.Send("Неправильный формат")
}
case "report_delay":
account.ReportDelay, err = strconv.ParseFloat(ctx.Text(), 64)
if err != nil {
return ctx.Send("Неправильный формат")
}
case "report_chance":
account.ReportChance, err = strconv.Atoi(ctx.Text())
if err != nil {
return ctx.Send("Неправильный формат")
}
case "mob_delay":
account.MobDelay, err = strconv.ParseFloat(ctx.Text(), 64)
if err != nil {
return ctx.Send("Неправильный формат")
}
case "mob_chance":
account.MobChance, err = strconv.Atoi(ctx.Text())
if err != nil {
return ctx.Send("Неправильный формат")
}
case "shark_delay":
account.SharkDelay, err = strconv.ParseFloat(ctx.Text(), 64)
if err != nil {
return ctx.Send("Неправильный формат")
}
case "motivation_command":
if !regexp.MustCompile("/.*").MatchString(ctx.Text()) {
return ctx.Send("Неправильный формат")
}
account.MotivationCommand = ctx.Text()
}
userbot.Userbots[id].Account = account
storage.DB.Save(&account)
return ctx.Send("Изменено")
}