channel_sync#

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. 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.

sync_pinned_post() keeps one pinned embed (a guide, a panel) in a channel others also post in, found again by its title.

sidequest_bot.lib.channel_sync.logger#
sidequest_bot.lib.channel_sync.find_text_channel(guild: discord.Guild, name: str) → discord.TextChannel | None[source]#

The one text channel called name anywhere in guild, or None.

async sidequest_bot.lib.channel_sync.ensure_channel_below(guild: discord.Guild, *, name: str, anchor_name: str, topic: str, reason: str) → discord.TextChannel | None[source]#

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.

class sidequest_bot.lib.channel_sync.RenderedPost(*, content: str | None = None, embed: discord.Embed | None = None)[source]#

One message to sync: either plain content (an intro) or a single section embed, never both.

content = None#
embed = None#
async sidequest_bot.lib.channel_sync.sync_messages(channel: discord.TextChannel, bot_user_id: int, posts: collections.abc.Sequence[RenderedPost], *, history_limit: int = 50) → None[source]#

Edit, post or delete channel’s own messages so they match posts, touching nothing else.

async sidequest_bot.lib.channel_sync.find_pinned_post(channel: discord.TextChannel, bot_user_id: int, title: str | None, *, history_limit: int = 100) → discord.Message | None[source]#

The bot’s post whose embed is titled title: among the pins, or else in recent history.

async sidequest_bot.lib.channel_sync.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[source]#

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.