Archived
1

Add small fix for battle regex and forward

This commit is contained in:
Vladimir Hodakov 2018-11-29 23:24:13 +04:00
parent 0ba20b3ed5
commit 593e02b10b
Signed by: Vladimir Hodakov
GPG Key ID: 673980B6882F82C6
2 changed files with 8 additions and 3 deletions

View File

@ -20,8 +20,8 @@ func New(cc *context.Context) {
c = cc
log = c.Logger.With().Str("domain", "battles").Int("version", 1).Logger()
fightRegex := regexp.MustCompile(`@FWorldBot\s(.*)fight_(.{12})$`)
router.RegisterPrivateRegexp(fightRegex, ForwardCommand)
fightRegexWithoutBot := regexp.MustCompile(`(.*)fight_(.{12})$`)
router.RegisterPrivateRegexp(fightRegexWithoutBot, ForwardCommand)
log.Info().Msg("Domain «battles» initialized")
}

View File

@ -12,8 +12,13 @@ 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)
itelegram.RespondWithoutMarkdown(c.Config.Announces.ChannelID, message)