Skip to main content

Module discord

Module discord 

Source
Expand description

Discord message link expansion.

This module provides functionality for parsing Discord message links and generating embed previews of the linked messages.

Migrated from preview.rs with support for multiple link expansion.

Re-exportsΒ§

use futures_util::future::join_all; πŸ”’
use futures_util::future::try_join_all; πŸ”’
use regex::Regex; πŸ”’
use std::collections::HashMap; πŸ”’
use std::collections::HashSet; πŸ”’
use std::sync::LazyLock; πŸ”’
use twilight_http::error::ErrorType; πŸ”’
use twilight_model::channel::message::Embed; πŸ”’
use twilight_model::channel::permission_overwrite::PermissionOverwrite; πŸ”’
use twilight_model::channel::permission_overwrite::PermissionOverwriteType; πŸ”’
use twilight_model::channel::Channel; πŸ”’
use twilight_model::channel::ChannelType; πŸ”’
use twilight_model::channel::Message; πŸ”’
use twilight_model::guild::Permissions; πŸ”’
use twilight_model::id::Id; πŸ”’
use twilight_model::id::marker::ChannelMarker; πŸ”’
use twilight_model::id::marker::GuildMarker; πŸ”’
use twilight_model::id::marker::MessageMarker; πŸ”’
use twilight_model::id::marker::RoleMarker; πŸ”’
use twilight_model::id::marker::UserMarker; πŸ”’
use twilight_model::user::User; πŸ”’
use twilight_util::builder::embed::EmbedAuthorBuilder; πŸ”’
use twilight_util::builder::embed::EmbedBuilder; πŸ”’
use twilight_util::builder::embed::EmbedFooterBuilder; πŸ”’
use twilight_util::builder::embed::ImageSource; πŸ”’
use super::ExpandContext; πŸ”’
use super::ExpandError; πŸ”’
use super::ExpandedContent; πŸ”’
use super::LinkExpander; πŸ”’
use crate::cache::CacheArgs; πŸ”’
use crate::cache::RolePermissions; πŸ”’
use crate::config::BabyriteConfig; πŸ”’
use crate::context::BotContext; πŸ”’

StructsΒ§

ChannelOverwrites πŸ”’
A channel’s permission overwrites, split by what they target and masked to the permissions that matter for that channel.
DiscordExpander
Discord message link expander.
MessageLinkIDs
Parsed IDs from a Discord message link.
Preview
A preview containing the message and its channel.
RoleGrant πŸ”’
What a set of roles contributes to a member’s permissions in the source and target channels.
Visibility πŸ”’
Decides whether everyone who can read the source channel could also read the target channel.

EnumsΒ§

PreviewError
Errors that can occur when generating a Discord message preview.

ConstantsΒ§

MAX_MEMBER_LOOKUPS πŸ”’
Most members check_visibility looks up for a single link.
NO_OVERWRITE πŸ”’
PREVIEW_EMBED_COLOUR πŸ”’
Accent colour of a message preview embed.
READ_SOURCE πŸ”’
Permissions a member needs to read the expanded reply in the source channel.
READ_TARGET πŸ”’
Permissions a member needs to read the linked message in a text channel.

StaticsΒ§

MESSAGE_LINK_REGEX
Regex pattern for matching Discord message links.

FunctionsΒ§

avatar_url πŸ”’
Returns the CDN URL of user’s avatar, or None when they have none.
channel_permissions πŸ”’
Applies Discord’s permission algorithm to one channel.
check_visibility πŸ”’
Validates that everyone who can read source_channel could also read the linked message in channel.
has_unknown_overwrite πŸ”’
Returns true if any overwrite targets a kind Discord added after this library was written.
has_unlisted_readers πŸ”’
Returns true when the readers of a channel of kind cannot be evaluated.
is_cross_guild πŸ”’
Returns true when a link crosses a guild boundary.
is_thread πŸ”’
Returns true for thread channel types.
member_roles πŸ”’
Fetches the roles of user_id, or None when they are not in the guild.
overwrites πŸ”’
The permission overwrites of channel; Discord omits the field when empty.
permission_channel πŸ”’
Resolves the channel that carries the properties a thread inherits β€” its permission overwrites and its NSFW flag.
preview_embed πŸ”’
Renders a fetched message as the embed posted in the requester’s channel.
read_source_requirement πŸ”’
Permissions a member needs to read the expanded reply in the source channel, when the link points to a channel of target_kind.
read_target_requirement πŸ”’
Permissions a member needs to read the linked message in a channel of kind.

Type AliasesΒ§

OverwritePair πŸ”’
The (allow, deny) pair of a permission overwrite.