Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ask for confirmation when banning members with elevated roles #2316

Merged
merged 33 commits into from
Mar 26, 2024

Conversation

Robin5605
Copy link
Contributor

@Robin5605 Robin5605 commented Oct 29, 2022

Closes #2314

Created a subclass of botcore.utils.Interactions.ViewWithUserAndRoleCheck that will be sent when a moderator attempts to ban staff (helper role or above) in bot/exts/moderation/infraction/_utils.py. Only the !ban command author and moderators are allowed to interact with this view. If cancelled, the view is deleted (NOTE: not the entire message). Similarly, if the timeout (10 seconds) is reached, the view will be deleted (once again, not the entire message). If confirmed, the user will be banned as usual.

Waiting for input:
image

After timeout or cancel:
image

bot/exts/moderation/infraction/infractions.py Outdated Show resolved Hide resolved
bot/exts/moderation/infraction/_utils.py Outdated Show resolved Hide resolved
bot/exts/moderation/infraction/_utils.py Outdated Show resolved Hide resolved
ionite34
ionite34 previously approved these changes Oct 30, 2022
Copy link
Member

@ionite34 ionite34 left a comment

Choose a reason for hiding this comment

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

Tested, LGTM. Also, I dedicate this PR in honor of @AbooMinister25

bot/exts/moderation/infraction/_utils.py Outdated Show resolved Hide resolved
bot/exts/moderation/infraction/_utils.py Outdated Show resolved Hide resolved
bot/exts/moderation/infraction/_utils.py Outdated Show resolved Hide resolved
bot/exts/moderation/infraction/_utils.py Outdated Show resolved Hide resolved
bot/exts/moderation/infraction/_utils.py Outdated Show resolved Hide resolved
bot/exts/moderation/infraction/_utils.py Outdated Show resolved Hide resolved
bot/exts/moderation/infraction/infractions.py Outdated Show resolved Hide resolved
bot/exts/moderation/infraction/infractions.py Outdated Show resolved Hide resolved
@wookie184
Copy link
Contributor

The linter error needs fixing

@wookie184 wookie184 added a: moderation Related to community moderation functionality: (moderation, defcon, verification) s: waiting for author Waiting for author to address a review or respond to a comment t: enhancement Changes or improvements to existing features labels Nov 27, 2022
@ichard26 ichard26 changed the title Add safeguard when banning staff Ask for confirmation when banning members with elevated roles Feb 20, 2023
@ichard26 ichard26 added s: needs review Author is waiting for someone to review and approve and removed s: waiting for author Waiting for author to address a review or respond to a comment labels Dec 25, 2023
Copy link
Contributor

@wookie184 wookie184 left a comment

Choose a reason for hiding this comment

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

Maybe we could send a reply indicating if the view timed out, like there is if it's cancelled manually, though I don't really mind.

bot/exts/moderation/infraction/infractions.py Outdated Show resolved Hide resolved
bot/exts/moderation/infraction/_utils.py Outdated Show resolved Hide resolved
@wookie184 wookie184 added s: waiting for author Waiting for author to address a review or respond to a comment and removed s: needs review Author is waiting for someone to review and approve labels Jan 28, 2024
@ichard26
Copy link
Member

Screenshots of the new behaviour:

image

image

@ichard26 ichard26 dismissed ChrisLovering’s stale review March 12, 2024 00:56

I would like more 👀 on my changes given I am not familiar with Discord.py

@hedyhli hedyhli added s: needs review Author is waiting for someone to review and approve and removed s: waiting for author Waiting for author to address a review or respond to a comment labels Mar 23, 2024
Copy link
Member

@MarkKoz MarkKoz left a comment

Choose a reason for hiding this comment

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

Just some nits

await interaction.response.send_message("Cancelled infraction.")
self.stop()

async def on_timeout(self) -> None:
Copy link
Member

Choose a reason for hiding this comment

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

Good place to use the typing.override decorator

https://docs.python.org/3/library/typing.html#typing.override

Copy link
Contributor

Choose a reason for hiding this comment

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

We're not on 3.12 yet, so can't use it yet (we were blocked until very recently waiting for dependencies to update).

class StaffBanConfirmationView(interactions.ViewWithUserAndRoleCheck):
"""The confirmation view that is sent when a moderator attempts to ban a staff member."""

confirmed = False
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be an instance attribute? Maybe this is fine if the instance is not re-used, but it's not clear this class's instances are not intended to be re-used nor would we have a good way to enforce that.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if making it an instance attribute nets us anything as the confirmed flag wouldn't be reset to false either way? But sure, why not.

Copy link
Member

Choose a reason for hiding this comment

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

I didn't correctly word what I was thinking. If it's a class attribute, then the state is persisted across all instances. This means confirmed will remain True for subsequent command invocations, right?

You're correct that as an instance attribute, the instance cannot be re-used because it's never reset. But I think an instance attribute solves the above case.

Copy link
Member

Choose a reason for hiding this comment

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

ichard26@asus-ubuntu:~$ cat test.py
class A:
    flag = False

a = A()
a2 = A()
a.flag = True
print(a.flag, a2.flag)
ichard26@asus-ubuntu:~$ python test.py
True False

As far as I understand, unless the class attribute is directly modified via the class, state won't persist across all instances.

Copy link
Member

Choose a reason for hiding this comment

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

Okay yeah, that makes sense now that I see it. Thanks for clearing that up - was not intuitive to me at a glance.

bot/exts/moderation/infraction/_utils.py Outdated Show resolved Hide resolved
bot/exts/moderation/infraction/infractions.py Outdated Show resolved Hide resolved
@ichard26
Copy link
Member

I'm not really happy with how long this PR and review revisions has taken; I sincerely hope this is close to be able to be merged. (Albeit if you have any more nits, please send them over.)

@ichard26 ichard26 requested a review from MarkKoz March 25, 2024 23:27
@ichard26 ichard26 dismissed wookie184’s stale review March 25, 2024 23:29

Changes have been implemented.

Copy link
Contributor

@wookie184 wookie184 left a comment

Choose a reason for hiding this comment

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

All good, thanks for working on this.

@wookie184 wookie184 enabled auto-merge (squash) March 26, 2024 13:57
@wookie184 wookie184 merged commit 3a5e386 into python-discord:main Mar 26, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: moderation Related to community moderation functionality: (moderation, defcon, verification) s: needs review Author is waiting for someone to review and approve t: enhancement Changes or improvements to existing features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Safeguards against accidentally banning staff members
10 participants