Skip to content

Added ThisIsAgainstRulesCommand (Scam and Job-Ad) (formerly ThisIsScam, only Scam) - #1567

Open
firasrg wants to merge 6 commits into
developfrom
firasrg/feature/new-command-rule-violation-alert
Open

firasrg wants to merge 6 commits into
developfrom
firasrg/feature/new-command-rule-violation-alert

Conversation

@firasrg

@firasrg firasrg commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

What

Replaces the this-is-scam message context command with a more generic
this-is-against-rules command (ThisIsAgainstRulesCommand).

When a user reports a message, mods now get three buttons instead of Yes/No:

Button What happens
Scam Same flow as before: DM, quarantine, then ban + unban to delete the recent messages.
Job-Ad DM, warning recorded (WARN), then ban + unban to delete the recent messages.
Dismiss Nothing happens, the alert is closed.

In both Scam and Job-Ad the ban/unban only serves to delete the message history,
the user can join back right away.

image

@firasrg
firasrg requested a review from a team as a code owner October 9, 2026 23:41
@firasrg
firasrg force-pushed the firasrg/feature/new-command-rule-violation-alert branch from d3aa2f7 to 1edf9cc Compare October 9, 2026 23:53
* </ul>
* The ban and unban only serves to delete the messages, the user is free to join back afterward.
*/
public final class ThisIsScamCommand extends BotCommandAdapter implements MessageContextCommand {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(rename the file, ThisIsAgainstRulesCommand)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do it at the end

Message message = event.getTarget();
Optional<TextChannel> modMailChannel = findModMailChannel(event);
if (modMailChannel.isEmpty()) {
reportedMessageToTimestamp.invalidate(message.getIdLong());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why that logic change?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an edge-case: I noticed an issue while doing the tests. I know the handleWasAlreadyReportedMessage() puts the message Id in reportedMessageToTimestamp before the alert is sent to mods, to block duplicate reports. But If the send then fails, the message stay marked as already reported for the cooldown duration. which is 1 day and I keep getting that msg again an again. But with this change, invalidating that entry on failure so the report can be retried once a problem is fixed. It only runs on the failure cases -> the successful alerts are unaffected

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont quite follow. can u provide details and maybe screenshots pls, thanks

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Background: handleWasAlreadyReportedMessage() stores the message ID in reportedMessageToTimestamp before the alert is posted to the mod channel, to block duplicate reports. That entry lives for 1 day. (The per-user cooldown is a separate 1 minute timer.)

The problem: if posting the alert then fails, the entry stays. Nobody can report that message again for 24h, even though the mods never saw it.

How to reproduce (I renamed the modmail channel so the pattern doesn’t match, but denying the bot “Send Messages” there fails the same way):

  1. Rename the modmail channel so the lookup fails, then report a message.
    👉 User gets “Sorry, there was an issue forwarding your report…” and the log says “Cannot find the designated mod mail channel…”

  2. Rename the channel back and report the same message again (after the 1 minute cooldown).

Without the invalidate calls: the second report is rejected with “This message was already reported.” although no alert was ever posted.

With the invalidate calls: the failure paths remove the entry, so the second report goes through and the mods get the alert.

Successful reports are unaffected, since invalidate only runs in the 2 failure branches (mod channel not found, and sending the alert failed).

It’s a small robustness fix, but if you’d prefer to keep it out of this PR I’m happy to split it into a separate one!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

proof (1)

@Zabuzard Zabuzard Oct 27, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pic

Remove your cache invalidate lines. Move the highlighted section where we are searching for the channel one section above, so it happens BEFORE we put the thing into the cache to begin with (it happens inside the handleWasAlreadyReportedMessage method). So if it fails to find the channel, we never put the entry into the cache to begin with, then we also have no need to invalidate anything.

For the second one, when the sending itself fails (despite all the previous checks), we simply dont handle the case. No invalidation, whatsoever. At this point the message is considered reported - even if the actual sending failed (for example due to discord api or network hicups).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done the changes like you said:

@Override
public void onMessageContext(MessageContextInteractionEvent event) {
    if (handleIsOnCooldown(event)) { return; }
    
    Optional<TextChannel> modChannel = findModChannel(event);
    if (modChannel.isEmpty()) {
        event.reply(FAILED_MESSAGE).setEphemeral(true).queue();
        return;
    }
    
    if (handleWasAlreadyReportedMessage(event)) { return; }
    
    Message message = event.getTarget();
    reportToMods(message, modChannel.orElseThrow()).mapToResult().map(result -> {
        if (result.isFailure()) {
            logger.warn("Unable to forward a report to the mod mail channel.",
                    result.getFailure());
            return FAILED_MESSAGE;
        }
        return "Thank you for your report, a moderator will take care of it 👍";
    }).flatMap(response -> event.reply(response).setEphemeral(true)).queue();
}

Result (it's worst i think):

thisisscam-issue-2.1.mp4

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thats not what i expected this code to do. it shouldnt have put it into the cache bc we returned before reaching the line that would add it. ill checkout ur code and figure out why its behaving like that.

@Zabuzard Zabuzard Oct 28, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please push the changes so i can test it easier, thanks

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@Zabuzard Zabuzard changed the title Feat: Turn “this is scam” command into a generic option (Scam | Job-Ad | Dismiss) Added ThisIsAgainstRulesCommand (Scam and Job-Ad) (formerly ThisIsScam, only Scam) Oct 10, 2026
@Zabuzard Zabuzard added enhance command Modify or improve an existing command or group of commands of the bot priority: normal priority: major and removed priority: normal labels Oct 10, 2026
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhance command Modify or improve an existing command or group of commands of the bot priority: major

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants