diff --git a/lib/err_embeds.py b/lib/err_embeds.py new file mode 100644 index 0000000..38790e1 --- /dev/null +++ b/lib/err_embeds.py @@ -0,0 +1,54 @@ +import discord + +footer_icon = "https://i.imgur.com/8xccUws.png" + + +def get_prefix(ctx): + """ + Attempt to get the prefix, if the command was used as a SlashCommand, return "/" + """ + try: + prefix = ctx.clean_prefix + except (discord.ApplicationCommandInvokeError, AttributeError): + prefix = "/" + + return prefix + + +def MissingBet(ctx): + """ + See MissingRequiredArgument + """ + embed = discord.Embed( + color=discord.Color.red(), + description=f"**{ctx.author.name}** please enter a bet.", + ) + embed.set_footer(text=f"For more info do '{get_prefix(ctx)}help {ctx.command}'", + icon_url=footer_icon) + return embed + + +def BadBetArgument(ctx): + """ + See BadArgument + """ + embed = discord.Embed( + color=discord.Color.red(), + description=f"**{ctx.author.name}** the bet you entered is invalid.", + ) + embed.set_footer(text=f"For more info do '{get_prefix(ctx)}help {ctx.command}'", + icon_url=footer_icon) + return embed + + +def InsufficientBalance(ctx): + """ + Error message for when the entered value exceeds the user's balance. + """ + embed = discord.Embed( + color=discord.Color.red(), + description=f"**{ctx.author.name}** you don't have enough cash.", + ) + embed.set_footer(text=f"Do '{get_prefix(ctx)}balance' to see how much you can spend.", + icon_url=footer_icon) + return embed diff --git a/main.py b/main.py index c79394a..ef6345b 100644 --- a/main.py +++ b/main.py @@ -180,6 +180,15 @@ def load_cogs(): logs.error(f"[MODULE] Failed to load module {filename}: {e}") +def load_modules(): + modules_list = [ + "economy" + ] + + for module in modules_list: + client.load_extension(f"modules.{module}") + + if __name__ == '__main__': """ This code is only ran when main.py is the primary module, @@ -189,7 +198,8 @@ if __name__ == '__main__': logs.info("RACU IS BOOTING") logs.info("\n") - load_cogs() + #load_cogs() + load_modules() # empty line to separate modules from system info in logs logs.info("\n") diff --git a/modules/balance.py b/modules/economy/balance.py similarity index 71% rename from modules/balance.py rename to modules/economy/balance.py index da860b6..93e0336 100644 --- a/modules/balance.py +++ b/modules/economy/balance.py @@ -1,5 +1,5 @@ import discord -from discord.ext import commands +from discord.ext import commands, bridge from dotenv import load_dotenv from services.Currency import Currency @@ -8,13 +8,16 @@ from lib import checks load_dotenv('.env') -class BalanceCog(commands.Cog): +class Balance(commands.Cog): def __init__(self, client): self.client = client - @commands.slash_command( + @bridge.bridge_command( name="balance", + aliases=["bal", "$"], description="See how much cash you have.", + help="Shows your current Racu balance. The economy system is global, meaning your balance will be the same in " + "all servers.", guild_only=True ) @commands.check(checks.channel) @@ -32,5 +35,6 @@ class BalanceCog(commands.Cog): await ctx.respond(embed=embed) + def setup(client): - client.add_cog(BalanceCog(client)) + client.add_cog(Balance(client)) diff --git a/modules/blackjack.py b/modules/economy/blackjack.py similarity index 92% rename from modules/blackjack.py rename to modules/economy/blackjack.py index fcd7546..ea7bd71 100644 --- a/modules/blackjack.py +++ b/modules/economy/blackjack.py @@ -4,14 +4,14 @@ from datetime import datetime import logging import discord import pytz -from discord.ext import commands +from discord.ext import commands, bridge from dotenv import load_dotenv from services.BlackJackStats import BlackJackStats from services.Currency import Currency from handlers.ItemHandler import ItemHandler from main import economy_config, strings -from lib import economy_embeds, economy_functions, checks, interaction, embeds +from lib import economy_embeds, economy_functions, checks, interaction, embeds, err_embeds logs = logging.getLogger('Racu.Core') load_dotenv('.env') @@ -114,13 +114,15 @@ class BlackJackCog(commands.Cog): def __init__(self, client): self.client = client - @commands.slash_command( + @bridge.bridge_command( name="blackjack", + aliases=["bj"], description="Start a game of blackjack.", + help="Start a game of blackjack.", guild_only=True ) @commands.check(checks.channel) - async def blackjack(self, ctx, *, bet: discord.Option(int)): + async def blackjack(self, ctx, *, bet: int): """ status states: @@ -143,9 +145,10 @@ class BlackJackCog(commands.Cog): # check if the user has enough cash player_balance = ctx_currency.balance - if bet > player_balance or bet <= 0: - await ctx.respond(embed=economy_embeds.not_enough_cash()) - return + if bet > player_balance: + return await ctx.respond(embed=err_embeds.InsufficientBalance(ctx)) + elif bet <= 0: + return await ctx.respond(embed=err_embeds.BadBetArgument(ctx)) # check if the bet exceeds the bet limit # bet_limit = int(economy_config["bet_limit"]) @@ -290,6 +293,15 @@ class BlackJackCog(commands.Cog): # remove player from active games list del active_blackjack_games[ctx.author.id] + @blackjack.error + async def on_command_error(self, ctx, error): + if isinstance(error, commands.MissingRequiredArgument): + await ctx.respond(embed=err_embeds.MissingBet(ctx)) + elif isinstance(error, commands.BadArgument): + await ctx.respond(embed=err_embeds.BadBetArgument(ctx)) + else: + raise error + def setup(client): client.add_cog(BlackJackCog(client)) diff --git a/modules/give.py b/modules/economy/give.py similarity index 100% rename from modules/give.py rename to modules/economy/give.py diff --git a/modules/inventory.py b/modules/economy/inventory.py similarity index 100% rename from modules/inventory.py rename to modules/economy/inventory.py diff --git a/modules/leaderboard.py b/modules/economy/leaderboard.py similarity index 95% rename from modules/leaderboard.py rename to modules/economy/leaderboard.py index 31fce19..c03061f 100644 --- a/modules/leaderboard.py +++ b/modules/economy/leaderboard.py @@ -1,7 +1,7 @@ import logging import discord -from discord.ext import commands +from discord.ext import commands, bridge from services.Currency import Currency from services.Xp import Xp @@ -12,7 +12,7 @@ from datetime import datetime, timedelta logs = logging.getLogger('Racu.Core') -class LeaderboardV2Cog(commands.Cog): +class Economy(commands.Cog): """ A rewrite of the leaderboard command. This aims to show more information & a new "dailies" leaderboard. @@ -21,13 +21,15 @@ class LeaderboardV2Cog(commands.Cog): def __init__(self, client): self.client = client - @commands.slash_command( + @bridge.bridge_command( name="leaderboard", + aliases=["lb", "xplb"], description="Are ya winning' son?", + help="Shows the guild's level leaderboard by default. You can switch to currency and /daily leaderboard.", guild_only=True ) @commands.check(checks.channel) - # @commands.cooldown(1, 180, commands.BucketType.user) + @commands.cooldown(1, 180, commands.BucketType.user) async def leaderboard_v2(self, ctx): """ Leaderboard command with a dropdown menu. @@ -209,4 +211,4 @@ class LeaderboardCommandView(discord.ui.View): def setup(client): - client.add_cog(LeaderboardV2Cog(client)) + client.add_cog(Economy(client)) diff --git a/modules/sell.py b/modules/economy/sell.py similarity index 100% rename from modules/sell.py rename to modules/economy/sell.py diff --git a/modules/slots.py b/modules/economy/slots.py similarity index 100% rename from modules/slots.py rename to modules/economy/slots.py diff --git a/modules/stats.py b/modules/economy/stats.py similarity index 100% rename from modules/stats.py rename to modules/economy/stats.py