Procházet zdrojové kódy

alpha version of the new ux system kinda in play with custom commands. Could so with some more though. Like the positive responses.

tags/v2.0.0
Roxie Gibson před 5 roky
rodič
revize
3c3d1a0e58
2 změnil soubory, kde provedl 17 přidání a 18 odebrání
  1. +13
    -13
      roxbot/cogs/customcommands.py
  2. +4
    -5
      roxbot/err_handle.py

+ 13
- 13
roxbot/cogs/customcommands.py Zobrazit soubor

@@ -156,13 +156,13 @@ class CustomCommands:
elif command_type in ("2", "embed"):
command_type = "2"
if len(output) < 2:
return await ctx.send(self.ERROR_EMBED_VALUE)
raise roxbot.UserError(self.ERROR_EMBED_VALUE)
try:
output = self._embed_parse_options(output)
except ValueError:
return await ctx.send(self.ERROR_OUTPUT_TOO_LONG)
raise roxbot.UserError(self.ERROR_OUTPUT_TOO_LONG)
else:
return await ctx.send(self.ERROR_INCORRECT_TYPE)
raise roxbot.UserError(self.ERROR_INCORRECT_TYPE)

settings = roxbot.guild_settings.get(ctx.guild)
no_prefix_commands = settings["custom_commands"]["0"]
@@ -171,15 +171,15 @@ class CustomCommands:
command = command.lower()

if ctx.message.mentions or ctx.message.mention_everyone or ctx.message.role_mentions:
return await ctx.send(self.ERROR_AT_MENTION)
raise roxbot.UserError(self.ERROR_AT_MENTION)
elif len(output) > 1800:
return await ctx.send(self.ERROR_OUTPUT_TOO_LONG)
raise roxbot.UserError(self.ERROR_OUTPUT_TOO_LONG)
elif command in self.bot.all_commands.keys() and command_type == "1":
return await ctx.send(self.ERROR_COMMAND_EXISTS_INTERNAL)
raise roxbot.UserError(self.ERROR_COMMAND_EXISTS_INTERNAL)
elif command in no_prefix_commands or command in prefix_commands or command in embed_commands:
return await ctx.send(self.ERROR_COMMAND_EXISTS)
raise roxbot.UserError(self.ERROR_COMMAND_EXISTS)
elif len(command.split(" ")) > 1 and command_type == "1":
return await ctx.send()
raise roxbot.UserError(self.ERROR_PREFIX_SPACE)

settings["custom_commands"][command_type][command] = output
settings.update(settings["custom_commands"], "custom_commands")
@@ -195,7 +195,7 @@ class CustomCommands:
embed_commands = settings["custom_commands"]["2"]

if ctx.message.mentions or ctx.message.mention_everyone or ctx.message.role_mentions:
return await ctx.send(self.ERROR_AT_MENTION)
raise roxbot.UserError(self.ERROR_AT_MENTION)

if command in no_prefix_commands:
if len(edit) == 1:
@@ -213,17 +213,17 @@ class CustomCommands:

elif command in embed_commands:
if len(edit) < 2:
return await ctx.send(self.ERROR_EMBED_VALUE)
raise roxbot.UserError(self.ERROR_EMBED_VALUE)
try:
edit = self._embed_parse_options(edit)
except ValueError:
return await ctx.send(self.ERROR_OUTPUT_TOO_LONG)
raise roxbot.UserError(self.ERROR_OUTPUT_TOO_LONG)
settings["custom_commands"]["2"][command] = edit
settings.update(settings["custom_commands"], "custom_commands")
return await ctx.send(self.OUTPUT_EDIT.format(command, edit))

else:
return await ctx.send(self.ERROR_COMMAND_NULL)
raise roxbot.UserError(self.ERROR_COMMAND_NULL)

@commands.has_permissions(manage_messages=True)
@custom.command()
@@ -243,7 +243,7 @@ class CustomCommands:
elif command in embed_commands:
command_type = "2"
else:
return await ctx.send(self.ERROR_COMMAND_NULL)
raise roxbot.UserError(self.ERROR_COMMAND_NULL)

settings["custom_commands"][command_type].pop(command)
settings.update(settings["custom_commands"], "custom_commands")

+ 4
- 5
roxbot/err_handle.py Zobrazit soubor

@@ -47,13 +47,12 @@ class ErrHandle:
traceback.print_exc()

async def on_command_error(self, ctx, error):
owner = self.bot.get_user(self.bot.owner_id)
if self.dev:
raise error
else:
# UserError warning section
user_errors = (commands.MissingRequiredArgument, commands.BadArgument, commands.TooManyArguments)
user_errors = (commands.MissingRequiredArgument, commands.BadArgument,
commands.TooManyArguments, roxbot.UserError)

if isinstance(error, user_errors):
embed = discord.Embed(colour=roxbot.EmbedColours.orange)
@@ -65,8 +64,6 @@ class ErrHandle:
embed.description = "Too many arguments given."
elif isinstance(error, roxbot.UserError):
embed.description = error.args[0]
elif isinstance(error, roxbot.CogSettingDisabled):
embed.description = "The following is not enabled on this server: {}".format(error.args[0])
return await ctx.send(embed=embed)

# ActualErrorHandling
@@ -75,6 +72,8 @@ class ErrHandle:
embed.description = "This command cannot be used in private messages."
elif isinstance(error, commands.DisabledCommand):
embed.description = "This command is disabled."
elif isinstance(error, roxbot.CogSettingDisabled):
embed.description = "The following is not enabled on this server: {}".format(error.args[0])
elif isinstance(error, commands.CommandNotFound):
try:
# Sadly this is the only part that makes a cog not modular. I have tried my best though to make it usable without the cog.

Načítá se…
Zrušit
Uložit