Ejemplo n.º 1
0
 async def add_admin(self, ctx):
     try:
         command = bot_tools.parse_command(ctx.message.content, 1)
     except ValueError:
         await ctx.send(embed=bot_tools.create_simple_embed(
             ctx=ctx,
             _title='Error',
             _description=
             f'{ctx.command.usage}. Use `!help {ctx.command.name}` for more details.'
         ))
         return
     [_, role_name] = command
     if bot_db.exists_admin_role(role_name):
         await ctx.send(embed=bot_tools.create_simple_embed(
             ctx=ctx,
             _title='Error',
             _description=f'The role `{role_name}` is already an admin.'))
         return
     else:
         if role_name in [roles.name for roles in ctx.guild.roles]:
             bot_db.add_admin_role(role_name)
             await ctx.send(embed=bot_tools.create_simple_embed(
                 ctx=ctx,
                 _title='Admin roles',
                 _description=
                 f'Successfully added the role `{role_name}` to the list of admins.'
             ))
         else:
             await ctx.send(embed=bot_tools.create_simple_embed(
                 ctx=ctx,
                 _title='Error',
                 _description=
                 f'The role `{role_name}` does not exist on this server.'))
Ejemplo n.º 2
0
 async def remove_admin(self, ctx):
     try:
         command = bot_tools.parse_command(ctx.message.content, 1)
     except ValueError:
         await ctx.send(embed=bot_tools.create_simple_embed(
             ctx=ctx,
             _title='Error',
             _description=
             f'{ctx.command.usage}. Use `!help {ctx.command.name}` for more details.'
         ))
         return
     [_, role_name] = command
     if not bot_db.exists_admin_role(role_name):
         await ctx.send(embed=bot_tools.create_simple_embed(
             ctx=ctx,
             _title='Error',
             _description=
             f'The role `{role_name}` is not on the list of admins.'))
         return
     else:
         bot_db.remove_admin_role(role_name)
         await ctx.send(embed=bot_tools.create_simple_embed(
             ctx=ctx,
             _title='Admin roles',
             _description=
             f'Successfully removed the role `{role_name}` from the list of admins.'
         ))
Ejemplo n.º 3
0
 async def get_tag(self, ctx):
     try:
         command = bot_tools.parse_command(ctx.message.content, 1)
     except ValueError:
         try:
             command = bot_tools.parse_command(ctx.message.content, 0)
         except:
             await ctx.send(embed=bot_tools.create_simple_embed(
                 ctx=ctx,
                 _title='Error',
                 _description=
                 f'{ctx.command.usage}. Use `!help {ctx.command.name}` for more details.'
             ))
             return
     if len(command) == 1:
         tags = [t['name'] for t in bot_db.get_all_tags()]
         await ctx.send(embed=bot_tools.create_list_embed(
             ctx=ctx,
             _title='Tags',
             _description='Here is a list of all the tags you can use.',
             _field_name='Tags',
             items=tags))
     else:
         [_, tag_name] = command
         tag = bot_db.get_tag(tag_name)
         if not bot_db.exists_tag(tag_name):
             await ctx.send(embed=bot_tools.create_simple_embed(
                 ctx=ctx,
                 _title='Error',
                 _description=f'The Tag `{tag_name}` does not exists.'))
         else:
             await ctx.send(tag['response'])
Ejemplo n.º 4
0
 async def user_info(self, ctx):
     try:
         command = bot_tools.parse_command(ctx.message.content, 1)
     except ValueError:
         try:
             command = bot_tools.parse_command(ctx.message.content, 0)
         except ValueError:
             await ctx.send(embed=bot_tools.create_simple_embed(
                 ctx=ctx,
                 _title='Error',
                 _description=
                 f'{ctx.command.usage}. Use `!help {ctx.command.name}` for more details.'
             ))
             return
     if len(command) == 1:
         member = ctx.guild.get_member(ctx.author.id)
         await ctx.send(embed=self.create_user_embed(ctx, member))
     else:
         [_, mention] = command
         user_id = 0
         try:
             user_id = int(
                 mention.replace('<@', '').replace('>',
                                                   '').replace('!', ''))
         except ValueError:
             await ctx.send(embed=bot_tools.create_simple_embed(
                 ctx=ctx, _title='Error', _description='Not a valid ping!'))
             return
         member = ctx.guild.get_member(user_id)
         if member == None:
             await ctx.send(embed=bot_tools.create_simple_embed(
                 ctx=ctx, _title='Error', _description='Not a valid ping!'))
         else:
             await ctx.send(embed=self.create_user_embed(ctx, member))
