From 440d36b29178a9aba87865e9c9b9cd40656289b9 Mon Sep 17 00:00:00 2001 From: Yiyang Kang Date: Wed, 23 Nov 2022 04:33:23 +0800 Subject: [PATCH] feat: announce command list --- cfg.go | 10 ++++++++-- main.go | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/cfg.go b/cfg.go index 86cfc33..7cbf6d4 100644 --- a/cfg.go +++ b/cfg.go @@ -10,8 +10,9 @@ import ( ) type Config struct { - AdminUIDs map[int64]struct{} - TGBotToken string + AdminUIDs map[int64]struct{} + TGBotToken string + TGAnnounceCommands bool WatchedInterface string MonthlyTrafficLimitGiB int @@ -42,6 +43,11 @@ func LoadCfg() error { cfg.AdminUIDs[uid] = struct{}{} } + announceCmdsEnv := os.Getenv("TG_ANNOUNCE_CMDS") + if !lo.Contains([]string{"", "no", "false", "0"}, strings.ToLower(announceCmdsEnv)) { + cfg.TGAnnounceCommands = true + } + cfg.WatchedInterface = "eth0" if iface := os.Getenv("TG_WATCHED_INTERFACE"); iface != "" { cfg.WatchedInterface = iface diff --git a/main.go b/main.go index dbc00b8..ca67af9 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "syscall" "go.uber.org/zap" + tele "gopkg.in/telebot.v3" "git.gensokyo.cafe/kkyy/tgbot_misaka_5882f7/utils" ) @@ -28,6 +29,19 @@ func runBot() { logger.Fatalw("Failed to initialize bot", "err", err) } + // Announce commands + if config.TGAnnounceCommands { + logger.Info("Announcing commands...") + + if err = bot.SetCommands([]tele.Command{ + {Text: "traffic", Description: "Show traffic usage."}, + {Text: "dig", Description: "Diggy diggy dig."}, + {Text: "year_progress", Description: "Time doesn't wait."}, + }); err != nil { + logger.Fatalw("Failed to announce commands", "err", err) + } + } + botFinCh := utils.WaitFor(bot.Start) logger.Infow("Bot started", "username", bot.Me.Username)