Add battle announces to channel
Channel ID is configured in fw_zookeeper.yaml.
This commit is contained in:
parent
eeee9a72e3
commit
0ba20b3ed5
27
domains/battles/v1/exported.go
Normal file
27
domains/battles/v1/exported.go
Normal 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")
|
||||
}
|
20
domains/battles/v1/forward.go
Normal file
20
domains/battles/v1/forward.go
Normal 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)
|
||||
}
|
9
internal/config/announces.go
Normal file
9
internal/config/announces.go
Normal file
@ -0,0 +1,9 @@
|
||||
// Fantasy World Zookeeper Bot
|
||||
// Copyright (c) 2018 Vladimir "fat0troll" Hodakov
|
||||
|
||||
package config
|
||||
|
||||
// Announces is a struct which handles announces configuration
|
||||
type Announces struct {
|
||||
ChannelID int64 `yaml:"channel_id"`
|
||||
}
|
@ -7,4 +7,5 @@ package config
|
||||
// structs within.
|
||||
type Struct struct {
|
||||
Telegram Telegram `yaml:"telegram"`
|
||||
Announces Announces `yaml:"announces"`
|
||||
}
|
||||
|
@ -24,3 +24,26 @@ func RespondWithMarkdown(chatID int64, message string) {
|
||||
log.Error().Err(err)
|
||||
}
|
||||
}
|
||||
|
||||
// RespondWithoutMarkdown will send message to given chat without parse mode
|
||||
func RespondWithoutMarkdown(chatID int64, message string) {
|
||||
messageParams := getMessageParams(chatID, message, false)
|
||||
messageParams.ParseMode = "HTML"
|
||||
|
||||
_, err := bot.SendMessage(&messageParams)
|
||||
if err != nil {
|
||||
log.Error().Err(err)
|
||||
}
|
||||
}
|
||||
|
||||
// RespondWithInlineKeyboard will send message to given chat with Markdown parse
|
||||
// mode and keyboard attached
|
||||
func RespondWithInlineKeyboard(chatID int64, message string, keyboard *telegram.InlineKeyboardMarkup) {
|
||||
messageParams := getMessageParams(chatID, message, false)
|
||||
messageParams.ReplyMarkup = keyboard
|
||||
|
||||
_, err := bot.SendMessage(&messageParams)
|
||||
if err != nil {
|
||||
log.Error().Err(err)
|
||||
}
|
||||
}
|
||||
|
@ -90,7 +90,6 @@ func StartBot() {
|
||||
log.Info().Msg("Connection with Telegram established")
|
||||
|
||||
for update := range updates {
|
||||
log.Debug().Msgf("%+v", update)
|
||||
go router.Respond(update)
|
||||
}
|
||||
}
|
||||
|
2
main.go
2
main.go
@ -5,6 +5,7 @@ package main
|
||||
|
||||
import (
|
||||
"lab.wtfteam.pro/fat0troll/fw_zookeeper/context"
|
||||
"lab.wtfteam.pro/fat0troll/fw_zookeeper/domains/battles/v1"
|
||||
"lab.wtfteam.pro/fat0troll/fw_zookeeper/domains/commands/v1"
|
||||
"lab.wtfteam.pro/fat0troll/fw_zookeeper/internal/router"
|
||||
"lab.wtfteam.pro/fat0troll/fw_zookeeper/internal/telegram"
|
||||
@ -27,6 +28,7 @@ func main() {
|
||||
|
||||
router.New(c)
|
||||
commandsv1.New(c)
|
||||
battlesv1.New(c)
|
||||
|
||||
telegram.New(c)
|
||||
|
||||
|
Reference in New Issue
Block a user