From a7fa5528b7f833a29779131f6b0b48f39c6bd7f9 Mon Sep 17 00:00:00 2001 From: Umputun Date: Wed, 6 Dec 2023 20:47:00 -0600 Subject: [PATCH] option to allow testing ids --- app/events/telegram.go | 16 +++++++++++++++- app/main.go | 3 +++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/events/telegram.go b/app/events/telegram.go index b7e7866e..402b5bb9 100644 --- a/app/events/telegram.go +++ b/app/events/telegram.go @@ -35,6 +35,7 @@ type TelegramListener struct { AdminGroup string // can be int64 or public group username (without "@" prefix) IdleDuration time.Duration SuperUsers SuperUser + TestingIDs []int64 StartupMsg string NoSpamReply bool Dry bool @@ -159,7 +160,8 @@ func (l *TelegramListener) procEvents(update tbapi.Update) error { log.Printf("[DEBUG] %s", string(msgJSON)) fromChat := update.Message.Chat.ID - if fromChat != l.chatID { // ignore messages from other chats + if !l.isChatAllowed(fromChat) { + // ignore messages from other chats return nil } @@ -207,6 +209,18 @@ func (l *TelegramListener) procEvents(update tbapi.Update) error { return errs.ErrorOrNil() } +func (l *TelegramListener) isChatAllowed(fromChat int64) bool { + if fromChat == l.chatID { + return true + } + for _, id := range l.TestingIDs { + if id == fromChat { + return true + } + } + return false +} + func (l *TelegramListener) forwardToAdmin(banUserStr string, msg *bot.Message) { log.Printf("[DEBUG] forward to admin ban data for %s, group: %d", banUserStr, l.adminChatID) forwardMsg := fmt.Sprintf("**permanently banned [%s](tg://user?id=%d)**\n[unban](%s) if it was a mistake\n\n%s\n----", diff --git a/app/main.go b/app/main.go index dd25859c..8f8d6584 100644 --- a/app/main.go +++ b/app/main.go @@ -34,6 +34,8 @@ var opts struct { Group string `long:"group" env:"GROUP" description:"admin group name/id"` } `group:"admin" namespace:"admin" env-namespace:"ADMIN"` + TestingIDs []int64 `long:"testing-id" env:"TESTING_ID" env-delim:"," description:"testing ids, allow bot to reply to them"` + LogsPath string `short:"l" long:"logs" env:"SPAM_LOGS" default:"logs" description:"path to spam logs"` SuperUsers events.SuperUser `long:"super" description:"super-users"` NoSpamReply bool `long:"no-spam-reply" env:"NO_SPAM_REPLY" description:"do not reply to spam messages"` @@ -147,6 +149,7 @@ func execute(ctx context.Context) error { AdminURL: opts.Admin.URL, AdminListenAddr: opts.Admin.Address, AdminSecret: opts.Admin.Secret, + TestingIDs: opts.TestingIDs, Dry: opts.Dry, }