bot
bot copied to clipboard
Ask for confirmation when banning members with elevated roles
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:

After timeout or cancel:

The linter error needs fixing
This works and the code looks good, although I have two possible suggestions:
- When the interaction times out the buttons should be removed, to avoid the "this interaction failed" message.
- There should be an acknowledgement that the ban was cancelled when clicking "cancel", e.g. editing the message or sending a followup message, to make it clear what happened.
Sounds great. I'll implement that.
When the interaction times out the buttons should be removed, to avoid the "this interaction failed" message.
I just realised that i'm not actually sure how this would be implemented, so it's probably fine to leave as is unless you have a simple idea.
When the interaction times out the buttons should be removed, to avoid the "this interaction failed" message.
I just realised that i'm not actually sure how this would be implemented, so it's probably fine to leave as is unless you have a simple idea.
You can use this view from bot-core
view = pydis_core.utils.interactions.ViewWithUserAndRoleCheck(
allowed_users = list_of_users,
allowed_roles = list_of_roles,
timeout = timeout,
)
view.message = await ctx.send("foo", view=view)
Removed the unnecessary __init__ as per @ChrisLovering 's suggestion and made the bot delete the buttons after the timeout and show an indicator as to whether or not the infraction was cancelled, as per @wookie184 's suggestion. Thanks!
Screenshots of the new behaviour:
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.)