Ejemplo n.º 5
0
    async def on_command_error(self, ctx, error):
        """The event triggered when an error is raised while invoking a command.
        ctx    : Context
        error  : Exception"""

        if hasattr(ctx.command, 'on_error'):
            return

        ignored = (commands.CommandNotFound, commands.UserInputError)
        error = getattr(error, 'original', error)

        if isinstance(error, ignored):
            return
        
        elif isinstance(error, commands.DisabledCommand):
            return await ctx.send(embed=bot_tools.create_simple_embed(_title='Error', _description=f'{ctx.command} has been disabled.'))

        elif isinstance(error, commands.NoPrivateMessage):
            try:
                return await ctx.author.send(embed=bot_tools.create_simple_embed(_title='Error', _description=f'{ctx.command} can not be used in DMs.'))
            except:
                pass


        elif isinstance(error, bot_tools.AdminCheckFailure):
            return await ctx.send(embed=bot_tools.create_simple_embed(_title='Error', _description=f'{ctx.command} can only be used by admins.'))

        elif isinstance(error, bot_tools.OwnerCheckFailure):
            return await ctx.send(embed=bot_tools.create_simple_embed(_title='Error', _description=f'{ctx.command} can only be used by the server owner.'))


        print('Ignoring exception in command {}:'.format(ctx.command), file=sys.stderr)
        traceback.print_exception(type(error), error, error.__traceback__, file=sys.stderr)
Ejemplo n.º 6
0
 async def add_vc_role(self, ctx):
     try:
         command = bot_tools.parse_command(ctx.message.content, 2)
     except:
         await ctx.send(embed=bot_tools.create_simple_embed(
             ctx=ctx,
             _title='Error',
             _description=
             f'{ctx.command.usage}. Use `!help {ctx.command.name}` for more details.'
         ))
         return
     [_, vc_id, tc_id] = command
     vc_id = int(vc_id)
     tc_id = int(tc_id)
     vc = ctx.guild.get_channel(vc_id)
     tc = ctx.guild.get_channel(tc_id)
     if bot_db.exists_voice_text(vc_id):
         await ctx.send(embed=bot_tools.create_simple_embed(
             ctx=ctx,
             _title='Error',
             _description=f'The role for `{vc.name}` is already set up.'))
         return
     else:
         if vc is None:
             await ctx.send(embed=bot_tools.create_simple_embed(
                 ctx=ctx,
                 _title='Error',
                 _description=
                 f'A voice channel with the provided id `{vc_id}` does not exist in this server!'
             ))
             return
         elif tc is None:
             await ctx.send(embed=bot_tools.create_simple_embed(
                 ctx=ctx,
                 _title='Error',
                 _description=
                 f'A text channel with the provided id `{tc_id}` does not exist in this server!'
             ))
             return
         else:
             # create role, set up perms, add db entry
             role = await ctx.guild.create_role(name=f'In {vc.name}')
             await tc.set_permissions(role, read_messages=True)
             bot_db.add_voice_text(vc_id, tc_id, role.id)
             await ctx.send(embed=bot_tools.create_simple_embed(
                 ctx=ctx,
                 _title='Voice role',
                 _description=
                 f'Successfully created the role `{role.name}` for users in `{vc.name}` to see `{tc.name}`.'
             ))
