Skip to content

Commit

Permalink
add option for no-reply to spam messages
Browse files Browse the repository at this point in the history
  • Loading branch information
umputun committed Dec 6, 2023
1 parent f8507a5 commit ff277c5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 5 additions & 2 deletions app/events/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type TelegramListener struct {
IdleDuration time.Duration
SuperUsers SuperUser
StartupMsg string
NoSpamReply bool

AdminURL string
AdminSecret string
Expand Down Expand Up @@ -162,8 +163,10 @@ func (l *TelegramListener) procEvents(update tbapi.Update) error {

resp := l.Bot.OnMessage(*msg)

if err := l.sendBotResponse(resp, fromChat); err != nil {
log.Printf("[WARN] failed to respond on update, %v", err)
if resp.Send && !l.NoSpamReply {
if err := l.sendBotResponse(resp, fromChat); err != nil {
log.Printf("[WARN] failed to respond on update, %v", err)
}
}

errs := new(multierror.Error)
Expand Down
6 changes: 4 additions & 2 deletions app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ var opts struct {
Group string `long:"group" env:"GROUP" description:"admin group name/id"`
} `group:"admin" namespace:"admin" env-namespace:"ADMIN"`

LogsPath string `short:"l" long:"logs" env:"SPAM_LOGS" default:"logs" description:"path to spam logs"`
SuperUsers events.SuperUser `long:"super" description:"super-users"`
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"`

CAS struct {
API string `long:"api" env:"API" default:"https://api.cas.chat" description:"CAS API"`
Expand Down Expand Up @@ -133,6 +134,7 @@ func execute(ctx context.Context) error {
SuperUsers: opts.SuperUsers,
Bot: spamBot,
StartupMsg: opts.Message.Startup,
NoSpamReply: opts.NoSpamReply,
SpamLogger: events.SpamLoggerFunc(func(msg *bot.Message, response *bot.Response) {
log.Printf("[INFO] spam detected from %v, response: %s", msg.From, response.Text)
log.Printf("[DEBUG] spam message: %q", msg.Text)
Expand Down

0 comments on commit ff277c5

Please sign in to comment.