channel_sync ============ .. py:module:: sidequest_bot.lib.channel_sync .. autoapi-nested-parse:: Shared logic for channels the bot keeps in step with backend data (``#addons``, ``#roles``, ...). Each read-only mirror channel is created once, below a fixed anchor channel with the anchor's own visibility, then holds one message per rendered section: plain ``content`` for an intro, or a single embed per section. :func:`sync_messages` edits, posts or deletes the channel's own messages so they match the wanted list, touching nothing else and never reposting unchanged content. :func:`sync_pinned_post` keeps one pinned embed (a guide, a panel) in a channel others also post in, found again by its title. .. py:data:: logger .. py:function:: find_text_channel(guild: discord.Guild, name: str) -> discord.TextChannel | None The one text channel called ``name`` anywhere in ``guild``, or ``None``. .. py:function:: ensure_channel_below(guild: discord.Guild, *, name: str, anchor_name: str, topic: str, reason: str) -> discord.TextChannel | None :async: The existing channel called ``name``, or a new one placed right below ``anchor_name`` with its overwrites. ``None`` if neither ``name`` nor ``anchor_name`` exists yet. .. py:class:: RenderedPost(*, content: str | None = None, embed: discord.Embed | None = None) One message to sync: either plain ``content`` (an intro) or a single section ``embed``, never both. .. py:attribute:: content :value: None .. py:attribute:: embed :value: None .. py:function:: sync_messages(channel: discord.TextChannel, bot_user_id: int, posts: collections.abc.Sequence[RenderedPost], *, history_limit: int = 50) -> None :async: Edit, post or delete ``channel``'s own messages so they match ``posts``, touching nothing else. .. py:function:: find_pinned_post(channel: discord.TextChannel, bot_user_id: int, title: str | None, *, history_limit: int = 100) -> discord.Message | None :async: The bot's post whose embed is titled ``title``: among the pins, or else in recent history. .. py:function:: sync_pinned_post(channel: discord.TextChannel, bot_user_id: int, embed: discord.Embed, *, view: discord.ui.View | None = None, pin_reason: str, history_limit: int = 100) -> None :async: Edit the bot's post titled like ``embed`` if its text changed, or post and pin it if it's missing. Only the embed's text is compared, so ``view`` should be fixed for a given embed. A failed pin is left for the next call to find in history rather than raised; any other Discord error is.