Allow tempban by ID and ban downgrade #5978

Merged
raidensakura merged 4 commits from tempban into V3/develop 2026-05-28 17:43:27 +02:00
raidensakura commented 2023-02-02 10:51:40 +01:00 (Migrated from github.com)

Description of the changes

  • tempban will allow banning user by ID
  • If using the command would cause a downgrade from permanent ban to temporary ban, a prompt will appear asking if command invoker wants to proceed
  • If the user is already tempbanned, a prompt will appear asking if command invoker wants to update the duration of the current tempban.
  • Prompt will be skipped if ctx.assume_yes evaluates to True

Fixes #5915

Have the changes in this PR been tested?

Yes.

Additional Notes

This is my first PR to this repo and I'm quite new to Python. Suggestions for improvement to my PR are very welcome.

### Description of the changes - tempban will allow banning user by ID - If using the command would cause a downgrade from permanent ban to temporary ban, a prompt will appear asking if command invoker wants to proceed - If the user is already tempbanned, a prompt will appear asking if command invoker wants to update the duration of the current tempban. - Prompt will be skipped if `ctx.assume_yes` evaluates to `True` Fixes #5915 ### Have the changes in this PR been tested? Yes. ### Additional Notes This is my first PR to this repo and I'm quite new to Python. Suggestions for improvement to my PR are very welcome.
Zephyrkul commented 2023-02-02 20:25:13 +01:00 (Migrated from github.com)
  • Prompt will be skipped if ctx.assume_yes evaluates to True

I don't think allowing tempban to be run on a schedule would be best here.

> - Prompt will be skipped if `ctx.assume_yes` evaluates to `True` I don't think allowing tempban to be run on a schedule would be best here.
raidensakura commented 2023-02-03 06:32:29 +01:00 (Migrated from github.com)

I don't think allowing tempban to be run on a schedule would be best here.

I'm only implementing this based on Jack's last statement in the issue discussion, it can be raised for discussion again if needed.

I personally think it's okay to include it since prompt only appear if user is already banned anyway, my concern is that whether it should be the default choice to downgrade instead of skipping it completely.

> I don't think allowing tempban to be run on a schedule would be best here. I'm only implementing this based on Jack's last statement in the issue discussion, it can be raised for discussion again if needed. I personally think it's okay to include it since prompt only appear if user is already banned anyway, my concern is that whether it should be the default choice to downgrade instead of skipping it completely.
Jackenmen commented 2023-02-03 10:34:34 +01:00 (Migrated from github.com)
  • Prompt will be skipped if ctx.assume_yes evaluates to True

I don't think allowing tempban to be run on a schedule would be best here.

It's not for scheduling, it's to allow for implementing a command that skips the prompt if someone prefers it that way.

> > * Prompt will be skipped if `ctx.assume_yes` evaluates to `True` > > I don't think allowing tempban to be run on a schedule would be best here. It's not for scheduling, it's to allow for implementing a command that skips the prompt if someone prefers it that way.
Jackenmen (Migrated from github.com) requested changes 2026-05-28 14:26:52 +02:00
@ -638,18 +644,19 @@ class KickBanMixin(MixinMeta):
_("I cannot let you do that. Self-harm is bad {}").format("\N{PENSIVE FACE}")
Jackenmen (Migrated from github.com) commented 2026-05-23 08:18:27 +02:00

Use i18n

                    _(
Use i18n ```suggestion _( ```
@ -665,9 +672,39 @@ class KickBanMixin(MixinMeta):
return
Jackenmen (Migrated from github.com) commented 2026-05-23 08:18:13 +02:00

This can be vastly simplified by using the ConfirmView:

            content = (
                _(
                    "User is already tempbanned (ban expires {relative_time}), do you want to proceed?"
                ).format(relative_time=f"<t:{banned_until}:R>")
                if banned_until
                else _("This will downgrade the ban to a tempban, do you want to proceed?")
            )
            view = ConfirmView(ctx.author)
            view.message = await ctx.send(content)
            await view.wait()
            return view.result

Also, you weren't using i18n for the strings (i.e. they weren't wrapped in _()), the above suggestion fixes that as well.
Bu the way, considering this inner function is only used once, it may make more sense to just put this code directly where the function is used.

This can be vastly simplified by using the `ConfirmView`: ```suggestion content = ( _( "User is already tempbanned (ban expires {relative_time}), do you want to proceed?" ).format(relative_time=f"<t:{banned_until}:R>") if banned_until else _("This will downgrade the ban to a tempban, do you want to proceed?") ) view = ConfirmView(ctx.author) view.message = await ctx.send(content) await view.wait() return view.result ``` Also, you weren't using i18n for the strings (i.e. they weren't wrapped in `_()`), the above suggestion fixes that as well. Bu the way, considering this inner function is only used once, it may make more sense to just put this code directly where the function is used.
Jackenmen (Migrated from github.com) commented 2026-05-28 14:20:23 +02:00

No need to use the context manager when we're only reading the value:

            current_tempbans = await self.config.guild(guild).current_tempbans()
            banned_until = False
            if member.id in current_tempbans:
                banned_until = await self.config.member_from_ids(
                    guild.id, member.id
                ).banned_until()
No need to use the context manager when we're only reading the value: ```suggestion current_tempbans = await self.config.guild(guild).current_tempbans() banned_until = False if member.id in current_tempbans: banned_until = await self.config.member_from_ids( guild.id, member.id ).banned_until() ```
Jackenmen (Migrated from github.com) commented 2026-05-28 14:23:12 +02:00

The not in operator is more readable when testing whether something is not in a collection:

            if member.id not in current_tempbans:
The `not in` operator is more readable when testing whether something is not in a collection: ```suggestion if member.id not in current_tempbans: ```
Jackenmen (Migrated from github.com) reviewed 2026-05-28 17:35:04 +02:00
Jackenmen (Migrated from github.com) left a comment
No description provided.
Looks good, thanks!
Jackenmen (Migrated from github.com) reviewed 2026-05-28 17:38:23 +02:00
Jackenmen (Migrated from github.com) commented 2026-05-28 17:38:23 +02:00
                    await ctx.send(_("Okay, I will not be doing that then."))
                    return
```suggestion await ctx.send(_("Okay, I will not be doing that then.")) return ```
Jackenmen (Migrated from github.com) approved these changes 2026-05-28 17:43:19 +02:00
Sign in to join this conversation.
No reviewers
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 milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Mrcoolgamer11/Red-DiscordBot!5978
No description provided.