hdkv
/
fwzookeeper
Archived
1
Fork 0

Move support of channel to helper with TDLib

Now we're discarding messages sent directly to us, except for
messages from @fw_zookeeper.
master
Vladimir Hodakov 2019-01-08 05:00:16 +04:00
parent 7e96abd339
commit 401f962bd2
Signed by: Vladimir Hodakov
GPG Key ID: 673980B6882F82C6
2 changed files with 60 additions and 10 deletions

View File

@ -0,0 +1,32 @@
// Fantasy World Zookeeper Bot
// Copyright (c) 2018 Vladimir "fat0troll" Hodakov
package battlesv1
import (
"gitlab.com/toby3d/telegram"
itelegram "lab.wtfteam.pro/fat0troll/fw_zookeeper/local/telegram"
"strings"
)
// AnnounceBattle posts battle announce to channel
func AnnounceBattle(update *telegram.Update) {
announcerID := 788961789
if update.Message.From.ID != announcerID {
log.Warn().Msgf("Someone trying to mimic announcer: user with ID %d and username %s", update.Message.From.ID, update.Message.From.Username)
return
}
battleInformationArray := strings.Split(update.Message.Text, " ")
if len(battleInformationArray) != 2 {
log.Error().Msgf("Unexpected battle information format: got %d elements instead of 2", len(battleInformationArray))
return
}
battleType := battleInformationArray[0]
battleTag := battleInformationArray[1]
log.Debug().Msgf("Battle type «%s», battle tag %s", battleType, battleTag)
itelegram.RespondWithoutMarkdown(c.Config.Announces.ChannelID, battleType)
itelegram.RespondWithoutMarkdown(c.Config.Announces.ChannelID, battleTag)
}

View File

@ -11,15 +11,33 @@ import (
// ForwardCommand responds to fight request
func ForwardCommand(update *telegram.Update) {
log.Info().Msg("Battle request received!")
if update.Message.Chat.ID == c.Config.Announces.ChannelID {
log.Info().Msg("This battle is already posted")
}
message := update.Message.Text
if !strings.Contains(message, "join") {
message = strings.Replace(message, "fight", "join_fight", 1)
}
message = strings.Replace(message, "@FWorldBot ", "", 1)
message := ""
if update.Message.From.ID != 788961789 {
message := "*Смотритель более не принимает прямые запросы*\n"
message += "Люди глупы и безрассудны. Им дали возможность позвать на помощь — но они пользуются ею, чтобы самоутвердиться. Довольно!\n"
message += "Зовите на помощь @fw\\_zookeeper, как живого человека — через кнопку «Позвать на помощь» в игре.\n"
message += "Доброй охоты!"
itelegram.RespondWithMarkdown(update.Message.Chat.ID, message)
} else {
switch {
case strings.HasPrefix(update.Message.Text, "Кабаны!"):
AnnounceBattle(update)
case strings.HasPrefix(update.Message.Text, "Огры!"):
AnnounceBattle(update)
case strings.HasPrefix(update.Message.Text, "Буйволы!"):
AnnounceBattle(update)
default:
log.Info().Msg("Battle request received!")
if update.Message.Chat.ID == c.Config.Announces.ChannelID {
log.Info().Msg("This battle is already posted")
}
message = update.Message.Text
if !strings.Contains(message, "join") {
message = strings.Replace(message, "fight", "join_fight", 1)
}
message = strings.Replace(message, "@FWorldBot ", "", 1)
itelegram.RespondWithoutMarkdown(c.Config.Announces.ChannelID, message)
itelegram.RespondWithoutMarkdown(c.Config.Announces.ChannelID, message)
}
}
}