Removed old wallet cog and replaced "client" with "bot" in the new one
This commit is contained in:
+5
-5
@@ -13,7 +13,7 @@ logger: Logger = logging.getLogger(__name__)
|
||||
|
||||
class CogWallet(commands.Cog):
|
||||
def __init__(self, client: PycordBot):
|
||||
self.client: PycordBot = client
|
||||
self.bot: PycordBot = client
|
||||
|
||||
command_group: SlashCommandGroup = SlashCommandGroup("wallet", "Wallet management")
|
||||
|
||||
@@ -28,11 +28,11 @@ class CogWallet(commands.Cog):
|
||||
)
|
||||
|
||||
await ctx.respond(
|
||||
self.client._("balance_own", "messages", "wallet", locale=ctx.locale).format(
|
||||
self.bot._("balance_own", "messages", "wallet", locale=ctx.locale).format(
|
||||
balance=wallet.balance
|
||||
)
|
||||
if user is None
|
||||
else self.client._("balance_user", "messages", "wallet", locale=ctx.locale).format(
|
||||
else self.bot._("balance_user", "messages", "wallet", locale=ctx.locale).format(
|
||||
balance=wallet.balance, user=user.display_name
|
||||
)
|
||||
)
|
||||
@@ -56,14 +56,14 @@ class CogWallet(commands.Cog):
|
||||
await wallet.transfer(user.id, ctx.guild_id, amount)
|
||||
except WalletInsufficientFunds:
|
||||
await ctx.respond(
|
||||
self.client._(
|
||||
self.bot._(
|
||||
"transfer_insufficient_funds", "messages", "wallet", locale=ctx.locale
|
||||
).format(amount=round(abs(wallet.balance - amount), 2))
|
||||
)
|
||||
return
|
||||
|
||||
await ctx.respond(
|
||||
self.client._("transfer_success", "messages", "wallet", locale=ctx.locale).format(
|
||||
self.bot._("transfer_success", "messages", "wallet", locale=ctx.locale).format(
|
||||
amount=amount, recipient=user.display_name
|
||||
)
|
||||
)
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
import logging
|
||||
from logging import Logger
|
||||
|
||||
from discord import ApplicationContext, SlashCommandGroup, User, option
|
||||
from discord.ext import commands
|
||||
|
||||
from classes.errors import WalletInsufficientFunds
|
||||
from classes.pycord_bot import PycordBot
|
||||
from classes.wallet import Wallet
|
||||
|
||||
logger: Logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class WalletCog(commands.Cog):
|
||||
def __init__(self, client: PycordBot):
|
||||
self.client: PycordBot = client
|
||||
|
||||
command_group: SlashCommandGroup = SlashCommandGroup("wallet", "Wallet management")
|
||||
|
||||
@command_group.command(
|
||||
name="balance",
|
||||
description="View wallet's balance",
|
||||
)
|
||||
@option("user", description="User whose balance to check (if not your own)", required=False)
|
||||
async def command_wallet_balance(self, ctx: ApplicationContext, user: User = None) -> None:
|
||||
wallet: Wallet = await Wallet.from_id(
|
||||
ctx.user.id if not user else user.id, ctx.guild_id
|
||||
)
|
||||
|
||||
await ctx.respond(
|
||||
self.client._("balance_own", "messages", "wallet", locale=ctx.locale).format(
|
||||
balance=wallet.balance
|
||||
)
|
||||
if user is None
|
||||
else self.client._("balance_user", "messages", "wallet", locale=ctx.locale).format(
|
||||
balance=wallet.balance, user=user.display_name
|
||||
)
|
||||
)
|
||||
|
||||
@command_group.command(
|
||||
name="transfer",
|
||||
description="View wallet's balance",
|
||||
)
|
||||
@option("user", description="Recipient")
|
||||
@option("amount", description="Amount", min_value=0.01)
|
||||
async def command_wallet_transfer(
|
||||
self, ctx: ApplicationContext, user: User, amount: float
|
||||
) -> None:
|
||||
amount = round(amount, 2)
|
||||
|
||||
# Guild will be needed for overdraft options
|
||||
# guild: PycordGuild = await PycordGuild.from_id(ctx.guild_id)
|
||||
wallet: Wallet = await Wallet.from_id(ctx.user.id, ctx.guild_id)
|
||||
|
||||
try:
|
||||
await wallet.transfer(user.id, ctx.guild_id, amount)
|
||||
except WalletInsufficientFunds:
|
||||
await ctx.respond(
|
||||
self.client._(
|
||||
"transfer_insufficient_funds", "messages", "wallet", locale=ctx.locale
|
||||
).format(amount=round(abs(wallet.balance - amount), 2))
|
||||
)
|
||||
return
|
||||
|
||||
await ctx.respond(
|
||||
self.client._("transfer_success", "messages", "wallet", locale=ctx.locale).format(
|
||||
amount=amount, recipient=user.display_name
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def setup(client: PycordBot) -> None:
|
||||
client.add_cog(WalletCog(client))
|
||||
Reference in New Issue
Block a user