|
|
|
@ -19,10 +19,7 @@ class CCRole(Cog):
|
|
|
|
|
def __init__(self, bot):
|
|
|
|
|
self.bot = bot
|
|
|
|
|
self.config = Config.get_conf(self, identifier=9999114111108101)
|
|
|
|
|
default_guild = {
|
|
|
|
|
"cmdlist": {},
|
|
|
|
|
"settings": {}
|
|
|
|
|
}
|
|
|
|
|
default_guild = {"cmdlist": {}, "settings": {}}
|
|
|
|
|
|
|
|
|
|
self.config.register_guild(**default_guild)
|
|
|
|
|
|
|
|
|
@ -54,17 +51,23 @@ class CCRole(Cog):
|
|
|
|
|
cmd_list = self.config.guild(guild).cmdlist
|
|
|
|
|
|
|
|
|
|
if await cmd_list.get_raw(command, default=None):
|
|
|
|
|
await ctx.send("This command already exists. Delete it with `{}ccrole delete` first.".format(ctx.prefix))
|
|
|
|
|
await ctx.send(
|
|
|
|
|
"This command already exists. Delete it with `{}ccrole delete` first.".format(
|
|
|
|
|
ctx.prefix
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
# Roles to add
|
|
|
|
|
await ctx.send('What roles should it add? (Must be **comma separated**)\nSay `None` to skip adding roles')
|
|
|
|
|
await ctx.send(
|
|
|
|
|
"What roles should it add? (Must be **comma separated**)\nSay `None` to skip adding roles"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def check(m):
|
|
|
|
|
return m.author == author and m.channel == channel
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
answer = await self.bot.wait_for('message', timeout=120, check=check)
|
|
|
|
|
answer = await self.bot.wait_for("message", timeout=120, check=check)
|
|
|
|
|
except asyncio.TimeoutError:
|
|
|
|
|
await ctx.send("Timed out, canceling")
|
|
|
|
|
return
|
|
|
|
@ -77,9 +80,11 @@ class CCRole(Cog):
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
# Roles to remove
|
|
|
|
|
await ctx.send('What roles should it remove? (Must be comma separated)\nSay `None` to skip removing roles')
|
|
|
|
|
await ctx.send(
|
|
|
|
|
"What roles should it remove? (Must be comma separated)\nSay `None` to skip removing roles"
|
|
|
|
|
)
|
|
|
|
|
try:
|
|
|
|
|
answer = await self.bot.wait_for('message', timeout=120, check=check)
|
|
|
|
|
answer = await self.bot.wait_for("message", timeout=120, check=check)
|
|
|
|
|
except asyncio.TimeoutError:
|
|
|
|
|
await ctx.send("Timed out, canceling")
|
|
|
|
|
return
|
|
|
|
@ -93,10 +98,11 @@ class CCRole(Cog):
|
|
|
|
|
|
|
|
|
|
# Roles to use
|
|
|
|
|
await ctx.send(
|
|
|
|
|
'What roles are allowed to use this command? (Must be comma separated)\nSay `None` to allow all roles')
|
|
|
|
|
"What roles are allowed to use this command? (Must be comma separated)\nSay `None` to allow all roles"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
answer = await self.bot.wait_for('message', timeout=120, check=check)
|
|
|
|
|
answer = await self.bot.wait_for("message", timeout=120, check=check)
|
|
|
|
|
except asyncio.TimeoutError:
|
|
|
|
|
await ctx.send("Timed out, canceling")
|
|
|
|
|
return
|
|
|
|
@ -109,10 +115,12 @@ class CCRole(Cog):
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
# Selfrole
|
|
|
|
|
await ctx.send('Is this a targeted command?(yes//no)\nNo will make this a selfrole command')
|
|
|
|
|
await ctx.send(
|
|
|
|
|
"Is this a targeted command?(yes//no)\nNo will make this a selfrole command"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
answer = await self.bot.wait_for('message', timeout=120, check=check)
|
|
|
|
|
answer = await self.bot.wait_for("message", timeout=120, check=check)
|
|
|
|
|
except asyncio.TimeoutError:
|
|
|
|
|
await ctx.send("Timed out, canceling")
|
|
|
|
|
return
|
|
|
|
@ -126,13 +134,14 @@ class CCRole(Cog):
|
|
|
|
|
|
|
|
|
|
# Message to send
|
|
|
|
|
await ctx.send(
|
|
|
|
|
'What message should the bot say when using this command?\n'
|
|
|
|
|
'Say `None` to send the default `Success!` message\n'
|
|
|
|
|
'Eval Options: `{author}`, `{target}`, `{server}`, `{channel}`, `{message}`\n'
|
|
|
|
|
'For example: `Welcome {target.mention} to {server.name}!`')
|
|
|
|
|
"What message should the bot say when using this command?\n"
|
|
|
|
|
"Say `None` to send the default `Success!` message\n"
|
|
|
|
|
"Eval Options: `{author}`, `{target}`, `{server}`, `{channel}`, `{message}`\n"
|
|
|
|
|
"For example: `Welcome {target.mention} to {server.name}!`"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
answer = await self.bot.wait_for('message', timeout=120, check=check)
|
|
|
|
|
answer = await self.bot.wait_for("message", timeout=120, check=check)
|
|
|
|
|
except asyncio.TimeoutError:
|
|
|
|
|
await ctx.send("Timed out, canceling")
|
|
|
|
|
return
|
|
|
|
@ -143,7 +152,13 @@ class CCRole(Cog):
|
|
|
|
|
|
|
|
|
|
# Save the command
|
|
|
|
|
|
|
|
|
|
out = {'text': text, 'aroles': arole_list, 'rroles': rrole_list, "proles": prole_list, "targeted": targeted}
|
|
|
|
|
out = {
|
|
|
|
|
"text": text,
|
|
|
|
|
"aroles": arole_list,
|
|
|
|
|
"rroles": rrole_list,
|
|
|
|
|
"proles": prole_list,
|
|
|
|
|
"targeted": targeted,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await cmd_list.set_raw(command, value=out)
|
|
|
|
|
|
|
|
|
@ -174,18 +189,24 @@ class CCRole(Cog):
|
|
|
|
|
await ctx.send("That command doesn't exist")
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
embed = discord.Embed(title=command,
|
|
|
|
|
description="{} custom command".format("Targeted" if cmd['targeted'] else "Non-Targeted"))
|
|
|
|
|
embed = discord.Embed(
|
|
|
|
|
title=command,
|
|
|
|
|
description="{} custom command".format(
|
|
|
|
|
"Targeted" if cmd["targeted"] else "Non-Targeted"
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def process_roles(role_list):
|
|
|
|
|
if not role_list:
|
|
|
|
|
return "None"
|
|
|
|
|
return ", ".join([discord.utils.get(ctx.guild.roles, id=roleid).name for roleid in role_list])
|
|
|
|
|
return ", ".join(
|
|
|
|
|
[discord.utils.get(ctx.guild.roles, id=roleid).name for roleid in role_list]
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
embed.add_field(name="Text", value="```{}```".format(cmd['text']))
|
|
|
|
|
embed.add_field(name="Adds Roles", value=process_roles(cmd['aroles']), inline=True)
|
|
|
|
|
embed.add_field(name="Removes Roles", value=process_roles(cmd['rroles']), inline=True)
|
|
|
|
|
embed.add_field(name="Role Restrictions", value=process_roles(cmd['proles']), inline=True)
|
|
|
|
|
embed.add_field(name="Text", value="```{}```".format(cmd["text"]))
|
|
|
|
|
embed.add_field(name="Adds Roles", value=process_roles(cmd["aroles"]), inline=True)
|
|
|
|
|
embed.add_field(name="Removes Roles", value=process_roles(cmd["rroles"]), inline=True)
|
|
|
|
|
embed.add_field(name="Role Restrictions", value=process_roles(cmd["proles"]), inline=True)
|
|
|
|
|
|
|
|
|
|
await ctx.send(embed=embed)
|
|
|
|
|
|
|
|
|
@ -198,13 +219,17 @@ class CCRole(Cog):
|
|
|
|
|
if not cmd_list:
|
|
|
|
|
await ctx.send(
|
|
|
|
|
"There are no custom commands in this server. Use `{}ccrole add` to start adding some.".format(
|
|
|
|
|
ctx.prefix))
|
|
|
|
|
ctx.prefix
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
cmd_list = ", ".join([ctx.prefix + c for c in sorted(cmd_list.keys())])
|
|
|
|
|
cmd_list = "Custom commands:\n\n" + cmd_list
|
|
|
|
|
|
|
|
|
|
if len(cmd_list) < 1500: # I'm allowed to have arbitrary numbers for when it's too much to dm dammit
|
|
|
|
|
if (
|
|
|
|
|
len(cmd_list) < 1500
|
|
|
|
|
): # I'm allowed to have arbitrary numbers for when it's too much to dm dammit
|
|
|
|
|
await ctx.send(box(cmd_list))
|
|
|
|
|
else:
|
|
|
|
|
for page in pagify(cmd_list, delims=[" ", "\n"]):
|
|
|
|
@ -231,7 +256,10 @@ class CCRole(Cog):
|
|
|
|
|
async def _get_roles_from_content(self, ctx, content):
|
|
|
|
|
content_list = content.split(",")
|
|
|
|
|
try:
|
|
|
|
|
role_list = [discord.utils.get(ctx.guild.roles, name=role.strip(' ')).id for role in content_list]
|
|
|
|
|
role_list = [
|
|
|
|
|
discord.utils.get(ctx.guild.roles, name=role.strip(" ")).id
|
|
|
|
|
for role in content_list
|
|
|
|
|
]
|
|
|
|
|
except (discord.HTTPException, AttributeError): # None.id is attribute error
|
|
|
|
|
return None
|
|
|
|
|
else:
|
|
|
|
@ -249,9 +277,7 @@ class CCRole(Cog):
|
|
|
|
|
"""
|
|
|
|
|
content = message.content
|
|
|
|
|
prefix_list = await self.bot.command_prefix(self.bot, message)
|
|
|
|
|
prefixes = sorted(prefix_list,
|
|
|
|
|
key=lambda pfx: len(pfx),
|
|
|
|
|
reverse=True)
|
|
|
|
|
prefixes = sorted(prefix_list, key=lambda pfx: len(pfx), reverse=True)
|
|
|
|
|
for p in prefixes:
|
|
|
|
|
if content.startswith(p):
|
|
|
|
|
return p
|
|
|
|
@ -259,25 +285,32 @@ class CCRole(Cog):
|
|
|
|
|
|
|
|
|
|
async def eval_cc(self, cmd, message):
|
|
|
|
|
"""Does all the work"""
|
|
|
|
|
if cmd['proles'] and not (set(role.id for role in message.author.roles) & set(cmd['proles'])):
|
|
|
|
|
if cmd["proles"] and not (
|
|
|
|
|
set(role.id for role in message.author.roles) & set(cmd["proles"])
|
|
|
|
|
):
|
|
|
|
|
return # Not authorized, do nothing
|
|
|
|
|
|
|
|
|
|
if cmd['targeted']:
|
|
|
|
|
if cmd["targeted"]:
|
|
|
|
|
try:
|
|
|
|
|
target = discord.utils.get(message.guild.members, mention=message.content.split()[1])
|
|
|
|
|
target = discord.utils.get(
|
|
|
|
|
message.guild.members, mention=message.content.split()[1]
|
|
|
|
|
)
|
|
|
|
|
except IndexError: # .split() return list of len<2
|
|
|
|
|
target = None
|
|
|
|
|
|
|
|
|
|
if not target:
|
|
|
|
|
out_message = "This custom command is targeted! @mention a target\n`{} <target>`".format(
|
|
|
|
|
message.content.split()[0])
|
|
|
|
|
message.content.split()[0]
|
|
|
|
|
)
|
|
|
|
|
await message.channel.send(out_message)
|
|
|
|
|
return
|
|
|
|
|
else:
|
|
|
|
|
target = message.author
|
|
|
|
|
|
|
|
|
|
if cmd['aroles']:
|
|
|
|
|
arole_list = [discord.utils.get(message.guild.roles, id=roleid) for roleid in cmd['aroles']]
|
|
|
|
|
if cmd["aroles"]:
|
|
|
|
|
arole_list = [
|
|
|
|
|
discord.utils.get(message.guild.roles, id=roleid) for roleid in cmd["aroles"]
|
|
|
|
|
]
|
|
|
|
|
# await self.bot.send_message(message.channel, "Adding: "+str([str(arole) for arole in arole_list]))
|
|
|
|
|
try:
|
|
|
|
|
await target.add_roles(*arole_list)
|
|
|
|
@ -285,8 +318,10 @@ class CCRole(Cog):
|
|
|
|
|
await message.channel.send("Permission error: Unable to add roles")
|
|
|
|
|
await asyncio.sleep(1)
|
|
|
|
|
|
|
|
|
|
if cmd['rroles']:
|
|
|
|
|
rrole_list = [discord.utils.get(message.guild.roles, id=roleid) for roleid in cmd['rroles']]
|
|
|
|
|
if cmd["rroles"]:
|
|
|
|
|
rrole_list = [
|
|
|
|
|
discord.utils.get(message.guild.roles, id=roleid) for roleid in cmd["rroles"]
|
|
|
|
|
]
|
|
|
|
|
# await self.bot.send_message(message.channel, "Removing: "+str([str(rrole) for rrole in rrole_list]))
|
|
|
|
|
try:
|
|
|
|
|
await target.remove_roles(*rrole_list)
|
|
|
|
@ -297,7 +332,7 @@ class CCRole(Cog):
|
|
|
|
|
await message.channel.send(out_message)
|
|
|
|
|
|
|
|
|
|
def format_cc(self, cmd, message, target):
|
|
|
|
|
out = cmd['text']
|
|
|
|
|
out = cmd["text"]
|
|
|
|
|
results = re.findall("{([^}]+)\}", out)
|
|
|
|
|
for result in results:
|
|
|
|
|
param = self.transform_parameter(result, message, target)
|
|
|
|
@ -316,7 +351,7 @@ class CCRole(Cog):
|
|
|
|
|
"channel": message.channel,
|
|
|
|
|
"server": message.guild,
|
|
|
|
|
"guild": message.guild,
|
|
|
|
|
"target": target
|
|
|
|
|
"target": target,
|
|
|
|
|
}
|
|
|
|
|
if result in objects:
|
|
|
|
|
return str(objects[result])
|
|
|
|
|