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

Fix a bunch of error outputs

This commit is contained in:
wlinator 2024-03-29 13:11:36 -04:00
parent 243bad0e53
commit 9c79db5ec3
11 changed files with 27 additions and 146 deletions

View file

@ -31,7 +31,7 @@ class GenericErrors:
@staticmethod
def bad_arg(ctx, error):
embed = clean_error_embed(ctx)
embed.description += str(error).lower()
embed.description += str(error)
embed.set_footer(text=f"For more info do {formatter.get_prefix(ctx)}help {formatter.get_invoked_name(ctx)}",
icon_url=question_icon)
@ -98,57 +98,6 @@ class GenericErrors:
class EconErrors:
@staticmethod
def missing_bet(ctx):
"""
See MissingRequiredArgument
"""
embed = clean_error_embed(ctx)
embed.description += "please enter a bet."
embed.set_footer(text=f"For more info do '{formatter.get_prefix(ctx)}help {formatter.get_invoked_name(ctx)}'",
icon_url=question_icon)
return embed
@staticmethod
def missing_argument(ctx):
"""
See MissingRequiredArgument
"""
embed = clean_error_embed(ctx)
embed.description += "your command is missing an argument."
embed.set_footer(text=f"For more info do '{formatter.get_prefix(ctx)}help {formatter.get_invoked_name(ctx)}'",
icon_url=question_icon)
return embed
@staticmethod
def bad_bet_argument(ctx):
"""
See BadArgument
"""
embed = clean_error_embed(ctx)
embed.description += "the bet you entered is invalid."
embed.set_footer(text=f"For more info do '{formatter.get_prefix(ctx)}help {formatter.get_invoked_name(ctx)}'",
icon_url=question_icon)
return embed
@staticmethod
def bad_argument(ctx):
"""
See BadArgument
"""
embed = clean_error_embed(ctx)
embed.description += "the argument you entered is invalid."
embed.set_footer(text=f"For more info do '{formatter.get_prefix(ctx)}help {formatter.get_invoked_name(ctx)}'",
icon_url=question_icon)
return embed
@staticmethod
def insufficient_balance(ctx):
embed = clean_error_embed(ctx)
embed.description += "you don't have enough cash."
embed.set_footer(text=f"Do '{formatter.get_prefix(ctx)}balance' to see how much you can spend",
icon_url=question_icon)
return embed
@staticmethod
def daily_already_claimed(ctx, unix_time):
@ -184,40 +133,6 @@ class BdayErrors:
return embed
@staticmethod
def invalid_date(ctx):
embed = clean_error_embed(ctx)
embed.description += "the date you entered is invalid."
return embed
@staticmethod
def slash_command_only(ctx):
embed = clean_error_embed(ctx)
embed.description += "you can use only slash commands for the birthday system."
embed.set_footer(text=f"For more info do '{formatter.get_prefix(ctx)}help {formatter.get_invoked_name(ctx)}'",
icon_url=question_icon)
return embed
@staticmethod
def bad_month(ctx):
embed = clean_error_embed(ctx)
embed.description += "I couldn't recognize that month."
embed.set_footer(text=f"For more info do '{formatter.get_prefix(ctx)}help {formatter.get_invoked_name(ctx)}'",
icon_url=question_icon)
return embed
@staticmethod
def missing_arg(ctx):
embed = clean_error_embed(ctx)
embed.description += "please enter a month and a day, in that order."
embed.set_footer(text=f"For more info do '{formatter.get_prefix(ctx)}help {formatter.get_invoked_name(ctx)}'",
icon_url=question_icon)
return embed
class MiscErrors:
@staticmethod
@ -229,15 +144,6 @@ class MiscErrors:
return embed
@staticmethod
def prefix_missing(ctx):
embed = clean_error_embed(ctx)
embed.description += "please specify a new prefix."
embed.set_footer(text=f"For more info do '{formatter.get_prefix(ctx)}help {formatter.get_invoked_name(ctx)}'",
icon_url=question_icon)
return embed
@staticmethod
def intro_no_guild(ctx):
embed = clean_error_embed(ctx)
@ -279,14 +185,3 @@ class IntroErrors:
icon_url=exclam_icon)
return embed
class ModErrors:
@staticmethod
def mod_error(ctx, error):
embed = clean_error_embed(ctx)
embed.description += error
embed.set_footer(text=f"For more info do '{formatter.get_prefix(ctx)}help {formatter.get_invoked_name(ctx)}'",
icon_url=question_icon)
return embed

View file