Ejemplo n.º 7
0
    async def purge_role(self, ctx):
        try:
            command = bot_tools.parse_command(ctx.message.content, 1)
        except ValueError:
            await ctx.send(embed=bot_tools.create_simple_embed(
                ctx=ctx,
                _title='Error',
                _description=
                f'{ctx.command.usage}. Use `!help {ctx.command.name}` for more details.'
            ))
            return

        [_, roles] = command
        roles = roles.split()
        role_ids = [
            int(role.replace('<@&', '').replace('>', '')) for role in roles
        ]
        invalid_roles = []
        valid_roles = []
        for role in role_ids:
            role_obj = discord.utils.get(ctx.guild.roles, id=role)
            if role_obj is None:
                invalid_roles.append(role)
            else:
                valid_roles.append(role_obj)

        invalid_roles_string = ' '.join(invalid_roles)
        if len(invalid_roles) > 0:
            await ctx.send(embed=bot_tools.create_simple_embed(
                ctx=ctx,
                _title='Error',
                _description=
                f'{invalid_roles_string} is/are not valid roles on this server.'
            ))
            return

        for user in ctx.guild.members:
            for role in valid_roles:
                if role in user.roles:
                    await user.remove_roles(role, reason=None, atomic=True)

        roles_string = ' '.join(roles)
        await ctx.send(embed=bot_tools.create_simple_embed(
            ctx=ctx,
            _title='Purge Role',
            _description=f'Successfully purged the role(s) {roles_string}.'))
Ejemplo n.º 8
0
    async def eightball(self, ctx):
        try:
            command = bot_tools.parse_command(ctx.message.content, 1)
        except:
            await ctx.send(embed=bot_tools.create_simple_embed(
                ctx=ctx,
                _title='Error',
                _description=
                f'{ctx.command.usage}. Use `!help {ctx.command.name}` for more details.'
            ))
            return

        [_, message] = command

        await ctx.send(embed=create_eightball_embed(ctx.author.name, message))
Ejemplo n.º 9
0
 async def remove_tag(self, ctx):
     try:
         command = bot_tools.parse_command(ctx.message.content, 1)
     except ValueError:
         await ctx.send(embed=bot_tools.create_simple_embed(
             ctx=ctx,
             _title='Error',
             _description=
             f'{ctx.command.usage}. Use `!help {ctx.command.name}` for more details.'
         ))
         return
     [_, tag_name] = command
     if not bot_db.exists_tag(tag_name):
         await ctx.send(embed=bot_tools.create_simple_embed(
             ctx=ctx,
             _title='Error',
             _description=f'`{tag_name}` does not exists!'))
         return
     else:
         bot_db.remove_tag(tag_name)
         await ctx.send(embed=bot_tools.create_simple_embed(
             ctx=ctx,
             _title='Tag',
             _description=f'Successfully removed tag `{tag_name}`'))
Ejemplo n.º 10
0
 async def add_tag(self, ctx):
     try:
         command = bot_tools.parse_command(ctx.message.content, 2)
     except ValueError:
         await ctx.send(embed=bot_tools.create_simple_embed(
             ctx=ctx,
             _title='Error',
             _description=
             f'{ctx.command.usage}. Use `!help {ctx.command.name}` for more details.'
         ))
         return
     [_, tag_name, tag_content] = command
     if bot_db.exists_tag(tag_name):
         await ctx.send(embed=bot_tools.create_simple_embed(
             ctx=ctx,
             _title='Error',
             _description=f'The tag `{tag_name}` already exists.'))
         return
     else:
         bot_db.add_tag(tag_name, tag_content)
         await ctx.send(embed=bot_tools.create_simple_embed(
             ctx=ctx,
             _title='Tag',
             _description=f'Successfully added tag `{tag_name}`!'))
