[p]warn ask to ban when user not in server #6481
No reviewers
Labels
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Mrcoolgamer11/Red-DiscordBot!6481
Loading…
Reference in a new issue
No description provided.
Delete branch "V3/develop"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description of the changes
This is to follow up with what @Flame442 said: "If a disruptive user is leaving before a moderator is able to take action, it may often make sense to consider them a troll and bypass the server's standard warnings track."
Instead of warning them, I check if they are in the discord guild; if they are not, then they will be banned.
Closes #6445
Have the changes in this PR been tested?
Note: the command here is "[p]wasd" because I tested it by implementing a new temporary cog.
My original comment was not intended to be complete approval of the idea of having this command default to banning the member if they have left the server. I think it could be useful to have it as an option (whether that be by asking if they should be banned as a prompt when
[p]warnis used on a member that left, or as a config option that causes[p]warnto ban when used on a member that has left), but I would consider it unexpected to happen automatically without any input from the server owner/mod. My comment was mostly intended to address the fact that this issue is one I would consider a fairly rare one to run into, and one that has a fairly easy manual second step to address it.Regarding the implementation of this fix, the
RawUserIdConverterwould be the preferred way to accept both a mention or a user ID, and is the converter used by other parts of the bot with similar behavior (ie,[p]ban).Additionally, you are currently failing the style checks. Please format your PR with
black -l 99using the instructions in our CONTRIBUTING.MD file.ok, I can add that as a prompt then. The bot should say "[User]" has left the server, so I cannot warn them. Would you like to ban them instead? [Y/N]". If the mod/owner responds with "Y", [User] will be banned. Else, no action will be taken.
I will submit another PR request with the changes.
*Reminder: the reason I used "[p]wasd" here is because I had to create a new separate cog in order to test for this kind of command. After I finished testing it, I carefully put in the modified parts.
From this image, we can see that the bot eventually timed out after it hasn't received a proper command (either Y or N).
The bot only registers the responses it expects. Otherwise it will not do anything and eventually time out.
This should use
RawUserIdConverterto handle the case where the user is no longer in the server. See the[p]bancommand for an example. Similar to that command, it should beUnioning theMemberandRawUserIdConverter, and having anisinstance(user, int)check to perform this banning logic instead of the existing warning behavior.Additionally, the name of the function parameter defines the name a user will see in
[p]help, so it should still be called eithermemberoruser, notidentifier.Avoid having multiple
sendcalls for the same input, as that spams the API. One way to handle this is to combine strings until one finalsend, but in this case the lastsendyou have already says basically the same thing, so this message is redundant.If this is intended to be a part of the help text, it must be within the string directly below the function header. Otherwise, don't use string literals, use comments.
fetch_useris a very heavily ratelimited call, and there is no reason for it to be used in this case since the actual user data isn't useful. As in the[p]bancommand, just havingself.bot.get_user(ident) or discord.Object(id=user)is enough to have something to pass toguild.ban(). You won't be able to useuser.name, but just repeating the.idor saying "that user" is probably fine.Instead of manually defining a check, you should use
.MessagePredicate.yes_or_no(example) to handle more ways to say "yes" or "no" as a text responseEDIT: I didn't know we already had a util for this, but now that buttons exist the best option is probably to use those. The
ConfirmViewutility should make it easy, see the examples in the docs.Implemented the fixes you have mentioned @Flame442
Here is what happens when you warn the user who is not in the server:
Here is what happens when it times out after 10 seconds.
If the ban is successful, it should create a modlog case (example).
@ -386,6 +387,49 @@ class Warnings(commands.Cog):or a custom reason if ``[p]warningset allowcustomreasons`` is set.This
tryshould only wrap around theban, not the entire block of code.10s is a bit short.
Allow the string to be translated (you might need to re-black format after accepting some of these changes).
No need to have a whole extra message for a slightly different case.
If the bot does not have
add_reactionspermissions, this will cause it to claim an error occurred while trying to ban a user, which isn't quite true. Either this should useawait ctx.tick()which handles that case correctly, or it should send a message instead to confirm.Translations.
Translations.
@ -389,0 +415,4 @@user,ctx.author,reason,until=None,Rather than asking and hoping we have perms, let's add a check to exit slightly earlier if the bot doesn't have them
@ -386,6 +387,49 @@ class Warnings(commands.Cog):or a custom reason if ``[p]warningset allowcustomreasons`` is set.yep, now I added a checker
@ -388,1 +389,4 @@guild = ctx.guildmember = Noneif isinstance(user, discord.Member):member = userI had the string simply stating that the user was not in the server, because when the
[p]warncommand is used, that is the best response the bot can give. Stating as a response that the bot cannot ban users, without explaining why it is trying to ban is confusing. I think it is better to just state that the user isn't in the server without worrying about the fact that it could have attempted to ban.ctx.tickis a shorthand forif permissions_for.add_reactions: add_reaction(CHECK). That's why I said before you could just replace theadd_reactioncall with a call totick, and let its error handling do the trick.@ -388,1 +389,4 @@guild = ctx.guildmember = Noneif isinstance(user, discord.Member):member = useroh ok, thank you for the clarification. Yes you're right, it would be strange to see that the bot suddenly prompts up with an error that it cannot ban a person when the [p]warn command is evoked. In that case, would you think it makes more sense for the bot to check "if not ctx.channel.permissions_for(ctx.guild.me).ban_members:" and then put the call to the ban() function in that if statement?
@ -388,1 +389,4 @@guild = ctx.guildmember = Noneif isinstance(user, discord.Member):member = userIn that case, do you want me to remove the "try...except"? I think the try..except block will be pointless then. All I need to do is add the check "if not ctx.channel.permissions_for(ctx.guild.me).ban_members:" before calling the ban() function. Because this ensures that there are no permission issues. However, as I didn't write the ban function, there could be another possible error, which is why I wanted to keep the try...except block in there.
@ -388,1 +389,4 @@guild = ctx.guildmember = Noneif isinstance(user, discord.Member):member = userNo. It makes no sense to ask if the user should be banned if the bot is not going to be able to ban them. A simpler failure message and an even earlier exist is sufficient.
@ -388,1 +389,4 @@guild = ctx.guildmember = Noneif isinstance(user, discord.Member):member = userThere is always the potential for error, but if an error you cannot think of happens, you probably don't want to suppress it. You want to be able to identify it so you know if it is something that needs to be dealt with. Any API call can error if the internet goes out, but it doesn't make sense to wrap every API call in a
tryjust in case.I don't think it hurts to keep an
HTTPExceptiontryon thebancall, since there are other cases that do make sense to catch, such as if the user is already banned. But the bot not having permissions is an obvious one that makes sense to have additional pre-check for. Thetryon thetickwould be unnecessary.@ -388,1 +389,4 @@guild = ctx.guildmember = Noneif isinstance(user, discord.Member):member = userSorry, I misinterpreted what you were correcting, but yes, I see what ctx.tick() does. I just wanted to keep it consistent with what the other commands did, and I saw that they were doing the add_reaction() call. Fixed it.
@ -388,1 +389,4 @@guild = ctx.guildmember = Noneif isinstance(user, discord.Member):member = userI'm not sure which ones you mean, in this file at least they are all using
tick.@ -388,1 +389,4 @@guild = ctx.guildmember = Noneif isinstance(user, discord.Member):member = usernevermind. I swore I saw there was some mention of it. Must've been in a different file.
@ -386,6 +387,49 @@ class Warnings(commands.Cog):or a custom reason if ``[p]warningset allowcustomreasons`` is set.Thanks for contributing!