1
Fork 0
mirror of https://github.com/wlinator/luminara.git synced 2024-10-03 00:23:13 +00:00
Lumi/modules/economy/give.py
wlinator 58b728d7b7 Fix major economy bug in .give
This fixes a bug where people could give unlimited money to someone by prefixing a huge amount with '-'.
2024-05-09 19:40:03 -04:00

35 lines
1,000 B
Python

import discord
from discord.ext import commands
from services.Currency import Currency
async def cmd(ctx, user, amount):
if ctx.author.id == user.id:
raise commands.BadArgument("you can't give money to yourself.")
elif user.bot:
raise commands.BadArgument("you can't give money to a bot.")
elif amount <= 0:
raise commands.BadArgument("invalid amount.")
# Currency handler
ctx_currency = Currency(ctx.author.id)
target_currency = Currency(user.id)
author_balance = ctx_currency.balance
if author_balance < amount or author_balance <= 0:
raise commands.BadArgument("you don't have enough cash.")
target_currency.add_balance(amount)
ctx_currency.take_balance(amount)
ctx_currency.push()
target_currency.push()
embed = discord.Embed(
color=discord.Color.green(),
description=f"**{ctx.author.name}** gave **${Currency.format(amount)}** to {user.name}."
)
await ctx.respond(embed=embed)