Ejemplo n.º 11
0
    async def remove_vc_role(self, ctx):
        try:
            command = bot_tools.parse_command(ctx.message.content, 1)
        except:
            await ctx.send(embed=bot_tools.create_simple_embed(
                ctx=ctx,
                _title='Error',
                _description=
                f'{ctx.command.usage}. Use `!help {ctx.command.name}` for more details.'
            ))
            return
        [_, vc_id] = command
        vc_id = int(vc_id)
        vc = ctx.guild.get_channel(vc_id)

        if bot_db.exists_voice_text(vc_id):
            entry = bot_db.get_voice_text(vc_id)
            role = ctx.guild.get_role(entry['r_id'])
            role_name = role.name
            tc = ctx.guild.get_channel(entry['tc_id'])
            await role.delete()
            bot_db.remove_voic_text(vc_id)
            await ctx.send(embed=bot_tools.create_simple_embed(
                ctx=ctx,
                _title='Voice role',
                _description=
                f'Successfully removed the voice role `{role_name}` from the voice/text pair `{vc.name}`/`{tc.name}`.'
            ))
            return
        else:
            await ctx.send(embed=bot_tools.create_simple_embed(
                ctx=ctx,
                _title='Error',
                _description=
                f'The specified voice chat id `{vc_id}` does not correspond to any role currently associated with a voice/text channel pair.'
            ))
Ejemplo n.º 12
0
    async def help_message(self, ctx):
        cogs = [
            cog for cog in self.bot.cogs.values() if cog.description[0] != '0'
        ]
        cogs = sorted(cogs, key=lambda x: x.qualified_name)
        other_commands = [
            command for command in self.bot.commands if command.cog is None
        ]
        try:
            command = bot_tools.parse_command(ctx.message.content, 1)
        except ValueError:
            try:
                command = bot_tools.parse_command(ctx.message.content, 0)
            except ValueError:
                return
            right_arrow = '\U000027A1'
            left_arrow = '\U00002B05'

            embeds = await create_help_embeds(ctx, cogs, other_commands)
            current = 0

            help_message = await ctx.send(embed=embeds[current])
            await help_message.add_reaction(left_arrow)
            await help_message.add_reaction(right_arrow)

            def check(reaction, user):
                return user == ctx.message.author and user != self.bot.user and (
                    str(reaction.emoji) == right_arrow
                    or left_arrow and reaction.message == help_message)

            while (True):
                try:
                    reaction, user = await self.bot.wait_for('reaction_add',
                                                             timeout=600.0,
                                                             check=check)
                except asyncio.TimeoutError:
                    await help_message.remove_reaction(left_arrow,
                                                       help_message.author)
                    await help_message.remove_reaction(right_arrow,
                                                       help_message.author)
                    return
                if str(reaction.emoji) == right_arrow:
                    if current < len(embeds) - 1:
                        current += 1
                        await help_message.edit(embed=embeds[current])
                    await reaction.remove(user)
                elif str(reaction.emoji) == left_arrow:
                    if current > 0:
                        current -= 1
                        await help_message.edit(embed=embeds[current])
                    await reaction.remove(user)

        [_, command_name] = command
        command_name = command_name.replace('!', '').replace('`', '')
        requested_command = discord.utils.get(self.bot.commands,
                                              name=command_name)
        if requested_command is None:
            for command in self.bot.commands:
                if command_name in command.aliases:
                    requested_command = command
            if requested_command is None:
                await ctx.send(embed=bot_tools.create_simple_embed(
                    ctx, 'Error',
                    f'Not a recoginzed command. {ctx.command.usage}'))
                return
        await ctx.send(
            embed=create_commmand_help_embed(ctx, requested_command))
