Ejemplo n.º 1
0
async def custom_command_detection(ev, message):
    if message.guild:
        prefix = ev.bot.get_prefix(message)
        if message.content.startswith(prefix):
            cmd = message.content[len(prefix):].lower()
            if cmd not in ev.bot.modules.commands:
                perms = GlobalCommandPermissions(ev, message)
                if perms.permitted:
                    custom_commands = ev.db.get_guild_settings(
                        message.guild.id, 'CustomCommands')
                    if custom_commands is None:
                        custom_commands = {}
                    if cmd in custom_commands:
                        response = custom_commands[cmd]
                        await message.channel.send(response)
Ejemplo n.º 2
0
async def custom_command(ev, message):
    if message.guild:
        prefix = ev.bot.get_prefix(message)
        if message.content.startswith(prefix):
            if message.content != prefix:
                cmd = message.content[len(prefix):].lower().split()[0]
                if cmd not in ev.bot.modules.commands:
                    perms = GlobalCommandPermissions(ev, message)
                    if perms.permitted:
                        custom_commands = ev.db.get_guild_settings(
                            message.guild.id, 'CustomCommands')
                        if custom_commands is None:
                            custom_commands = {}
                        if cmd in custom_commands:
                            cmd_text = custom_commands[cmd]
                            response = command_message_parser(
                                message, cmd_text)
                            log_command_usage(ev.log, message, cmd)
                            await message.channel.send(response)
Ejemplo n.º 3
0
 async def check_permissions(self, payload):
     """
     Runs all permission checks and initializers.
     :type payload: sigma.core.mechanics.payload.CommandPayload
     :rtype: GlobalCommandPermissions, ServerCommandPermissions
     """
     perms = GlobalCommandPermissions(self, payload)
     await perms.check_black_usr()
     await perms.check_black_srv()
     perms.generate_response()
     perms.check_final()
     guild_perms = ServerCommandPermissions(self, payload.msg)
     await guild_perms.check_perms()
     return perms, guild_perms
Ejemplo n.º 4
0
 async def execute(self, message, args):
     if self.bot.ready:
         if message.guild:
             delete_command_message = self.db.get_guild_settings(message.guild.id, 'DeleteCommands')
             if delete_command_message:
                 try:
                     await message.delete()
                 except discord.Forbidden:
                     pass
                 except discord.NotFound:
                     pass
         if not self.bot.cfg.dsc.bot and message.author.id != self.bot.user.id:
             self.log.warning(f'{message.author.name} tried using me.')
             return
         perms = GlobalCommandPermissions(self, message)
         guild_allowed = ServerCommandPermissions(self, message)
         self.log_command_usage(message, args)
         if perms.permitted:
             if guild_allowed.permitted:
                 requirements = CommandRequirements(self, message)
                 if requirements.reqs_met:
                     try:
                         await getattr(self.command, self.name)(self, message, args)
                         await add_cmd_stat(self.db, self, message, args)
                     except self.get_exception() as e:
                         await self.respond_with_icon(message, '❗')
                         err_token = secrets.token_hex(16)
                         self.log_error(message, args, e, err_token)
                         title = '❗ An Error Occurred!'
                         err_text = 'Something seems to have gone wrong.'
                         err_text += '\nPlease send this token to our support server.'
                         err_text += f'\nThe invite link is in the **{self.bot.get_prefix(message)}help** command.'
                         err_text += f'\nToken: **{err_token}**'
                         error_embed = discord.Embed(color=0xBE1931)
                         error_embed.add_field(name=title, value=err_text)
                         try:
                             await message.author.send(embed=error_embed)
                         except discord.Forbidden:
                             pass
                 else:
                     await self.respond_with_icon(message, '❗')
                     reqs_embed = discord.Embed(color=0xBE1931)
                     reqs_error_title = f'❗ I am missing permissions!'
                     reqs_error_list = ''
                     for req in requirements.missing_list:
                         req = req.replace('_', ' ').title()
                         reqs_error_list += f'\n- {req}'
                     reqs_embed.add_field(name=reqs_error_title, value=f'```\n{reqs_error_list}\n```')
                     reqs_embed.set_footer(text=f'{self.bot.get_prefix(message)}{self.name}')
                     try:
                         await message.author.send(embed=reqs_embed)
                     except discord.Forbidden:
                         pass
             else:
                 self.log.warning('ACCESS DENIED: This module or command is not allowed on this server.')
                 await self.respond_with_icon(message, '⛔')
         else:
             self.log_unpermitted(perms)
             await self.respond_with_icon(message, '⛔')
             if perms.response:
                 try:
                     await message.author.send(embed=perms.response)
                 except discord.Forbidden:
                     pass
