Merge branch 'ccrole-develop'
This commit is contained in:
		
						commit
						27eb943bd9
					
				
							
								
								
									
										256
									
								
								ccrole/ccrole.py
									
									
									
									
									
								
							
							
						
						
									
										256
									
								
								ccrole/ccrole.py
									
									
									
									
									
								
							@ -1,14 +1,11 @@
 | 
				
			|||||||
import discord
 | 
					import asyncio
 | 
				
			||||||
import asyncio 
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
from discord.ext import commands
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
from redbot.core import Config, checks
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
from redbot.core.utils.chat_formatting import pagify, box
 | 
					 | 
				
			||||||
import os
 | 
					 | 
				
			||||||
import re
 | 
					import re
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import discord
 | 
				
			||||||
 | 
					from discord.ext import commands
 | 
				
			||||||
 | 
					from redbot.core import Config, checks
 | 
				
			||||||
 | 
					from redbot.core.utils.chat_formatting import pagify, box
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class CCRole:
 | 
					class CCRole:
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
@ -20,23 +17,27 @@ class CCRole:
 | 
				
			|||||||
        self.bot = bot
 | 
					        self.bot = bot
 | 
				
			||||||
        self.config = Config.get_conf(self, identifier=9999114111108101)
 | 
					        self.config = Config.get_conf(self, identifier=9999114111108101)
 | 
				
			||||||
        default_guild = {
 | 
					        default_guild = {
 | 
				
			||||||
            "cmdlist" : {}, 
 | 
					            "cmdlist": {},
 | 
				
			||||||
            "settings": {}
 | 
					            "settings": {}
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        self.config.register_guild(**default_guild)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        self.config.register_guild(**default_guild)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @commands.group(no_pm=True)
 | 
					    @commands.group(no_pm=True)
 | 
				
			||||||
    async def ccrole(self, ctx):
 | 
					    async def ccrole(self, ctx):
 | 
				
			||||||
        """Custom commands management"""
 | 
					        """Custom commands management with roles
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Highly customizable custom commands with role management."""
 | 
				
			||||||
        if not ctx.invoked_subcommand:
 | 
					        if not ctx.invoked_subcommand:
 | 
				
			||||||
            await ctx.send_help()
 | 
					            await ctx.send_help()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @ccrole.command(name="add")
 | 
					    @ccrole.command(name="add")
 | 
				
			||||||
    @checks.mod_or_permissions(administrator=True)
 | 
					    @checks.mod_or_permissions(administrator=True)
 | 
				
			||||||
    async def ccrole_add(self, ctx, command : str):
 | 
					    async def ccrole_add(self, ctx, command: str):
 | 
				
			||||||
        """Adds a custom command with roles"""
 | 
					        """Adds a custom command with roles
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        When adding text, put arguments in `{}` to eval them
 | 
				
			||||||
 | 
					        Options: `{author}`, `{target}`, `{server}`, `{channel}`, `{message}`"""
 | 
				
			||||||
        command = command.lower()
 | 
					        command = command.lower()
 | 
				
			||||||
        if command in self.bot.all_commands:
 | 
					        if command in self.bot.all_commands:
 | 
				
			||||||
            await ctx.send("That command is already a standard command.")
 | 
					            await ctx.send("That command is already a standard command.")
 | 
				
			||||||
@ -45,125 +46,164 @@ class CCRole:
 | 
				
			|||||||
        guild = ctx.guild
 | 
					        guild = ctx.guild
 | 
				
			||||||
        author = ctx.author
 | 
					        author = ctx.author
 | 
				
			||||||
        channel = ctx.channel
 | 
					        channel = ctx.channel
 | 
				
			||||||
        
 | 
					
 | 
				
			||||||
        cmdlist = self.config.guild(ctx.guild).cmdlist
 | 
					        cmd_list = self.config.guild(guild).cmdlist
 | 
				
			||||||
        
 | 
					
 | 
				
			||||||
        if await cmdlist.get_raw(command, default=None):
 | 
					        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
 | 
					            return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Roles to add
 | 
					        # 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):
 | 
					        def check(m):
 | 
				
			||||||
            return m.author == author and m.channel==channel
 | 
					            return m.author == author and m.channel == channel
 | 
				
			||||||
        
 | 
					
 | 
				
			||||||
        try:
 | 
					        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:
 | 
					        except asyncio.TimeoutError:
 | 
				
			||||||
            await ctx.send("Timed out, canceling")
 | 
					            await ctx.send("Timed out, canceling")
 | 
				
			||||||
            
 | 
					            return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        arole_list = []
 | 
					        arole_list = []
 | 
				
			||||||
        if answer.content.upper()!="NONE":
 | 
					        if answer.content.upper() != "NONE":
 | 
				
			||||||
            arole_list = await self._get_roles_from_content(ctx, answer.content)
 | 
					            arole_list = await self._get_roles_from_content(ctx, answer.content)
 | 
				
			||||||
            if arole_list is None:
 | 
					            if arole_list is None:
 | 
				
			||||||
                await ctx.send("Invalid answer, canceling")
 | 
					                await ctx.send("Invalid answer, canceling")
 | 
				
			||||||
                return
 | 
					                return
 | 
				
			||||||
        
 | 
					
 | 
				
			||||||
        # Roles to remove
 | 
					        # 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:
 | 
					        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:
 | 
					        except asyncio.TimeoutError:
 | 
				
			||||||
            await ctx.send("Timed out, canceling")
 | 
					            await ctx.send("Timed out, canceling")
 | 
				
			||||||
        
 | 
					            return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        rrole_list = []
 | 
					        rrole_list = []
 | 
				
			||||||
        if answer.content.upper()!="NONE":
 | 
					        if answer.content.upper() != "NONE":
 | 
				
			||||||
            rrole_list = await self._get_roles_from_content(ctx, answer.content)
 | 
					            rrole_list = await self._get_roles_from_content(ctx, answer.content)
 | 
				
			||||||
            if rrole_list is None:
 | 
					            if rrole_list is None:
 | 
				
			||||||
                await ctx.send("Invalid answer, canceling")
 | 
					                await ctx.send("Invalid answer, canceling")
 | 
				
			||||||
                return
 | 
					                return
 | 
				
			||||||
                
 | 
					
 | 
				
			||||||
        # Roles to use
 | 
					        # Roles to use
 | 
				
			||||||
        await ctx.send('What roles are allowed to use this command? (Must be comma separated)\nSay `None` to allow all roles')
 | 
					        await ctx.send(
 | 
				
			||||||
        
 | 
					            'What roles are allowed to use this command? (Must be comma separated)\nSay `None` to allow all roles')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        try:
 | 
					        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:
 | 
					        except asyncio.TimeoutError:
 | 
				
			||||||
            await ctx.send("Timed out, canceling")
 | 
					            await ctx.send("Timed out, canceling")
 | 
				
			||||||
        
 | 
					            return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        prole_list = []
 | 
					        prole_list = []
 | 
				
			||||||
        if answer.content.upper()!="NONE":
 | 
					        if answer.content.upper() != "NONE":
 | 
				
			||||||
            prole_list = await self._get_roles_from_content(ctx, answer.content)
 | 
					            prole_list = await self._get_roles_from_content(ctx, answer.content)
 | 
				
			||||||
            if prole_list is None:
 | 
					            if prole_list is None:
 | 
				
			||||||
                await ctx.send("Invalid answer, canceling")
 | 
					                await ctx.send("Invalid answer, canceling")
 | 
				
			||||||
                return
 | 
					                return
 | 
				
			||||||
                
 | 
					
 | 
				
			||||||
        # Selfrole
 | 
					        # 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:
 | 
					        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:
 | 
					        except asyncio.TimeoutError:
 | 
				
			||||||
            await ctx.send("Timed out, canceling")
 | 
					            await ctx.send("Timed out, canceling")
 | 
				
			||||||
        
 | 
					            return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if answer.content.upper() in ["Y", "YES"]:
 | 
					        if answer.content.upper() in ["Y", "YES"]:
 | 
				
			||||||
            targeted = True
 | 
					            targeted = True
 | 
				
			||||||
            await ctx.send("This command will be **`targeted`**")
 | 
					            await ctx.send("This command will be **`targeted`**")
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            targeted = False
 | 
					            targeted = False
 | 
				
			||||||
            await ctx.send("This command will be **`selfrole`**")
 | 
					            await ctx.send("This command will be **`selfrole`**")
 | 
				
			||||||
        
 | 
					
 | 
				
			||||||
        # Message to send
 | 
					        # Message to send
 | 
				
			||||||
        await ctx.send('What message should the bot say when using this command?\nSay `None` to send the default `Success!` message')
 | 
					        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}!`')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        try:
 | 
					        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:
 | 
					        except asyncio.TimeoutError:
 | 
				
			||||||
            await ctx.send("Timed out, canceling")
 | 
					            await ctx.send("Timed out, canceling")
 | 
				
			||||||
 | 
					            return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        text = "Success!"
 | 
					        text = "Success!"
 | 
				
			||||||
        if answer.content.upper()!="NONE":
 | 
					        if answer.content.upper() != "NONE":
 | 
				
			||||||
            text = answer.content
 | 
					            text = answer.content
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Save the command
 | 
					        # 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 cmdlist.set_raw(command, value=out)
 | 
					        await cmd_list.set_raw(command, value=out)
 | 
				
			||||||
        
 | 
					
 | 
				
			||||||
        ctx.send("Custom Command **`{}`** successfully added".format(command))
 | 
					        await ctx.send("Custom Command **`{}`** successfully added".format(command))
 | 
				
			||||||
        
 | 
					
 | 
				
			||||||
    @ccrole.command(name="delete")
 | 
					    @ccrole.command(name="delete")
 | 
				
			||||||
    @checks.mod_or_permissions(administrator=True)
 | 
					    @checks.mod_or_permissions(administrator=True)
 | 
				
			||||||
    async def ccrole_delete(self, ctx, command : str):
 | 
					    async def ccrole_delete(self, ctx, command: str):
 | 
				
			||||||
        """Deletes a custom command
 | 
					        """Deletes a custom command
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Example:
 | 
					        Example:
 | 
				
			||||||
        [p]ccrole delete yourcommand"""
 | 
					        `[p]ccrole delete yourcommand`"""
 | 
				
			||||||
        guild = ctx.guild
 | 
					        guild = ctx.guild
 | 
				
			||||||
        command = command.lower()
 | 
					        command = command.lower()
 | 
				
			||||||
        if not await self.config.guild(ctx.guild).cmdlist.get_raw(command, default=None):
 | 
					        if not await self.config.guild(guild).cmdlist.get_raw(command, default=None):
 | 
				
			||||||
            await ctx.send("That command doesn't exist")
 | 
					            await ctx.send("That command doesn't exist")
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            await self.config.guild(ctx.guild).cmdlist.set_raw(command, value=None)
 | 
					            await self.config.guild(guild).cmdlist.set_raw(command, value=None)
 | 
				
			||||||
            await ctx.send("Custom command successfully deleted.")
 | 
					            await ctx.send("Custom command successfully deleted.")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @ccrole.command(name="details")
 | 
				
			||||||
 | 
					    async def ccrole_details(self, ctx, command: str):
 | 
				
			||||||
 | 
					        """Provide details about passed custom command"""
 | 
				
			||||||
 | 
					        guild = ctx.guild
 | 
				
			||||||
 | 
					        command = command.lower()
 | 
				
			||||||
 | 
					        cmd = await self.config.guild(guild).cmdlist.get_raw(command, default=None)
 | 
				
			||||||
 | 
					        if cmd is None:
 | 
				
			||||||
 | 
					            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"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        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])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        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)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @ccrole.command(name="list")
 | 
					    @ccrole.command(name="list")
 | 
				
			||||||
    async def ccrole_list(self, ctx):
 | 
					    async def ccrole_list(self, ctx):
 | 
				
			||||||
        """Shows custom commands list"""
 | 
					        """Shows custom commands list"""
 | 
				
			||||||
        guild = ctx.guild
 | 
					        guild = ctx.guild
 | 
				
			||||||
        commands = await self.config.guild(ctx.guild).cmdlist()
 | 
					        cmd_list = await self.config.guild(guild).cmdlist()
 | 
				
			||||||
 | 
					        cmd_list = {k: v for k,v in cmd_list.items() if v}
 | 
				
			||||||
        if not commands:
 | 
					        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))
 | 
					            await ctx.send(
 | 
				
			||||||
 | 
					                "There are no custom commands in this server. Use `{}ccrole add` to start adding some.".format(
 | 
				
			||||||
 | 
					                    ctx.prefix))
 | 
				
			||||||
            return
 | 
					            return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        commands = ", ".join([ctx.prefix + c for c in sorted(commands.keys())])
 | 
					        cmd_list = ", ".join([ctx.prefix + c for c in sorted(cmd_list.keys())])
 | 
				
			||||||
        commands = "Custom commands:\n\n" + commands
 | 
					        cmd_list = "Custom commands:\n\n" + cmd_list
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if len(commands) < 1500:
 | 
					        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(commands))
 | 
					            await ctx.send(box(cmd_list))
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            for page in pagify(commands, delims=[" ", "\n"]):
 | 
					            for page in pagify(cmd_list, delims=[" ", "\n"]):
 | 
				
			||||||
                await ctx.author.send(box(page))
 | 
					                await ctx.author.send(box(page))
 | 
				
			||||||
            await ctx.send("Command list DM'd")
 | 
					            await ctx.send("Command list DM'd")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -177,24 +217,22 @@ class CCRole:
 | 
				
			|||||||
        except ValueError:
 | 
					        except ValueError:
 | 
				
			||||||
            return
 | 
					            return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        cmdlist = self.config.guild(guild).cmdlist
 | 
					        cmdlist = self.config.guild(guild).cmdlist
 | 
				
			||||||
        cmd = message.content[len(prefix):].split()[0]
 | 
					        cmd = message.content[len(prefix):].split()[0].lower()
 | 
				
			||||||
        cmd = await cmdlist.get_raw(cmd.lower(), default=None)
 | 
					        cmd = await cmdlist.get_raw(cmd, default=None)
 | 
				
			||||||
        
 | 
					
 | 
				
			||||||
        if cmd:
 | 
					        if cmd is not None:
 | 
				
			||||||
            await self.eval_cc(cmd, message)
 | 
					            await self.eval_cc(cmd, message)
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    async def _get_roles_from_content(self, ctx, content):
 | 
					    async def _get_roles_from_content(self, ctx, content):
 | 
				
			||||||
        content_list = content.split(",")
 | 
					        content_list = content.split(",")
 | 
				
			||||||
        role_list = []
 | 
					 | 
				
			||||||
        try:
 | 
					        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:
 | 
					        except (discord.HTTPException, AttributeError):  # None.id is attribute error
 | 
				
			||||||
            return None
 | 
					            return None
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            return role_list
 | 
					            return role_list
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    async def get_prefix(self, message: discord.Message) -> str:
 | 
					    async def get_prefix(self, message: discord.Message) -> str:
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        Borrowed from alias cog
 | 
					        Borrowed from alias cog
 | 
				
			||||||
@ -214,27 +252,26 @@ class CCRole:
 | 
				
			|||||||
            if content.startswith(p):
 | 
					            if content.startswith(p):
 | 
				
			||||||
                return p
 | 
					                return p
 | 
				
			||||||
        raise ValueError
 | 
					        raise ValueError
 | 
				
			||||||
        
 | 
					
 | 
				
			||||||
    async def eval_cc(self, cmd, message):
 | 
					    async def eval_cc(self, cmd, message):
 | 
				
			||||||
        """Does all the work"""
 | 
					        """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
 | 
					            return  # Not authorized, do nothing
 | 
				
			||||||
        
 | 
					
 | 
				
			||||||
        if cmd['targeted']:
 | 
					        if cmd['targeted']:
 | 
				
			||||||
            try:
 | 
					            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:
 | 
					            except IndexError:  # .split() return list of len<2
 | 
				
			||||||
                target = None
 | 
					                target = None
 | 
				
			||||||
            
 | 
					
 | 
				
			||||||
            if not target:
 | 
					            if not target:
 | 
				
			||||||
                out_message = "This command is targeted! @mention a target\n`{} <target>`".format(message.content.split()[0])
 | 
					                out_message = "This custom command is targeted! @mention a target\n`{} <target>`".format(
 | 
				
			||||||
                
 | 
					                    message.content.split()[0])
 | 
				
			||||||
                await message.channel.send(out_message)
 | 
					                await message.channel.send(out_message)
 | 
				
			||||||
                
 | 
					 | 
				
			||||||
                return
 | 
					                return
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            target = message.author
 | 
					            target = message.author
 | 
				
			||||||
            
 | 
					
 | 
				
			||||||
        if cmd['aroles']:
 | 
					        if cmd['aroles']:
 | 
				
			||||||
            arole_list = [discord.utils.get(message.guild.roles, id=roleid) for roleid in 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]))
 | 
					            # await self.bot.send_message(message.channel, "Adding: "+str([str(arole) for arole in arole_list]))
 | 
				
			||||||
@ -243,7 +280,7 @@ class CCRole:
 | 
				
			|||||||
            except discord.Forbidden:
 | 
					            except discord.Forbidden:
 | 
				
			||||||
                await message.channel.send("Permission error: Unable to add roles")
 | 
					                await message.channel.send("Permission error: Unable to add roles")
 | 
				
			||||||
        await asyncio.sleep(1)
 | 
					        await asyncio.sleep(1)
 | 
				
			||||||
        
 | 
					
 | 
				
			||||||
        if cmd['rroles']:
 | 
					        if cmd['rroles']:
 | 
				
			||||||
            rrole_list = [discord.utils.get(message.guild.roles, id=roleid) for roleid in 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]))
 | 
					            # await self.bot.send_message(message.channel, "Removing: "+str([str(rrole) for rrole in rrole_list]))
 | 
				
			||||||
@ -251,37 +288,40 @@ class CCRole:
 | 
				
			|||||||
                await target.remove_roles(*rrole_list)
 | 
					                await target.remove_roles(*rrole_list)
 | 
				
			||||||
            except discord.Forbidden:
 | 
					            except discord.Forbidden:
 | 
				
			||||||
                await message.channel.send("Permission error: Unable to remove roles")
 | 
					                await message.channel.send("Permission error: Unable to remove roles")
 | 
				
			||||||
        await message.channel.send(cmd['text'])
 | 
					 | 
				
			||||||
            
 | 
					 | 
				
			||||||
        # {'text': text, 'aroles': arole_list, 'rroles': rrole_list, "proles", prole_list, "targeted": targeted}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # def format_cc(self, command, message):
 | 
					        out_message = self.format_cc(cmd, message, target)
 | 
				
			||||||
        # results = re.findall("\{([^}]+)\}", command)
 | 
					        await message.channel.send(out_message)
 | 
				
			||||||
        # for result in results:
 | 
					 | 
				
			||||||
            # param = self.transform_parameter(result, message)
 | 
					 | 
				
			||||||
            # command = command.replace("{" + result + "}", param)
 | 
					 | 
				
			||||||
        # return command
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # def transform_parameter(self, result, message):
 | 
					    def format_cc(self, cmd, message, target):
 | 
				
			||||||
        # """
 | 
					        out = cmd['text']
 | 
				
			||||||
        # For security reasons only specific objects are allowed
 | 
					        results = re.findall("{([^}]+)\}", out)
 | 
				
			||||||
        # Internals are ignored
 | 
					        for result in results:
 | 
				
			||||||
        # """
 | 
					            param = self.transform_parameter(result, message, target)
 | 
				
			||||||
        # raw_result = "{" + result + "}"
 | 
					            out = out.replace("{" + result + "}", param)
 | 
				
			||||||
        # objects = {
 | 
					        return out
 | 
				
			||||||
            # "message" : message,
 | 
					
 | 
				
			||||||
            # "author"  : message.author,
 | 
					    def transform_parameter(self, result, message, target):
 | 
				
			||||||
            # "channel" : message.channel,
 | 
					        """
 | 
				
			||||||
            # "server"  : message.server
 | 
					        For security reasons only specific objects are allowed
 | 
				
			||||||
        # }
 | 
					        Internals are ignored
 | 
				
			||||||
        # if result in objects:
 | 
					        """
 | 
				
			||||||
            # return str(objects[result])
 | 
					        raw_result = "{" + result + "}"
 | 
				
			||||||
        # try:
 | 
					        objects = {
 | 
				
			||||||
            # first, second = result.split(".")
 | 
					            "message": message,
 | 
				
			||||||
        # except ValueError:
 | 
					            "author": message.author,
 | 
				
			||||||
            # return raw_result
 | 
					            "channel": message.channel,
 | 
				
			||||||
        # if first in objects and not second.startswith("_"):
 | 
					            "server": message.guild,
 | 
				
			||||||
            # first = objects[first]
 | 
					            "guild": message.guild,
 | 
				
			||||||
        # else:
 | 
					            "target": target
 | 
				
			||||||
            # return raw_result
 | 
					        }
 | 
				
			||||||
        # return str(getattr(first, second, raw_result))
 | 
					        if result in objects:
 | 
				
			||||||
 | 
					            return str(objects[result])
 | 
				
			||||||
 | 
					        try:
 | 
				
			||||||
 | 
					            first, second = result.split(".")
 | 
				
			||||||
 | 
					        except ValueError:
 | 
				
			||||||
 | 
					            return raw_result
 | 
				
			||||||
 | 
					        if first in objects and not second.startswith("_"):
 | 
				
			||||||
 | 
					            first = objects[first]
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            return raw_result
 | 
				
			||||||
 | 
					        return str(getattr(first, second, raw_result))
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user