mirror of
https://github.com/wlinator/luminara.git
synced 2024-10-02 20:23:12 +00:00
feat: Add give command
This commit is contained in:
parent
1ad14ddc3f
commit
8bea18a142
4 changed files with 71 additions and 1 deletions
|
@ -187,7 +187,7 @@
|
|||
"give_error_insufficient_funds": "you don't have enough cash.",
|
||||
"give_error_invalid_amount": "invalid amount.",
|
||||
"give_error_self": "you can't give money to yourself.",
|
||||
"give_success": "**{0}** gave **${1}** to {2}.",
|
||||
"give_success": "you gave **${1}** to {2}.",
|
||||
"greet_default_description": "_ _\n**Welcome** to **{0}**",
|
||||
"greet_template_description": "\u2193\u2193\u2193\n{0}",
|
||||
"help_use_prefix": "Please use Lumi's prefix to get help. Type `{0}help`",
|
||||
|
|
|
@ -13,6 +13,7 @@ class Balance(commands.Cog):
|
|||
name="balance",
|
||||
aliases=["bal", "$"],
|
||||
)
|
||||
@commands.guild_only()
|
||||
async def daily(
|
||||
self,
|
||||
ctx: commands.Context[commands.Bot],
|
||||
|
|
|
@ -30,6 +30,7 @@ class Daily(commands.Cog):
|
|||
name="daily",
|
||||
aliases=["timely"],
|
||||
)
|
||||
@commands.guild_only()
|
||||
async def daily(
|
||||
self,
|
||||
ctx: commands.Context[commands.Bot],
|
||||
|
|
68
modules/economy/give.py
Normal file
68
modules/economy/give.py
Normal file
|
@ -0,0 +1,68 @@
|
|||
import discord
|
||||
from discord.ext import commands
|
||||
|
||||
from lib.const import CONST
|
||||
from lib.exceptions import LumiException
|
||||
from services.currency_service import Currency
|
||||
from ui.embeds import Builder
|
||||
|
||||
|
||||
class Give(commands.Cog):
|
||||
def __init__(self, bot: commands.Bot) -> None:
|
||||
self.bot: commands.Bot = bot
|
||||
|
||||
@commands.hybrid_command(
|
||||
name="give",
|
||||
)
|
||||
@commands.guild_only()
|
||||
async def give(
|
||||
self,
|
||||
ctx: commands.Context[commands.Bot],
|
||||
user: discord.User,
|
||||
amount: int,
|
||||
) -> None:
|
||||
"""
|
||||
Give currency to another user.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
ctx : commands.Context[commands.Bot]
|
||||
The context of the command.
|
||||
user : discord.User
|
||||
The user to give currency to.
|
||||
amount : int
|
||||
The amount of currency to give.
|
||||
"""
|
||||
if ctx.author.id == user.id:
|
||||
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"])
|
||||
|
||||
ctx_currency = Currency(ctx.author.id)
|
||||
target_currency = Currency(user.id)
|
||||
|
||||
if ctx_currency.balance < amount:
|
||||
raise LumiException(CONST.STRINGS["give_error_insufficient_funds"])
|
||||
|
||||
target_currency.add_balance(amount)
|
||||
ctx_currency.take_balance(amount)
|
||||
|
||||
ctx_currency.push()
|
||||
target_currency.push()
|
||||
|
||||
embed = Builder.create_embed(
|
||||
theme="success",
|
||||
user_name=ctx.author.name,
|
||||
description=CONST.STRINGS["give_success"].format(
|
||||
Currency.format(amount),
|
||||
user.name,
|
||||
),
|
||||
)
|
||||
|
||||
await ctx.send(embed=embed)
|
||||
|
||||
|
||||
async def setup(bot: commands.Bot) -> None:
|
||||
await bot.add_cog(Give(bot))
|
Loading…
Reference in a new issue