mirror of
https://github.com/wlinator/luminara.git
synced 2024-10-02 18:23:12 +00:00
Add error embeds
This commit is contained in:
parent
9a067594ce
commit
c37fd0e743
10 changed files with 99 additions and 17 deletions
54
lib/err_embeds.py
Normal file
54
lib/err_embeds.py
Normal file
|
@ -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
|
12
main.py
12
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")
|
||||
|
|
|
@ -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))
|
|
@ -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))
|
|
@ -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))
|
Loading…
Reference in a new issue