Exemple #1
0
    async def run(self, context: Context) -> None:
        """
        Run the navigator under the given context.

        Args:
            context (:obj:`~.context.Context`): Context to run the navigator under

        Returns:
            ``None``

        Raises:
            :obj:`hikari.MissingIntentError`: If the bot does not have the relevant reaction intent(s) for
                the navigator to function.
        """
        intent_to_check_for = (hikari.Intents.GUILD_MESSAGE_REACTIONS
                               if context.guild_id is not None else
                               hikari.Intents.DM_MESSAGE_REACTIONS)
        if not (context.bot.intents
                & intent_to_check_for) == intent_to_check_for:
            raise hikari.MissingIntentError(intent_to_check_for)

        self._context = context
        context.bot.subscribe(hikari.ReactionAddEvent,
                              self._process_reaction_add)
        self._msg = await self._send_initial_msg(
            self.pages[self.current_page_index])
        for emoji in [button.emoji for button in self.buttons]:
            await self._msg.add_reaction(emoji)

        if self._timeout_task is not None:
            self._timeout_task.cancel()
        self._timeout_task = asyncio.create_task(self._timeout_coro())
Exemple #2
0
async def _has_guild_permissions(ctx: context.Context, *, permissions: hikari.Permissions):
    if not (ctx.bot.intents & hikari.Intents.GUILDS) == hikari.Intents.GUILDS:
        raise hikari.MissingIntentError(hikari.Intents.GUILDS)

    await _guild_only(ctx)

    roles = ctx.bot.cache.get_roles_view_for_guild(ctx.guild_id).values()
    missing_perms = _get_missing_perms(permissions, [role for role in roles if role.id in ctx.member.role_ids])

    if missing_perms:
        raise errors.MissingRequiredPermission(
            "You are missing one or more permissions required in order to run this command", permissions=missing_perms
        )
    return True
Exemple #3
0
    async def run(self, context: lightbulb.Context) -> None:
        intent_to_check_for = (hikari.Intents.GUILD_MESSAGE_REACTIONS
                               if context.guild_id is not None else
                               hikari.Intents.DM_MESSAGE_REACTIONS)
        if not (context.app.intents
                & intent_to_check_for) == intent_to_check_for:
            raise hikari.MissingIntentError(intent_to_check_for)

        self._context = context
        context.app.subscribe(hikari.ReactionAddEvent,
                              self._process_reaction_add)
        self._msg = await self._send_initial_message(self.__menu__)
        for button in self._get_available_buttons(self.__menu__):
            await self._msg.add_reaction(button.emoji)

        if self._timeout_task is not None:
            self._timeout_task.cancel()
        self._timeout_task = asyncio.create_task(self._timeout_coro())
Exemple #4
0
async def _has_permissions(ctx: context.Context, *, permissions: hikari.Permissions) -> bool:
    if not (ctx.bot.intents & hikari.Intents.GUILDS) == hikari.Intents.GUILDS:
        raise hikari.MissingIntentError(hikari.Intents.GUILDS)

    await _guild_only(ctx)

    perm_over = ctx.channel.permission_overwrites.values()
    perm_none = hikari.Permissions.NONE

    allowed_perms = functools.reduce(
        operator.or_, (override.allow if override.id in ctx.member.role_ids else perm_none for override in perm_over)
    )

    missing_perms = allowed_perms ^ permissions

    if missing_perms:
        raise errors.MissingRequiredPermission(
            "You are missing one or more permissions required in order to run this command", permissions=missing_perms
        )
    return True
Exemple #5
0
    async def run(self, context: lightbulb.context.Context) -> None:
        intent_to_check_for = (hikari.Intents.GUILD_MESSAGE_REACTIONS
                               if context.guild_id is not None else
                               hikari.Intents.DM_MESSAGE_REACTIONS)
        if not (context.app.intents
                & intent_to_check_for) == intent_to_check_for:
            raise hikari.MissingIntentError(intent_to_check_for)

        self._context = context
        context.app.subscribe(hikari.ReactionAddEvent,
                              self._process_reaction_add)
        if self._msg is None:
            self._msg = await self._send_initial_msg(
                self.pages[self.current_page_index])
        else:
            await self._msg.edit(self.pages[self.current_page_index])
        for button in self.buttons:
            await self._msg.add_reaction(button.emoji)

        if self._timeout_task is not None:
            self._timeout_task.cancel()
        self._timeout_task = asyncio.create_task(self._timeout_coro())