Ejemplo n.º 13
0
    async def set_role_message(self, ctx):
        try:
            command = bot_tools.parse_command(ctx.message.content, 2)
        except ValueError:
            await ctx.send(embed=bot_tools.create_simple_embed(
                ctx=ctx,
                _title='Error',
                _description=
                f'{ctx.command.usage}. Use `!help {ctx.command.name}` for more details.'
            ))
            return

        [_, ch_id, msg_id] = command
        try:
            ch_id = int(ch_id)
            msg_id = int(msg_id)
        except:
            await ctx.send(embed=bot_tools.create_simple_embed(
                ctx=ctx, _title='Error', _description='IDs must be numbers!'))
            return
        data = bot_db.get_role_data()
        if data is None:
            channel = discord.utils.get(ctx.guild.text_channels, id=ch_id)
            if channel is None:
                await ctx.send(embed=bot_tools.create_simple_embed(
                    ctx=ctx,
                    _title='Error',
                    _description='Not a valid channel id!'))
                return
            message = discord.utils.get(await channel.history().flatten(),
                                        id=msg_id)
            if message is None:
                await ctx.send(embed=bot_tools.create_simple_embed(
                    ctx=ctx,
                    _title='Error',
                    _description='Not a valid message id!'))
                return
            bot_db.fill_role_data(msg_id, ch_id)
            await ctx.send(embed=bot_tools.create_simple_embed(
                ctx=ctx,
                _title='Reaction Role Message',
                _description=
                f'Successfully set reaction role channel to <#{channel.id}> and message to {message.jump_url} !'
            ))
        else:
            channel = discord.utils.get(ctx.guild.text_channels,
                                        id=data[0]['channel_id'])
            message = discord.utils.get(await channel.history().flatten(),
                                        id=data[0]['message_id'])

            try:
                response = await ctx.send(embed=bot_tools.create_simple_embed(
                    ctx=ctx,
                    _title='Reaction Role Message',
                    _description=
                    f'The current reaction role channel is <#{channel.id}> and the message {message.jump_url} ! Are you sure you want to change it?'
                ))
            except:
                response = await ctx.send(embed=bot_tools.create_simple_embed(
                    ctx=ctx,
                    _title='Reaction Role Message',
                    _description=
                    f'The current reaction role channel is <#{channel.id}> but the message cannot be found. It was most likely deleted. Do you want to overwrite?'
                ))
            check_mark = '\U00002714'
            cross_mark = '\U0000274C'
            await response.add_reaction(check_mark)
            await response.add_reaction(cross_mark)

            def check(reaction, user):
                return user == ctx.message.author and user != self.bot.user and (
                    str(reaction.emoji) == check_mark or cross_mark)

            try:
                reaction, user = await self.bot.wait_for('reaction_add',
                                                         timeout=60.0,
                                                         check=check)
            except asyncio.TimeoutError:
                await ctx.send('Timed out! Try again!')
                return
            else:
                if str(reaction.emoji) == check_mark:
                    channel = discord.utils.get(ctx.guild.text_channels,
                                                id=ch_id)
                    if channel is None:
                        await ctx.send(embed=bot_tools.create_simple_embed(
                            ctx=ctx,
                            _title='Error',
                            _description='Not a valid channel id!'))
                        return
                    message = discord.utils.get(await
                                                channel.history().flatten(),
                                                id=msg_id)
                    if message is None:
                        await ctx.send(embed=bot_tools.create_simple_embed(
                            ctx=ctx,
                            _title='Error',
                            _description='Not a valid message id!'))
                        return
                    bot_db.change_role_data(msg_id, ch_id)
                    await ctx.send(embed=bot_tools.create_simple_embed(
                        ctx=ctx,
                        _title='Reaction Role Message',
                        _description=
                        f'Successfully set reaction role channel to <#{channel.id}> and message to {message.jump_url} !'
                    ))
                elif str(reaction.emoji) == cross_mark:
                    await ctx.send('Cancelled!')
                    return

        message_words = message.content.split()

        filtered_message = [
            entry.replace('<', '').replace('>', '').replace('@&', '')
            for entry in message_words if '<' in entry
        ]

        emote_dict = {}

        for emote, role in bot_tools.grouped(filtered_message, 2):
            emote_dict.update({emote: int(role)})

        bot_db.update_role_data(emote_dict)

        for emote, role in emote_dict.items():
            emote_id = emote.split(':')[2]
            emoji = self.bot.get_emoji(int(emote_id))
            await message.add_reaction(emoji)