From 593e02b10beeb849b16478f4fe68abcb7e475650 Mon Sep 17 00:00:00 2001 From: Vladimir Hodakov Date: Thu, 29 Nov 2018 23:24:13 +0400 Subject: [PATCH] Add small fix for battle regex and forward --- domains/battles/v1/exported.go | 4 ++-- domains/battles/v1/forward.go | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/domains/battles/v1/exported.go b/domains/battles/v1/exported.go index 06bbef5..260cd5c 100644 --- a/domains/battles/v1/exported.go +++ b/domains/battles/v1/exported.go @@ -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") } diff --git a/domains/battles/v1/forward.go b/domains/battles/v1/forward.go index ab5f656..01c8657 100644 --- a/domains/battles/v1/forward.go +++ b/domains/battles/v1/forward.go @@ -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 - message = strings.Replace(message, " fight", " join_fight", 1) + 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)