@ -35,7 +35,6 @@ logs = LoggingHandler.setup_logger()
@client.listen()
async def on_message(message):
if (
message.author.bot or
message.guild is None or
@ -116,13 +115,12 @@ async def on_error(event: str, *args, **kwargs) -> None:
def load_modules():
module_list = [d for d in os.listdir("modules") if os.path.isdir(os.path.join("modules", d))]
loaded_modules = set()
for module in module_list:
if module in loaded_modules:
continue # module is already loaded
continue # module is already loaded
try:
client.load_extension(f"modules.{module}")

View file

@ -14,7 +14,7 @@ async def cmd(ctx, month, month_index, day):
max_days = calendar.monthrange(leap_year, month_index)[1]
if not (1 <= day <= max_days):
return await ctx.respond(embed=BdayErrors.invalid_date(ctx))
raise commands.BadArgument("the date you entered is invalid.")
date_str = f"{leap_year}-{month_index:02d}-{day:02d}"
date_obj = datetime.datetime.strptime(date_str, '%Y-%m-%d')
@ -32,7 +32,7 @@ async def get_month_name(string, mapping):
if string.startswith(month):
return mapping[month]
raise commands.BadArgument
raise commands.BadArgument("I couldn't recognize that month.")
async def get_month_index(string, mapping):

View file

@ -8,7 +8,7 @@ from config.parser import JsonCache
from lib import formatter
from lib.embeds.error import MiscErrors
from lib.embeds.greet import Greet
from modules.config import config, prefix
from modules.config import config, set_prefix
from services.GuildConfig import GuildConfig
strings = JsonCache.read_json("strings")
@ -41,13 +41,13 @@ class Config(commands.Cog):
)
@commands.guild_only()
@commands.has_permissions(manage_channels=True)
async def setprefix_command(self, ctx, *, new_prefix: str):
async def setprefix_command(self, ctx, *, prefix: str):
"""
Set the prefix for Racu in this server. The maximum length of a prefix is 25.
Requires Manage Channels permissions.
"""
await prefix.set_cmd(ctx, new_prefix)
await set_prefix.set_cmd(ctx, prefix)
config = SlashCommandGroup("config", "server config commands.", guild_only=True,
default_member_permissions=discord.Permissions(manage_channels=True))

View file

@ -73,7 +73,7 @@ class Economy(commands.Cog):
try:
member = await ctx.guild.fetch_member(user.id)
except discord.HTTPException:
raise commands.BadArgument
raise commands.BadArgument("I couldn't find that user in this server.")
return await give.cmd(ctx, member, amount)

View file

@ -3,6 +3,7 @@ import logging
from datetime import datetime
import discord
from discord.ext import commands
import pytz
from dotenv import load_dotenv
@ -43,9 +44,9 @@ async def cmd(ctx, bet: int):
# check if the user has enough cash
player_balance = ctx_currency.balance
if bet > player_balance:
return await ctx.respond(embed=EconErrors.insufficient_balance(ctx))
raise commands.BadArgument("you don't have enough cash.")
elif bet <= 0:
return await ctx.respond(embed=EconErrors.bad_bet_argument(ctx))
raise commands.BadArgument("the bet you entered is invalid.")
active_blackjack_games[ctx.author.id] = True

View file

@ -1,48 +1,34 @@
import discord
from discord.ext import commands
from lib.embeds.error import EconErrors
from services.Currency import Currency
async def cmd(ctx, user, amount):
if ctx.author.id == user.id:
embed = discord.Embed(
color=discord.Color.red(),
description=f"You can't give money to yourself, silly."
)
return await ctx.respond(embed=embed)
raise commands.BadArgument("you can't give money to yourself.")
elif user.bot:
embed = discord.Embed(
color=discord.Color.red(),
description=f"You can't give money to a bot, silly."
)
return await ctx.respond(embed=embed)
raise commands.BadArgument("you can't give money to a bot.")
# Currency handler
ctx_currency = Currency(ctx.author.id)
target_currency = Currency(user.id)
try:
author_balance = ctx_currency.balance
author_balance = ctx_currency.balance
if author_balance < amount or author_balance <= 0:
return await ctx.respond(embed=EconErrors.insufficient_balance(ctx))
if author_balance < amount or author_balance <= 0:
raise commands.BadArgument("you don't have enough cash.")
target_currency.add_balance(amount)
ctx_currency.take_balance(amount)
target_currency.add_balance(amount)
ctx_currency.take_balance(amount)
ctx_currency.push()
target_currency.push()
except Exception as e:
await ctx.respond("Something funky happened.. Sorry about that.", ephemeral=True)
print(e)
return
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.set_footer(text="Say thanks! :)")
await ctx.respond(embed=embed)

View file

@ -4,6 +4,7 @@ import random
from collections import Counter
import discord
from discord.ext import commands
import pytz
from lib.embeds.error import EconErrors
@ -22,9 +23,9 @@ async def cmd(self, ctx, bet):
# check if the user has enough cash
player_balance = ctx_currency.balance
if bet > player_balance:
return await ctx.respond(embed=EconErrors.insufficient_balance(ctx))
raise commands.BadArgument("you don't have enough cash.")
elif bet <= 0:
return await ctx.respond(embed=EconErrors.bad_bet_argument(ctx))
raise commands.BadArgument("the bet you entered is invalid.")
# # check if the bet exceeds the bet limit
# bet_limit = int(resources["bet_limit"])

View file

@ -5,7 +5,7 @@ from discord.ext import commands, bridge, tasks
from lib import checks
from lib.embeds.info import MiscInfo
from modules.misc import introduction, invite, backup, info
from modules.config import prefix
from modules.config import set_prefix
class Misc(commands.Cog):
@ -57,7 +57,7 @@ class Misc(commands.Cog):
@commands.guild_only()
@checks.allowed_in_channel()
async def prefix_command(self, ctx):
return await prefix.get_cmd(ctx)
return await set_prefix.get_cmd(ctx)
@bridge.bridge_command(
name="info",

View file

@ -8,7 +8,7 @@ from lib.embeds.error import ModErrors
from lib import checks
from lib.embeds.info import MiscInfo
from modules.misc import introduction, invite, backup, info
from modules.config import prefix
from modules.config import set_prefix
class Moderation(commands.Cog):