Add return constants package, and common message sender functions
Trying to resolve as much as possible ``gometalinter`` issues.
This commit is contained in:
parent
049fdd7235
commit
4abfc457ce
@ -15,6 +15,7 @@ import (
|
|||||||
"source.wtfteam.pro/i2_bot/i2_bot/lib/pokedexer"
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/pokedexer"
|
||||||
"source.wtfteam.pro/i2_bot/i2_bot/lib/reminder"
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/reminder"
|
||||||
"source.wtfteam.pro/i2_bot/i2_bot/lib/router"
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/router"
|
||||||
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/sender"
|
||||||
"source.wtfteam.pro/i2_bot/i2_bot/lib/squader"
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/squader"
|
||||||
"source.wtfteam.pro/i2_bot/i2_bot/lib/statistics"
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/statistics"
|
||||||
"source.wtfteam.pro/i2_bot/i2_bot/lib/talkers"
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/talkers"
|
||||||
@ -34,6 +35,7 @@ func main() {
|
|||||||
migrations.New(c)
|
migrations.New(c)
|
||||||
c.RunDatabaseMigrations()
|
c.RunDatabaseMigrations()
|
||||||
datacache.New(c)
|
datacache.New(c)
|
||||||
|
sender.New(c)
|
||||||
forwarder.New(c)
|
forwarder.New(c)
|
||||||
pokedexer.New(c)
|
pokedexer.New(c)
|
||||||
pinner.New(c)
|
pinner.New(c)
|
||||||
|
@ -1,16 +1,18 @@
|
|||||||
// i2_bot – Instinct PokememBro Bot
|
// i2_bot – Instinct PokememBro Bot
|
||||||
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
// Copyright (c) 2017-2018 Vladimir "fat0troll" Hodakov
|
||||||
|
|
||||||
package appcontext
|
package appcontext
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"bitbucket.org/pztrn/flagger"
|
"bitbucket.org/pztrn/flagger"
|
||||||
"bitbucket.org/pztrn/mogrus"
|
"bitbucket.org/pztrn/mogrus"
|
||||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
"github.com/robfig/cron"
|
"github.com/robfig/cron"
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
"source.wtfteam.pro/i2_bot/i2_bot/lib/broadcaster/broadcasterinterface"
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/broadcaster/broadcasterinterface"
|
||||||
"source.wtfteam.pro/i2_bot/i2_bot/lib/chatter/chatterinterface"
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/chatter/chatterinterface"
|
||||||
"source.wtfteam.pro/i2_bot/i2_bot/lib/config"
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/config"
|
||||||
@ -23,12 +25,12 @@ import (
|
|||||||
"source.wtfteam.pro/i2_bot/i2_bot/lib/pokedexer/pokedexerinterface"
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/pokedexer/pokedexerinterface"
|
||||||
"source.wtfteam.pro/i2_bot/i2_bot/lib/reminder/reminderinterface"
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/reminder/reminderinterface"
|
||||||
"source.wtfteam.pro/i2_bot/i2_bot/lib/router/routerinterface"
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/router/routerinterface"
|
||||||
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/sender/senderinterface"
|
||||||
"source.wtfteam.pro/i2_bot/i2_bot/lib/squader/squaderinterface"
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/squader/squaderinterface"
|
||||||
"source.wtfteam.pro/i2_bot/i2_bot/lib/statistics/statisticsinterface"
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/statistics/statisticsinterface"
|
||||||
"source.wtfteam.pro/i2_bot/i2_bot/lib/talkers/talkersinterface"
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/talkers/talkersinterface"
|
||||||
"source.wtfteam.pro/i2_bot/i2_bot/lib/users/usersinterface"
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/users/usersinterface"
|
||||||
"source.wtfteam.pro/i2_bot/i2_bot/lib/welcomer/welcomerinterface"
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/welcomer/welcomerinterface"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Context is an application context struct
|
// Context is an application context struct
|
||||||
@ -50,6 +52,7 @@ type Context struct {
|
|||||||
Pinner pinnerinterface.PinnerInterface
|
Pinner pinnerinterface.PinnerInterface
|
||||||
Reminder reminderinterface.ReminderInterface
|
Reminder reminderinterface.ReminderInterface
|
||||||
Chatter chatterinterface.ChatterInterface
|
Chatter chatterinterface.ChatterInterface
|
||||||
|
Sender senderinterface.SenderInterface
|
||||||
Squader squaderinterface.SquaderInterface
|
Squader squaderinterface.SquaderInterface
|
||||||
Users usersinterface.UsersInterface
|
Users usersinterface.UsersInterface
|
||||||
Statistics statisticsinterface.StatisticsInterface
|
Statistics statisticsinterface.StatisticsInterface
|
||||||
@ -89,7 +92,7 @@ func (c *Context) Init() {
|
|||||||
c.Cfg = config.New()
|
c.Cfg = config.New()
|
||||||
c.Cfg.Init(c.Log, configPath)
|
c.Cfg.Init(c.Log, configPath)
|
||||||
|
|
||||||
logFile, err := os.OpenFile(c.Cfg.Logs.LogPath, os.O_RDWR|os.O_APPEND|os.O_CREATE, 0660)
|
logFile, err := os.OpenFile(c.Cfg.Logs.LogPath, os.O_RDWR|os.O_APPEND|os.O_CREATE, 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
@ -161,6 +164,12 @@ func (c *Context) RegisterRouterInterface(ri routerinterface.RouterInterface) {
|
|||||||
c.Router.Init()
|
c.Router.Init()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RegisterSenderInterface registering sender interface in application
|
||||||
|
func (c *Context) RegisterSenderInterface(si senderinterface.SenderInterface) {
|
||||||
|
c.Sender = si
|
||||||
|
c.Sender.Init()
|
||||||
|
}
|
||||||
|
|
||||||
// RegisterStatisticsInterface registers statistics interface in application
|
// RegisterStatisticsInterface registers statistics interface in application
|
||||||
func (c *Context) RegisterStatisticsInterface(si statisticsinterface.StatisticsInterface) {
|
func (c *Context) RegisterStatisticsInterface(si statisticsinterface.StatisticsInterface) {
|
||||||
c.Statistics = si
|
c.Statistics = si
|
||||||
@ -193,8 +202,14 @@ func (c *Context) RegisterUsersInterface(ui usersinterface.UsersInterface) {
|
|||||||
|
|
||||||
// RunDatabaseMigrations applies migrations on bot's startup
|
// RunDatabaseMigrations applies migrations on bot's startup
|
||||||
func (c *Context) RunDatabaseMigrations() {
|
func (c *Context) RunDatabaseMigrations() {
|
||||||
c.Migrations.SetDialect("mysql")
|
err := c.Migrations.SetDialect("mysql")
|
||||||
c.Migrations.Migrate()
|
if err != nil {
|
||||||
|
c.Log.Fatal(err.Error())
|
||||||
|
}
|
||||||
|
err = c.Migrations.Migrate()
|
||||||
|
if err != nil {
|
||||||
|
c.Log.Fatal(err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// StartBot starts listening for Telegram updates
|
// StartBot starts listening for Telegram updates
|
||||||
@ -205,7 +220,12 @@ func (c *Context) StartBot() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updates := c.Bot.ListenForWebhook("/" + c.Bot.Token)
|
updates := c.Bot.ListenForWebhook("/" + c.Bot.Token)
|
||||||
go http.ListenAndServe(c.Cfg.Telegram.ListenAddress, nil)
|
go func() {
|
||||||
|
err = http.ListenAndServe(c.Cfg.Telegram.ListenAddress, nil)
|
||||||
|
}()
|
||||||
|
if err != nil {
|
||||||
|
c.Log.Fatal(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
c.Log.Info("Listening on " + c.Cfg.Telegram.ListenAddress)
|
c.Log.Info("Listening on " + c.Cfg.Telegram.ListenAddress)
|
||||||
c.Log.Info("Webhook URL: " + c.Cfg.Telegram.WebHookDomain + c.Bot.Token)
|
c.Log.Info("Webhook URL: " + c.Cfg.Telegram.WebHookDomain + c.Bot.Token)
|
||||||
@ -214,13 +234,13 @@ func (c *Context) StartBot() {
|
|||||||
if update.Message != nil {
|
if update.Message != nil {
|
||||||
if update.Message.From != nil {
|
if update.Message.From != nil {
|
||||||
if update.Message.Date > (int(time.Now().Unix()) - 5) {
|
if update.Message.Date > (int(time.Now().Unix()) - 5) {
|
||||||
go c.Router.RouteRequest(&update)
|
go c.Router.RouteRequest(update)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if update.InlineQuery != nil {
|
} else if update.InlineQuery != nil {
|
||||||
c.Router.RouteInline(&update)
|
c.Router.RouteInline(update)
|
||||||
} else if update.CallbackQuery != nil {
|
} else if update.CallbackQuery != nil {
|
||||||
c.Router.RouteCallback(&update)
|
c.Router.RouteCallback(update)
|
||||||
} else if update.ChosenInlineResult != nil {
|
} else if update.ChosenInlineResult != nil {
|
||||||
c.Log.Debug(update.ChosenInlineResult.ResultID)
|
c.Log.Debug(update.ChosenInlineResult.ResultID)
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,12 +1,8 @@
|
|||||||
// i2_bot – Instinct PokememBro Bot
|
// i2_bot – Instinct PokememBro Bot
|
||||||
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
// Copyright (c) 2017-2018 Vladimir "fat0troll" Hodakov
|
||||||
|
|
||||||
package appcontext
|
package appcontext
|
||||||
|
|
||||||
var (
|
|
||||||
a *Context
|
|
||||||
)
|
|
||||||
|
|
||||||
// New is a Context creation function
|
// New is a Context creation function
|
||||||
func New() *Context {
|
func New() *Context {
|
||||||
c := &Context{}
|
c := &Context{}
|
||||||
|
@ -1,48 +1,41 @@
|
|||||||
// i2_bot – Instinct PokememBro Bot
|
// i2_bot – Instinct PokememBro Bot
|
||||||
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
// Copyright (c) 2017-2018 Vladimir "fat0troll" Hodakov
|
||||||
|
|
||||||
package broadcaster
|
package broadcaster
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||||
"source.wtfteam.pro/i2_bot/i2_bot/lib/dbmapping"
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/dbmapping"
|
||||||
"strconv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// AdminBroadcastMessageCompose saves message for future broadcast
|
// AdminBroadcastMessageCompose saves message for future broadcast
|
||||||
func (b *Broadcaster) AdminBroadcastMessageCompose(update *tgbotapi.Update, playerRaw *dbmapping.Player) string {
|
func (b *Broadcaster) AdminBroadcastMessageCompose(update *tgbotapi.Update, playerRaw *dbmapping.Player) string {
|
||||||
broadcastingMessageBody := update.Message.CommandArguments()
|
broadcastingMessageBody := update.Message.CommandArguments()
|
||||||
messageRaw, ok := dbmapping.Broadcast{}, false
|
messageMode := "none"
|
||||||
|
|
||||||
switch update.Message.Command() {
|
switch update.Message.Command() {
|
||||||
case "send_all":
|
case "send_all":
|
||||||
messageRaw, ok = b.createBroadcastMessage(playerRaw, broadcastingMessageBody, "all")
|
messageMode = "all"
|
||||||
if !ok {
|
|
||||||
return "fail"
|
|
||||||
}
|
|
||||||
case "send_league":
|
case "send_league":
|
||||||
messageRaw, ok = b.createBroadcastMessage(playerRaw, broadcastingMessageBody, "league")
|
messageMode = "league"
|
||||||
|
}
|
||||||
|
|
||||||
|
messageRaw, ok := b.createBroadcastMessage(playerRaw, broadcastingMessageBody, messageMode)
|
||||||
if !ok {
|
if !ok {
|
||||||
return "fail"
|
return "fail"
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
message := "Сообщение сохранено в базу.\n"
|
message := "Сообщение сохранено в базу.\n"
|
||||||
message += "Выглядеть оно будет так:"
|
message += "Выглядеть оно будет так:"
|
||||||
|
|
||||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
c.Sender.SendMarkdownAnswer(update, message)
|
||||||
msg.ParseMode = "Markdown"
|
|
||||||
|
|
||||||
c.Bot.Send(msg)
|
|
||||||
|
|
||||||
broadcastingMessage := "*Привет, %username%!*\n\n"
|
broadcastingMessage := "*Привет, %username%!*\n\n"
|
||||||
broadcastingMessage += "*Важное сообщение от администратора " + update.Message.From.FirstName + " " + update.Message.From.LastName + "* (@" + update.Message.From.UserName + ")\n\n"
|
broadcastingMessage += "*Важное сообщение от администратора " + update.Message.From.FirstName + " " + update.Message.From.LastName + "* (@" + update.Message.From.UserName + ")\n\n"
|
||||||
broadcastingMessage += messageRaw.Text
|
broadcastingMessage += messageRaw.Text
|
||||||
|
|
||||||
msg = tgbotapi.NewMessage(update.Message.Chat.ID, broadcastingMessage)
|
c.Sender.SendMarkdownAnswer(update, broadcastingMessage)
|
||||||
msg.ParseMode = "Markdown"
|
|
||||||
|
|
||||||
c.Bot.Send(msg)
|
|
||||||
|
|
||||||
switch update.Message.Command() {
|
switch update.Message.Command() {
|
||||||
case "send_all":
|
case "send_all":
|
||||||
@ -51,10 +44,7 @@ func (b *Broadcaster) AdminBroadcastMessageCompose(update *tgbotapi.Update, play
|
|||||||
message = "Чтобы отправить сообщение всем игрокам лиги Инстинкт, отправь команду /send\\_confirm " + strconv.Itoa(messageRaw.ID)
|
message = "Чтобы отправить сообщение всем игрокам лиги Инстинкт, отправь команду /send\\_confirm " + strconv.Itoa(messageRaw.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
msg = tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
c.Sender.SendMarkdownAnswer(update, message)
|
||||||
msg.ParseMode = "Markdown"
|
|
||||||
|
|
||||||
c.Bot.Send(msg)
|
|
||||||
|
|
||||||
return "ok"
|
return "ok"
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
// i2_bot – Instinct PokememBro Bot
|
// i2_bot – Instinct PokememBro Bot
|
||||||
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
// Copyright (c) 2017-2018 Vladimir "fat0troll" Hodakov
|
||||||
|
|
||||||
package broadcaster
|
package broadcaster
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
|
||||||
"source.wtfteam.pro/i2_bot/i2_bot/lib/dbmapping"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||||
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/constants"
|
||||||
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/dbmapping"
|
||||||
)
|
)
|
||||||
|
|
||||||
// AdminBroadcastMessageSend sends saved message to all private chats
|
// AdminBroadcastMessageSend sends saved message to all private chats
|
||||||
@ -15,13 +17,13 @@ func (b *Broadcaster) AdminBroadcastMessageSend(update *tgbotapi.Update, playerR
|
|||||||
messageNumInt, _ := strconv.Atoi(messageNum)
|
messageNumInt, _ := strconv.Atoi(messageNum)
|
||||||
messageRaw, ok := b.getBroadcastMessageByID(messageNumInt)
|
messageRaw, ok := b.getBroadcastMessageByID(messageNumInt)
|
||||||
if !ok {
|
if !ok {
|
||||||
return "fail"
|
return constants.BotError
|
||||||
}
|
}
|
||||||
if messageRaw.AuthorID != playerRaw.ID {
|
if messageRaw.AuthorID != playerRaw.ID {
|
||||||
return "fail"
|
return constants.UserRequestForbidden
|
||||||
}
|
}
|
||||||
if messageRaw.Status != "new" {
|
if messageRaw.Status != "new" {
|
||||||
return "fail"
|
return constants.UserRequestFailed
|
||||||
}
|
}
|
||||||
|
|
||||||
broadcastingMessageBody := messageRaw.Text
|
broadcastingMessageBody := messageRaw.Text
|
||||||
@ -29,7 +31,7 @@ func (b *Broadcaster) AdminBroadcastMessageSend(update *tgbotapi.Update, playerR
|
|||||||
profileRaw, err := c.DataCache.GetProfileByPlayerID(playerRaw.ID)
|
profileRaw, err := c.DataCache.GetProfileByPlayerID(playerRaw.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Log.Error(err.Error())
|
c.Log.Error(err.Error())
|
||||||
return "fail"
|
return constants.UserRequestFailed
|
||||||
}
|
}
|
||||||
|
|
||||||
prettyName := profileRaw.Nickname + " (@" + profileRaw.TelegramNickname + ")"
|
prettyName := profileRaw.Nickname + " (@" + profileRaw.TelegramNickname + ")"
|
||||||
@ -48,22 +50,17 @@ func (b *Broadcaster) AdminBroadcastMessageSend(update *tgbotapi.Update, playerR
|
|||||||
broadcastingMessage += "*Важное сообщение от администратора *" + prettyName + "\n\n"
|
broadcastingMessage += "*Важное сообщение от администратора *" + prettyName + "\n\n"
|
||||||
broadcastingMessage += broadcastingMessageBody
|
broadcastingMessage += broadcastingMessageBody
|
||||||
|
|
||||||
msg := tgbotapi.NewMessage(int64(chat.TelegramID), broadcastingMessage)
|
c.Sender.SendMarkdownMessageToChatID(chat.TelegramID, broadcastingMessage)
|
||||||
msg.ParseMode = "Markdown"
|
|
||||||
c.Bot.Send(msg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
messageRaw, ok = b.updateBroadcastMessageStatus(messageRaw.ID, "sent")
|
messageRaw, ok = b.updateBroadcastMessageStatus(messageRaw.ID, "sent")
|
||||||
if !ok {
|
if !ok {
|
||||||
return "fail"
|
return constants.BotError
|
||||||
}
|
}
|
||||||
|
|
||||||
message := "Сообщение отправлено. Надеюсь, пользователи бота за него тебя не убьют.\n"
|
message := "Сообщение отправлено. Надеюсь, пользователи бота за него тебя не убьют.\n"
|
||||||
|
|
||||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
c.Sender.SendMarkdownAnswer(update, message)
|
||||||
msg.ParseMode = "Markdown"
|
|
||||||
|
|
||||||
c.Bot.Send(msg)
|
return constants.UserRequestSuccess
|
||||||
|
|
||||||
return "ok"
|
|
||||||
}
|
}
|
||||||
|
15
lib/constants/constants.go
Normal file
15
lib/constants/constants.go
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// i2_bot – Instinct PokememBro Bot
|
||||||
|
// Copyright (c) 2017-2018 Vladimir "fat0troll" Hodakov
|
||||||
|
|
||||||
|
package constants
|
||||||
|
|
||||||
|
const (
|
||||||
|
// BotError is return value, if something went wrong with bot's internal data handling
|
||||||
|
BotError = "bot_error"
|
||||||
|
// UserRequestFailed is return value, if something went wrong with user input
|
||||||
|
UserRequestFailed = "fail"
|
||||||
|
// UserRequestSuccess is success return value
|
||||||
|
UserRequestSuccess = "ok"
|
||||||
|
// UserRequestForbidden is return value, if user can't perform some action
|
||||||
|
UserRequestForbidden = "forbidden"
|
||||||
|
)
|
@ -1,5 +1,5 @@
|
|||||||
// i2_bot – Instinct PokememBro Bot
|
// i2_bot – Instinct PokememBro Bot
|
||||||
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
// Copyright (c) 2017-2018 Vladimir "fat0troll" Hodakov
|
||||||
|
|
||||||
package migrations
|
package migrations
|
||||||
|
|
||||||
@ -9,36 +9,30 @@ import (
|
|||||||
|
|
||||||
// UpdateLeaguesUp fixes some fuckup with leagues' emoji
|
// UpdateLeaguesUp fixes some fuckup with leagues' emoji
|
||||||
func UpdateLeaguesUp(tx *sql.Tx) error {
|
func UpdateLeaguesUp(tx *sql.Tx) error {
|
||||||
_, err := tx.Exec("UPDATE `leagues` SET symbol='🈸' WHERE symbol=':u7533:';")
|
_, err := tx.Exec("UPDATE `leagues` SET symbol='🈸' WHERE symbol=':u7533:'")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = tx.Exec("UPDATE `leagues` SET symbol='🈳 ' WHERE symbol=':u6e80';")
|
_, err = tx.Exec("UPDATE `leagues` SET symbol='🈳 ' WHERE symbol=':u6e80'")
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
_, err = tx.Exec("UPDATE `leagues` SET symbol='🈵' WHERE symbol=':u7a7a:';")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
_, err = tx.Exec("UPDATE `leagues` SET symbol='🈵' WHERE symbol=':u7a7a:'")
|
||||||
|
|
||||||
return nil
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateLeaguesDown returns leagues emoji fuckup for sanity purposes
|
// UpdateLeaguesDown returns leagues emoji fuckup for sanity purposes
|
||||||
func UpdateLeaguesDown(tx *sql.Tx) error {
|
func UpdateLeaguesDown(tx *sql.Tx) error {
|
||||||
_, err := tx.Exec("UPDATE `leagues` SET symbol=':u7533:' WHERE symbol='🈸';")
|
_, err := tx.Exec("UPDATE `leagues` SET symbol=':u7533:' WHERE symbol='🈸'")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = tx.Exec("UPDATE `leagues` SET symbol=':u6e80' WHERE symbol='🈳 ';")
|
_, err = tx.Exec("UPDATE `leagues` SET symbol=':u6e80' WHERE symbol='🈳 '")
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
_, err = tx.Exec("UPDATE `leagues` SET symbol=':u7a7a:' WHERE symbol='🈵';")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
_, err = tx.Exec("UPDATE `leagues` SET symbol=':u7a7a:' WHERE symbol='🈵'")
|
||||||
|
|
||||||
return nil
|
return err
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
|
|
||||||
// ProfileDataAdditionsUp creates some helping databases for profiles
|
// ProfileDataAdditionsUp creates some helping databases for profiles
|
||||||
func ProfileDataAdditionsUp(tx *sql.Tx) error {
|
func ProfileDataAdditionsUp(tx *sql.Tx) error {
|
||||||
_, err := tx.Exec("ALTER TABLE `profiles` ADD `pokeballs` INT(11) DEFAULT 5 NOT NULL COMMENT 'Покеболы' AFTER `level_id`;")
|
_, err := tx.Exec("ALTER TABLE `profiles` ADD `pokeballs` INT(11) DEFAULT 5 NOT NULL COMMENT 'Покеболы' AFTER `level_id`")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -22,64 +22,58 @@ func ProfileDataAdditionsUp(tx *sql.Tx) error {
|
|||||||
request += "PRIMARY KEY (`id`),"
|
request += "PRIMARY KEY (`id`),"
|
||||||
request += "UNIQUE KEY `id` (`id`),"
|
request += "UNIQUE KEY `id` (`id`),"
|
||||||
request += "KEY `levels_created_at` (`created_at`)"
|
request += "KEY `levels_created_at` (`created_at`)"
|
||||||
request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Уровни';"
|
request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Уровни'"
|
||||||
_, err = tx.Exec(request)
|
_, err = tx.Exec(request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert levels
|
// Insert levels
|
||||||
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 200, 6, NOW());")
|
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 200, 6, NOW())")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 400, 12, NOW());")
|
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 400, 12, NOW())")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 800, 24, NOW());")
|
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 800, 24, NOW())")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 1600, 48, NOW());")
|
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 1600, 48, NOW())")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 3200, 96, NOW());")
|
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 3200, 96, NOW())")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 6400, 192, NOW());")
|
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 6400, 192, NOW())")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 12800, 384, NOW());")
|
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 12800, 384, NOW())")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 25600, 768, NOW());")
|
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 25600, 768, NOW())")
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 51200, 1536, NOW());")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
_, err = tx.Exec("INSERT INTO `levels` VALUES(NULL, 51200, 1536, NOW())")
|
||||||
|
|
||||||
return nil
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// ProfileDataAdditionsDown drops `levels` table and `pokeballs` column of `profiles` table
|
// ProfileDataAdditionsDown drops `levels` table and `pokeballs` column of `profiles` table
|
||||||
func ProfileDataAdditionsDown(tx *sql.Tx) error {
|
func ProfileDataAdditionsDown(tx *sql.Tx) error {
|
||||||
_, err := tx.Exec("ALTER TABLE `profiles` DROP COLUMN `pokeballs`;")
|
_, err := tx.Exec("ALTER TABLE `profiles` DROP COLUMN `pokeballs`")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = tx.Exec("DROP TABLE `levels`;")
|
_, err = tx.Exec("DROP TABLE `levels`")
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return err
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// i2_bot – Instinct PokememBro Bot
|
// i2_bot – Instinct PokememBro Bot
|
||||||
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
// Copyright (c) 2017-2018 Vladimir "fat0troll" Hodakov
|
||||||
|
|
||||||
package migrations
|
package migrations
|
||||||
|
|
||||||
@ -21,19 +21,16 @@ func CreatePlayersUp(tx *sql.Tx) error {
|
|||||||
request += "UNIQUE KEY `id` (`id`),"
|
request += "UNIQUE KEY `id` (`id`),"
|
||||||
request += "KEY `players_created_at` (`created_at`),"
|
request += "KEY `players_created_at` (`created_at`),"
|
||||||
request += "KEY `players_updated_at` (`updated_at`)"
|
request += "KEY `players_updated_at` (`updated_at`)"
|
||||||
request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Зарегистрированные игроки';"
|
request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Зарегистрированные игроки'"
|
||||||
|
|
||||||
_, err := tx.Exec(request)
|
_, err := tx.Exec(request)
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreatePlayersDown drops `players` table
|
// CreatePlayersDown drops `players` table
|
||||||
func CreatePlayersDown(tx *sql.Tx) error {
|
func CreatePlayersDown(tx *sql.Tx) error {
|
||||||
_, err := tx.Exec("DROP TABLE `players`;")
|
_, err := tx.Exec("DROP TABLE `players`;")
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// i2_bot – Instinct PokememBro Bot
|
// i2_bot – Instinct PokememBro Bot
|
||||||
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
// Copyright (c) 2017-2018 Vladimir "fat0troll" Hodakov
|
||||||
|
|
||||||
package migrations
|
package migrations
|
||||||
|
|
||||||
@ -25,19 +25,16 @@ func CreateProfilesUp(tx *sql.Tx) error {
|
|||||||
request += "UNIQUE KEY `id` (`id`),"
|
request += "UNIQUE KEY `id` (`id`),"
|
||||||
request += "KEY `profiles_created_at` (`created_at`),"
|
request += "KEY `profiles_created_at` (`created_at`),"
|
||||||
request += "KEY `profiles_nickname` (`nickname`)"
|
request += "KEY `profiles_nickname` (`nickname`)"
|
||||||
request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Профили зарегистрированных игроков';"
|
request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Профили зарегистрированных игроков'"
|
||||||
|
|
||||||
_, err := tx.Exec(request)
|
_, err := tx.Exec(request)
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateProfilesDown drops `profiles` table
|
// CreateProfilesDown drops `profiles` table
|
||||||
func CreateProfilesDown(tx *sql.Tx) error {
|
func CreateProfilesDown(tx *sql.Tx) error {
|
||||||
_, err := tx.Exec("DROP TABLE `profiles`;")
|
_, err := tx.Exec("DROP TABLE `profiles`")
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// i2_bot – Instinct PokememBro Bot
|
// i2_bot – Instinct PokememBro Bot
|
||||||
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
// Copyright (c) 2017-2018 Vladimir "fat0troll" Hodakov
|
||||||
|
|
||||||
package migrations
|
package migrations
|
||||||
|
|
||||||
@ -27,19 +27,16 @@ func CreatePokememesUp(tx *sql.Tx) error {
|
|||||||
request += "UNIQUE KEY `id` (`id`),"
|
request += "UNIQUE KEY `id` (`id`),"
|
||||||
request += "KEY `pokememes_created_at` (`created_at`),"
|
request += "KEY `pokememes_created_at` (`created_at`),"
|
||||||
request += "KEY `pokememes_player_id` (`player_id`)"
|
request += "KEY `pokememes_player_id` (`player_id`)"
|
||||||
request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Покемемы';"
|
request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Покемемы'"
|
||||||
|
|
||||||
_, err := tx.Exec(request)
|
_, err := tx.Exec(request)
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreatePokememesDown drops `pokememes` table
|
// CreatePokememesDown drops `pokememes` table
|
||||||
func CreatePokememesDown(tx *sql.Tx) error {
|
func CreatePokememesDown(tx *sql.Tx) error {
|
||||||
_, err := tx.Exec("DROP TABLE `pokememes`;")
|
_, err := tx.Exec("DROP TABLE `pokememes`")
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// i2_bot – Instinct PokememBro Bot
|
// i2_bot – Instinct PokememBro Bot
|
||||||
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
// Copyright (c) 2017-2018 Vladimir "fat0troll" Hodakov
|
||||||
|
|
||||||
package migrations
|
package migrations
|
||||||
|
|
||||||
@ -17,46 +17,41 @@ func CreateLocationsUp(tx *sql.Tx) error {
|
|||||||
request += "PRIMARY KEY (`id`),"
|
request += "PRIMARY KEY (`id`),"
|
||||||
request += "UNIQUE KEY `id` (`id`),"
|
request += "UNIQUE KEY `id` (`id`),"
|
||||||
request += "KEY `locations_created_at` (`created_at`)"
|
request += "KEY `locations_created_at` (`created_at`)"
|
||||||
request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Локации';"
|
request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Локации'"
|
||||||
_, err := tx.Exec(request)
|
_, err := tx.Exec(request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert locations
|
// Insert locations
|
||||||
_, err = tx.Exec("INSERT INTO `locations` VALUES(NULL, ':evergreen_tree:', 'Лес', NOW());")
|
_, err = tx.Exec("INSERT INTO `locations` VALUES(NULL, ':evergreen_tree:', 'Лес', NOW())")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = tx.Exec("INSERT INTO `locations` VALUES(NULL, '⛰', 'Горы', NOW());")
|
_, err = tx.Exec("INSERT INTO `locations` VALUES(NULL, '⛰', 'Горы', NOW())")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = tx.Exec("INSERT INTO `locations` VALUES(NULL, ':rowboat:', 'Озеро', NOW());")
|
_, err = tx.Exec("INSERT INTO `locations` VALUES(NULL, ':rowboat:', 'Озеро', NOW())")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = tx.Exec("INSERT INTO `locations` VALUES(NULL, '🏙', 'Город', NOW());")
|
_, err = tx.Exec("INSERT INTO `locations` VALUES(NULL, '🏙', 'Город', NOW())")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = tx.Exec("INSERT INTO `locations` VALUES(NULL, '🏛', 'Катакомбы', NOW());")
|
_, err = tx.Exec("INSERT INTO `locations` VALUES(NULL, '🏛', 'Катакомбы', NOW())")
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
_, err = tx.Exec("INSERT INTO `locations` VALUES(NULL, ':church:', 'Кладбище', NOW());")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
_, err = tx.Exec("INSERT INTO `locations` VALUES(NULL, ':church:', 'Кладбище', NOW())")
|
||||||
|
|
||||||
return nil
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateLocationsDown drops `locations` table
|
// CreateLocationsDown drops `locations` table
|
||||||
func CreateLocationsDown(tx *sql.Tx) error {
|
func CreateLocationsDown(tx *sql.Tx) error {
|
||||||
_, err := tx.Exec("DROP TABLE `locations`;")
|
_, err := tx.Exec("DROP TABLE `locations`")
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// i2_bot – Instinct PokememBro Bot
|
// i2_bot – Instinct PokememBro Bot
|
||||||
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
// Copyright (c) 2017-2018 Vladimir "fat0troll" Hodakov
|
||||||
|
|
||||||
package migrations
|
package migrations
|
||||||
|
|
||||||
@ -18,70 +18,65 @@ func CreateElementsUp(tx *sql.Tx) error {
|
|||||||
request += "PRIMARY KEY (`id`),"
|
request += "PRIMARY KEY (`id`),"
|
||||||
request += "UNIQUE KEY `id` (`id`),"
|
request += "UNIQUE KEY `id` (`id`),"
|
||||||
request += "KEY `elements_created_at` (`created_at`)"
|
request += "KEY `elements_created_at` (`created_at`)"
|
||||||
request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Элементы';"
|
request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Элементы'"
|
||||||
_, err := tx.Exec(request)
|
_, err := tx.Exec(request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert elements
|
// Insert elements
|
||||||
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '👊', 'Боевой', 1, NOW());")
|
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '👊', 'Боевой', 1, NOW())")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '🌀', 'Летающий', 1, NOW());")
|
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '🌀', 'Летающий', 1, NOW())")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '💀', 'Ядовитый', 1, NOW());")
|
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '💀', 'Ядовитый', 1, NOW())")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '🗿', 'Каменный', 1, NOW());")
|
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '🗿', 'Каменный', 1, NOW())")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '🔥', 'Огненный', 2, NOW());")
|
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '🔥', 'Огненный', 2, NOW())")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '⚡', 'Электрический', 2, NOW());")
|
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '⚡', 'Электрический', 2, NOW())")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '💧', 'Водяной', 2, NOW());")
|
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '💧', 'Водяной', 2, NOW())")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '🍀', 'Травяной', 2, NOW());")
|
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '🍀', 'Травяной', 2, NOW())")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '💩', 'Шоколадный', 3, NOW());")
|
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '💩', 'Шоколадный', 3, NOW())")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '👁', 'Психический', 3, NOW());")
|
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '👁', 'Психический', 3, NOW())")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '👿', 'Темный', 3, NOW());")
|
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '👿', 'Темный', 3, NOW())")
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '⌛', 'Времени', 1, NOW());")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
_, err = tx.Exec("INSERT INTO `elements` VALUES(NULL, '⌛', 'Времени', 1, NOW())")
|
||||||
|
|
||||||
return nil
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateElementsDown drops `elements` table
|
// CreateElementsDown drops `elements` table
|
||||||
func CreateElementsDown(tx *sql.Tx) error {
|
func CreateElementsDown(tx *sql.Tx) error {
|
||||||
_, err := tx.Exec("DROP TABLE `elements`;")
|
_, err := tx.Exec("DROP TABLE `elements`")
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// i2_bot – Instinct PokememBro Bot
|
// i2_bot – Instinct PokememBro Bot
|
||||||
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
// Copyright (c) 2017-2018 Vladimir "fat0troll" Hodakov
|
||||||
|
|
||||||
package migrations
|
package migrations
|
||||||
|
|
||||||
@ -17,34 +17,29 @@ func CreateLeaguesUp(tx *sql.Tx) error {
|
|||||||
request += "PRIMARY KEY (`id`),"
|
request += "PRIMARY KEY (`id`),"
|
||||||
request += "UNIQUE KEY `id` (`id`),"
|
request += "UNIQUE KEY `id` (`id`),"
|
||||||
request += "KEY `leagues_created_at` (`created_at`)"
|
request += "KEY `leagues_created_at` (`created_at`)"
|
||||||
request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Лиги';"
|
request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Лиги'"
|
||||||
_, err := tx.Exec(request)
|
_, err := tx.Exec(request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert locations
|
// Insert locations
|
||||||
_, err = tx.Exec("INSERT INTO `leagues` VALUES(NULL, ':u7533:', 'ИНСТИНКТ', NOW());")
|
_, err = tx.Exec("INSERT INTO `leagues` VALUES(NULL, ':u7533:', 'ИНСТИНКТ', NOW())")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = tx.Exec("INSERT INTO `leagues` VALUES(NULL, ':u6e80', 'ОТВАГА', NOW());")
|
_, err = tx.Exec("INSERT INTO `leagues` VALUES(NULL, ':u6e80', 'ОТВАГА', NOW())")
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
_, err = tx.Exec("INSERT INTO `leagues` VALUES(NULL, ':u7a7a:', 'МИСТИКА', NOW());")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
_, err = tx.Exec("INSERT INTO `leagues` VALUES(NULL, ':u7a7a:', 'МИСТИКА', NOW())")
|
||||||
|
|
||||||
return nil
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateLeaguesDown drops `leagues` table
|
// CreateLeaguesDown drops `leagues` table
|
||||||
func CreateLeaguesDown(tx *sql.Tx) error {
|
func CreateLeaguesDown(tx *sql.Tx) error {
|
||||||
_, err := tx.Exec("DROP TABLE `leagues`;")
|
_, err := tx.Exec("DROP TABLE `leagues`")
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// i2_bot – Instinct PokememBro Bot
|
// i2_bot – Instinct PokememBro Bot
|
||||||
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
// Copyright (c) 2017-2018 Vladimir "fat0troll" Hodakov
|
||||||
|
|
||||||
package migrations
|
package migrations
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ func CreateRelationsUp(tx *sql.Tx) error {
|
|||||||
request += "PRIMARY KEY (`id`),"
|
request += "PRIMARY KEY (`id`),"
|
||||||
request += "UNIQUE KEY `id` (`id`),"
|
request += "UNIQUE KEY `id` (`id`),"
|
||||||
request += "KEY `pokememes_locations_created_at` (`created_at`)"
|
request += "KEY `pokememes_locations_created_at` (`created_at`)"
|
||||||
request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Связь Покемемы-Локации';"
|
request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Связь Покемемы-Локации'"
|
||||||
_, err := tx.Exec(request)
|
_, err := tx.Exec(request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -31,23 +31,19 @@ func CreateRelationsUp(tx *sql.Tx) error {
|
|||||||
request += "PRIMARY KEY (`id`),"
|
request += "PRIMARY KEY (`id`),"
|
||||||
request += "UNIQUE KEY `id` (`id`),"
|
request += "UNIQUE KEY `id` (`id`),"
|
||||||
request += "KEY `pokememes_elements_created_at` (`created_at`)"
|
request += "KEY `pokememes_elements_created_at` (`created_at`)"
|
||||||
request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Связь Покемемы-Элементы';"
|
request += ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='Связь Покемемы-Элементы'"
|
||||||
_, err2 := tx.Exec(request)
|
_, err = tx.Exec(request)
|
||||||
if err2 != nil {
|
|
||||||
return err2
|
return err
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateRelationsDown drops pokememe-* relations tables
|
// CreateRelationsDown drops pokememe-* relations tables
|
||||||
func CreateRelationsDown(tx *sql.Tx) error {
|
func CreateRelationsDown(tx *sql.Tx) error {
|
||||||
_, err := tx.Exec("DROP TABLE `pokememes_locations`;")
|
_, err := tx.Exec("DROP TABLE `pokememes_locations`")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err2 := tx.Exec("DROP TABLE `pokememes_elements`;")
|
_, err = tx.Exec("DROP TABLE `pokememes_elements`;")
|
||||||
if err2 != nil {
|
|
||||||
return err2
|
return err
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// i2_bot – Instinct PokememBro Bot
|
// i2_bot – Instinct PokememBro Bot
|
||||||
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
// Copyright (c) 2017-2018 Vladimir "fat0troll" Hodakov
|
||||||
|
|
||||||
package migrations
|
package migrations
|
||||||
|
|
||||||
@ -9,36 +9,30 @@ import (
|
|||||||
|
|
||||||
// UpdateLocationsUp fixes some fuckup with locations' emoji
|
// UpdateLocationsUp fixes some fuckup with locations' emoji
|
||||||
func UpdateLocationsUp(tx *sql.Tx) error {
|
func UpdateLocationsUp(tx *sql.Tx) error {
|
||||||
_, err := tx.Exec("UPDATE `locations` SET symbol='⛪' WHERE symbol=':church:';")
|
_, err := tx.Exec("UPDATE `locations` SET symbol='⛪' WHERE symbol=':church:'")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = tx.Exec("UPDATE `locations` SET symbol='🌲' WHERE symbol=':evergreen_tree:';")
|
_, err = tx.Exec("UPDATE `locations` SET symbol='🌲' WHERE symbol=':evergreen_tree:'")
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
_, err = tx.Exec("UPDATE `locations` SET symbol='🚣' WHERE symbol=':rowboat:';")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
_, err = tx.Exec("UPDATE `locations` SET symbol='🚣' WHERE symbol=':rowboat:'")
|
||||||
|
|
||||||
return nil
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateLocationsDown returns location emoji fuckup for sanity purposes
|
// UpdateLocationsDown returns location emoji fuckup for sanity purposes
|
||||||
func UpdateLocationsDown(tx *sql.Tx) error {
|
func UpdateLocationsDown(tx *sql.Tx) error {
|
||||||
_, err := tx.Exec("UPDATE `locations` SET symbol=':church:' WHERE symbol='⛪'';")
|
_, err := tx.Exec("UPDATE `locations` SET symbol=':church:' WHERE symbol='⛪''")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = tx.Exec("UPDATE `locations` SET symbol=':evergreen_tree:' WHERE symbol='🌲';")
|
_, err = tx.Exec("UPDATE `locations` SET symbol=':evergreen_tree:' WHERE symbol='🌲'")
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
_, err = tx.Exec("UPDATE `locations` SET symbol=':rowboat:' WHERE symbol='🚣';")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
_, err = tx.Exec("UPDATE `locations` SET symbol=':rowboat:' WHERE symbol='🚣'")
|
||||||
|
|
||||||
return nil
|
return err
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,13 @@
|
|||||||
package router
|
package router
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
|
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RouteCallback routes inline requests to bot
|
// RouteCallback routes inline requests to bot
|
||||||
func (r *Router) RouteCallback(update *tgbotapi.Update) string {
|
func (r *Router) RouteCallback(update tgbotapi.Update) string {
|
||||||
playerRaw, err := c.DataCache.GetOrCreatePlayerByTelegramID(update.CallbackQuery.From.ID)
|
playerRaw, err := c.DataCache.GetOrCreatePlayerByTelegramID(update.CallbackQuery.From.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Log.Error(err.Error())
|
c.Log.Error(err.Error())
|
||||||
@ -17,7 +18,7 @@ func (r *Router) RouteCallback(update *tgbotapi.Update) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if playerRaw.Status == "banned" {
|
if playerRaw.Status == "banned" {
|
||||||
return c.Talkers.BanError(update)
|
return c.Talkers.BanError(&update)
|
||||||
}
|
}
|
||||||
|
|
||||||
var enableAlarmCallback = regexp.MustCompile("enable_reminder_(\\d+)\\z")
|
var enableAlarmCallback = regexp.MustCompile("enable_reminder_(\\d+)\\z")
|
||||||
@ -25,9 +26,9 @@ func (r *Router) RouteCallback(update *tgbotapi.Update) string {
|
|||||||
|
|
||||||
switch {
|
switch {
|
||||||
case enableAlarmCallback.MatchString(update.CallbackQuery.Data):
|
case enableAlarmCallback.MatchString(update.CallbackQuery.Data):
|
||||||
return c.Reminder.CreateAlarmSetting(update, playerRaw)
|
return c.Reminder.CreateAlarmSetting(&update, playerRaw)
|
||||||
case disableAlarmCallback.MatchString(update.CallbackQuery.Data):
|
case disableAlarmCallback.MatchString(update.CallbackQuery.Data):
|
||||||
return c.Reminder.DestroyAlarmSetting(update, playerRaw)
|
return c.Reminder.DestroyAlarmSetting(&update, playerRaw)
|
||||||
}
|
}
|
||||||
|
|
||||||
return "ok"
|
return "ok"
|
||||||
|
@ -4,13 +4,14 @@
|
|||||||
package router
|
package router
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
|
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||||
"source.wtfteam.pro/i2_bot/i2_bot/lib/dbmapping"
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/dbmapping"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (r *Router) routeGroupRequest(update *tgbotapi.Update, playerRaw *dbmapping.Player, chatRaw *dbmapping.Chat) string {
|
func (r *Router) routeGroupRequest(update tgbotapi.Update, playerRaw *dbmapping.Player, chatRaw *dbmapping.Chat) string {
|
||||||
text := update.Message.Text
|
text := update.Message.Text
|
||||||
// Regular expressions
|
// Regular expressions
|
||||||
var durakMsg = regexp.MustCompile("(Д|д)(У|у)(Р|р)(А|а|Е|е|О|о)")
|
var durakMsg = regexp.MustCompile("(Д|д)(У|у)(Р|р)(А|а|Е|е|О|о)")
|
||||||
@ -19,7 +20,7 @@ func (r *Router) routeGroupRequest(update *tgbotapi.Update, playerRaw *dbmapping
|
|||||||
var ebMsg = regexp.MustCompile("(\\s|^|ЗА|За|зА|за)(Е|е|Ё|ё)(Б|б)(\\s|Л|л|А|а|Т|т|У|у|Е|е|Ё|ё|И|и)")
|
var ebMsg = regexp.MustCompile("(\\s|^|ЗА|За|зА|за)(Е|е|Ё|ё)(Б|б)(\\s|Л|л|А|а|Т|т|У|у|Е|е|Ё|ё|И|и)")
|
||||||
var piMsg = regexp.MustCompile("(П|п)(И|и)(З|з)(Д|д)")
|
var piMsg = regexp.MustCompile("(П|п)(И|и)(З|з)(Д|д)")
|
||||||
|
|
||||||
restrictionStatus := c.Chatter.ProtectChat(update, playerRaw, chatRaw)
|
restrictionStatus := c.Chatter.ProtectChat(&update, playerRaw, chatRaw)
|
||||||
if restrictionStatus != "protection_passed" {
|
if restrictionStatus != "protection_passed" {
|
||||||
return restrictionStatus
|
return restrictionStatus
|
||||||
}
|
}
|
||||||
@ -28,7 +29,7 @@ func (r *Router) routeGroupRequest(update *tgbotapi.Update, playerRaw *dbmapping
|
|||||||
if update.Message.NewChatMembers != nil {
|
if update.Message.NewChatMembers != nil {
|
||||||
newUsers := *update.Message.NewChatMembers
|
newUsers := *update.Message.NewChatMembers
|
||||||
if len(newUsers) > 0 {
|
if len(newUsers) > 0 {
|
||||||
return c.Welcomer.GroupWelcomeMessage(update)
|
return c.Welcomer.GroupWelcomeMessage(&update)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// New chat names
|
// New chat names
|
||||||
@ -47,21 +48,21 @@ func (r *Router) routeGroupRequest(update *tgbotapi.Update, playerRaw *dbmapping
|
|||||||
if trigger == 4 {
|
if trigger == 4 {
|
||||||
switch {
|
switch {
|
||||||
case huMsg.MatchString(text):
|
case huMsg.MatchString(text):
|
||||||
return c.Talkers.MatMessage(update)
|
return c.Talkers.MatMessage(&update)
|
||||||
case blMsg.MatchString(text):
|
case blMsg.MatchString(text):
|
||||||
return c.Talkers.MatMessage(update)
|
return c.Talkers.MatMessage(&update)
|
||||||
case ebMsg.MatchString(text):
|
case ebMsg.MatchString(text):
|
||||||
return c.Talkers.MatMessage(update)
|
return c.Talkers.MatMessage(&update)
|
||||||
case piMsg.MatchString(text):
|
case piMsg.MatchString(text):
|
||||||
return c.Talkers.MatMessage(update)
|
return c.Talkers.MatMessage(&update)
|
||||||
case durakMsg.MatchString(text):
|
case durakMsg.MatchString(text):
|
||||||
return c.Talkers.DurakMessage(update)
|
return c.Talkers.DurakMessage(&update)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case update.Message.Command() == "long":
|
case update.Message.Command() == "long":
|
||||||
return c.Talkers.LongMessage(update)
|
return c.Talkers.LongMessage(&update)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ah, we're still here
|
// Ah, we're still here
|
||||||
|
@ -4,13 +4,14 @@
|
|||||||
package router
|
package router
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RouteInline routes inline requests to bot
|
// RouteInline routes inline requests to bot
|
||||||
func (r *Router) RouteInline(update *tgbotapi.Update) string {
|
func (r *Router) RouteInline(update tgbotapi.Update) string {
|
||||||
playerRaw, err := c.DataCache.GetOrCreatePlayerByTelegramID(update.InlineQuery.From.ID)
|
playerRaw, err := c.DataCache.GetOrCreatePlayerByTelegramID(update.InlineQuery.From.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Log.Error(err.Error())
|
c.Log.Error(err.Error())
|
||||||
|
@ -4,12 +4,13 @@
|
|||||||
package router
|
package router
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
|
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||||
"source.wtfteam.pro/i2_bot/i2_bot/lib/dbmapping"
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/dbmapping"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (r *Router) routePrivateRequest(update *tgbotapi.Update, playerRaw *dbmapping.Player, chatRaw *dbmapping.Chat) string {
|
func (r *Router) routePrivateRequest(update tgbotapi.Update, playerRaw *dbmapping.Player, chatRaw *dbmapping.Chat) string {
|
||||||
text := update.Message.Text
|
text := update.Message.Text
|
||||||
|
|
||||||
// Commands with regexps
|
// Commands with regexps
|
||||||
@ -21,7 +22,7 @@ func (r *Router) routePrivateRequest(update *tgbotapi.Update, playerRaw *dbmappi
|
|||||||
var orderSendMsg = regexp.MustCompile("/send_order(\\d+)\\z")
|
var orderSendMsg = regexp.MustCompile("/send_order(\\d+)\\z")
|
||||||
|
|
||||||
if playerRaw.Status == "banned" {
|
if playerRaw.Status == "banned" {
|
||||||
return c.Talkers.BanError(update)
|
return c.Talkers.BanError(&update)
|
||||||
}
|
}
|
||||||
|
|
||||||
if update.Message.ForwardFrom != nil {
|
if update.Message.ForwardFrom != nil {
|
||||||
@ -30,9 +31,9 @@ func (r *Router) routePrivateRequest(update *tgbotapi.Update, playerRaw *dbmappi
|
|||||||
} else {
|
} else {
|
||||||
c.Log.Info("Forward from PokememBro bot! Processing...")
|
c.Log.Info("Forward from PokememBro bot! Processing...")
|
||||||
if playerRaw.ID != 0 {
|
if playerRaw.ID != 0 {
|
||||||
c.Forwarder.ProcessForward(update, playerRaw)
|
c.Forwarder.ProcessForward(&update, playerRaw)
|
||||||
} else {
|
} else {
|
||||||
return c.Talkers.AnyMessageUnauthorized(update)
|
return c.Talkers.AnyMessageUnauthorized(&update)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -41,181 +42,174 @@ func (r *Router) routePrivateRequest(update *tgbotapi.Update, playerRaw *dbmappi
|
|||||||
case update.Message.Command() == "start":
|
case update.Message.Command() == "start":
|
||||||
if playerRaw.LeagueID != 0 {
|
if playerRaw.LeagueID != 0 {
|
||||||
if playerRaw.Status == "special" {
|
if playerRaw.Status == "special" {
|
||||||
c.Welcomer.PrivateWelcomeMessageSpecial(update, playerRaw)
|
c.Welcomer.PrivateWelcomeMessageSpecial(&update, playerRaw)
|
||||||
return "ok"
|
return "ok"
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Welcomer.PrivateWelcomeMessageAuthorized(update, playerRaw)
|
c.Welcomer.PrivateWelcomeMessageAuthorized(&update, playerRaw)
|
||||||
return "ok"
|
return "ok"
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Welcomer.PrivateWelcomeMessageUnauthorized(update)
|
c.Welcomer.PrivateWelcomeMessageUnauthorized(&update)
|
||||||
return "ok"
|
return "ok"
|
||||||
|
|
||||||
case update.Message.Command() == "help":
|
case update.Message.Command() == "help":
|
||||||
c.Talkers.HelpMessage(update, playerRaw)
|
c.Talkers.HelpMessage(&update, playerRaw)
|
||||||
return "ok"
|
return "ok"
|
||||||
case update.Message.Command() == "faq":
|
case update.Message.Command() == "faq":
|
||||||
return c.Talkers.FAQMessage(update)
|
return c.Talkers.FAQMessage(&update)
|
||||||
case update.Message.Command() == "academy":
|
case update.Message.Command() == "academy":
|
||||||
c.Talkers.AcademyMessage(update, playerRaw)
|
c.Talkers.AcademyMessage(&update, playerRaw)
|
||||||
return "ok"
|
return "ok"
|
||||||
case update.Message.Command() == "bastion":
|
case update.Message.Command() == "bastion":
|
||||||
c.Talkers.BastionMessage(update, playerRaw)
|
c.Talkers.BastionMessage(&update, playerRaw)
|
||||||
return "ok"
|
return "ok"
|
||||||
|
|
||||||
case pokedexMsg.MatchString(text):
|
case pokedexMsg.MatchString(text):
|
||||||
c.Pokedexer.PokememesList(update)
|
c.Pokedexer.PokememesList(&update)
|
||||||
return "ok"
|
return "ok"
|
||||||
case pokememeInfoMsg.MatchString(text):
|
case pokememeInfoMsg.MatchString(text):
|
||||||
c.Pokedexer.PokememeInfo(update, playerRaw)
|
c.Pokedexer.PokememeInfo(&update, playerRaw)
|
||||||
return "ok"
|
return "ok"
|
||||||
case update.Message.Command() == "delete_pokememe":
|
case update.Message.Command() == "delete_pokememe":
|
||||||
if c.Users.PlayerBetterThan(playerRaw, "owner") {
|
if c.Users.PlayerBetterThan(playerRaw, "owner") {
|
||||||
return c.Pokedexer.DeletePokememe(update)
|
return c.Pokedexer.DeletePokememe(&update)
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.Talkers.AnyMessageUnauthorized(update)
|
return c.Talkers.AnyMessageUnauthorized(&update)
|
||||||
case update.Message.Command() == "me":
|
case update.Message.Command() == "me":
|
||||||
if playerRaw.ID != 0 {
|
if playerRaw.ID != 0 {
|
||||||
c.Users.ProfileMessage(update, playerRaw)
|
c.Users.ProfileMessage(&update, playerRaw)
|
||||||
return "ok"
|
return "ok"
|
||||||
}
|
}
|
||||||
case update.Message.Command() == "top":
|
case update.Message.Command() == "top":
|
||||||
if playerRaw.ID != 0 {
|
if playerRaw.ID != 0 {
|
||||||
return c.Statistics.TopList(update, playerRaw)
|
return c.Statistics.TopList(&update, playerRaw)
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.Talkers.AnyMessageUnauthorized(update)
|
return c.Talkers.AnyMessageUnauthorized(&update)
|
||||||
case update.Message.Command() == "top_my":
|
case update.Message.Command() == "top_my":
|
||||||
if playerRaw.ID != 0 {
|
if playerRaw.ID != 0 {
|
||||||
return c.Statistics.TopList(update, playerRaw)
|
return c.Statistics.TopList(&update, playerRaw)
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.Talkers.AnyMessageUnauthorized(update)
|
return c.Talkers.AnyMessageUnauthorized(&update)
|
||||||
|
|
||||||
case update.Message.Command() == "best":
|
case update.Message.Command() == "best":
|
||||||
c.Pokedexer.AdvicePokememesList(update, playerRaw)
|
c.Pokedexer.AdvicePokememesList(&update, playerRaw)
|
||||||
return "ok"
|
return "ok"
|
||||||
case update.Message.Command() == "advice":
|
case update.Message.Command() == "advice":
|
||||||
c.Pokedexer.AdvicePokememesList(update, playerRaw)
|
c.Pokedexer.AdvicePokememesList(&update, playerRaw)
|
||||||
return "ok"
|
return "ok"
|
||||||
case update.Message.Command() == "best_all":
|
case update.Message.Command() == "best_all":
|
||||||
c.Pokedexer.AdvicePokememesList(update, playerRaw)
|
c.Pokedexer.AdvicePokememesList(&update, playerRaw)
|
||||||
return "ok"
|
return "ok"
|
||||||
case update.Message.Command() == "advice_all":
|
case update.Message.Command() == "advice_all":
|
||||||
c.Pokedexer.AdvicePokememesList(update, playerRaw)
|
c.Pokedexer.AdvicePokememesList(&update, playerRaw)
|
||||||
return "ok"
|
return "ok"
|
||||||
case update.Message.Command() == "best_nofilter":
|
case update.Message.Command() == "best_nofilter":
|
||||||
c.Pokedexer.AdvicePokememesList(update, playerRaw)
|
c.Pokedexer.AdvicePokememesList(&update, playerRaw)
|
||||||
return "ok"
|
return "ok"
|
||||||
case update.Message.Command() == "reminders":
|
case update.Message.Command() == "reminders":
|
||||||
return c.Reminder.AlarmsList(update, playerRaw)
|
return c.Reminder.AlarmsList(&update, playerRaw)
|
||||||
|
|
||||||
case update.Message.Command() == "send_all":
|
case update.Message.Command() == "send_all":
|
||||||
if c.Users.PlayerBetterThan(playerRaw, "admin") {
|
if c.Users.PlayerBetterThan(playerRaw, "admin") {
|
||||||
c.Broadcaster.AdminBroadcastMessageCompose(update, playerRaw)
|
c.Broadcaster.AdminBroadcastMessageCompose(&update, playerRaw)
|
||||||
return "ok"
|
return "ok"
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.Talkers.AnyMessageUnauthorized(update)
|
return c.Talkers.AnyMessageUnauthorized(&update)
|
||||||
case update.Message.Command() == "send_league":
|
case update.Message.Command() == "send_league":
|
||||||
if c.Users.PlayerBetterThan(playerRaw, "admin") {
|
if c.Users.PlayerBetterThan(playerRaw, "admin") {
|
||||||
c.Broadcaster.AdminBroadcastMessageCompose(update, playerRaw)
|
c.Broadcaster.AdminBroadcastMessageCompose(&update, playerRaw)
|
||||||
return "ok"
|
return "ok"
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.Talkers.AnyMessageUnauthorized(update)
|
return c.Talkers.AnyMessageUnauthorized(&update)
|
||||||
case update.Message.Command() == "send_confirm":
|
case update.Message.Command() == "send_confirm":
|
||||||
if c.Users.PlayerBetterThan(playerRaw, "admin") {
|
if c.Users.PlayerBetterThan(playerRaw, "admin") {
|
||||||
go c.Broadcaster.AdminBroadcastMessageSend(update, playerRaw)
|
go c.Broadcaster.AdminBroadcastMessageSend(&update, playerRaw)
|
||||||
return "ok"
|
return "ok"
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.Talkers.AnyMessageUnauthorized(update)
|
return c.Talkers.AnyMessageUnauthorized(&update)
|
||||||
case update.Message.Command() == "chats":
|
case update.Message.Command() == "chats":
|
||||||
if c.Users.PlayerBetterThan(playerRaw, "admin") {
|
if c.Users.PlayerBetterThan(playerRaw, "admin") {
|
||||||
c.Chatter.GroupsList(update)
|
c.Chatter.GroupsList(&update)
|
||||||
return "ok"
|
return "ok"
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.Talkers.AnyMessageUnauthorized(update)
|
return c.Talkers.AnyMessageUnauthorized(&update)
|
||||||
case update.Message.Command() == "squads":
|
case update.Message.Command() == "squads":
|
||||||
return c.Squader.SquadsList(update, playerRaw)
|
return c.Squader.SquadsList(&update, playerRaw)
|
||||||
|
|
||||||
case update.Message.Command() == "pin":
|
case update.Message.Command() == "pin":
|
||||||
if c.Users.PlayerBetterThan(playerRaw, "admin") {
|
if c.Users.PlayerBetterThan(playerRaw, "admin") {
|
||||||
return c.Pinner.PinMessageToSomeChats(update)
|
return c.Pinner.PinMessageToSomeChats(&update)
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.Talkers.AnyMessageUnauthorized(update)
|
return c.Talkers.AnyMessageUnauthorized(&update)
|
||||||
case update.Message.Command() == "pin_all":
|
case update.Message.Command() == "pin_all":
|
||||||
if c.Users.PlayerBetterThan(playerRaw, "admin") {
|
if c.Users.PlayerBetterThan(playerRaw, "admin") {
|
||||||
return c.Pinner.PinMessageToAllChats(update)
|
return c.Pinner.PinMessageToAllChats(&update)
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.Talkers.AnyMessageUnauthorized(update)
|
return c.Talkers.AnyMessageUnauthorized(&update)
|
||||||
|
|
||||||
case update.Message.Command() == "orders":
|
case update.Message.Command() == "orders":
|
||||||
if c.Users.PlayerBetterThan(playerRaw, "admin") {
|
if c.Users.PlayerBetterThan(playerRaw, "admin") {
|
||||||
return c.Orders.ListAllOrders(update)
|
return c.Orders.ListAllOrders(&update)
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.Talkers.AnyMessageUnauthorized(update)
|
return c.Talkers.AnyMessageUnauthorized(&update)
|
||||||
case orderSendMsg.MatchString(text):
|
case orderSendMsg.MatchString(text):
|
||||||
if c.Users.PlayerBetterThan(playerRaw, "admin") {
|
if c.Users.PlayerBetterThan(playerRaw, "admin") {
|
||||||
return c.Orders.SendOrder(update)
|
return c.Orders.SendOrder(&update)
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.Talkers.AnyMessageUnauthorized(update)
|
return c.Talkers.AnyMessageUnauthorized(&update)
|
||||||
|
|
||||||
case usersMsg.MatchString(text):
|
case usersMsg.MatchString(text):
|
||||||
if c.Users.PlayerBetterThan(playerRaw, "academic") {
|
if c.Users.PlayerBetterThan(playerRaw, "academic") {
|
||||||
return c.Users.UsersList(update)
|
return c.Users.UsersList(&update)
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.Talkers.AnyMessageUnauthorized(update)
|
return c.Talkers.AnyMessageUnauthorized(&update)
|
||||||
|
|
||||||
case profileMsg.MatchString(text):
|
case profileMsg.MatchString(text):
|
||||||
if c.Users.PlayerBetterThan(playerRaw, "academic") {
|
if c.Users.PlayerBetterThan(playerRaw, "academic") {
|
||||||
return c.Users.ForeignProfileMessage(update)
|
return c.Users.ForeignProfileMessage(&update)
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.Talkers.AnyMessageUnauthorized(update)
|
return c.Talkers.AnyMessageUnauthorized(&update)
|
||||||
|
|
||||||
case update.Message.Command() == "find_level":
|
case update.Message.Command() == "find_level":
|
||||||
if c.Users.PlayerBetterThan(playerRaw, "academic") {
|
if c.Users.PlayerBetterThan(playerRaw, "academic") {
|
||||||
return c.Users.FindByLevel(update)
|
return c.Users.FindByLevel(&update)
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.Talkers.AnyMessageUnauthorized(update)
|
return c.Talkers.AnyMessageUnauthorized(&update)
|
||||||
case update.Message.Command() == "find_user":
|
case update.Message.Command() == "find_user":
|
||||||
if c.Users.PlayerBetterThan(playerRaw, "academic") {
|
if c.Users.PlayerBetterThan(playerRaw, "academic") {
|
||||||
return c.Users.FindByName(update)
|
return c.Users.FindByName(&update)
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.Talkers.AnyMessageUnauthorized(update)
|
return c.Talkers.AnyMessageUnauthorized(&update)
|
||||||
case update.Message.Command() == "find_top_attack":
|
case update.Message.Command() == "find_top_attack":
|
||||||
if c.Users.PlayerBetterThan(playerRaw, "academic") {
|
if c.Users.PlayerBetterThan(playerRaw, "academic") {
|
||||||
return c.Users.FindByTopAttack(update)
|
return c.Users.FindByTopAttack(&update)
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.Talkers.AnyMessageUnauthorized(update)
|
return c.Talkers.AnyMessageUnauthorized(&update)
|
||||||
|
|
||||||
case update.Message.Command() == "squad_add_user":
|
case update.Message.Command() == "squad_add_user":
|
||||||
return c.Squader.AddUserToSquad(update, playerRaw)
|
return c.Squader.AddUserToSquad(&update, playerRaw)
|
||||||
case update.Message.Command() == "squad_add_commander":
|
case update.Message.Command() == "squad_add_commander":
|
||||||
return c.Squader.AddUserToSquad(update, playerRaw)
|
return c.Squader.AddUserToSquad(&update, playerRaw)
|
||||||
|
|
||||||
case squadInfoMsg.MatchString(text):
|
case squadInfoMsg.MatchString(text):
|
||||||
return c.Squader.SquadInfo(update, playerRaw)
|
return c.Squader.SquadInfo(&update, playerRaw)
|
||||||
|
|
||||||
case update.Message.Command() == "five_offer":
|
|
||||||
if c.Users.PlayerBetterThan(playerRaw, "admin") {
|
|
||||||
return c.Talkers.FiveOffer(update)
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.Talkers.AnyMessageUnauthorized(update)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// i2_bot – Instinct PokememBro Bot
|
// i2_bot – Instinct PokememBro Bot
|
||||||
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
// Copyright (c) 2017-2018 Vladimir "fat0troll" Hodakov
|
||||||
|
|
||||||
package router
|
package router
|
||||||
|
|
||||||
@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// RouteRequest decides, what to do with user input
|
// RouteRequest decides, what to do with user input
|
||||||
func (r *Router) RouteRequest(update *tgbotapi.Update) string {
|
func (r *Router) RouteRequest(update tgbotapi.Update) string {
|
||||||
c.Log.Debugln(update)
|
c.Log.Debugln(update)
|
||||||
playerRaw, err := c.DataCache.GetOrCreatePlayerByTelegramID(update.Message.From.ID)
|
playerRaw, err := c.DataCache.GetOrCreatePlayerByTelegramID(update.Message.From.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -18,7 +18,7 @@ func (r *Router) RouteRequest(update *tgbotapi.Update) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
c.Log.Debug("Getting chat...")
|
c.Log.Debug("Getting chat...")
|
||||||
chatRaw, err := c.DataCache.GetOrCreateChat(update)
|
chatRaw, err := c.DataCache.GetOrCreateChat(&update)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Log.Error(err.Error())
|
c.Log.Error(err.Error())
|
||||||
return "fail"
|
return "fail"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// i2_bot – Instinct PokememBro Bot
|
// i2_bot – Instinct PokememBro Bot
|
||||||
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
// Copyright (c) 2017-2018 Vladimir "fat0troll" Hodakov
|
||||||
|
|
||||||
package routerinterface
|
package routerinterface
|
||||||
|
|
||||||
@ -11,7 +11,7 @@ import (
|
|||||||
type RouterInterface interface {
|
type RouterInterface interface {
|
||||||
Init()
|
Init()
|
||||||
|
|
||||||
RouteCallback(update *tgbotapi.Update) string
|
RouteCallback(update tgbotapi.Update) string
|
||||||
RouteInline(update *tgbotapi.Update) string
|
RouteInline(update tgbotapi.Update) string
|
||||||
RouteRequest(update *tgbotapi.Update) string
|
RouteRequest(update tgbotapi.Update) string
|
||||||
}
|
}
|
||||||
|
28
lib/sender/exported.go
Normal file
28
lib/sender/exported.go
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
// i2_bot – Instinct PokememBro Bot
|
||||||
|
// Copyright (c) 2018 Vladimir "fat0troll" Hodakov
|
||||||
|
|
||||||
|
package sender
|
||||||
|
|
||||||
|
import (
|
||||||
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/appcontext"
|
||||||
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/sender/senderinterface"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
c *appcontext.Context
|
||||||
|
)
|
||||||
|
|
||||||
|
// Sender is a function-handling struct for sender
|
||||||
|
type Sender struct{}
|
||||||
|
|
||||||
|
// New is a appcontext initialization function
|
||||||
|
func New(ac *appcontext.Context) {
|
||||||
|
c = ac
|
||||||
|
s := &Sender{}
|
||||||
|
c.RegisterSenderInterface(senderinterface.SenderInterface(s))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Init is an initialization function for sender
|
||||||
|
func (s *Sender) Init() {
|
||||||
|
c.Log.Info("Initializing Sender...")
|
||||||
|
}
|
30
lib/sender/sender.go
Normal file
30
lib/sender/sender.go
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
// i2_bot – Instinct PokememBro Bot
|
||||||
|
// Copyright (c) 2018 Vladimir "fat0troll" Hodakov
|
||||||
|
|
||||||
|
package sender
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||||
|
)
|
||||||
|
|
||||||
|
// SendMarkdownAnswer sends markdown-powered message as reply
|
||||||
|
func (s *Sender) SendMarkdownAnswer(update *tgbotapi.Update, message string) {
|
||||||
|
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
||||||
|
msg.ParseMode = "Markdown"
|
||||||
|
|
||||||
|
_, err := c.Bot.Send(msg)
|
||||||
|
if err != nil {
|
||||||
|
c.Log.Error(err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SendMarkdownMessageToChatID sends markdown-powered message to specified chat
|
||||||
|
func (s *Sender) SendMarkdownMessageToChatID(chatID int64, message string) {
|
||||||
|
msg := tgbotapi.NewMessage(chatID, message)
|
||||||
|
msg.ParseMode = "Markdown"
|
||||||
|
|
||||||
|
_, err := c.Bot.Send(msg)
|
||||||
|
if err != nil {
|
||||||
|
c.Log.Error(err.Error())
|
||||||
|
}
|
||||||
|
}
|
16
lib/sender/senderinterface/senderinterface.go
Normal file
16
lib/sender/senderinterface/senderinterface.go
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// i2_bot – Instinct PokememBro Bot
|
||||||
|
// Copyright (c) 2018 Vladimir "fat0troll" Hodakov
|
||||||
|
|
||||||
|
package senderinterface
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||||
|
)
|
||||||
|
|
||||||
|
// SenderInterface implements Sender for importing via appcontext
|
||||||
|
type SenderInterface interface {
|
||||||
|
Init()
|
||||||
|
|
||||||
|
SendMarkdownAnswer(update *tgbotapi.Update, message string)
|
||||||
|
SendMarkdownMessageToChatID(chatID int64, message string)
|
||||||
|
}
|
@ -1,13 +1,14 @@
|
|||||||
// i2_bot – Instinct PokememBro Bot
|
// i2_bot – Instinct PokememBro Bot
|
||||||
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
// Copyright (c) 2017-2018 Vladimir "fat0troll" Hodakov
|
||||||
|
|
||||||
package talkers
|
package talkers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||||
)
|
)
|
||||||
|
|
||||||
// LongMessage is an easter egg
|
// LongMessage is an easter egg
|
||||||
@ -20,10 +21,7 @@ func (t *Talkers) LongMessage(update *tgbotapi.Update) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
c.Sender.SendMarkdownAnswer(update, message)
|
||||||
msg.ReplyToMessageID = update.Message.MessageID
|
|
||||||
|
|
||||||
c.Bot.Send(msg)
|
|
||||||
|
|
||||||
return "ok"
|
return "ok"
|
||||||
}
|
}
|
||||||
@ -42,6 +40,7 @@ func (t *Talkers) DurakMessage(update *tgbotapi.Update) string {
|
|||||||
if update.Message.From.ID == 324205150 {
|
if update.Message.From.ID == 324205150 {
|
||||||
message = "Молодец, Яру. Возьми с полки пирожок."
|
message = "Молодец, Яру. Возьми с полки пирожок."
|
||||||
}
|
}
|
||||||
|
|
||||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
||||||
msg.ReplyToMessageID = update.Message.MessageID
|
msg.ReplyToMessageID = update.Message.MessageID
|
||||||
|
|
||||||
|
@ -12,10 +12,7 @@ func (t *Talkers) AnyMessageUnauthorized(update *tgbotapi.Update) string {
|
|||||||
message := "Извини, действие для тебя недоступно. Возможно, у меня нет твоего профиля или же твои права недостаточны для совершения данного действия\n\n"
|
message := "Извини, действие для тебя недоступно. Возможно, у меня нет твоего профиля или же твои права недостаточны для совершения данного действия\n\n"
|
||||||
message += "Техническая поддержка бота: https://t.me/joinchat/AAkt5EgFBU9Q9iXJMvDG6A.\n"
|
message += "Техническая поддержка бота: https://t.me/joinchat/AAkt5EgFBU9Q9iXJMvDG6A.\n"
|
||||||
|
|
||||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
c.Sender.SendMarkdownAnswer(update, message)
|
||||||
msg.ParseMode = "Markdown"
|
|
||||||
|
|
||||||
c.Bot.Send(msg)
|
|
||||||
|
|
||||||
return "fail"
|
return "fail"
|
||||||
}
|
}
|
||||||
@ -24,10 +21,7 @@ func (t *Talkers) AnyMessageUnauthorized(update *tgbotapi.Update) string {
|
|||||||
func (t *Talkers) BanError(update *tgbotapi.Update) string {
|
func (t *Talkers) BanError(update *tgbotapi.Update) string {
|
||||||
message := "Вам здесь не рады. Использование бота для вас запрещено."
|
message := "Вам здесь не рады. Использование бота для вас запрещено."
|
||||||
|
|
||||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
c.Sender.SendMarkdownAnswer(update, message)
|
||||||
msg.ParseMode = "Markdown"
|
|
||||||
|
|
||||||
c.Bot.Send(msg)
|
|
||||||
|
|
||||||
return "fail"
|
return "fail"
|
||||||
}
|
}
|
||||||
@ -37,10 +31,7 @@ func (t *Talkers) BotError(update *tgbotapi.Update) string {
|
|||||||
message := "Ой, внутренняя ошибка в боте :(\n\n"
|
message := "Ой, внутренняя ошибка в боте :(\n\n"
|
||||||
message += "Техническая поддержка бота: https://t.me/joinchat/AAkt5EgFBU9Q9iXJMvDG6A. Напиши сюда, приложив скриншоты с перепиской бота.\n"
|
message += "Техническая поддержка бота: https://t.me/joinchat/AAkt5EgFBU9Q9iXJMvDG6A. Напиши сюда, приложив скриншоты с перепиской бота.\n"
|
||||||
|
|
||||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
c.Sender.SendMarkdownAnswer(update, message)
|
||||||
msg.ParseMode = "Markdown"
|
|
||||||
|
|
||||||
c.Bot.Send(msg)
|
|
||||||
|
|
||||||
return "fail"
|
return "fail"
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
// i2_bot – Instinct PokememBro Bot
|
// i2_bot – Instinct PokememBro Bot
|
||||||
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
// Copyright (c) 2017-2018 Vladimir "fat0troll" Hodakov
|
||||||
|
|
||||||
package talkers
|
package talkers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||||
"source.wtfteam.pro/i2_bot/i2_bot/lib/config"
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/config"
|
||||||
"source.wtfteam.pro/i2_bot/i2_bot/lib/dbmapping"
|
"source.wtfteam.pro/i2_bot/i2_bot/lib/dbmapping"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// AcademyMessage gives user link to Bastion
|
// AcademyMessage gives user link to Bastion
|
||||||
@ -42,10 +43,7 @@ func (t *Talkers) BastionMessage(update *tgbotapi.Update, playerRaw *dbmapping.P
|
|||||||
message += "Общий чат лиги расположен по ссылке: https://t.me/joinchat/G2vME0mIX-QHjjxE\\_JBzoQ"
|
message += "Общий чат лиги расположен по ссылке: https://t.me/joinchat/G2vME0mIX-QHjjxE\\_JBzoQ"
|
||||||
}
|
}
|
||||||
|
|
||||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
c.Sender.SendMarkdownAnswer(update, message)
|
||||||
msg.ParseMode = "Markdown"
|
|
||||||
|
|
||||||
c.Bot.Send(msg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// HelpMessage gives user all available commands
|
// HelpMessage gives user all available commands
|
||||||
@ -96,10 +94,7 @@ func (t *Talkers) HelpMessage(update *tgbotapi.Update, playerRaw *dbmapping.Play
|
|||||||
message += "Выразить благодарность и попасть в список: 4377 7300 0246 7362\n"
|
message += "Выразить благодарность и попасть в список: 4377 7300 0246 7362\n"
|
||||||
message += "_Топ ранжируется по размеру благодарности. Здесь может быть ваша реклама!_"
|
message += "_Топ ранжируется по размеру благодарности. Здесь может быть ваша реклама!_"
|
||||||
|
|
||||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
c.Sender.SendMarkdownAnswer(update, message)
|
||||||
msg.ParseMode = "Markdown"
|
|
||||||
|
|
||||||
c.Bot.Send(msg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FAQMessage prints frequently asked questions
|
// FAQMessage prints frequently asked questions
|
||||||
@ -142,39 +137,7 @@ func (t *Talkers) FAQMessage(update *tgbotapi.Update) string {
|
|||||||
message += "_Если не открывать 🥚яйцо, когда оно наберется до нужного количества, оно не будет дальше расти?_\n"
|
message += "_Если не открывать 🥚яйцо, когда оно наберется до нужного количества, оно не будет дальше расти?_\n"
|
||||||
message += "Не будет."
|
message += "Не будет."
|
||||||
|
|
||||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
c.Sender.SendMarkdownAnswer(update, message)
|
||||||
msg.ParseMode = "Markdown"
|
|
||||||
|
|
||||||
c.Bot.Send(msg)
|
|
||||||
|
|
||||||
return "ok"
|
|
||||||
}
|
|
||||||
|
|
||||||
// FiveOffer sends all users with 5 pokeballs limit offer for increasing pokeballs limit
|
|
||||||
func (t *Talkers) FiveOffer(update *tgbotapi.Update) string {
|
|
||||||
players := []dbmapping.Player{}
|
|
||||||
|
|
||||||
err := c.Db.Select(&players, "SELECT p.* FROM players p, profiles pp WHERE p.id = pp.player_id AND pp.pokeballs = 5")
|
|
||||||
if err != nil {
|
|
||||||
c.Log.Error(err.Error())
|
|
||||||
return "fail"
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := range players {
|
|
||||||
message := "Псст, я тут заметил, что у тебя всего 5 покеболов? Хочешь увеличить их лимит на 2 или даже больше? У всех игроков есть возможность получить бонус!\n\n1. Перейти по ссылке: https://telegram.me/storebot?start=pokemembrobot\n2. Нажать Start\n3. Выбрать ⭐️⭐️⭐️⭐️⭐️\n4. ОБЯЗАТЕЛЬНО написать, что вам нравится в игре (на русском языке). Оставьте большой и красочный отзыв!\n5. Переслать переписку с @storebot в тех поддержку игры @PBhelp<— только ему! и больше никому! (с текстом вашего отзыва)\n6. После проверки получить бонус 🎁 +2 к лимиту ⭕️ А если отзыв понравится админам (и это бывает очень часто), то бонус будет больше!\n7. Проверка - может занять некоторое время. Админы обязательно ответят вам о результатах проверки."
|
|
||||||
|
|
||||||
msg := tgbotapi.NewMessage(int64(players[i].TelegramID), message)
|
|
||||||
msg.ParseMode = "Markdown"
|
|
||||||
|
|
||||||
c.Bot.Send(msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
message := "Enlarge your pokeballs! Сообщение отправлено."
|
|
||||||
|
|
||||||
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
|
|
||||||
msg.ParseMode = "Markdown"
|
|
||||||
|
|
||||||
c.Bot.Send(msg)
|
|
||||||
|
|
||||||
return "ok"
|
return "ok"
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// i2_bot – Instinct PokememBro Bot
|
// i2_bot – Instinct PokememBro Bot
|
||||||
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
// Copyright (c) 2017-2018 Vladimir "fat0troll" Hodakov
|
||||||
|
|
||||||
package talkersinterface
|
package talkersinterface
|
||||||
|
|
||||||
@ -16,7 +16,6 @@ type TalkersInterface interface {
|
|||||||
BastionMessage(update *tgbotapi.Update, playerRaw *dbmapping.Player)
|
BastionMessage(update *tgbotapi.Update, playerRaw *dbmapping.Player)
|
||||||
HelpMessage(update *tgbotapi.Update, playerRaw *dbmapping.Player)
|
HelpMessage(update *tgbotapi.Update, playerRaw *dbmapping.Player)
|
||||||
FAQMessage(update *tgbotapi.Update) string
|
FAQMessage(update *tgbotapi.Update) string
|
||||||
FiveOffer(update *tgbotapi.Update) string
|
|
||||||
|
|
||||||
AnyMessageUnauthorized(update *tgbotapi.Update) string
|
AnyMessageUnauthorized(update *tgbotapi.Update) string
|
||||||
BanError(update *tgbotapi.Update) string
|
BanError(update *tgbotapi.Update) string
|
||||||
|
Reference in New Issue
Block a user