Skip to content

Commit

Permalink
option to allow testing ids
Browse files Browse the repository at this point in the history
  • Loading branch information
umputun committed Dec 7, 2023
1 parent dcd06c1 commit a7fa552
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
16 changes: 15 additions & 1 deletion app/events/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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----",
Expand Down
3 changes: 3 additions & 0 deletions app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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,
}

Expand Down

0 comments on commit a7fa552

Please sign in to comment.