Ejemplo n.º 5
0
 async def execute(self, message: discord.Message, args: list):
     if self.bot.ready:
         if message.guild:
             delete_command_message = await self.db.get_guild_settings(
                 message.guild.id, 'delete_commands')
             if delete_command_message:
                 try:
                     await message.delete()
                 except (discord.Forbidden, discord.NotFound):
                     pass
             if await self.check_black_args(message.guild, args):
                 await self.respond_with_icon(message, '🛡')
                 return
         if not self.bot.cfg.dsc.bot and message.author.id != self.bot.user.id:
             self.log.warning(f'{message.author.name} tried using me.')
             return
         if not self.cd.is_cooling(message):
             if not await self.bot.cool_down.on_cooldown(
                     f'{self.name}_core', message.author):
                 await self.update_cooldown(message.author)
                 perms = GlobalCommandPermissions(self, message)
                 await perms.check_black_usr()
                 await perms.check_black_srv()
                 await perms.generate_response()
                 perms.check_final()
                 guild_allowed = ServerCommandPermissions(self, message)
                 await guild_allowed.check_perms()
                 self.log_command_usage(message, args,
                                        arrow.utcnow().float_timestamp)
                 self.cd.set_cooling(message)
                 if perms.permitted:
                     if guild_allowed.permitted:
                         requirements = CommandRequirements(self, message)
                         if requirements.reqs_met:
                             try:
                                 await getattr(self.command,
                                               self.name)(self, message,
                                                          args)
                                 await add_cmd_stat(self)
                                 # await self.add_usage_exp(message)
                                 self.bot.command_count += 1
                                 event_task = self.bot.queue.event_runner(
                                     'command', self, message, args)
                                 self.bot.loop.create_task(event_task)
                             except self.get_exception() as e:
                                 error = SigmaError(self, e)
                                 await error.error_handler(message, args)
                         else:
                             await self.respond_with_icon(message, '📝')
                             reqs_embed = discord.Embed(color=0xBE1931)
                             reqs_error_title = f'❗ {self.bot.user.name} is missing permissions!'
                             reqs_error_list = ''
                             for req in requirements.missing_list:
                                 req = req.replace('_', ' ').title()
                                 reqs_error_list += f'\n- {req}'
                             prefix = await self.db.get_prefix(message)
                             reqs_embed.add_field(
                                 name=reqs_error_title,
                                 value=f'```\n{reqs_error_list}\n```')
                             reqs_embed.set_footer(
                                 text=
                                 f'{prefix}{self.name} could not execute.')
                             try:
                                 await message.channel.send(embed=reqs_embed
                                                            )
                             except (discord.Forbidden, discord.NotFound):
                                 pass
                     else:
                         self.log.warning(
                             'ACCESS DENIED: This module or command is not allowed in this location.'
                         )
                         await self.respond_with_icon(message, '🔒')
                 else:
                     perms.log_unpermitted()
                     await self.respond_with_icon(message, '⛔')
                     if perms.response:
                         try:
                             await message.channel.send(embed=perms.response
                                                        )
                         except (discord.Forbidden, discord.NotFound):
                             pass
             else:
                 await self.respond_with_icon(message, '❄')
         else:
             await self.respond_with_icon(message, '🕙')
Ejemplo n.º 6
0
 async def execute(self, message: discord.Message, args: list):
     if self.bot.ready:
         if message.guild:
             delete_command_message = await self.db.get_guild_settings(message.guild.id, 'DeleteCommands')
             if delete_command_message:
                 try:
                     await message.delete()
                 except discord.Forbidden:
                     pass
                 except discord.NotFound:
                     pass
         if not self.bot.cfg.dsc.bot and message.author.id != self.bot.user.id:
             self.log.warning(f'{message.author.name} tried using me.')
             return
         if not self.cd.is_cooling(message):
             perms = GlobalCommandPermissions(self, message)
             await perms.check_black_usr()
             await perms.check_black_srv()
             await perms.generate_response()
             perms.check_final()
             guild_allowed = ServerCommandPermissions(self, message)
             await guild_allowed.check_perms()
             self.log_command_usage(message, args)
             self.cd.set_cooling(message)
             if perms.permitted:
                 if guild_allowed.permitted:
                     requirements = CommandRequirements(self, message)
                     if requirements.reqs_met:
                         try:
                             await getattr(self.command, self.name)(self, message, args)
                             await add_cmd_stat(self)
                             if self.stats:
                                 await self.add_elastic_stats(message, args)
                             await self.add_usage_exp(message)
                             self.bot.command_count += 1
                             self.bot.loop.create_task(self.bot.queue.event_runner('command', self, message, args))
                         except self.get_exception() as e:
                             await self.respond_with_icon(message, '❗')
                             err_token = secrets.token_hex(16)
                             await self.log_error(message, args, e, err_token)
                             prefix = await self.db.get_prefix(message)
                             title = '❗ An Error Occurred!'
                             err_text = 'Something seems to have gone wrong.'
                             err_text += '\nPlease send this token to our support server.'
                             err_text += f'\nThe invite link is in the **{prefix}help** command.'
                             err_text += f'\nToken: **{err_token}**'
                             error_embed = discord.Embed(color=0xBE1931)
                             error_embed.add_field(name=title, value=err_text)
                             try:
                                 await message.channel.send(embed=error_embed)
                             except discord.Forbidden:
                                 pass
                     else:
                         await self.respond_with_icon(message, '❗')
                         reqs_embed = discord.Embed(color=0xBE1931)
                         reqs_error_title = f'❗ Sigma is missing permissions!'
                         reqs_error_list = ''
                         for req in requirements.missing_list:
                             req = req.replace('_', ' ').title()
                             reqs_error_list += f'\n- {req}'
                         prefix = await self.db.get_prefix(message)
                         reqs_embed.add_field(name=reqs_error_title, value=f'```\n{reqs_error_list}\n```')
                         reqs_embed.set_footer(text=f'{prefix}{self.name} could not execute.')
                         try:
                             await message.channel.send(embed=reqs_embed)
                         except discord.Forbidden:
                             pass
                 else:
                     self.log.warning('ACCESS DENIED: This module or command is not allowed in this location.')
                     await self.respond_with_icon(message, '⛔')
             else:
                 perms.log_unpermitted()
                 await self.respond_with_icon(message, '⛔')
                 if perms.response:
                     try:
                         await message.channel.send(embed=perms.response)
                     except discord.Forbidden:
                         pass
         else:
             await self.respond_with_icon(message, '🕙')