Pins to supergroups, managed by admins
This commit is contained in:
@@ -4,17 +4,14 @@
|
||||
package talkers
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"strconv"
|
||||
"strings"
|
||||
// 3rd party
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
// local
|
||||
"lab.pztrn.name/fat0troll/i2_bot/lib/dbmapping"
|
||||
)
|
||||
|
||||
// AdminBroadcastMessageCompose saves message for future broadcast
|
||||
func (t *Talkers) AdminBroadcastMessageCompose(update tgbotapi.Update, playerRaw *dbmapping.Player) string {
|
||||
func (t *Talkers) AdminBroadcastMessageCompose(update *tgbotapi.Update, playerRaw *dbmapping.Player) string {
|
||||
broadcastingMessageBody := strings.Replace(update.Message.Text, "/send_all ", "", 1)
|
||||
|
||||
messageRaw, ok := c.Getters.CreateBroadcastMessage(playerRaw, broadcastingMessageBody, "all")
|
||||
@@ -50,7 +47,7 @@ func (t *Talkers) AdminBroadcastMessageCompose(update tgbotapi.Update, playerRaw
|
||||
}
|
||||
|
||||
// AdminBroadcastMessageSend sends saved message to all private chats
|
||||
func (t *Talkers) AdminBroadcastMessageSend(update tgbotapi.Update, playerRaw *dbmapping.Player) string {
|
||||
func (t *Talkers) AdminBroadcastMessageSend(update *tgbotapi.Update, playerRaw *dbmapping.Player) string {
|
||||
messageNum := strings.Replace(update.Message.Text, "/send_confirm ", "", 1)
|
||||
messageNumInt, _ := strconv.Atoi(messageNum)
|
||||
messageRaw, ok := c.Getters.GetBroadcastMessageByID(messageNumInt)
|
||||
|
@@ -4,14 +4,12 @@
|
||||
package talkers
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"strconv"
|
||||
// 3rd party
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// GroupsList lists all known pokememes
|
||||
func (t *Talkers) GroupsList(update tgbotapi.Update) string {
|
||||
// GroupsList lists all chats where bot exist
|
||||
func (t *Talkers) GroupsList(update *tgbotapi.Update) string {
|
||||
groupChats, ok := c.Getters.GetAllGroupChatsWithSquads()
|
||||
if !ok {
|
||||
return "fail"
|
||||
|
@@ -4,18 +4,13 @@
|
||||
package talkers
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"log"
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
"math/rand"
|
||||
"time"
|
||||
// 3rd party
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
)
|
||||
|
||||
// DurakMessage is an easter egg
|
||||
func (t *Talkers) DurakMessage(update tgbotapi.Update) {
|
||||
log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text)
|
||||
|
||||
func (t *Talkers) DurakMessage(update *tgbotapi.Update) {
|
||||
reactions := make([]string, 0)
|
||||
reactions = append(reactions, "Сам такой!",
|
||||
"А ты типа нет?",
|
||||
@@ -31,9 +26,7 @@ func (t *Talkers) DurakMessage(update tgbotapi.Update) {
|
||||
}
|
||||
|
||||
// MatMessage is an easter rgg
|
||||
func (t *Talkers) MatMessage(update tgbotapi.Update) {
|
||||
log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text)
|
||||
|
||||
func (t *Talkers) MatMessage(update *tgbotapi.Update) {
|
||||
reactions := make([]string, 0)
|
||||
reactions = append(reactions, "Фу, как некультурно!",
|
||||
"Иди рот с мылом помой",
|
||||
|
@@ -4,12 +4,11 @@
|
||||
package talkers
|
||||
|
||||
import (
|
||||
// 3rd party
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
)
|
||||
|
||||
// AnyMessageUnauthorized throws when user can't do something
|
||||
func (t *Talkers) AnyMessageUnauthorized(update tgbotapi.Update) {
|
||||
func (t *Talkers) AnyMessageUnauthorized(update *tgbotapi.Update) {
|
||||
message := "Извини, действие для тебя недоступно. Возможно, у меня нет твоего профиля или же твои права недостаточны для совершения данного действия\n\n"
|
||||
message += "Если тебе кажется, что это ошибка, пиши @fat0troll.\n"
|
||||
|
||||
@@ -20,7 +19,7 @@ func (t *Talkers) AnyMessageUnauthorized(update tgbotapi.Update) {
|
||||
}
|
||||
|
||||
// GetterError throws when bot can't get something
|
||||
func (t *Talkers) GetterError(update tgbotapi.Update) {
|
||||
func (t *Talkers) GetterError(update *tgbotapi.Update) {
|
||||
message := "Ой, внутренняя ошибка в боте :(\n\n"
|
||||
message += "Напиши @fat0troll, приложив форвардом последние сообщения до этого.\n"
|
||||
|
||||
|
@@ -4,9 +4,6 @@
|
||||
package talkers
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"log"
|
||||
// local
|
||||
"lab.pztrn.name/fat0troll/i2_bot/lib/appcontext"
|
||||
"lab.pztrn.name/fat0troll/i2_bot/lib/talkers/talkersinterface"
|
||||
)
|
||||
@@ -27,5 +24,5 @@ func New(ac *appcontext.Context) {
|
||||
|
||||
// Init is an initialization function for talkers
|
||||
func (t *Talkers) Init() {
|
||||
log.Printf("Initializing responders...")
|
||||
c.Log.Info("Initializing responders...")
|
||||
}
|
||||
|
@@ -4,14 +4,12 @@
|
||||
package talkers
|
||||
|
||||
import (
|
||||
// 3rd party
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
// local
|
||||
"lab.pztrn.name/fat0troll/i2_bot/lib/dbmapping"
|
||||
)
|
||||
|
||||
// HelloMessageUnauthorized tell new user what to do.
|
||||
func (t *Talkers) HelloMessageUnauthorized(update tgbotapi.Update) {
|
||||
func (t *Talkers) HelloMessageUnauthorized(update *tgbotapi.Update) {
|
||||
message := "*Бот Инстинкта приветствует тебя!*\n\n"
|
||||
message += "Для начала работы с ботом, пожалуйста, перешли от бота игры @PokememBroBot профиль героя.\n"
|
||||
message += "Все дальнейшие действия с ботом возможны лишь при наличии профиля игрока."
|
||||
@@ -23,7 +21,7 @@ func (t *Talkers) HelloMessageUnauthorized(update tgbotapi.Update) {
|
||||
}
|
||||
|
||||
// HelloMessageAuthorized greets existing user
|
||||
func (t *Talkers) HelloMessageAuthorized(update tgbotapi.Update, playerRaw dbmapping.Player) {
|
||||
func (t *Talkers) HelloMessageAuthorized(update *tgbotapi.Update, playerRaw *dbmapping.Player) {
|
||||
message := "*Бот Инстинкта приветствует тебя. Снова.*\n\n"
|
||||
message += "Привет, " + update.Message.From.FirstName + " " + update.Message.From.LastName + "!\n"
|
||||
message += "Последнее обновление информации о тебе: " + playerRaw.UpdatedAt.Format("02.01.2006 15:04:05 -0700")
|
||||
|
@@ -4,15 +4,13 @@
|
||||
package talkers
|
||||
|
||||
import (
|
||||
// 3rd party
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
// local
|
||||
"lab.pztrn.name/fat0troll/i2_bot/lib/config"
|
||||
"lab.pztrn.name/fat0troll/i2_bot/lib/dbmapping"
|
||||
)
|
||||
|
||||
// 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) {
|
||||
message := "*Бот Инстинкта Enchanched.*\n\n"
|
||||
message += "Текущая версия: *" + config.VERSION + "*\n\n"
|
||||
message += "Список команд\n\n"
|
||||
@@ -22,6 +20,7 @@ func (t *Talkers) HelpMessage(update tgbotapi.Update, playerRaw *dbmapping.Playe
|
||||
if c.Getters.PlayerBetterThan(playerRaw, "admin") {
|
||||
message += "+ /send\\_all _текст_ — отправить сообщение всем пользователям бота\n"
|
||||
message += "+ /group\\_chats — получить список групп, в которых работает бот.\n"
|
||||
message += "+ /pin _текст_ — отправить сообщение во все группы, где находится бот. Сообщение будет автоматически запинено.\n"
|
||||
}
|
||||
message += "+ /help – выводит данное сообщение\n"
|
||||
|
||||
|
@@ -4,18 +4,15 @@
|
||||
package talkers
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
"lab.pztrn.name/fat0troll/i2_bot/lib/dbmapping"
|
||||
"strconv"
|
||||
"strings"
|
||||
// 3rd party
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
// local
|
||||
"lab.pztrn.name/fat0troll/i2_bot/lib/dbmapping"
|
||||
)
|
||||
|
||||
// Internal functions
|
||||
|
||||
func (t *Talkers) pokememesListing(update tgbotapi.Update, page int, pokememesArray []dbmapping.PokememeFull) {
|
||||
func (t *Talkers) pokememesListing(update *tgbotapi.Update, page int, pokememesArray []dbmapping.PokememeFull) {
|
||||
message := "*Известные боту покемемы*\n"
|
||||
message += "Список отсортирован по грейду и алфавиту.\n"
|
||||
message += "Покедекс: " + strconv.Itoa(len(pokememesArray)) + " / 219\n"
|
||||
@@ -62,7 +59,13 @@ func (t *Talkers) pokememesListing(update tgbotapi.Update, page int, pokememesAr
|
||||
// External functions
|
||||
|
||||
// PokememesList lists all known pokememes
|
||||
func (t *Talkers) PokememesList(update tgbotapi.Update, page int) {
|
||||
func (t *Talkers) PokememesList(update *tgbotapi.Update) {
|
||||
pageNumber := strings.Replace(update.Message.Text, "/pokedex", "", 1)
|
||||
pageNumber = strings.Replace(pageNumber, "/pokedeks", "", 1)
|
||||
page, _ := strconv.Atoi(pageNumber)
|
||||
if page == 0 {
|
||||
page = 1
|
||||
}
|
||||
pokememesArray, ok := c.Getters.GetPokememes()
|
||||
if !ok {
|
||||
t.GetterError(update)
|
||||
@@ -72,7 +75,7 @@ func (t *Talkers) PokememesList(update tgbotapi.Update, page int) {
|
||||
}
|
||||
|
||||
// PokememeInfo shows information about single pokememe based on internal ID
|
||||
func (t *Talkers) PokememeInfo(update tgbotapi.Update, playerRaw dbmapping.Player) string {
|
||||
func (t *Talkers) PokememeInfo(update *tgbotapi.Update, playerRaw *dbmapping.Player) string {
|
||||
pokememeNumber := strings.Replace(update.Message.Text, "/pk", "", 1)
|
||||
var calculatePossibilites = true
|
||||
profileRaw, ok := c.Getters.GetProfile(playerRaw.ID)
|
||||
|
@@ -4,12 +4,11 @@
|
||||
package talkers
|
||||
|
||||
import (
|
||||
// 3rd party
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
)
|
||||
|
||||
// PokememeAddSuccessMessage shows pokememe adding success message
|
||||
func (t *Talkers) PokememeAddSuccessMessage(update tgbotapi.Update) {
|
||||
func (t *Talkers) PokememeAddSuccessMessage(update *tgbotapi.Update) {
|
||||
message := "*Покемем успешно добавлен.*\n\n"
|
||||
message += "Посмотреть всех известных боту покемемов можно командой /pokedeks"
|
||||
|
||||
@@ -20,7 +19,7 @@ func (t *Talkers) PokememeAddSuccessMessage(update tgbotapi.Update) {
|
||||
}
|
||||
|
||||
// PokememeAddDuplicateMessage shows pokememe add duplication message
|
||||
func (t *Talkers) PokememeAddDuplicateMessage(update tgbotapi.Update) {
|
||||
func (t *Talkers) PokememeAddDuplicateMessage(update *tgbotapi.Update) {
|
||||
message := "*Мы уже знаем об этом покемеме*\n\n"
|
||||
message += "Посмотреть всех известных боту покемемов можно командой /pokedeks\n\n"
|
||||
message += "Если у покемема изменились описание или характеристики, напиши @fat0troll для обновления базы."
|
||||
@@ -32,7 +31,7 @@ func (t *Talkers) PokememeAddDuplicateMessage(update tgbotapi.Update) {
|
||||
}
|
||||
|
||||
// PokememeAddFailureMessage shows pokememe add error message
|
||||
func (t *Talkers) PokememeAddFailureMessage(update tgbotapi.Update) {
|
||||
func (t *Talkers) PokememeAddFailureMessage(update *tgbotapi.Update) {
|
||||
message := "*Неудачно получилось :(*\n\n"
|
||||
message += "Случилась жуткая ошибка, и мы не смогли записать покемема в базу. Напиши @fat0troll, он разберется.\n\n"
|
||||
message += "Посмотреть всех известных боту покемемов можно командой /pokedeks"
|
||||
|
@@ -4,17 +4,13 @@
|
||||
package talkers
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"log"
|
||||
"strconv"
|
||||
// 3rd party
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
// local
|
||||
"lab.pztrn.name/fat0troll/i2_bot/lib/dbmapping"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// ProfileMessage shows current player's profile
|
||||
func (t *Talkers) ProfileMessage(update tgbotapi.Update, playerRaw dbmapping.Player) string {
|
||||
func (t *Talkers) ProfileMessage(update *tgbotapi.Update, playerRaw *dbmapping.Player) string {
|
||||
profileRaw, ok := c.Getters.GetProfile(playerRaw.ID)
|
||||
if !ok {
|
||||
c.Talkers.AnyMessageUnauthorized(update)
|
||||
@@ -23,29 +19,29 @@ func (t *Talkers) ProfileMessage(update tgbotapi.Update, playerRaw dbmapping.Pla
|
||||
league := dbmapping.League{}
|
||||
err := c.Db.Get(&league, c.Db.Rebind("SELECT * FROM leagues WHERE id=?"), playerRaw.LeagueID)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
c.Log.Error(err)
|
||||
}
|
||||
level := dbmapping.Level{}
|
||||
err = c.Db.Get(&level, c.Db.Rebind("SELECT * FROM levels WHERE id=?"), profileRaw.LevelID)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
c.Log.Error(err)
|
||||
}
|
||||
weapon := dbmapping.Weapon{}
|
||||
if profileRaw.WeaponID != 0 {
|
||||
err = c.Db.Get(&weapon, c.Db.Rebind("SELECT * FROM weapons WHERE id=?"), profileRaw.WeaponID)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
c.Log.Error(err)
|
||||
}
|
||||
}
|
||||
profilePokememes := []dbmapping.ProfilePokememe{}
|
||||
err = c.Db.Select(&profilePokememes, c.Db.Rebind("SELECT * FROM profiles_pokememes WHERE profile_id=?"), profileRaw.ID)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
c.Log.Error(err)
|
||||
}
|
||||
pokememes := []dbmapping.Pokememe{}
|
||||
err = c.Db.Select(&pokememes, c.Db.Rebind("SELECT * FROM pokememes"))
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
c.Log.Error(err)
|
||||
}
|
||||
|
||||
attackPokememes := 0
|
||||
|
@@ -4,12 +4,11 @@
|
||||
package talkers
|
||||
|
||||
import (
|
||||
// 3rd party
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
)
|
||||
|
||||
// ProfileAddSuccessMessage shows profile addition success message
|
||||
func (t *Talkers) ProfileAddSuccessMessage(update tgbotapi.Update) {
|
||||
func (t *Talkers) ProfileAddSuccessMessage(update *tgbotapi.Update) {
|
||||
message := "*Профиль успешно обновлен.*\n\n"
|
||||
message += "Функциональность бота держится на актуальности профилей. Обновляйся почаще, и да пребудет с тобой Рандом!\n"
|
||||
message += "Сохраненный профиль ты можешь просмотреть командой /me.\n\n"
|
||||
@@ -22,7 +21,7 @@ func (t *Talkers) ProfileAddSuccessMessage(update tgbotapi.Update) {
|
||||
}
|
||||
|
||||
// ProfileAddFailureMessage shows profile addition failure message
|
||||
func (t *Talkers) ProfileAddFailureMessage(update tgbotapi.Update) {
|
||||
func (t *Talkers) ProfileAddFailureMessage(update *tgbotapi.Update) {
|
||||
message := "*Неудачно получилось :(*\n\n"
|
||||
message += "Случилась жуткая ошибка, и мы не смогли записать профиль в базу. Напиши @fat0troll, он разберется."
|
||||
|
||||
|
@@ -4,20 +4,16 @@
|
||||
package talkers
|
||||
|
||||
import (
|
||||
// stdlib
|
||||
"log"
|
||||
"strconv"
|
||||
// 3rd party
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
// local
|
||||
"lab.pztrn.name/fat0troll/i2_bot/lib/dbmapping"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// BestPokememesList shows list for catching based on player league and grade
|
||||
func (t *Talkers) BestPokememesList(update tgbotapi.Update, playerRaw dbmapping.Player) string {
|
||||
func (t *Talkers) BestPokememesList(update *tgbotapi.Update, playerRaw *dbmapping.Player) string {
|
||||
pokememes, ok := c.Getters.GetBestPokememes(playerRaw.ID)
|
||||
if !ok {
|
||||
log.Printf("Cannot get pokememes from getter!")
|
||||
c.Log.Error("Cannot get pokememes from getter!")
|
||||
return "fail"
|
||||
}
|
||||
|
||||
|
@@ -4,37 +4,35 @@
|
||||
package talkersinterface
|
||||
|
||||
import (
|
||||
// 3rd party
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
// local
|
||||
"lab.pztrn.name/fat0troll/i2_bot/lib/dbmapping"
|
||||
)
|
||||
|
||||
// TalkersInterface implements Talkers for importing via appcontex
|
||||
type TalkersInterface interface {
|
||||
Init()
|
||||
HelloMessageUnauthorized(update tgbotapi.Update)
|
||||
HelloMessageAuthorized(update tgbotapi.Update, playerRaw dbmapping.Player)
|
||||
HelpMessage(update tgbotapi.Update, playerRaw *dbmapping.Player)
|
||||
PokememesList(update tgbotapi.Update, page int)
|
||||
PokememeInfo(update tgbotapi.Update, playerRaw dbmapping.Player) string
|
||||
BestPokememesList(update tgbotapi.Update, playerRaw dbmapping.Player) string
|
||||
HelloMessageUnauthorized(update *tgbotapi.Update)
|
||||
HelloMessageAuthorized(update *tgbotapi.Update, playerRaw *dbmapping.Player)
|
||||
HelpMessage(update *tgbotapi.Update, playerRaw *dbmapping.Player)
|
||||
PokememesList(update *tgbotapi.Update)
|
||||
PokememeInfo(update *tgbotapi.Update, playerRaw *dbmapping.Player) string
|
||||
BestPokememesList(update *tgbotapi.Update, playerRaw *dbmapping.Player) string
|
||||
|
||||
PokememeAddSuccessMessage(update tgbotapi.Update)
|
||||
PokememeAddDuplicateMessage(update tgbotapi.Update)
|
||||
PokememeAddFailureMessage(update tgbotapi.Update)
|
||||
ProfileAddSuccessMessage(update tgbotapi.Update)
|
||||
ProfileAddFailureMessage(update tgbotapi.Update)
|
||||
ProfileMessage(update tgbotapi.Update, playerRaw dbmapping.Player) string
|
||||
PokememeAddSuccessMessage(update *tgbotapi.Update)
|
||||
PokememeAddDuplicateMessage(update *tgbotapi.Update)
|
||||
PokememeAddFailureMessage(update *tgbotapi.Update)
|
||||
ProfileAddSuccessMessage(update *tgbotapi.Update)
|
||||
ProfileAddFailureMessage(update *tgbotapi.Update)
|
||||
ProfileMessage(update *tgbotapi.Update, playerRaw *dbmapping.Player) string
|
||||
|
||||
AnyMessageUnauthorized(update tgbotapi.Update)
|
||||
GetterError(update tgbotapi.Update)
|
||||
AnyMessageUnauthorized(update *tgbotapi.Update)
|
||||
GetterError(update *tgbotapi.Update)
|
||||
|
||||
AdminBroadcastMessageCompose(update tgbotapi.Update, playerRaw *dbmapping.Player) string
|
||||
AdminBroadcastMessageSend(update tgbotapi.Update, playerRaw *dbmapping.Player) string
|
||||
AdminBroadcastMessageCompose(update *tgbotapi.Update, playerRaw *dbmapping.Player) string
|
||||
AdminBroadcastMessageSend(update *tgbotapi.Update, playerRaw *dbmapping.Player) string
|
||||
|
||||
GroupsList(update tgbotapi.Update) string
|
||||
GroupsList(update *tgbotapi.Update) string
|
||||
|
||||
DurakMessage(update tgbotapi.Update)
|
||||
MatMessage(update tgbotapi.Update)
|
||||
DurakMessage(update *tgbotapi.Update)
|
||||
MatMessage(update *tgbotapi.Update)
|
||||
}
|
||||
|
Reference in New Issue
Block a user