On This Page

Builders and Formatting

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.instance.resolve 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: AssetHelpers
TypeScript
import { 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: ColorHelpers

display#

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: DisplayHelpers

format#

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: FormatHelpers
TypeScript
import { 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,
        }
    })

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: LinkHelpers

snowflakes#

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: SnowflakeHelpers

text#

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: TextHelpers
TypeScript
import { 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 throws HelperError. For colors received from users, use tryParse, which reports the same HelperError without throwing

(value: ColorInput) => number
toHex#

Turn a color integer into a lowercase six-digit string such as "#000001", including leading zeroes

Accepts only integers from 0 through 0xffffff, not the strings or arrays accepted by parse. Throws HelperError for invalid numbers

(value: number) => string
toRgb#

Split a color integer into a new frozen [red, green, blue] array, each from 0 through 255

Accepts only integers from 0 through 0xffffff. Throws HelperError for invalid numbers

(value: number) => RgbColor
tryParse#

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 with HelperError. 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<{ … }>
channelMention#

Create <#id> text linking to a channel, such as <#123>, and return it directly

Throws HelperError for an invalid decimal-string ID, and no channel lookup occurs

(id: string) => string
customEmoji#

Create <:name:id> text, or <a:name:id> when animated is true

A GuildEmoji can be passed directly. Throws HelperError for invalid names, IDs or animation values. This does not upload or look up an emoji

(input: CustomEmojiMarkup) => string
escapeMarkdown#

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 allowedMentions or enable notifications

(value: string) => string
parseCustomEmoji#

Read exactly one <:name:id> or <a:name:id> string into frozen name, ID and animated fields

Throws HelperError for malformed markup. This does not resolve shortcodes such as :smile: or parse Unicode emoji. For text received from users, use tryParseCustomEmoji, which reports the same HelperError without throwing

(value: string) => CustomEmojiMarkup
parseMention#

Read a string containing exactly one user, role or channel mention into a frozen { kind, id } object

Both <@id> and <@!id> produce kind "user". Throws HelperError for surrounding text, malformed markup or an invalid decimal ID. For text received from users, use tryParseMention, which reports the same HelperError without throwing

(value: string) => Mention
parseTimestamp#

Read exactly one <t:seconds:style> or <t:seconds> string into a frozen object with a new Date and style

A missing style becomes ShortDateTime. The Date has whole-second precision. Throws HelperError for malformed markup, nonpositive seconds or dates outside JavaScript's range. For text received from users, use tryParseTimestamp, which reports the same HelperError without throwing

(value: string) => TimestampMarkup
roleMention#

Create <@&id> text for a decimal role ID, such as <@&123>, and return it directly

Throws HelperError for an invalid ID. Role members are not notified merely because this text appears in a message, and allowedMentions must be set separately

(id: string) => string
timestamp#

Create <t:seconds:style> message text from a Date, which Fluxer displays in the reader's local time

The style defaults to ShortDateTime, and milliseconds are dropped. The whole Unix second must be from 1 through 8_640_000_000_000. Throws HelperError for 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
tryParseCustomEmoji#

Read custom-emoji markup with the same rules as parseCustomEmoji, but report invalid text without throwing

The 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 with HelperError. 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
  >
tryParseMention#

Read a mention with the same rules as parseMention, but report invalid text without throwing

The default API returns a Result holding the frozen { kind, id } object or HelperError. The native API returns an Effect that reads the text when run and fails with HelperError. 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
  >
tryParseTimestamp#

Read timestamp markup with the same rules as parseTimestamp, but report invalid text without throwing

The 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 with HelperError. 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
  >
userMention#

Create <@id> text for a decimal user ID, such as <@123>, and return it directly

Throws HelperError when the ID is not a valid decimal-string snowflake. This does not look up the user, and allowedMentions must 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 HelperError for 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
createdAt#

Return a new UTC Date for the creation time encoded in an ID

Throws HelperError for 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
isValid#

Return true for a decimal string from "0" through "9223372036854775807", with no extra leading zeroes

Returns 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 HelperError for an invalid ID. For IDs received from users, use tryParse, which reports the same HelperError without throwing

(value: string) => bigint
shardFor#

Return the shard that receives a community's gateway events when the bot runs totalShards shards

Fluxer 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. Throws HelperError for an invalid ID or a totalShards outside 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
tryParse#

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

AssetFormats#
Choose the image format for an asset URL
TimestampStyles#
Choose how Fluxer displays a timestamp in a message
builders#
Start optional chainable builders for embed and message objects
EmbedBuilder#
Assemble an embed by chaining methods, then pass the builder or build()'s plain object in a message operation's embeds
MessageBuilder#
Assemble a message by chaining methods, then send the plain object returned by build()
AssetUrlOptions#
Choose the format, size and animation to request in an asset URL
CustomEmojiMarkup#
Custom-emoji fields used by Fluxer's explicit <:name:id> or <a:name:id> markup
EmbedFieldOptions#
Display settings for one field added with EmbedBuilder.field
InstallationLinkOptions#
Optional raw permission bitfield requested by a hosted bot-installation page
StickerAssetUrlOptions#
Choose sticker size and animation
TextSplitOptions#
Choose the largest piece text.split may return
TextTruncateOptions#
Choose where text.truncate cuts and what it appends
TimestampMarkup#
One parsed timestamp markup value
AssetFormat#
One image encoding the hosted Fluxer media proxy can produce
AssetHelpers#
Methods of the assets helper, which builds image URLs for avatars, banners, community images, emoji and stickers
ChannelLinkTarget#
The channel information needed to make a web link: Its id and, for a community channel, its guildId
ColorInput#
A color accepted by colors.parse: A number from 0 through 0xffffff, six hexadecimal digits such as "#ff8800", or [255, 136, 0]
DisplayHelpers#
Methods of the display helper, which chooses a display name from supplied user or member data
LinkHelpers#
Methods of the links helper, which builds Fluxer channel, message and installation URLs
MissingMessageBody#
The type of MessageBuilder.build before a body is selected
RgbColor#
A three-item array of red, green and blue amounts, in that order
TextHelpers#
Methods of the text helper, which splits and truncates long strings
TimestampStyle#
One Fluxer timestamp-markup display style