1
Fork 0
mirror of https://github.com/wlinator/luminara.git synced 2024-10-02 18:23:12 +00:00

refactor give emote

This commit is contained in:
wlinator 2024-08-22 23:10:21 +02:00
parent af7f3901fc
commit 818fdc7412
2 changed files with 24 additions and 15 deletions

View file

@ -284,5 +284,10 @@
"xp_server_rank": "Server Rank: #{0}",
"balance_cash": "**Cash**: ${0}",
"balance_author": "{0}'s wallet",
"balance_footer": "Check out /daily"
"balance_footer": "check out /daily",
"give_error_self": "you can't give money to yourself.",
"give_error_bot": "you can't give money to a bot.",
"give_error_invalid_amount": "invalid amount.",
"give_error_insufficient_funds": "you don't have enough cash.",
"give_success": "**{0}** gave **${1}** to {2}."
}

View file

@ -2,24 +2,24 @@ import discord
from discord.ext import commands
from services.currency_service import Currency
from lib.constants import CONST
from lib.embed_builder import EmbedBuilder
from lib.exceptions.LumiExceptions import LumiException
async def cmd(ctx, user, amount):
async def cmd(ctx: commands.Context, user: discord.User, amount: int) -> None:
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.")
raise LumiException(CONST.STRINGS["give_error_self"])
if user.bot:
raise LumiException(CONST.STRINGS["give_error_bot"])
if amount <= 0:
raise LumiException(CONST.STRINGS["give_error_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.")
if ctx_currency.balance < amount:
raise LumiException(CONST.STRINGS["give_error_insufficient_funds"])
target_currency.add_balance(amount)
ctx_currency.take_balance(amount)
@ -27,9 +27,13 @@ async def cmd(ctx, user, 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}.",
embed = EmbedBuilder.create_success_embed(
ctx,
description=CONST.STRINGS["give_success"].format(
ctx.author.name,
Currency.format(amount),
user.name,
),
)
await ctx.respond(embed=embed)