Browse Source

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 5 years ago
parent
commit
3c3d1a0e58
2 changed files with 17 additions and 18 deletions
  1. +13
    -13
      roxbot/cogs/customcommands.py
  2. +4
    -5
      roxbot/err_handle.py

+ 13
- 13
roxbot/cogs/customcommands.py View File

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


settings = roxbot.guild_settings.get(ctx.guild) settings = roxbot.guild_settings.get(ctx.guild)
no_prefix_commands = settings["custom_commands"]["0"] no_prefix_commands = settings["custom_commands"]["0"]
command = command.lower() command = command.lower()


if ctx.message.mentions or ctx.message.mention_everyone or ctx.message.role_mentions: 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: 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": 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: 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": 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["custom_commands"][command_type][command] = output
settings.update(settings["custom_commands"], "custom_commands") settings.update(settings["custom_commands"], "custom_commands")
embed_commands = settings["custom_commands"]["2"] embed_commands = settings["custom_commands"]["2"]


if ctx.message.mentions or ctx.message.mention_everyone or ctx.message.role_mentions: 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 command in no_prefix_commands:
if len(edit) == 1: if len(edit) == 1:


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


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


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


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

+ 4
- 5
roxbot/err_handle.py View File

traceback.print_exc() traceback.print_exc()


async def on_command_error(self, ctx, error): async def on_command_error(self, ctx, error):
owner = self.bot.get_user(self.bot.owner_id)
if self.dev: if self.dev:
raise error raise error
else: else:
# UserError warning section # 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): if isinstance(error, user_errors):
embed = discord.Embed(colour=roxbot.EmbedColours.orange) embed = discord.Embed(colour=roxbot.EmbedColours.orange)
embed.description = "Too many arguments given." embed.description = "Too many arguments given."
elif isinstance(error, roxbot.UserError): elif isinstance(error, roxbot.UserError):
embed.description = error.args[0] 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) return await ctx.send(embed=embed)


# ActualErrorHandling # ActualErrorHandling
embed.description = "This command cannot be used in private messages." embed.description = "This command cannot be used in private messages."
elif isinstance(error, commands.DisabledCommand): elif isinstance(error, commands.DisabledCommand):
embed.description = "This command is disabled." 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): elif isinstance(error, commands.CommandNotFound):
try: 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. # 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.

Loading…
Cancel
Save