mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-08 12:18:54 -05:00
[CC] Moved commands to [p]customcom command group
This commit is contained in:
parent
f68667b628
commit
7a38da9152
@ -7,27 +7,38 @@ import re
|
||||
|
||||
|
||||
class CustomCommands:
|
||||
"""Custom commands."""
|
||||
"""Custom commands
|
||||
|
||||
Creates commands used to display text"""
|
||||
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.file_path = "data/customcom/commands.json"
|
||||
self.c_commands = dataIO.load_json(self.file_path)
|
||||
|
||||
@commands.command(pass_context=True, no_pm=True)
|
||||
@commands.group(aliases=["cc"], pass_context=True, no_pm=True)
|
||||
@checks.mod_or_permissions(administrator=True)
|
||||
async def addcom(self, ctx, command : str, *, text):
|
||||
async def customcom(self, ctx):
|
||||
"""Custom commands management"""
|
||||
if ctx.invoked_subcommand is None:
|
||||
await self.bot.send_cmd_help(ctx)
|
||||
|
||||
@customcom.command(name="add", pass_context=True)
|
||||
async def cc_add(self, ctx, command : str, *, text):
|
||||
"""Adds a custom command
|
||||
|
||||
Example:
|
||||
!addcom yourcommand Text you want
|
||||
[p]customcom add yourcommand Text you want
|
||||
|
||||
CCs can be enhanced with arguments:
|
||||
https://twentysix26.github.io/Red-Docs/red_guide_command_args/
|
||||
"""
|
||||
server = ctx.message.server
|
||||
command = command.lower()
|
||||
if command in self.bot.commands.keys():
|
||||
if command in self.bot.commands:
|
||||
await self.bot.say("That command is already a standard command.")
|
||||
return
|
||||
if not server.id in self.c_commands:
|
||||
if server.id not in self.c_commands:
|
||||
self.c_commands[server.id] = {}
|
||||
cmdlist = self.c_commands[server.id]
|
||||
if command not in cmdlist:
|
||||
@ -36,15 +47,16 @@ class CustomCommands:
|
||||
dataIO.save_json(self.file_path, self.c_commands)
|
||||
await self.bot.say("Custom command successfully added.")
|
||||
else:
|
||||
await self.bot.say("This command already exists. Use editcom to edit it.")
|
||||
await self.bot.say("This command already exists. Use "
|
||||
"`{}customcom edit` to edit it."
|
||||
"".format(ctx.prefix))
|
||||
|
||||
@commands.command(pass_context=True, no_pm=True)
|
||||
@checks.mod_or_permissions(administrator=True)
|
||||
async def editcom(self, ctx, command : str, *, text):
|
||||
@customcom.command(name="edit", pass_context=True)
|
||||
async def cc_edit(self, ctx, command : str, *, text):
|
||||
"""Edits a custom command
|
||||
|
||||
Example:
|
||||
!editcom yourcommand Text you want
|
||||
[p]customcom edit yourcommand Text you want
|
||||
"""
|
||||
server = ctx.message.server
|
||||
command = command.lower()
|
||||
@ -56,17 +68,20 @@ class CustomCommands:
|
||||
dataIO.save_json(self.file_path, self.c_commands)
|
||||
await self.bot.say("Custom command successfully edited.")
|
||||
else:
|
||||
await self.bot.say("That command doesn't exist. Use addcom [command] [text]")
|
||||
await self.bot.say("That command doesn't exist. Use "
|
||||
"`{}customcom add` to add it."
|
||||
"".format(ctx.prefix))
|
||||
else:
|
||||
await self.bot.say("There are no custom commands in this server. Use addcom [command] [text]")
|
||||
await self.bot.say("There are no custom commands in this server."
|
||||
" Use `{}customcom add` to start adding some."
|
||||
"".format(ctx.prefix))
|
||||
|
||||
@commands.command(pass_context=True, no_pm=True)
|
||||
@checks.mod_or_permissions(administrator=True)
|
||||
async def delcom(self, ctx, command : str):
|
||||
@customcom.command(name="delete", pass_context=True)
|
||||
async def cc_delete(self, ctx, command : str):
|
||||
"""Deletes a custom command
|
||||
|
||||
Example:
|
||||
!delcom yourcommand"""
|
||||
[p]customcom delete yourcommand"""
|
||||
server = ctx.message.server
|
||||
command = command.lower()
|
||||
if server.id in self.c_commands:
|
||||
@ -79,10 +94,12 @@ class CustomCommands:
|
||||
else:
|
||||
await self.bot.say("That command doesn't exist.")
|
||||
else:
|
||||
await self.bot.say("There are no custom commands in this server. Use addcom [command] [text]")
|
||||
await self.bot.say("There are no custom commands in this server."
|
||||
" Use `{}customcom add` to start adding some."
|
||||
"".format(ctx.prefix))
|
||||
|
||||
@commands.command(pass_context=True, no_pm=True)
|
||||
async def customcommands(self, ctx):
|
||||
@customcom.command(name="list", pass_context=True)
|
||||
async def cc_list(self, ctx):
|
||||
"""Shows custom commands list"""
|
||||
server = ctx.message.server
|
||||
if server.id in self.c_commands:
|
||||
@ -90,7 +107,7 @@ class CustomCommands:
|
||||
if cmdlist:
|
||||
i = 0
|
||||
msg = ["```Custom commands:\n"]
|
||||
for cmd in sorted([cmd for cmd in cmdlist.keys()]):
|
||||
for cmd in sorted([cmd for cmd in cmdlist]):
|
||||
if len(msg[i]) + len(ctx.prefix) + len(cmd) + 5 > 2000:
|
||||
msg[i] += "```"
|
||||
i += 1
|
||||
@ -101,11 +118,15 @@ class CustomCommands:
|
||||
for cmds in msg:
|
||||
await self.bot.whisper(cmds)
|
||||
else:
|
||||
await self.bot.say("There are no custom commands in this server. Use addcom [command] [text]")
|
||||
await self.bot.say("There are no custom commands in this server."
|
||||
" Use `{}customcom add` to start adding some."
|
||||
"".format(ctx.prefix))
|
||||
else:
|
||||
await self.bot.say("There are no custom commands in this server. Use addcom [command] [text]")
|
||||
await self.bot.say("There are no custom commands in this server."
|
||||
" Use `{}customcom add` to start adding some."
|
||||
"".format(ctx.prefix))
|
||||
|
||||
async def checkCC(self, message):
|
||||
async def on_message(self, message):
|
||||
if len(message.content) < 2 or message.channel.is_private:
|
||||
return
|
||||
|
||||
@ -118,11 +139,11 @@ class CustomCommands:
|
||||
if server.id in self.c_commands and user_allowed(message):
|
||||
cmdlist = self.c_commands[server.id]
|
||||
cmd = message.content[len(prefix):]
|
||||
if cmd in cmdlist.keys():
|
||||
if cmd in cmdlist:
|
||||
cmd = cmdlist[cmd]
|
||||
cmd = self.format_cc(cmd, message)
|
||||
await self.bot.send_message(message.channel, cmd)
|
||||
elif cmd.lower() in cmdlist.keys():
|
||||
elif cmd.lower() in cmdlist:
|
||||
cmd = cmdlist[cmd.lower()]
|
||||
cmd = self.format_cc(cmd, message)
|
||||
await self.bot.send_message(message.channel, cmd)
|
||||
@ -170,15 +191,15 @@ def check_folders():
|
||||
print("Creating data/customcom folder...")
|
||||
os.makedirs("data/customcom")
|
||||
|
||||
|
||||
def check_files():
|
||||
f = "data/customcom/commands.json"
|
||||
if not dataIO.is_valid_json(f):
|
||||
print("Creating empty commands.json...")
|
||||
dataIO.save_json(f, {})
|
||||
|
||||
|
||||
def setup(bot):
|
||||
check_folders()
|
||||
check_files()
|
||||
n = CustomCommands(bot)
|
||||
bot.add_listener(n.checkCC, "on_message")
|
||||
bot.add_cog(n)
|
||||
bot.add_cog(CustomCommands(bot))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user