bot icon indicating copy to clipboard operation
bot copied to clipboard

Ask for confirmation when banning members with elevated roles

Open Robin5605 opened this issue 2 years ago • 6 comments

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

Robin5605 avatar Oct 29 '22 21:10 Robin5605

The linter error needs fixing

wookie184 avatar Nov 12 '22 19:11 wookie184

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.

wookie184 avatar Mar 04 '23 11:03 wookie184

Sounds great. I'll implement that.

Robin5605 avatar Mar 04 '23 17:03 Robin5605

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.

wookie184 avatar Mar 05 '23 12:03 wookie184

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)

ChrisLovering avatar Mar 05 '23 12:03 ChrisLovering

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!

Robin5605 avatar Jun 27 '23 02:06 Robin5605

Screenshots of the new behaviour:

image

image

ichard26 avatar Mar 12 '24 00:03 ichard26

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 avatar Mar 25 '24 23:03 ichard26