fluxer_util crate contains helper utilities that are independent of the client or structs.
Permissions
Permissions is a bitflags struct for working with Fluxer access permissions. Based on the bitflags 2 crate.
Flags
| Constant | Bit | Hex | Description |
|---|---|---|---|
CREATE_INSTANT_INVITE | 0 | 0x1 | Create invites. |
KICK_MEMBERS | 1 | 0x2 | Kick members. |
BAN_MEMBERS | 2 | 0x4 | Ban members. |
ADMINISTRATOR | 3 | 0x8 | All permissions, bypasses channel overwrites. |
MANAGE_CHANNELS | 4 | 0x10 | Manage channels. |
MANAGE_GUILD | 5 | 0x20 | Manage guild settings. |
ADD_REACTIONS | 6 | 0x40 | Add reactions. |
VIEW_AUDIT_LOG | 7 | 0x80 | View audit log. |
PRIORITY_SPEAKER | 8 | 0x100 | Priority speaker in voice channels. |
STREAM | 9 | 0x200 | Screen share (Go Live). |
VIEW_CHANNEL | 10 | 0x400 | View channel. |
SEND_MESSAGES | 11 | 0x800 | Send messages. |
SEND_TTS_MESSAGES | 12 | 0x1000 | Send TTS messages. |
MANAGE_MESSAGES | 13 | 0x2000 | Delete and pin others’ messages. |
EMBED_LINKS | 14 | 0x4000 | Embed links. |
ATTACH_FILES | 15 | 0x8000 | Attach files. |
READ_MESSAGE_HISTORY | 16 | 0x10000 | Read message history. |
MENTION_EVERYONE | 17 | 0x20000 | Mention @everyone and @here. |
USE_EXTERNAL_EMOJIS | 18 | 0x40000 | Use external emojis. |
CONNECT | 20 | 0x100000 | Connect to voice channels. |
SPEAK | 21 | 0x200000 | Speak in voice channels. |
MUTE_MEMBERS | 22 | 0x400000 | Mute members. |
DEAFEN_MEMBERS | 23 | 0x800000 | Deafen members. |
MOVE_MEMBERS | 24 | 0x1000000 | Move members between channels. |
USE_VAD | 25 | 0x2000000 | Use voice activity detection. |
CHANGE_NICKNAME | 26 | 0x4000000 | Change own nickname. |
MANAGE_NICKNAMES | 27 | 0x8000000 | Change other members’ nicknames. |
MANAGE_ROLES | 28 | 0x10000000 | Manage roles. |
MANAGE_WEBHOOKS | 29 | 0x20000000 | Manage webhooks. |
MANAGE_EXPRESSIONS | 30 | 0x40000000 | Manage emojis and stickers. |
USE_EXTERNAL_STICKERS | - | 0x2000000000 | Use external stickers. |
MODERATE_MEMBERS | - | 0x10000000000 | Time out members. |
CREATE_EXPRESSIONS | - | 0x80000000000 | Create emojis and stickers. |
PIN_MESSAGES | - | 0x8000000000000 | Pin messages. |
BYPASS_SLOWMODE | - | 0x10000000000000 | Bypass slowmode. |
UPDATE_RTC_REGION | - | 0x20000000000000 | Change voice region. |
parse_permissions
Permissions. Returns an empty set on parse error.
permissions_to_string
Permissions back into a bitfield string for passing to the API.
ALL_PERMISSIONS
Permissions::all().
Flag Operations
Permissions supports standard bitflags operations:
| Operation | Example | Description |
|---|---|---|
| Check presence | perms.contains(Permissions::BAN_MEMBERS) | true if the flag is set. |
| Union | perms | Permissions::KICK_MEMBERS | Add flags. |
| Intersection | perms & Permissions::MANAGE_ROLES | Keep only common flags. |
| Inversion | !perms | Flip all flags. |
| Difference | perms - Permissions::SEND_MESSAGES | Remove a flag. |
Example: check member permissions
Example: check member permissions
Example: build a bitfield for a channel overwrite
Example: build a bitfield for a channel overwrite
SnowflakeUtil
Utilities for working with Snowflake IDs. Fluxer epoch:1 420 070 400 000 ms (January 1, 2015, 00:00:00 UTC).
date_from_snowflake
None if the ID is not a number.
timestamp_ms_from_snowflake
snowflake_from_timestamp
is_valid
true if the string is a valid Snowflake (non-empty string, parseable as u64).
Example: determine account age
Example: determine account age
Example: time-based pagination via snowflake_from_timestamp
Example: time-based pagination via snowflake_from_timestamp
CDN
URL-building functions for Fluxer media resources. Exported fromfluxer_core::util::cdn.
Base URLs
| Constant | Value | Usage |
|---|---|---|
CDN_URL | https://fluxerusercontent.com | Avatars, banners, icons (user-generated content). |
STATIC_CDN_URL | https://fluxerstatic.com | Default avatars and static resources. |
Functions
| Function | Description |
|---|---|
cdn_avatar_url(user_id, hash, opts) | User avatar URL. None if hash is None. |
cdn_display_avatar_url(user_id, hash, opts) | Avatar URL with a fallback to the default. Always returns a string. |
cdn_banner_url(resource_id, hash, opts) | Banner URL (user or guild). |
cdn_guild_icon_url(guild_id, hash, opts) | Guild icon URL. |
cdn_guild_splash_url(guild_id, hash, opts) | Guild invite splash URL. |
cdn_member_avatar_url(guild_id, user_id, hash, opts) | Member server avatar URL. |
cdn_member_banner_url(guild_id, user_id, hash, opts) | Member server banner URL. |
cdn_emoji_url(emoji_id, animated) | Custom emoji image URL. |
cdn_sticker_url(sticker_id, animated) | Sticker image URL. |
cdn_default_avatar_url(user_id) | Default avatar URL by user ID (index 0–5). |
File Extension Logic
- If the hash starts with
a_- the extension is alwaysgif(animated resource). - Otherwise
CdnOptions.extensionis used, or"png"by default.
Example: get avatar URL at 128px in webp format
Example: get avatar URL at 128px in webp format
Example: custom emoji URL
Example: custom emoji URL
Formatters
Text utilities fromfluxer_util::formatters.
truncate
max_len characters. If the string is longer - the last character is replaced with … (U+2026).
Use
truncate before passing user-provided data into MessagePayload::content or EmbedBuilder fields to avoid panics when exceeding limits.escape_markdown
*, _, ~, `, |, >, #.
format_color
#RRGGBB. Clamps values above 0xFFFFFF.
format_timestamp
<t:timestamp:style>.
| Style | Character | Display Example |
|---|---|---|
| Short time | t | 12:00 |
| Long time | T | 12:00:00 |
| Short date | d | 01/15/2024 |
| Long date | D | January 15, 2024 |
| Date and time | f | January 15, 2024, 12:00 (default) |
| Full date and time | F | Monday, January 15, 2024, 12:00 |
| Relative time | R | 3 minutes ago |
Example: embed with event time
Example: embed with event time
Tenor
Utilities for working with Tenor GIF links fromfluxer_util::tenor.
is_tenor_url
true if the URL is a Tenor link.
Recognizes the following formats:
https://tenor.com/view/...https://tenor.com/embed/...https://media.tenor.com/...
extract_tenor_id
| URL Format | Example | Result |
|---|---|---|
tenor.com/view/name-12345 | .../funny-cat-12345 | "12345" |
tenor.com/embed/12345 | .../embed/12345 | "12345" |
None if the ID is not found or is not a number.
tenor_media_url
resolve_tenor_to_image_url
extract_tenor_id and tenor_media_url. Accepts a Tenor share/embed URL and returns a direct link to the GIF. Returns None if the URL is not recognized.
Example: handle a Tenor link in a message
Example: handle a Tenor link in a message
Resolvers
Helper functions fromfluxer_util::resolvers for working with colors.
resolve_color
"#RRGGBB" and "RRGGBB" formats.
resolve_color_rgb
Emoji
Utilities fromfluxer_util::emoji for emoji formatting.
format_emoji
| Parameters | Result | Usage |
|---|---|---|
name = "👍", id = None | "👍" | Unicode emoji. |
name = "fluxer", id = Some("123"), animated = false | "fluxer:123" | Custom static. |
name = "fluxer", id = Some("123"), animated = true | "a_fluxer:123" | Custom animated. |
parse_emoji_str
(name, id, animated).
| Input String | Result |
|---|---|
"👍" | ("👍", None, false) |
"fluxer:123" | ("fluxer", Some("123"), false) |
"a_fluxer:123" | ("fluxer", Some("123"), true) |
