34 symbols from @neontechspace/fluxerly/effect
Variables#
assets#
Build image URLs for hosted Fluxer from supplied user, member, community, emoji or sticker data
Methods return URLs immediately, the same as in the default API, and use fixed hosted addresses. Use client for URLs on a selected self-hosted instance. Invalid targets, IDs, hashes or options throw AssetUrlError, and such a throw inside Effect code becomes a defect. Image format defaults to WebP
Omit size to leave pixel size selection to Fluxer. Options are validated even when the supplied asset is absent. These helpers do not fetch profiles, change caches, download bytes, refresh URLs or change attachment or embed URLs. Custom base addresses are not accepted by this hosted namespace. Omitted optional asset hashes become undefined
Known absent hashes become null. A returned URL does not prove the asset exists
const assets: AssetHelpersimport { assets, AssetFormats, type Guild, type GuildEmoji, type GuildMember, type User, type UserProfile } from "@neontechspace/fluxerly/effect"
export const assetsEffectExample = (user: Pick<User, "id" | "avatar">, member: Pick<GuildMember, "guildId" | "userId" | "avatar" | "profileFlags">, guild: Pick<Guild, "id" | "icon">, emoji: Pick<GuildEmoji, "id" | "animated">, profile: UserProfile) => ({
avatar: assets.displayAvatar(user, { size: 256, format: AssetFormats.Webp }),
memberAvatar: assets.displayMemberAvatar(user, member, { size: 256 }),
icon: assets.guildIcon(guild, { format: AssetFormats.Png }),
emojiUrl: assets.emoji(emoji, { animated: emoji.animated }),
banner: assets.userBanner(profile),
})
colors#
Convert RGB colors between integers, hex strings and channel tuples
Methods return plain values immediately. Invalid values throw HelperError instead of being coerced or clamped, and CSS color names are not accepted. Such a throw inside Effect code becomes a defect. For colors received from users, tryParse returns an Effect that fails with HelperError instead
const colors: ColorHelpersdisplay#
Choose a display name from user data and an optional community member, without a request or cache lookup
The display.name helper prefers the member nickname, then the user's displayName, then username. Only null or undefined trigger a fallback. Supply a member belonging to the same user, because this helper does not check identity
const display: DisplayHelpersformat#
Create and read Fluxer mention, timestamp and custom-emoji markup without a client or network requests
Most methods return plain values immediately, the same as in the default API, and throw HelperError for invalid input. Inside Effect code such a throw becomes a defect rather than a typed failure, because invalid input is a programming mistake. For text received from users, tryParseMention, tryParseTimestamp and tryParseCustomEmoji return Effects that read the text when run and fail with HelperError. Mention markup alone does not enable notifications
const format: FormatHelpersimport { Effect } from "effect"
import { format, links, type GuildChannel } from "@neontechspace/fluxerly/effect"
export const helpersEffectExample = (userId: string, messageId: string, channel: GuildChannel, userText: string) =>
Effect.gen(function* () {
const mentioned = yield* format.tryParseMention(userText)
return {
escaped: format.escapeMarkdown("@everyone: **literal**"),
mention: format.userMention(userId),
message: links.message({ id: messageId, channelId: channel.id }, channel),
mentionedId: mentioned.id,
}
})
links#
Build hosted Fluxer channel, message and bot-installation links from supplied IDs
Methods return URLs immediately, the same as in the default API, and throw HelperError for invalid input. Such a throw inside Effect code becomes a defect. Building a link does not visit it or check access
const links: LinkHelperssnowflakes#
Validate Fluxer IDs, read their creation time or create pagination boundaries
A snowflake is Fluxer's time-based decimal-string ID. Conversions use bigint to avoid Number precision loss. They return plain values and throw HelperError for invalid input, which becomes a defect inside Effect code. For IDs received from users, tryParse returns an Effect that fails with HelperError instead
const snowflakes: SnowflakeHelperstext#
Split long text into length-bounded pieces without losing its contents, or truncate it to a length with a marker
Each lone surrogate becomes U+FFFD (�) first. The caller chooses the length limit, how to send the result and any Markdown handling. The maxLength option of split and truncate counts UTF-16 code units, and cuts fall between visible characters, so a result can be shorter
Only split cuts inside a single character, and only one longer than maxLength. Truncate returns the suffix alone when its first character does not fit before the suffix. The split and truncate methods return their result directly, without sending it
Invalid text or options throw HelperError, and such a throw inside Effect code becomes a defect
const text: TextHelpersimport { Effect } from "effect"
import { permissionBits, colors, text } from "@neontechspace/fluxerly/effect"
export function pureHelpersExample(bits: bigint, content: string, colorText: string) {
return Effect.gen(function* () {
const color = yield* colors.tryParse(colorText)
return {
required: permissionBits.from(["ManageRoles", "ManageMessages"]),
missing: permissionBits.missing(bits, ["ManageRoles", "ManageMessages"]),
inspection: permissionBits.inspect(bits),
color,
chunks: text.split(content, { maxLength: 2_000 }),
title: text.truncate(content, { maxLength: 100 }),
}
})
}
Type Aliases#
ColorHelpers #
Methods of the native colors helper, which converts RGB numbers, hex strings and tuples
Most methods return plain values and throw HelperError for invalid input, and such a throw inside Effect code becomes a defect. The tryParse method returns an Effect that fails with HelperError in the error channel
type ColorHelpers = Readonly<{ … }>parse#-
Convert a six-digit hexadecimal string, an RGB array of three integer channels from 0 through 255, or a color number to the integer used by embeds and roles
The leading
#is optional. CSS names, three-digit shorthand, alpha channels and surrounding whitespace are rejected. Values are never rounded or clamped, and invalid input throwsHelperError. For colors received from users, usetryParse, which reports the sameHelperErrorwithout throwing(value: ColorInput) => number to#Hex -
Turn a color integer into a lowercase six-digit string such as
"#000001", including leading zeroesAccepts only integers from 0 through 0xffffff, not the strings or arrays accepted by
parse. ThrowsHelperErrorfor invalid numbers(value: number) => string to#Rgb -
Split a color integer into a new frozen
[red, green, blue]array, each from 0 through 255Accepts only integers from 0 through 0xffffff. Throws
HelperErrorfor invalid numbers(value: number) => RgbColor try#Parse -
Convert a color with the same rules as parse, but report invalid input without throwing
The default API returns a Result holding the color integer or
HelperError. The native API returns an Effect that reads the input when run and fails withHelperError. Use it for colors received from users or other untrusted sources(value: ColorInput) => Effect.Effect<number, HelperError, never>(value: ColorInput) => Effect.Effect< number, HelperError, never >
FormatHelpers #
Methods of the native format helper, which creates and reads mention, timestamp and custom-emoji markup and escapes Markdown
Most methods return plain values and throw HelperError for invalid input, and such a throw inside Effect code becomes a defect. The try-prefixed parsers accept untrusted text and return Effects that fail with HelperError in the error channel
type FormatHelpers = Readonly<{ … }>type FormatHelpers =
Readonly<{ … }>channel#Mention -
Create
<#id>text linking to a channel, such as<#123>, and return it directlyThrows
HelperErrorfor an invalid decimal-string ID, and no channel lookup occurs(id: string) => string custom#Emoji -
Create
<:name:id>text, or<a:name:id>when animated is trueA
GuildEmojican be passed directly. ThrowsHelperErrorfor invalid names, IDs or animation values. This does not upload or look up an emoji(input: CustomEmojiMarkup) => string escape#Markdown -
Add backslashes so text is treated literally by Fluxer's markup parser, for example escaping
**bold**Returns the escaped string immediately and never throws for string input. It does not change a message's
allowedMentionsor enable notifications(value: string) => string parse#Custom Emoji -
Read exactly one
<:name:id>or<a:name:id>string into frozen name, ID and animated fieldsThrows
HelperErrorfor malformed markup. This does not resolve shortcodes such as:smile:or parse Unicode emoji. For text received from users, usetryParseCustomEmoji, which reports the sameHelperErrorwithout throwing(value: string) => CustomEmojiMarkup parse#Mention -
Read a string containing exactly one user, role or channel mention into a frozen
{ kind, id }objectBoth
<@id>and<@!id>produce kind"user". ThrowsHelperErrorfor surrounding text, malformed markup or an invalid decimal ID. For text received from users, usetryParseMention, which reports the sameHelperErrorwithout throwing(value: string) => Mention parse#Timestamp -
Read exactly one
<t:seconds:style>or<t:seconds>string into a frozen object with a new Date and styleA missing style becomes ShortDateTime. The Date has whole-second precision. Throws
HelperErrorfor malformed markup, nonpositive seconds or dates outside JavaScript's range. For text received from users, usetryParseTimestamp, which reports the sameHelperErrorwithout throwing(value: string) => TimestampMarkup role#Mention -
Create
<@&id>text for a decimal role ID, such as<@&123>, and return it directlyThrows
HelperErrorfor an invalid ID. Role members are not notified merely because this text appears in a message, andallowedMentionsmust be set separately(id: string) => string timestamp#-
Create
<t:seconds:style>message text from a Date, which Fluxer displays in the reader's local timeThe style defaults to ShortDateTime, and milliseconds are dropped. The whole Unix second must be from 1 through 8_640_000_000_000. Throws
HelperErrorfor an invalid Date, a time outside that range or an unsupported style. The input Date is not changed(value: Date, style?: TimestampStyle) => string(value: Date, style?: TimestampStyle) => string try#Parse Custom Emoji -
Read custom-emoji markup with the same rules as
parseCustomEmoji, but report invalid text without throwingThe default API returns a Result holding the frozen name, ID and animated fields or
HelperError. The native API returns an Effect that reads the text when run and fails withHelperError. Use it for text received from users or other untrusted sources(value: string) => Effect.Effect<CustomEmojiMarkup, HelperError, never>(value: string) => Effect.Effect< CustomEmojiMarkup, HelperError, never > try#Parse Mention -
Read a mention with the same rules as
parseMention, but report invalid text without throwingThe default API returns a Result holding the frozen
{ kind, id }object orHelperError. The native API returns an Effect that reads the text when run and fails withHelperError. Use it for text received from users or other untrusted sources(value: string) => Effect.Effect<Mention, HelperError, never>(value: string) => Effect.Effect< Mention, HelperError, never > try#Parse Timestamp -
Read timestamp markup with the same rules as
parseTimestamp, but report invalid text without throwingThe default API returns a Result holding the frozen date and style or
HelperError. The native API returns an Effect that reads the text when run and fails withHelperError. Use it for text received from users or other untrusted sources(value: string) => Effect.Effect<TimestampMarkup, HelperError, never>(value: string) => Effect.Effect< TimestampMarkup, HelperError, never > user#Mention -
Create
<@id>text for a decimal user ID, such as<@123>, and return it directlyThrows
HelperErrorwhen the ID is not a valid decimal-string snowflake. This does not look up the user, andallowedMentionsmust be set separately to request a notification(id: string) => string
SnowflakeHelpers #
Methods of the native snowflakes helper, which reads and converts decimal Fluxer IDs without losing precision
Conversions return plain values and throw HelperError for invalid input, and such a throw inside Effect code becomes a defect. The tryParse method returns an Effect that fails with HelperError in the error channel
type SnowflakeHelpers = Readonly<{ … }>type SnowflakeHelpers =
Readonly<{ … }>boundary#-
Make the smallest ID for a Date's exact UTC millisecond, useful as a time-based pagination boundary
Throws
HelperErrorfor an invalid Date, a date before 2015-01-01 UTC or a result outside the ID range. This does not create a resource. Whether the boundary is included depends on the endpoint using it(value: Date) => string created#At -
Return a new UTC Date for the creation time encoded in an ID
Throws
HelperErrorfor an invalid ID. This decodes the ID's high 41 timestamp bits relative to 2015-01-01 UTC, and does not fetch the resource or prove it is visible(value: string) => Date is#Valid -
Return true for a decimal string from
"0"through"9223372036854775807", with no extra leading zeroesReturns false immediately for numbers, whitespace and invalid strings, without converting through Number or failing
(value: unknown) => value is string parse#-
Convert a valid decimal-string ID to bigint without losing precision
Throws
HelperErrorfor an invalid ID. For IDs received from users, usetryParse, which reports the sameHelperErrorwithout throwing(value: string) => bigint shard#For -
Return the shard that receives a community's gateway events when the bot runs
totalShardsshardsFluxer calls a community a guild, so the first argument is a guild ID. Fluxer routes each community with (
guildId>> 22) %totalShards, and this helper applies the same formula. Use it to find which process owns a community when shards run in several processes. ThrowsHelperErrorfor an invalid ID or atotalShardsoutside 1 through 16,384. It does not check whether the bot belongs to that community(guildId: string, totalShards: number) => number(guildId: string, totalShards: number) => number try#Parse -
Convert a decimal-string ID with the same rules as parse, but report an invalid ID without throwing
The default API returns a Result holding the bigint or
HelperError. The native API returns an Effect that reads the ID when run and fails withHelperError. Use it for IDs received from users or other untrusted sources(value: string) => Effect.Effect<bigint, HelperError, never>(value: string) => Effect.Effect< bigint, HelperError, never >
Re-Exports#
Declared in JavaScript & TypeScript and documented there. Import them from @neontechspace/fluxerly/effect as well
Asset#Formats - Choose the image format for an asset URL
Timestamp#Styles - Choose how Fluxer displays a timestamp in a message
Embed#Builder - Assemble an embed by chaining methods, then pass the builder or
build()'s plain object in a message operation's embeds Message#Builder - Assemble a message by chaining methods, then send the plain object returned by
build() Asset#Url Options - Choose the format, size and animation to request in an asset URL
Custom#Emoji Markup - Custom-emoji fields used by Fluxer's explicit
<:name:id>or<a:name:id>markup Embed#Field Options - Display settings for one field added with
EmbedBuilder.field Installation#Link Options - Optional raw permission bitfield requested by a hosted bot-installation page
Sticker#Asset Url Options - Choose sticker size and animation
Text#Split Options - Choose the largest piece
text.splitmay return Text#Truncate Options - Choose where
text.truncatecuts and what it appends Timestamp#Markup - One parsed timestamp markup value
Asset#Format - One image encoding the hosted Fluxer media proxy can produce
Asset#Helpers - Methods of the assets helper, which builds image URLs for avatars, banners, community images, emoji and stickers
Channel#Link Target - The channel information needed to make a web link: Its
idand, for a community channel, itsguildId Color#Input - A color accepted by
colors.parse: A number from 0 through 0xffffff, six hexadecimal digits such as"#ff8800", or[255, 136, 0] Display#Helpers - Methods of the display helper, which chooses a display name from supplied user or member data
Link#Helpers - Methods of the links helper, which builds Fluxer channel, message and installation URLs
Mention#- The result of
format.parseMention Missing#Message Body - The type of
MessageBuilder.buildbefore a body is selected Text#Helpers - Methods of the text helper, which splits and truncates long strings
Timestamp#Style - One Fluxer timestamp-markup display style