[Bank] Dispatch events for account events #5325

Closed
yamikaitou wants to merge 10 commits from bank-events into V3/develop
yamikaitou commented 2021-09-18 18:10:51 +02:00 (Migrated from github.com)

Adds some event dispatches to Bank

red_bank_set_global
red_bank_set_balance
red_bank_transfer_credits
red_bank_wipe
red_bank_prune_accounts

Resolves #5141

Adds some event dispatches to Bank red_bank_set_global red_bank_set_balance red_bank_transfer_credits red_bank_wipe red_bank_prune_accounts Resolves #5141
vertyco (Migrated from github.com) reviewed 2024-03-25 13:55:36 +01:00
@ -1085,3 +1120,24 @@ def cost(amount: int):
return coro_or_command
vertyco (Migrated from github.com) commented 2024-03-25 13:55:36 +01:00

The type annotation for pruned_users should be Union[List[int], Dict[str, List[int]]] instead of Union(List[int], Dict[str, List[int]])

The type annotation for `pruned_users` should be `Union[List[int], Dict[str, List[int]]]` instead of `Union(List[int], Dict[str, List[int]])`
Zephyrkul commented 2024-03-26 15:56:38 +01:00 (Migrated from github.com)

Would it be possible it to make these payload classes into NamedTuples instead? That should be a free performance improvement since these classes don't need to be modified after they're created.

Would it be possible it to make these payload classes into [NamedTuple](https://docs.python.org/3/library/typing.html#typing.NamedTuple)s instead? That should be a free performance improvement since these classes don't need to be modified after they're created.
Flame442 (Migrated from github.com) requested changes 2024-03-28 01:41:03 +01:00
Flame442 (Migrated from github.com) left a comment

Initial design feedback.

Initial design feedback.
@ -7,0 +13,4 @@
.. py:method:: red_bank_set_balance(payload: redbot.core.bank.BankSetBalanceInformation)
Dispatched when a user has their balance changed.
Flame442 (Migrated from github.com) commented 2024-03-28 00:53:15 +01:00

The documented events that dispatch custom objects should link to those objects in some way. It might make sense to use a similar format as the autogenerated API descriptions for methods, which have a "parameters" section describing each of the parameters in detail.

The documented events that dispatch custom objects should link to those objects in some way. It might make sense to use a similar format as the autogenerated API descriptions for methods, which have a "parameters" section describing each of the parameters in detail.
@ -7,0 +21,4 @@
.. py:method:: red_bank_wipe(guild_id: int)
Dispatched when the Bank gets wiped. :code:`guild_id` will be the ID of the Guild that was wiped, 0 if all Guilds were wiped (Bank is Local), or -1 if all Users were wiped (Bank is Global)
Flame442 (Migrated from github.com) commented 2024-03-28 01:26:41 +01:00

Having both 0 and -1 as special values seems a bit smelly. Is there a meaningful difference for the CC to account for that makes differentiating between wiping guilds or users something that needs to happen? If so, I think it would be neater to just have a second argument, whether or not the bank was global at the time of wiping.

I would say the CC can just check if the bank is global or not to get the same value, but that only applies for [p]bankset reset. [p]bankset toggleglobal also implicitly results in this being called, since it clears the bank during the process of swapping scope. Trying to test for it at that time would likely result in an incorrect value due to race conditions.

Having both 0 and -1 as special values seems a bit smelly. Is there a meaningful difference for the CC to account for that makes differentiating between wiping guilds or users something that needs to happen? If so, I think it would be neater to just have a second argument, whether or not the bank was global at the time of wiping. I would say the CC can just check if the bank is global or not to get the same value, but that only applies for `[p]bankset reset`. `[p]bankset toggleglobal` also implicitly results in this being called, since it clears the bank during the process of swapping scope. Trying to test for it at that time would likely result in an incorrect value due to race conditions.
Flame442 (Migrated from github.com) commented 2024-03-28 01:12:28 +01:00

It's more typical for guild like attributes to be Optional and use None as the value to represent non-guild actions (IE, message.guild). If it is consistently possible to provide the full user/guild object rather than an ID, I also think that would be preferred.

It's more typical for `guild` like attributes to be `Optional` and use `None` as the value to represent non-guild actions (IE, `message.guild`). If it is consistently possible to provide the full user/guild object rather than an ID, I also think that would be preferred.
Flame442 (Migrated from github.com) commented 2024-03-28 01:10:04 +01:00

Leftover print?

Leftover print?
Flame442 (Migrated from github.com) commented 2024-03-28 01:40:37 +01:00

tmp is only defined when user_id is None. This errors if a particular user is pruned.
(I do think the conditionally defined variables in this function are smelly, making this sort of error very easy to make)

`tmp` is only defined when `user_id is None`. This errors if a particular user is pruned. (I do think the conditionally defined variables in this function are smelly, making this sort of error very easy to make)
Flame442 (Migrated from github.com) commented 2024-03-28 00:54:49 +01:00

These objects should be added to __all__, since they are part of the public API. They also need to be documented, which may or may not happen automatically after doing so.

These objects should be added to `__all__`, since they are part of the public API. They also need to be documented, which may or may not happen automatically after doing so.
Flame442 (Migrated from github.com) reviewed 2024-03-28 01:45:09 +01:00
Flame442 (Migrated from github.com) commented 2024-03-28 01:45:08 +01:00

Forgot to hit submit on the comment I was writing here....

Doing it like this loses the ability to know what guild was being pruned. Unless there is some reason to differentiate between specifically pruning a member and a single member happening to be the only invalid member from a bulk prune, the signature of this event object would likely be better as:
guild: Optional[discord.Guild], pruned_user_ids: List[int]

Forgot to hit submit on the comment I was writing here.... Doing it like this loses the ability to know what guild was being pruned. Unless there is some reason to differentiate between specifically pruning a member and a single member happening to be the only invalid member from a bulk prune, the signature of this event object would likely be better as: `guild: Optional[discord.Guild], pruned_user_ids: List[int]`
Jackenmen commented 2026-05-22 07:21:04 +02:00 (Migrated from github.com)

It would seem that this got superseded by #6339 - we'll definitely make sure that you are listed as one of the authors before the merge.

It would seem that this got superseded by #6339 - we'll definitely make sure that you are listed as one of the authors before the merge.
Mrcoolgamer11 referenced this pull request from a commit 2026-11-21 15:44:25 +01:00

Pull request closed

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!5325
No description provided.