Move support of channel to helper with TDLib
Now we're discarding messages sent directly to us, except for messages from @fw_zookeeper.
This commit is contained in:
parent
7e96abd339
commit
401f962bd2
32
domains/battles/v1/announce.go
Normal file
32
domains/battles/v1/announce.go
Normal 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)
|
||||
}
|
@ -11,15 +11,33 @@ import (
|
||||
|
||||
// ForwardCommand responds to fight request
|
||||
func ForwardCommand(update *telegram.Update) {
|
||||
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
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user