diff --git a/cmd/i2_bot/i2_bot.go b/cmd/i2_bot/i2_bot.go index 44ed52b..563adf7 100644 --- a/cmd/i2_bot/i2_bot.go +++ b/cmd/i2_bot/i2_bot.go @@ -21,6 +21,7 @@ import ( "git.wtfteam.pro/fat0troll/i2_bot/lib/users" "git.wtfteam.pro/fat0troll/i2_bot/lib/welcomer" "github.com/go-telegram-bot-api/telegram-bot-api" + "net/http" "time" ) @@ -56,10 +57,16 @@ func main() { c.Cron.Start() c.Log.Info("> Cron started.") - u := tgbotapi.NewUpdate(0) - u.Timeout = 60 + _, err := c.Bot.SetWebhook(tgbotapi.NewWebhook(c.Cfg.Telegram.WebHookDomain)) + if err != nil { + c.Log.Fatal(err.Error()) + } - updates, _ := c.Bot.GetUpdatesChan(u) + updates := c.Bot.ListenForWebhook("/" + c.Bot.Token) + go http.ListenAndServe(c.Cfg.Telegram.ListenAddress, nil) + + c.Log.Info("Listening on " + c.Cfg.Telegram.ListenAddress) + c.Log.Info("Webhook URL: " + c.Cfg.Telegram.WebHookDomain) for update := range updates { if update.Message != nil { diff --git a/config.yml.example b/config.yml.example index 2d1f24f..f2abe48 100644 --- a/config.yml.example +++ b/config.yml.example @@ -1,5 +1,7 @@ telegram_connection: api_token: "your-awesome-token" + webhook_domain: "https://i2bot.wtfteam.pro" + listen_address: "0.0.0.0:5000" database_connection: host: "localhost" port: "3306" diff --git a/lib/broadcaster/sender.go b/lib/broadcaster/sender.go index 437b758..9bc3721 100644 --- a/lib/broadcaster/sender.go +++ b/lib/broadcaster/sender.go @@ -32,7 +32,7 @@ func (b *Broadcaster) AdminBroadcastMessageSend(update *tgbotapi.Update, playerR return "fail" } - prettyName := profileRaw.Nickname + "(@" + profileRaw.TelegramNickname + ")" + prettyName := profileRaw.Nickname + " (@" + profileRaw.TelegramNickname + ")" privateChats := []dbmapping.Chat{} switch messageRaw.BroadcastType { diff --git a/lib/config/config.go b/lib/config/config.go index dc0add6..9deef35 100644 --- a/lib/config/config.go +++ b/lib/config/config.go @@ -24,7 +24,9 @@ type DatabaseConnection struct { // TelegramConnection handles settings for Telegram connection in config.yaml type TelegramConnection struct { - APIToken string `yaml:"api_token"` + APIToken string `yaml:"api_token"` + WebHookDomain string `yaml:"webhook_domain"` + ListenAddress string `yaml:"listen_address"` } // SpecialChats handles settings for special chats