Add fixes and linter improvements to talkers package
This commit is contained in:
		| @@ -12,6 +12,10 @@ var ( | ||||
| 	c *appcontext.Context | ||||
| ) | ||||
|  | ||||
| const ( | ||||
| 	parseMode = "Markdown" | ||||
| ) | ||||
|  | ||||
| // Sender is a function-handling struct for sender | ||||
| type Sender struct{} | ||||
|  | ||||
|   | ||||
| @@ -7,10 +7,10 @@ import ( | ||||
| 	"github.com/go-telegram-bot-api/telegram-bot-api" | ||||
| ) | ||||
|  | ||||
| // SendMarkdownAnswer sends markdown-powered message as reply | ||||
| // SendMarkdownAnswer sends markdown-powered message as answer | ||||
| func (s *Sender) SendMarkdownAnswer(update *tgbotapi.Update, message string) { | ||||
| 	msg := tgbotapi.NewMessage(update.Message.Chat.ID, message) | ||||
| 	msg.ParseMode = "Markdown" | ||||
| 	msg.ParseMode = parseMode | ||||
|  | ||||
| 	_, err := c.Bot.Send(msg) | ||||
| 	if err != nil { | ||||
| @@ -21,7 +21,19 @@ func (s *Sender) SendMarkdownAnswer(update *tgbotapi.Update, message string) { | ||||
| // SendMarkdownMessageToChatID sends markdown-powered message to specified chat | ||||
| func (s *Sender) SendMarkdownMessageToChatID(chatID int64, message string) { | ||||
| 	msg := tgbotapi.NewMessage(chatID, message) | ||||
| 	msg.ParseMode = "Markdown" | ||||
| 	msg.ParseMode = parseMode | ||||
|  | ||||
| 	_, err := c.Bot.Send(msg) | ||||
| 	if err != nil { | ||||
| 		c.Log.Error(err.Error()) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // SendMarkdownReply sends markdown-powered message as reply | ||||
| func (s *Sender) SendMarkdownReply(update *tgbotapi.Update, message string, messageID int) { | ||||
| 	msg := tgbotapi.NewMessage(update.Message.Chat.ID, message) | ||||
| 	msg.ParseMode = parseMode | ||||
| 	msg.ReplyToMessageID = messageID | ||||
|  | ||||
| 	_, err := c.Bot.Send(msg) | ||||
| 	if err != nil { | ||||
|   | ||||
| @@ -13,4 +13,5 @@ type SenderInterface interface { | ||||
|  | ||||
| 	SendMarkdownAnswer(update *tgbotapi.Update, message string) | ||||
| 	SendMarkdownMessageToChatID(chatID int64, message string) | ||||
| 	SendMarkdownReply(update *tgbotapi.Update, message string, messageID int) | ||||
| } | ||||
|   | ||||
| @@ -9,6 +9,7 @@ import ( | ||||
| 	"time" | ||||
|  | ||||
| 	"github.com/go-telegram-bot-api/telegram-bot-api" | ||||
| 	"source.wtfteam.pro/i2_bot/i2_bot/lib/constants" | ||||
| ) | ||||
|  | ||||
| // LongMessage is an easter egg | ||||
| @@ -23,7 +24,7 @@ func (t *Talkers) LongMessage(update *tgbotapi.Update) string { | ||||
|  | ||||
| 	c.Sender.SendMarkdownAnswer(update, message) | ||||
|  | ||||
| 	return "ok" | ||||
| 	return constants.UserRequestSuccess | ||||
| } | ||||
|  | ||||
| // DurakMessage is an easter egg | ||||
| @@ -41,12 +42,9 @@ func (t *Talkers) DurakMessage(update *tgbotapi.Update) string { | ||||
| 		message = "Молодец, Яру. Возьми с полки пирожок." | ||||
| 	} | ||||
|  | ||||
| 	msg := tgbotapi.NewMessage(update.Message.Chat.ID, message) | ||||
| 	msg.ReplyToMessageID = update.Message.MessageID | ||||
| 	c.Sender.SendMarkdownReply(update, message, update.Message.MessageID) | ||||
|  | ||||
| 	c.Bot.Send(msg) | ||||
|  | ||||
| 	return "ok" | ||||
| 	return constants.UserRequestSuccess | ||||
| } | ||||
|  | ||||
| // MatMessage is an easter rgg | ||||
| @@ -60,12 +58,9 @@ func (t *Talkers) MatMessage(update *tgbotapi.Update) string { | ||||
|  | ||||
| 	// Praise the Random Gods! | ||||
| 	rand.Seed(time.Now().Unix()) | ||||
| 	msg := tgbotapi.NewMessage(update.Message.Chat.ID, reactions[rand.Intn(len(reactions))]) | ||||
| 	msg.ReplyToMessageID = update.Message.MessageID | ||||
| 	c.Sender.SendMarkdownReply(update, reactions[rand.Intn(len(reactions))], update.Message.MessageID) | ||||
|  | ||||
| 	c.Bot.Send(msg) | ||||
|  | ||||
| 	return "ok" | ||||
| 	return constants.UserRequestSuccess | ||||
| } | ||||
|  | ||||
| // NewYearMessage2018 pins new year 2018 message to bastion, default and academy chats. | ||||
| @@ -73,6 +68,7 @@ func (t *Talkers) NewYearMessage2018() { | ||||
| 	academyChatID, _ := strconv.ParseInt(c.Cfg.SpecialChats.AcademyID, 10, 64) | ||||
| 	bastionChatID, _ := strconv.ParseInt(c.Cfg.SpecialChats.BastionID, 10, 64) | ||||
| 	defaultChatID, _ := strconv.ParseInt(c.Cfg.SpecialChats.DefaultID, 10, 64) | ||||
| 	parseMode := "Markdown" | ||||
|  | ||||
| 	message := "*Совет лиги Инстинкт поздравляет вас, дорогие игроки, с Новым 2018 Годом!*\n" | ||||
| 	message += "*Важное сообщение от* Совета лиги Инстинкт (коллективное сознательное)\n\n" | ||||
| @@ -87,7 +83,7 @@ func (t *Talkers) NewYearMessage2018() { | ||||
| 	message += "*Х*уй им, в общем, всем — с бантиком!" | ||||
|  | ||||
| 	msg := tgbotapi.NewMessage(defaultChatID, message) | ||||
| 	msg.ParseMode = "Markdown" | ||||
| 	msg.ParseMode = parseMode | ||||
|  | ||||
| 	pinnableMessage, _ := c.Bot.Send(msg) | ||||
|  | ||||
| @@ -103,7 +99,7 @@ func (t *Talkers) NewYearMessage2018() { | ||||
| 	} | ||||
|  | ||||
| 	msg = tgbotapi.NewMessage(bastionChatID, message) | ||||
| 	msg.ParseMode = "Markdown" | ||||
| 	msg.ParseMode = parseMode | ||||
|  | ||||
| 	pinnableMessage, _ = c.Bot.Send(msg) | ||||
|  | ||||
| @@ -119,7 +115,7 @@ func (t *Talkers) NewYearMessage2018() { | ||||
| 	} | ||||
|  | ||||
| 	msg = tgbotapi.NewMessage(academyChatID, message) | ||||
| 	msg.ParseMode = "Markdown" | ||||
| 	msg.ParseMode = parseMode | ||||
|  | ||||
| 	pinnableMessage, _ = c.Bot.Send(msg) | ||||
|  | ||||
|   | ||||
| @@ -5,6 +5,7 @@ package talkers | ||||
|  | ||||
| import ( | ||||
| 	"github.com/go-telegram-bot-api/telegram-bot-api" | ||||
| 	"source.wtfteam.pro/i2_bot/i2_bot/lib/constants" | ||||
| ) | ||||
|  | ||||
| // AnyMessageUnauthorized throws when user can't do something | ||||
| @@ -14,7 +15,7 @@ func (t *Talkers) AnyMessageUnauthorized(update *tgbotapi.Update) string { | ||||
|  | ||||
| 	c.Sender.SendMarkdownAnswer(update, message) | ||||
|  | ||||
| 	return "fail" | ||||
| 	return constants.UserRequestFailed | ||||
| } | ||||
|  | ||||
| // BanError throws error for persona non grata | ||||
| @@ -23,7 +24,7 @@ func (t *Talkers) BanError(update *tgbotapi.Update) string { | ||||
|  | ||||
| 	c.Sender.SendMarkdownAnswer(update, message) | ||||
|  | ||||
| 	return "fail" | ||||
| 	return constants.UserRequestForbidden | ||||
| } | ||||
|  | ||||
| // BotError throws when bot can't do something | ||||
| @@ -33,5 +34,5 @@ func (t *Talkers) BotError(update *tgbotapi.Update) string { | ||||
|  | ||||
| 	c.Sender.SendMarkdownAnswer(update, message) | ||||
|  | ||||
| 	return "fail" | ||||
| 	return constants.BotError | ||||
| } | ||||
|   | ||||
| @@ -26,5 +26,6 @@ func New(ac *appcontext.Context) { | ||||
| func (t *Talkers) Init() { | ||||
| 	c.Log.Info("Initializing common Responders...") | ||||
|  | ||||
| 	c.Cron.AddFunc("0 0 0 1 1 *", t.NewYearMessage2018) | ||||
| 	// Uncomment and edit this before New Year 2019! | ||||
| 	// c.Cron.AddFunc("0 0 0 1 1 *", t.NewYearMessage2018) | ||||
| } | ||||
|   | ||||
| @@ -8,11 +8,12 @@ import ( | ||||
|  | ||||
| 	"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/constants" | ||||
| 	"source.wtfteam.pro/i2_bot/i2_bot/lib/dbmapping" | ||||
| ) | ||||
|  | ||||
| // AcademyMessage gives user link to Bastion | ||||
| func (t *Talkers) AcademyMessage(update *tgbotapi.Update, playerRaw *dbmapping.Player) { | ||||
| func (t *Talkers) AcademyMessage(update *tgbotapi.Update, playerRaw *dbmapping.Player) string { | ||||
| 	message := "" | ||||
|  | ||||
| 	if playerRaw.LeagueID > 1 { | ||||
| @@ -24,14 +25,13 @@ func (t *Talkers) AcademyMessage(update *tgbotapi.Update, playerRaw *dbmapping.P | ||||
| 		message += "Чат для обучения новичков предумростям игры расположен по ссылке: https://t.me/joinchat/G2vME04jk02v2etRmumylg" | ||||
| 	} | ||||
|  | ||||
| 	msg := tgbotapi.NewMessage(update.Message.Chat.ID, message) | ||||
| 	msg.ParseMode = "Markdown" | ||||
| 	c.Sender.SendMarkdownAnswer(update, message) | ||||
|  | ||||
| 	c.Bot.Send(msg) | ||||
| 	return constants.UserRequestSuccess | ||||
| } | ||||
|  | ||||
| // BastionMessage gives user link to Bastion | ||||
| func (t *Talkers) BastionMessage(update *tgbotapi.Update, playerRaw *dbmapping.Player) { | ||||
| func (t *Talkers) BastionMessage(update *tgbotapi.Update, playerRaw *dbmapping.Player) string { | ||||
| 	message := "" | ||||
|  | ||||
| 	if playerRaw.LeagueID > 1 { | ||||
| @@ -44,10 +44,12 @@ func (t *Talkers) BastionMessage(update *tgbotapi.Update, playerRaw *dbmapping.P | ||||
| 	} | ||||
|  | ||||
| 	c.Sender.SendMarkdownAnswer(update, message) | ||||
|  | ||||
| 	return constants.UserRequestSuccess | ||||
| } | ||||
|  | ||||
| // HelpMessage gives user all available commands | ||||
| func (t *Talkers) HelpMessage(update *tgbotapi.Update, playerRaw *dbmapping.Player) { | ||||
| func (t *Talkers) HelpMessage(update *tgbotapi.Update, playerRaw *dbmapping.Player) string { | ||||
| 	message := "*Бот Инстинкта Enhanced.*\n\n" | ||||
| 	message += "Текущая версия: *" + config.VERSION + "*\n\n" | ||||
| 	message += "Список команд\n\n" | ||||
| @@ -95,6 +97,8 @@ func (t *Talkers) HelpMessage(update *tgbotapi.Update, playerRaw *dbmapping.Play | ||||
| 	message += "_Топ ранжируется по размеру благодарности. Здесь может быть ваша реклама!_" | ||||
|  | ||||
| 	c.Sender.SendMarkdownAnswer(update, message) | ||||
|  | ||||
| 	return constants.UserRequestSuccess | ||||
| } | ||||
|  | ||||
| // FAQMessage prints frequently asked questions | ||||
| @@ -139,5 +143,5 @@ func (t *Talkers) FAQMessage(update *tgbotapi.Update) string { | ||||
|  | ||||
| 	c.Sender.SendMarkdownAnswer(update, message) | ||||
|  | ||||
| 	return "ok" | ||||
| 	return constants.UserRequestSuccess | ||||
| } | ||||
|   | ||||
| @@ -12,9 +12,9 @@ import ( | ||||
| type TalkersInterface interface { | ||||
| 	Init() | ||||
|  | ||||
| 	AcademyMessage(update *tgbotapi.Update, playerRaw *dbmapping.Player) | ||||
| 	BastionMessage(update *tgbotapi.Update, playerRaw *dbmapping.Player) | ||||
| 	HelpMessage(update *tgbotapi.Update, playerRaw *dbmapping.Player) | ||||
| 	AcademyMessage(update *tgbotapi.Update, playerRaw *dbmapping.Player) string | ||||
| 	BastionMessage(update *tgbotapi.Update, playerRaw *dbmapping.Player) string | ||||
| 	HelpMessage(update *tgbotapi.Update, playerRaw *dbmapping.Player) string | ||||
| 	FAQMessage(update *tgbotapi.Update) string | ||||
|  | ||||
| 	AnyMessageUnauthorized(update *tgbotapi.Update) string | ||||
|   | ||||
		Reference in New Issue
	
	Block a user