mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-21 10:17:59 -05:00
[Bank] Check recipient balance before completing transfer (#2925)
* Fixed `[p]local start` Playlist picker auto selects if theres just 1 playlist found `[p]queue cleanself` added Signed-off-by: Guy <guyreis96@gmail.com> * Black.... you are supposed to trigger before commits Signed-off-by: Guy <guyreis96@gmail.com> * Added `BalanceTooHigh` to the docstrings of `bank.transfer_credits()` Signed-off-by: guyre <27962761+drapersniper@users.noreply.github.com> * Bring this in line with #2926 to reduce conflicts,`is_global()` already is called inside `get_currency_name` and as such it does not need to be called outside Signed-off-by: guyre <27962761+drapersniper@users.noreply.github.com>
This commit is contained in:
@@ -186,11 +186,7 @@ async def set_balance(member: discord.Member, amount: int) -> int:
|
||||
if amount < 0:
|
||||
raise ValueError("Not allowed to have negative balance.")
|
||||
if amount > MAX_BALANCE:
|
||||
currency = (
|
||||
await get_currency_name()
|
||||
if await is_global()
|
||||
else await get_currency_name(member.guild)
|
||||
)
|
||||
currency = await get_currency_name(member.guild)
|
||||
raise errors.BalanceTooHigh(
|
||||
user=member.display_name, max_balance=MAX_BALANCE, currency_name=currency
|
||||
)
|
||||
@@ -305,6 +301,9 @@ async def transfer_credits(from_: discord.Member, to: discord.Member, amount: in
|
||||
If the amount is invalid or if ``from_`` has insufficient funds.
|
||||
TypeError
|
||||
If the amount is not an `int`.
|
||||
BalanceTooHigh
|
||||
If the balance after the transfer would be greater than
|
||||
``bank.MAX_BALANCE``
|
||||
|
||||
"""
|
||||
if not isinstance(amount, int):
|
||||
@@ -312,6 +311,12 @@ async def transfer_credits(from_: discord.Member, to: discord.Member, amount: in
|
||||
if _invalid_amount(amount):
|
||||
raise ValueError("Invalid transfer amount {} <= 0".format(amount))
|
||||
|
||||
if await get_balance(to) + amount > MAX_BALANCE:
|
||||
currency = await get_currency_name(to.guild)
|
||||
raise errors.BalanceTooHigh(
|
||||
user=to.display_name, max_balance=MAX_BALANCE, currency_name=currency
|
||||
)
|
||||
|
||||
await withdraw_credits(from_, amount)
|
||||
return await deposit_credits(to, amount)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user