Skip to content

Commit

Permalink
Fix logic for admins and pattern matching.
Browse files Browse the repository at this point in the history
  • Loading branch information
marcopaganini authored and mpinheir committed Jun 28, 2024
1 parent 24b3548 commit 765d60a
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,23 +139,19 @@ func (x *opBot) Run(bot *tgbotapi.BotAPI) {
// Notifications.
x.notifications.manageNotifications(bot, update)

// Determine if the user is an admin. This is used below to exclude
// admins from some actions.
admin, err := isAdmin(bot, update.Message.Chat.ID, update.Message.From.ID)
if err != nil {
log.Printf("Unable to determine if user (id: %d) is an admin in chat (id: %d). Assuming not.", update.Message.From.ID, update.Message.Chat.ID)
}

// Handle ban patterns before proceeding.
match, err := x.handledPatternMatching(bot, update)
if err != nil {
// Just log errors, but do nothing in this case.
log.Printf("Error handling pattern matching: %v\n", err)
} else if !admin {
switch match {
case opBan, opKick:
// Handle ban patterns before proceeding. Non admin users only.
if !admin {
match, err := x.handledPatternMatching(bot, update)
if err != nil {
log.Printf("Error handling pattern matching: %v\n", err)
} else if match == opBan || match == opKick {
// For these cases, there is no need to send a captcha.
log.Printf("Not sending captcha to user %d because pattern matched with action %q\n", update.Message.From.ID, match.String())
log.Printf("Kick/Ban pattern match for userID %d, action %q\n", update.Message.From.ID, match.String())
continue
}
}
Expand Down

0 comments on commit 765d60a

Please sign in to comment.