Exemple #1
0
    async def parse_poll_options(self, ctx, options):
        emote_options = {}
        is_valid_emote = (lambda e: e in EMOJI_UNICODE_ENGLISH.values() or e in
                          EMOJI_ALIAS_UNICODE_ENGLISH.values())
        encoded = options[0].split(":")[0].strip().encode()
        # check if user wants to have custom emotes
        first_emote = options[0].split(":")[0].strip()
        if (is_valid_emote(first_emote)
                or is_valid_emote(self.remove_last_char(first_emote))
                or get_custom_emote(ctx, ":".join(options[0].split(":")[:3]))):
            for option in options:
                option = option.strip()
                option_split = option.split(":")
                emote = option_split[0].replace(" ", "")
                custom_emote = get_custom_emote(ctx,
                                                ":".join(option_split[:3]))

                if custom_emote:
                    emote = str(custom_emote)
                    option = ":".join(option_split[3:])
                else:
                    option = ":".join(option_split[1:])

                if len(option_split) > 1:
                    emote_options[emote] = option
                # in case user wanted to use options with emotes, but one of them didn't match
                else:
                    return await embed_maker.error(
                        ctx, f"Invalid emote provided for option: {emote}")
        else:
            if len(options) > 9:
                return await embed_maker.error(
                    ctx,
                    "Too many options given, max without custom emotes is 9")

            all_num_emotes = [
                "1️⃣",
                "2️⃣",
                "3️⃣",
                "4️⃣",
                "5️⃣",
                "6️⃣",
                "7️⃣",
                "8️⃣",
                "9️⃣",
            ]
            emote_options = {
                e: options[i]
                for i, e in enumerate(all_num_emotes[:len(options)])
            }

        return emote_options
Exemple #2
0
    async def emote_roles(self, ctx, user_input: str = None):
        if user_input is None:
            return await embed_maker.command_error(ctx)

        # check if user_input is emote
        role = None

        emote = get_custom_emote(ctx, user_input)
        if not emote:
            role = await get_guild_role(ctx.guild, user_input)

        if emote:
            if emote.roles:
                return await embed_maker.message(
                    ctx,
                    description=
                    f'This emote is restricted to: {", ".join([f"<@&{r.id}>" for r in emote.roles])}',
                    send=True)
            else:
                return await embed_maker.message(
                    ctx,
                    description='This emote is available to everyone',
                    send=True)
        elif role:
            emotes = []
            for emote in ctx.guild.emojis:
                if role in emote.roles:
                    emotes.append(emote)

            if emotes:
                return await embed_maker.message(
                    ctx,
                    description=
                    f'This role has access to: {", ".join([f"<:{emote.name}:{emote.name}> " for emote in emotes])}',
                    send=True)
            else:
                return await embed_maker.message(
                    ctx,
                    description=
                    'This role doesn\'t have special access to any emotes',
                    send=True)
Exemple #3
0
    async def emote_role(self, ctx: Context, action: str = None, *, args: Union[ParseArgs, dict] = None):
        if action and action.isdigit():
            page = int(action)
        else:
            page = 1

        if action not in ['add', 'remove']:
            emotes = ctx.guild.emojis
            max_pages = math.ceil(len(emotes) / 10)

            if page > max_pages or page < 1:
                return await embed_maker.error(ctx, 'Invalid page number given')

            emotes = emotes[10 * (page - 1):10 * page]

            description = ''
            index = 0
            for emote in emotes:
                if not emote.roles:
                    continue

                emote_roles = " | ".join(f'<@&{role.id}>' for role in emote.roles)
                description += f'\n<:{emote.name}:{emote.id}> -> {emote_roles}'
                index += 1

                if index == 10:
                    break

            return await embed_maker.message(
                ctx,
                description=description,
                send=True,
                footer={'text': f'Page {page}/{max_pages}'}
            )

        # return error if required variables are not given
        if 'role' not in args or not args['role']:
            return await embed_maker.error(ctx, "Missing role arg")

        if 'emotes' not in args or not args['emotes']:
            return await embed_maker.error(ctx, "Missing emotes arg")

        role = await get_guild_role(ctx.guild, args['role'])
        emotes = args['emotes']

        if not emotes:
            return await embed_maker.command_error(ctx, '[emotes]')

        if not role:
            return await embed_maker.command_error(ctx, '[role]')

        emote_list = [*filter(lambda e: e is not None, [get_custom_emote(ctx, emote) for emote in emotes.split(' ')])]
        if not emote_list:
            return await embed_maker.command_error(ctx, '[emotes]')

        msg = None
        for emote in emote_list:
            emote_roles = emote.roles

            if action == 'add':
                emote_roles.append(role)
                # add bot role to emote_roles
                if ctx.guild.self_role not in emote_roles:
                    emote_roles.append(ctx.guild.self_role)

                emote_roles = [*set(emote_roles)]

                await emote.edit(roles=emote_roles)

            elif action == 'remove':
                for i, r in enumerate(emote_roles):
                    if r.id == role.id:
                        emote_roles.pop(i)
                        await emote.edit(roles=emote_roles)
                else:
                    msg = f'<@&{role.id}> is not whitelisted for emote {emote}'
                    break

        if not msg:
            if action == 'add':
                msg = f'<@&{role.id}> has been added to whitelisted roles of emotes {emotes}'
            elif action == 'remove':
                msg = f'<@&{role.id}> has been removed from whitelisted roles of emotes {emotes}'

        return await embed_maker.message(ctx, description=msg, colour='green', send=True)