Skip to content

Feature: Add self-service Unquarantine button for some quarantined users - #1603

Open
firasrg wants to merge 6 commits into
developfrom
firasrg/feature/1594-unquarantine-selfservice
Open

firasrg wants to merge 6 commits into
developfrom
firasrg/feature/1594-unquarantine-selfservice

Conversation

@firasrg

@firasrg firasrg commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

When a user is quarantined, the bot posts a message in the #quarantine-zone channel that pings them and offers an "Unquarantine me" button. Users who regained control of their account can get back in without a mod.

demo-qss.mp4

New

  • ModerationUtils#quarantine:
    • Checks the user's history in the store before recording the new action, to determine whether this is their first quarantine.
    • After the role was applied successfully, posts a message in the quarantine channel that pings the user and has an "Unquarantine me" button. It is sent only for first-time quarantines.
  • QuarantineCommand#onButtonClick handles the button:
    • Only the quarantined user can use it, otherwise an ephemeral rejection.
    • Removes the quarantine role, records UNQUARANTINE in the store with the bot as author, and disables the button.
  • Config: new required key quarantineChannelPattern, used to find the quarantine channel

Moved

  • The quarantine logic moved into the new ModerationUtils#quarantine. It used to be duplicated in 2 places:
    • QuarantineCommand#quarantineUser (private method, removed)
    • ScamBlocker#quarantineAuthor (now just calls ModerationUtils#quarantine)
  • Quarantine and ScamBlocker commands therefore all work the same way: the self-service message is sent for every quarantine operation. The behaviour of the quarantine itself is unchanged: same action stored, same role, same reason.

How the button is wired

  • The button ID is generated by the caller and passed in as a Supplier<String>, since ModerationUtils is static and can't generate component IDs.
  • QuarantineCommand generates it itself. ScamBlocker uses a ComponentIdInteractor pointing at the quarantine command's name, so clicks from both paths end up in QuarantineCommand#onButtonClick. COMMAND_NAME is now public for this.
  • IDs use Lifespan.PERMANENT, because users may come back weeks later.

Untouched

  • UnquarantineCommand and its mod permission checks.
  • The DM sent by /quarantine.

Closes #1594

@firasrg
firasrg requested a review from a team as a code owner November 22, 2026 13:26
@firasrg firasrg linked an issue Nov 22, 2026 that may be closed by this pull request
@firasrg
firasrg force-pushed the firasrg/feature/1594-unquarantine-selfservice branch from 15dae73 to d25a231 Compare November 22, 2026 13:31

@Tais993 Tais993 left a comment

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 see potential

Comment on lines +651 to +654
boolean isFirsttime =
actionsStore.getActionsByTargetAscending(guild.getIdLong(), target.getIdLong())
.stream()
.noneMatch(action -> action.actionType() == ModerationAction.QUARANTINE);

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.

Use findLastActionAgainstTargetByType and rename isFirsttime to isFirstTime

Suggested change
boolean isFirsttime =
actionsStore.getActionsByTargetAscending(guild.getIdLong(), target.getIdLong())
.stream()
.noneMatch(action -> action.actionType() == ModerationAction.QUARANTINE);
boolean isFirstTime = actionsStore
.findLastActionAgainstTargetByType(guild.getIdLong(), target.getIdLong(),
ModerationAction.QUARANTINE)
.isEmpty();

final String guildId = guild.getId();
final String targetId = target.getId();

if (!isFirsttime) {

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.

Suggested change
if (!isFirsttime) {
if (!isFirstTime) {

Corresponding to above

Member member = Objects.requireNonNull(event.getMember());

if (!Guilds.hasMemberRole(member, ModerationUtils.getIsQuarantinedRolePredicate(config))) {
event.reply("You are not quarantined anymore!").setEphemeral(true).queue();

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.

Suggested change
event.reply("You are not quarantined anymore!").setEphemeral(true).queue();
event.reply("You are not quarantined anymore!").setEphemeral(true).queue();

Comment on lines +234 to +239
if (member == null) {
logger.warn(LogMarkers.SENSITIVE,
"scam message detected from a user that is not a member of the guild '{}'.",
guild.getId());
return;
}

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.

The only channels that are read are TextChannel's (a MessageChannel specifically for Guilds), that said if the user is not a Member of the guild we would have a shitton of NPE's before we arrive at this point. See ScamBlocker:142

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.

What do you suggest to do instead ?

@Tais993 Tais993 Nov 24, 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.

I forgot to say that this can just be removed, it just can't happen

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.

So that means, regardless the JDA stuff, we remove the check on a nullable getter here?

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.

You can replace it with Objects.requireNonNull(member) or just do no checks at all

@Zabuzard

Copy link
Copy Markdown
Member

could u please add to ur PR description a description of what u changed in the code and how. so we can better review it? like, which parts are new code, what has been moved from where to where? that kind of stuff

@Tais993 Tais993 left a comment

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.

Everything else looks good, genuinely the only thing lol

private void quarantineAuthor(Guild guild, Member author, SelfUser bot) {
String reason = "User posted scam that was automatically detected";
Guild guild = event.getGuild();
Member member = event.getMember();

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.

Suggested change
Member member = event.getMember();
Member member = Objects.requireNonNull(event.getMember());

A bit nitpicky but do it here instead of during the method call

@firasrg
firasrg force-pushed the firasrg/feature/1594-unquarantine-selfservice branch from b5f67ba to 0b6e905 Compare November 26, 2026 16:48
@sonarqubecloud

Copy link
Copy Markdown

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unquarantine Self-Service

3 participants