|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CustomCommands: |
|
|
class CustomCommands: |
|
|
|
|
|
ERROR_AT_MENTION = "Custom Commands cannot mention people/roles/everyone." |
|
|
|
|
|
ERROR_COMMAND_NULL = "That Custom Command doesn't exist." |
|
|
|
|
|
ERROR_COMMAND_EXISTS = "Custom Command already exists." |
|
|
|
|
|
ERROR_COMMAND_EXISTS_INTERNAL = "This is already the name of a built in command." |
|
|
|
|
|
ERROR_EMBED_VALUE = "Not enough options given to generate embed." |
|
|
|
|
|
ERROR_INCORRECT_TYPE = "Incorrect type given." |
|
|
|
|
|
ERROR_OUTPUT_TOO_LONG = "Failed to set output. Given output was too long." |
|
|
|
|
|
ERROR_PREFIX_SPACE = "Custom commands with a prefix can only be one word with no spaces." |
|
|
|
|
|
|
|
|
|
|
|
OUTPUT_ADD = "{} has been added with the output: '{}'" |
|
|
|
|
|
OUTPUT_EDIT = "Edit made. {} now outputs {}" |
|
|
|
|
|
OUTPUT_REMOVE = "Removed {} custom command" |
|
|
|
|
|
|
|
|
def __init__(self, bot_client): |
|
|
def __init__(self, bot_client): |
|
|
self.bot = bot_client |
|
|
self.bot = bot_client |
|
|
self.embed_fields = ("title", "description", "colour", "color", "footer", "image", "thumbnail", "url") |
|
|
self.embed_fields = ("title", "description", "colour", "color", "footer", "image", "thumbnail", "url") |
|
|
|
|
|
|
|
|
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("Not enough options given to generate embed.") |
|
|
|
|
|
|
|
|
return await ctx.send(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("Failed to set output. Given output was too long.") |
|
|
|
|
|
|
|
|
return await ctx.send(self.ERROR_OUTPUT_TOO_LONG) |
|
|
else: |
|
|
else: |
|
|
return await ctx.send("Incorrect type given.") |
|
|
|
|
|
|
|
|
return await ctx.send(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("Custom Commands cannot mention people/roles/everyone.") |
|
|
|
|
|
|
|
|
return await ctx.send(self.ERROR_AT_MENTION) |
|
|
elif len(output) > 1800: |
|
|
elif len(output) > 1800: |
|
|
return await ctx.send("The output is too long") |
|
|
|
|
|
|
|
|
return await ctx.send(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("This is already the name of a built in command.") |
|
|
|
|
|
|
|
|
return await ctx.send(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("Custom Command already exists.") |
|
|
|
|
|
|
|
|
return await ctx.send(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("Custom commands with a prefix can only be one word with no spaces.") |
|
|
|
|
|
|
|
|
return await ctx.send() |
|
|
|
|
|
|
|
|
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") |
|
|
return await ctx.send("{} has been added with the output: '{}'".format(command, output)) |
|
|
|
|
|
|
|
|
return await ctx.send(self.OUTPUT_ADD.format(command, output)) |
|
|
|
|
|
|
|
|
@custom.command() |
|
|
@custom.command() |
|
|
async def edit(self, ctx, command, *edit): |
|
|
async def edit(self, ctx, command, *edit): |
|
|
|
|
|
|
|
|
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("Custom Commands cannot mention people/roles/everyone.") |
|
|
|
|
|
|
|
|
return await ctx.send(self.ERROR_AT_MENTION) |
|
|
|
|
|
|
|
|
if command in no_prefix_commands: |
|
|
if command in no_prefix_commands: |
|
|
if len(edit) == 1: |
|
|
if len(edit) == 1: |
|
|
edit = edit[0] |
|
|
edit = edit[0] |
|
|
settings.custom_commands["0"][command] = edit |
|
|
settings.custom_commands["0"][command] = edit |
|
|
settings.update(settings.custom_commands, "custom_commands") |
|
|
settings.update(settings.custom_commands, "custom_commands") |
|
|
return await ctx.send("Edit made. {} now outputs {}".format(command, edit)) |
|
|
|
|
|
|
|
|
return await ctx.send(self.OUTPUT_EDIT.format(command, edit)) |
|
|
|
|
|
|
|
|
elif command in prefix_commands: |
|
|
elif command in prefix_commands: |
|
|
if len(edit) == 1: |
|
|
if len(edit) == 1: |
|
|
edit = edit[0] |
|
|
edit = edit[0] |
|
|
settings.custom_commands["1"][command] = edit |
|
|
settings.custom_commands["1"][command] = edit |
|
|
settings.update(settings.custom_commands, "custom_commands") |
|
|
settings.update(settings.custom_commands, "custom_commands") |
|
|
return await ctx.send("Edit made. {} now outputs {}".format(command, edit)) |
|
|
|
|
|
|
|
|
return await ctx.send(self.OUTPUT_EDIT.format(command, edit)) |
|
|
|
|
|
|
|
|
elif command in embed_commands: |
|
|
elif command in embed_commands: |
|
|
if len(edit) < 2: |
|
|
if len(edit) < 2: |
|
|
return await ctx.send("Not enough options given to generate embed.") |
|
|
|
|
|
|
|
|
return await ctx.send(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("Failed to set output. Given output was too long.") |
|
|
|
|
|
|
|
|
return await ctx.send(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("Edit made. {} now outputs {}".format(command, edit)) |
|
|
|
|
|
|
|
|
return await ctx.send(self.OUTPUT_EDIT.format(command, edit)) |
|
|
|
|
|
|
|
|
else: |
|
|
else: |
|
|
return await ctx.send("That Custom Command doesn't exist.") |
|
|
|
|
|
|
|
|
return await ctx.send(self.ERROR_COMMAND_NULL) |
|
|
|
|
|
|
|
|
@custom.command() |
|
|
@custom.command() |
|
|
async def remove(self, ctx, command): |
|
|
async def remove(self, ctx, command): |
|
|
|
|
|
|
|
|
elif command in embed_commands: |
|
|
elif command in embed_commands: |
|
|
command_type = "2" |
|
|
command_type = "2" |
|
|
else: |
|
|
else: |
|
|
return await ctx.send("Custom Command doesn't exist.") |
|
|
|
|
|
|
|
|
return await ctx.send(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") |
|
|
return await ctx.send("Removed {} custom command".format(command)) |
|
|
|
|
|
|
|
|
return await ctx.send(self.OUTPUT_REMOVE.format(command)) |
|
|
|
|
|
|
|
|
@custom.command() |
|
|
@custom.command() |
|
|
async def list(self, ctx, debug="0"): |
|
|
async def list(self, ctx, debug="0"): |