Source code for miru.ext.nav.navigator

from __future__ import annotations

import logging
import typing as t

import attr
import hikari

from miru.context import Context
from miru.view import View

from .items import FirstButton, IndicatorButton, LastButton, NavButton, NavItem, NextButton, PrevButton

if t.TYPE_CHECKING:
    import datetime

    import typing_extensions as te

    from miru.abc import Item

logger = logging.getLogger(__name__)

__all__ = ("NavigatorView", "Page")






[docs] @attr.define(slots=True) class Page: """Allows for the building of more complex pages for use with NavigatorView.""" content: hikari.UndefinedOr[t.Any] = hikari.UNDEFINED """The content of the message. Anything passed here will be cast to str.""" attachment: hikari.UndefinedOr[hikari.Resourceish] = hikari.UNDEFINED """An attachment to add to this page.""" attachments: hikari.UndefinedOr[t.Sequence[hikari.Resourceish]] = hikari.UNDEFINED """A sequence of attachments to add to this page.""" embed: hikari.UndefinedOr[hikari.Embed] = hikari.UNDEFINED """An embed to add to this page.""" embeds: hikari.UndefinedOr[t.Sequence[hikari.Embed]] = hikari.UNDEFINED """A sequence of embeds to add to this page.""" mentions_everyone: hikari.UndefinedOr[bool] = hikari.UNDEFINED """If True, mentioning @everyone will be allowed in this page's message.""" user_mentions: hikari.UndefinedOr[t.Union[hikari.SnowflakeishSequence[hikari.PartialUser], bool]] = hikari.UNDEFINED """The set of allowed user mentions in this page's message. Set to True to allow all.""" role_mentions: hikari.UndefinedOr[t.Union[hikari.SnowflakeishSequence[hikari.PartialRole], bool]] = hikari.UNDEFINED """The set of allowed role mentions in this page's message. Set to True to allow all.""" def _build_payload(self) -> t.Dict[str, t.Any]: d: t.Dict[str, t.Any] = { "content": self.content or None, "attachments": self.attachments or None, "embeds": self.embeds or None, "mentions_everyone": self.mentions_everyone or False, "user_mentions": self.user_mentions or False, "role_mentions": self.role_mentions or False, } if not d["attachments"] and self.attachment: d["attachments"] = [self.attachment] if not d["embeds"] and self.embed: d["embeds"] = [self.embed] return d
# MIT License # # Copyright (c) 2022-present hypergonial # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE.