Archived
1

Add battle announces to channel

Channel ID is configured in fw_zookeeper.yaml.
This commit is contained in:
2018-11-29 22:15:21 +04:00
parent eeee9a72e3
commit 0ba20b3ed5
7 changed files with 83 additions and 2 deletions

View File

@@ -0,0 +1,27 @@
// Fantasy World Zookeeper Bot
// Copyright (c) 2018 Vladimir "fat0troll" Hodakov
package battlesv1
import (
"github.com/rs/zerolog"
"lab.wtfteam.pro/fat0troll/fw_zookeeper/context"
"lab.wtfteam.pro/fat0troll/fw_zookeeper/internal/router"
"regexp"
)
var (
c *context.Context
log zerolog.Logger
)
// New initializes package
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)
log.Info().Msg("Domain «battles» initialized")
}

View File

@@ -0,0 +1,20 @@
// Fantasy World Zookeeper Bot
// Copyright (c) 2018 Vladimir "fat0troll" Hodakov
package battlesv1
import (
"gitlab.com/toby3d/telegram"
itelegram "lab.wtfteam.pro/fat0troll/fw_zookeeper/internal/telegram"
"strings"
)
// ForwardCommand responds to fight request
func ForwardCommand(update *telegram.Update) {
log.Info().Msg("Battle request received!")
message := update.Message.Text
message = strings.Replace(message, " fight", " join_fight", 1)
message = strings.Replace(message, "@FWorldBot ", "", 1)
itelegram.RespondWithoutMarkdown(c.Config.Announces.ChannelID, message)
}