privage.js 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +503 -0
- package/dist/Client.d.ts +192 -0
- package/dist/Client.js +904 -0
- package/dist/attachments.d.ts +41 -0
- package/dist/attachments.js +63 -0
- package/dist/collectors.d.ts +41 -0
- package/dist/collectors.js +52 -0
- package/dist/commands.d.ts +108 -0
- package/dist/commands.js +216 -0
- package/dist/compat.d.ts +72 -0
- package/dist/compat.js +75 -0
- package/dist/components.d.ts +137 -0
- package/dist/components.js +226 -0
- package/dist/embeds.d.ts +97 -0
- package/dist/embeds.js +125 -0
- package/dist/errors.d.ts +32 -0
- package/dist/errors.js +48 -0
- package/dist/formatters.d.ts +16 -0
- package/dist/formatters.js +43 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +101 -0
- package/dist/intents.d.ts +28 -0
- package/dist/intents.js +33 -0
- package/dist/modals.d.ts +96 -0
- package/dist/modals.js +162 -0
- package/dist/rest.d.ts +208 -0
- package/dist/rest.js +356 -0
- package/dist/structures/Channel.d.ts +25 -0
- package/dist/structures/Channel.js +34 -0
- package/dist/structures/Interaction.d.ts +149 -0
- package/dist/structures/Interaction.js +170 -0
- package/dist/structures/Member.d.ts +35 -0
- package/dist/structures/Member.js +55 -0
- package/dist/structures/Message.d.ts +181 -0
- package/dist/structures/Message.js +191 -0
- package/dist/structures/Role.d.ts +17 -0
- package/dist/structures/Role.js +20 -0
- package/dist/structures/Server.d.ts +29 -0
- package/dist/structures/Server.js +36 -0
- package/dist/structures/ServerChannels.d.ts +24 -0
- package/dist/structures/ServerChannels.js +50 -0
- package/dist/types.d.ts +195 -0
- package/dist/types.js +2 -0
- package/package.json +49 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Message formatting helpers. Mention syntax matches the wire format the
|
|
4
|
+
* backend parses and the client renders: `<@userId>`, `<@&roleId>`,
|
|
5
|
+
* `<#channelId>`, plus the `@everyone` / `@here` broadcasts (rate-limited
|
|
6
|
+
* server-side). The rest is standard markdown.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.here = exports.everyone = void 0;
|
|
10
|
+
exports.userMention = userMention;
|
|
11
|
+
exports.roleMention = roleMention;
|
|
12
|
+
exports.channelMention = channelMention;
|
|
13
|
+
exports.bold = bold;
|
|
14
|
+
exports.italic = italic;
|
|
15
|
+
exports.strikethrough = strikethrough;
|
|
16
|
+
exports.inlineCode = inlineCode;
|
|
17
|
+
exports.codeBlock = codeBlock;
|
|
18
|
+
function userMention(userId) {
|
|
19
|
+
return `<@${userId}>`;
|
|
20
|
+
}
|
|
21
|
+
function roleMention(roleId) {
|
|
22
|
+
return `<@&${roleId}>`;
|
|
23
|
+
}
|
|
24
|
+
function channelMention(channelId) {
|
|
25
|
+
return `<#${channelId}>`;
|
|
26
|
+
}
|
|
27
|
+
exports.everyone = '@everyone';
|
|
28
|
+
exports.here = '@here';
|
|
29
|
+
function bold(text) {
|
|
30
|
+
return `**${text}**`;
|
|
31
|
+
}
|
|
32
|
+
function italic(text) {
|
|
33
|
+
return `*${text}*`;
|
|
34
|
+
}
|
|
35
|
+
function strikethrough(text) {
|
|
36
|
+
return `~~${text}~~`;
|
|
37
|
+
}
|
|
38
|
+
function inlineCode(text) {
|
|
39
|
+
return `\`${text.replaceAll('`', '`')}\``;
|
|
40
|
+
}
|
|
41
|
+
function codeBlock(content, language = '') {
|
|
42
|
+
return `\`\`\`${language}\n${content.replaceAll('```', '```')}\n\`\`\``;
|
|
43
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export { Client } from './Client';
|
|
2
|
+
export { Intents } from './intents';
|
|
3
|
+
export type { Intent } from './intents';
|
|
4
|
+
export { Message, TextChannel } from './structures/Message';
|
|
5
|
+
export type { MessageThread, MessageReference, ReferencedMessage, MessageAttachment, MessageEmbed, } from './structures/Message';
|
|
6
|
+
export { Member } from './structures/Member';
|
|
7
|
+
export { Server } from './structures/Server';
|
|
8
|
+
export { Channel } from './structures/Channel';
|
|
9
|
+
export { Role } from './structures/Role';
|
|
10
|
+
export { ServerChannels } from './structures/ServerChannels';
|
|
11
|
+
export type { SendMessageOptions, KickBanOptions, TimeoutOptions, FetchMessagesOptions, FetchMembersOptions, PresenceStatus, Activity, } from './rest';
|
|
12
|
+
export { ActivityType } from './rest';
|
|
13
|
+
export { EmbedBuilder, EmbedLimits } from './embeds';
|
|
14
|
+
export type { Embed, EmbedField, EmbedAuthor, EmbedFooter } from './embeds';
|
|
15
|
+
export { AttachmentBuilder } from './attachments';
|
|
16
|
+
export type { AttachmentSource } from './attachments';
|
|
17
|
+
export type { CreatePollOptions, CreateWebhookOptions, EditWebhookOptions } from './rest';
|
|
18
|
+
export { ButtonBuilder, SelectMenuBuilder, ActionRowBuilder, ComponentLimits, ButtonStyle } from './components';
|
|
19
|
+
export type { Button, SelectMenu, SelectOption, ActionRow } from './components';
|
|
20
|
+
export { ModalBuilder, TextInputBuilder, ModalLimits, TextInputStyle } from './modals';
|
|
21
|
+
export type { Modal, TextInput } from './modals';
|
|
22
|
+
export { Events, Colors } from './compat';
|
|
23
|
+
export { Interaction, InteractionCommand } from './structures/Interaction';
|
|
24
|
+
export type { InteractionKind, InteractionUpdateData, InteractionReplyData, CommandOptionType, CommandInteractionOption, ModalSubmitField, } from './structures/Interaction';
|
|
25
|
+
export { CommandsManager, CommandLimits, SlashCommandBuilder, SlashCommandOptionBuilder } from './commands';
|
|
26
|
+
export type { BotCommand, BotCommandData, CommandOptionData, CommandChoice } from './commands';
|
|
27
|
+
export type { EditMessageOptions } from './rest';
|
|
28
|
+
export { MessageCollector } from './collectors';
|
|
29
|
+
export type { MessageCollectorOptions, CollectorEndReason } from './collectors';
|
|
30
|
+
export * as formatters from './formatters';
|
|
31
|
+
export { userMention, roleMention, channelMention, bold, italic, strikethrough, inlineCode, codeBlock, } from './formatters';
|
|
32
|
+
export type { ClientOptions, ClientEvents, ReadyPayload, BotUser, Author, MessageDelete, MessageDeleteBulk, ReactionUpdate, ReactionAction, MemberLeave, RoleChange, MemberUpdate, MemberBan, MemberTimeout, MemberUntimeout, MessagePin, TypingEvent, ChannelDelete, RoleDelete, PollVote, PollClose, } from './types';
|
|
33
|
+
export { PrivageError, PrivageAuthError, PrivagePermissionError, PrivageConnectionError, PrivageRateLimitError, PrivageHTTPError, } from './errors';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.PrivageHTTPError = exports.PrivageRateLimitError = exports.PrivageConnectionError = exports.PrivagePermissionError = exports.PrivageAuthError = exports.PrivageError = exports.codeBlock = exports.inlineCode = exports.strikethrough = exports.italic = exports.bold = exports.channelMention = exports.roleMention = exports.userMention = exports.formatters = exports.MessageCollector = exports.SlashCommandOptionBuilder = exports.SlashCommandBuilder = exports.CommandLimits = exports.CommandsManager = exports.InteractionCommand = exports.Interaction = exports.Colors = exports.Events = exports.TextInputStyle = exports.ModalLimits = exports.TextInputBuilder = exports.ModalBuilder = exports.ButtonStyle = exports.ComponentLimits = exports.ActionRowBuilder = exports.SelectMenuBuilder = exports.ButtonBuilder = exports.AttachmentBuilder = exports.EmbedLimits = exports.EmbedBuilder = exports.ActivityType = exports.ServerChannels = exports.Role = exports.Channel = exports.Server = exports.Member = exports.TextChannel = exports.Message = exports.Intents = exports.Client = void 0;
|
|
37
|
+
var Client_1 = require("./Client");
|
|
38
|
+
Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return Client_1.Client; } });
|
|
39
|
+
var intents_1 = require("./intents");
|
|
40
|
+
Object.defineProperty(exports, "Intents", { enumerable: true, get: function () { return intents_1.Intents; } });
|
|
41
|
+
var Message_1 = require("./structures/Message");
|
|
42
|
+
Object.defineProperty(exports, "Message", { enumerable: true, get: function () { return Message_1.Message; } });
|
|
43
|
+
Object.defineProperty(exports, "TextChannel", { enumerable: true, get: function () { return Message_1.TextChannel; } });
|
|
44
|
+
var Member_1 = require("./structures/Member");
|
|
45
|
+
Object.defineProperty(exports, "Member", { enumerable: true, get: function () { return Member_1.Member; } });
|
|
46
|
+
var Server_1 = require("./structures/Server");
|
|
47
|
+
Object.defineProperty(exports, "Server", { enumerable: true, get: function () { return Server_1.Server; } });
|
|
48
|
+
var Channel_1 = require("./structures/Channel");
|
|
49
|
+
Object.defineProperty(exports, "Channel", { enumerable: true, get: function () { return Channel_1.Channel; } });
|
|
50
|
+
var Role_1 = require("./structures/Role");
|
|
51
|
+
Object.defineProperty(exports, "Role", { enumerable: true, get: function () { return Role_1.Role; } });
|
|
52
|
+
var ServerChannels_1 = require("./structures/ServerChannels");
|
|
53
|
+
Object.defineProperty(exports, "ServerChannels", { enumerable: true, get: function () { return ServerChannels_1.ServerChannels; } });
|
|
54
|
+
var rest_1 = require("./rest");
|
|
55
|
+
Object.defineProperty(exports, "ActivityType", { enumerable: true, get: function () { return rest_1.ActivityType; } });
|
|
56
|
+
var embeds_1 = require("./embeds");
|
|
57
|
+
Object.defineProperty(exports, "EmbedBuilder", { enumerable: true, get: function () { return embeds_1.EmbedBuilder; } });
|
|
58
|
+
Object.defineProperty(exports, "EmbedLimits", { enumerable: true, get: function () { return embeds_1.EmbedLimits; } });
|
|
59
|
+
var attachments_1 = require("./attachments");
|
|
60
|
+
Object.defineProperty(exports, "AttachmentBuilder", { enumerable: true, get: function () { return attachments_1.AttachmentBuilder; } });
|
|
61
|
+
var components_1 = require("./components");
|
|
62
|
+
Object.defineProperty(exports, "ButtonBuilder", { enumerable: true, get: function () { return components_1.ButtonBuilder; } });
|
|
63
|
+
Object.defineProperty(exports, "SelectMenuBuilder", { enumerable: true, get: function () { return components_1.SelectMenuBuilder; } });
|
|
64
|
+
Object.defineProperty(exports, "ActionRowBuilder", { enumerable: true, get: function () { return components_1.ActionRowBuilder; } });
|
|
65
|
+
Object.defineProperty(exports, "ComponentLimits", { enumerable: true, get: function () { return components_1.ComponentLimits; } });
|
|
66
|
+
Object.defineProperty(exports, "ButtonStyle", { enumerable: true, get: function () { return components_1.ButtonStyle; } });
|
|
67
|
+
var modals_1 = require("./modals");
|
|
68
|
+
Object.defineProperty(exports, "ModalBuilder", { enumerable: true, get: function () { return modals_1.ModalBuilder; } });
|
|
69
|
+
Object.defineProperty(exports, "TextInputBuilder", { enumerable: true, get: function () { return modals_1.TextInputBuilder; } });
|
|
70
|
+
Object.defineProperty(exports, "ModalLimits", { enumerable: true, get: function () { return modals_1.ModalLimits; } });
|
|
71
|
+
Object.defineProperty(exports, "TextInputStyle", { enumerable: true, get: function () { return modals_1.TextInputStyle; } });
|
|
72
|
+
var compat_1 = require("./compat");
|
|
73
|
+
Object.defineProperty(exports, "Events", { enumerable: true, get: function () { return compat_1.Events; } });
|
|
74
|
+
Object.defineProperty(exports, "Colors", { enumerable: true, get: function () { return compat_1.Colors; } });
|
|
75
|
+
var Interaction_1 = require("./structures/Interaction");
|
|
76
|
+
Object.defineProperty(exports, "Interaction", { enumerable: true, get: function () { return Interaction_1.Interaction; } });
|
|
77
|
+
Object.defineProperty(exports, "InteractionCommand", { enumerable: true, get: function () { return Interaction_1.InteractionCommand; } });
|
|
78
|
+
var commands_1 = require("./commands");
|
|
79
|
+
Object.defineProperty(exports, "CommandsManager", { enumerable: true, get: function () { return commands_1.CommandsManager; } });
|
|
80
|
+
Object.defineProperty(exports, "CommandLimits", { enumerable: true, get: function () { return commands_1.CommandLimits; } });
|
|
81
|
+
Object.defineProperty(exports, "SlashCommandBuilder", { enumerable: true, get: function () { return commands_1.SlashCommandBuilder; } });
|
|
82
|
+
Object.defineProperty(exports, "SlashCommandOptionBuilder", { enumerable: true, get: function () { return commands_1.SlashCommandOptionBuilder; } });
|
|
83
|
+
var collectors_1 = require("./collectors");
|
|
84
|
+
Object.defineProperty(exports, "MessageCollector", { enumerable: true, get: function () { return collectors_1.MessageCollector; } });
|
|
85
|
+
exports.formatters = __importStar(require("./formatters"));
|
|
86
|
+
var formatters_1 = require("./formatters");
|
|
87
|
+
Object.defineProperty(exports, "userMention", { enumerable: true, get: function () { return formatters_1.userMention; } });
|
|
88
|
+
Object.defineProperty(exports, "roleMention", { enumerable: true, get: function () { return formatters_1.roleMention; } });
|
|
89
|
+
Object.defineProperty(exports, "channelMention", { enumerable: true, get: function () { return formatters_1.channelMention; } });
|
|
90
|
+
Object.defineProperty(exports, "bold", { enumerable: true, get: function () { return formatters_1.bold; } });
|
|
91
|
+
Object.defineProperty(exports, "italic", { enumerable: true, get: function () { return formatters_1.italic; } });
|
|
92
|
+
Object.defineProperty(exports, "strikethrough", { enumerable: true, get: function () { return formatters_1.strikethrough; } });
|
|
93
|
+
Object.defineProperty(exports, "inlineCode", { enumerable: true, get: function () { return formatters_1.inlineCode; } });
|
|
94
|
+
Object.defineProperty(exports, "codeBlock", { enumerable: true, get: function () { return formatters_1.codeBlock; } });
|
|
95
|
+
var errors_1 = require("./errors");
|
|
96
|
+
Object.defineProperty(exports, "PrivageError", { enumerable: true, get: function () { return errors_1.PrivageError; } });
|
|
97
|
+
Object.defineProperty(exports, "PrivageAuthError", { enumerable: true, get: function () { return errors_1.PrivageAuthError; } });
|
|
98
|
+
Object.defineProperty(exports, "PrivagePermissionError", { enumerable: true, get: function () { return errors_1.PrivagePermissionError; } });
|
|
99
|
+
Object.defineProperty(exports, "PrivageConnectionError", { enumerable: true, get: function () { return errors_1.PrivageConnectionError; } });
|
|
100
|
+
Object.defineProperty(exports, "PrivageRateLimitError", { enumerable: true, get: function () { return errors_1.PrivageRateLimitError; } });
|
|
101
|
+
Object.defineProperty(exports, "PrivageHTTPError", { enumerable: true, get: function () { return errors_1.PrivageHTTPError; } });
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public, curated intents. The wire gateway has 16 intents, several of which
|
|
3
|
+
* are dead or no-ops in v1 (see protocol spec §6/§11); the SDK exposes only
|
|
4
|
+
* the ones that actually work. Each maps to a wire intent string.
|
|
5
|
+
*
|
|
6
|
+
* IMPORTANT: an empty intent list means the gateway delivers ALL events
|
|
7
|
+
* (firehose). The SDK always sends the explicit resolved list — declare what
|
|
8
|
+
* you handle.
|
|
9
|
+
*/
|
|
10
|
+
export declare const Intents: {
|
|
11
|
+
/** New/edited/deleted messages (including in-thread replies), pins, polls, tip jars. */
|
|
12
|
+
readonly Messages: "messages";
|
|
13
|
+
/** Reaction updates. */
|
|
14
|
+
readonly Reactions: "reactions";
|
|
15
|
+
/** Typing start/stop. */
|
|
16
|
+
readonly Typing: "typing";
|
|
17
|
+
/** Member joins/leaves/updates, role add/remove, nickname changes. */
|
|
18
|
+
readonly Members: "member_events";
|
|
19
|
+
/** Bans, unbans, kicks, timeouts. */
|
|
20
|
+
readonly Moderation: "server_moderation";
|
|
21
|
+
/** Server/channel/category/role/emoji structure + config changes. */
|
|
22
|
+
readonly Servers: "servers";
|
|
23
|
+
/** All `interaction` events — button clicks, select-menu choices, slash-command invocations, and modal submissions. Delivered bot-direct — no message reading required. */
|
|
24
|
+
readonly Interactions: "interactions";
|
|
25
|
+
};
|
|
26
|
+
export type Intent = typeof Intents[keyof typeof Intents];
|
|
27
|
+
/** Dedupe + normalize the declared intents into the wire list. */
|
|
28
|
+
export declare function resolveIntents(intents: Intent[]): string[];
|
package/dist/intents.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Intents = void 0;
|
|
4
|
+
exports.resolveIntents = resolveIntents;
|
|
5
|
+
/**
|
|
6
|
+
* Public, curated intents. The wire gateway has 16 intents, several of which
|
|
7
|
+
* are dead or no-ops in v1 (see protocol spec §6/§11); the SDK exposes only
|
|
8
|
+
* the ones that actually work. Each maps to a wire intent string.
|
|
9
|
+
*
|
|
10
|
+
* IMPORTANT: an empty intent list means the gateway delivers ALL events
|
|
11
|
+
* (firehose). The SDK always sends the explicit resolved list — declare what
|
|
12
|
+
* you handle.
|
|
13
|
+
*/
|
|
14
|
+
exports.Intents = {
|
|
15
|
+
/** New/edited/deleted messages (including in-thread replies), pins, polls, tip jars. */
|
|
16
|
+
Messages: 'messages',
|
|
17
|
+
/** Reaction updates. */
|
|
18
|
+
Reactions: 'reactions',
|
|
19
|
+
/** Typing start/stop. */
|
|
20
|
+
Typing: 'typing',
|
|
21
|
+
/** Member joins/leaves/updates, role add/remove, nickname changes. */
|
|
22
|
+
Members: 'member_events',
|
|
23
|
+
/** Bans, unbans, kicks, timeouts. */
|
|
24
|
+
Moderation: 'server_moderation',
|
|
25
|
+
/** Server/channel/category/role/emoji structure + config changes. */
|
|
26
|
+
Servers: 'servers',
|
|
27
|
+
/** All `interaction` events — button clicks, select-menu choices, slash-command invocations, and modal submissions. Delivered bot-direct — no message reading required. */
|
|
28
|
+
Interactions: 'interactions',
|
|
29
|
+
};
|
|
30
|
+
/** Dedupe + normalize the declared intents into the wire list. */
|
|
31
|
+
function resolveIntents(intents) {
|
|
32
|
+
return Array.from(new Set(intents));
|
|
33
|
+
}
|
package/dist/modals.d.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modals (interactions v2 §4) + fluent builders — siblings of the embed and
|
|
3
|
+
* component builders. A modal is opened with `interaction.showModal(...)`
|
|
4
|
+
* (valid only from a pending interaction, once, not after `defer()`); the
|
|
5
|
+
* user's submission arrives as a fresh `interaction` event with
|
|
6
|
+
* `kind: 'modal_submit'`.
|
|
7
|
+
*
|
|
8
|
+
* Wire shape (the `modal` callback payload, exactly per spec §4):
|
|
9
|
+
* { title, custom_id, fields: [
|
|
10
|
+
* { custom_id, label, style: 'short' | 'paragraph', required?,
|
|
11
|
+
* placeholder?, min_length?, max_length?, value? },
|
|
12
|
+
* ]}
|
|
13
|
+
*/
|
|
14
|
+
/** Server-enforced modal limits (mirrored client-side). */
|
|
15
|
+
export declare const ModalLimits: {
|
|
16
|
+
readonly Title: 45;
|
|
17
|
+
readonly CustomId: 100;
|
|
18
|
+
/** Text inputs per modal. */
|
|
19
|
+
readonly Fields: 5;
|
|
20
|
+
readonly Label: 45;
|
|
21
|
+
readonly Placeholder: 100;
|
|
22
|
+
/** Max `min_length`/`max_length` (paragraph style). */
|
|
23
|
+
readonly FieldLength: 4000;
|
|
24
|
+
/** `max_length` cap for `short`-style inputs. */
|
|
25
|
+
readonly ShortFieldLength: 1024;
|
|
26
|
+
};
|
|
27
|
+
export type TextInputStyle = 'short' | 'paragraph';
|
|
28
|
+
/** discord.js-style constants for {@link TextInputStyle} — `setStyle(TextInputStyle.Short)` ports verbatim. */
|
|
29
|
+
export declare const TextInputStyle: {
|
|
30
|
+
readonly Short: "short";
|
|
31
|
+
readonly Paragraph: "paragraph";
|
|
32
|
+
};
|
|
33
|
+
/** One text input inside a modal. */
|
|
34
|
+
export interface TextInput {
|
|
35
|
+
/** ≤100 chars, unique within the modal. Keys the submitted value (`interaction.getField`). */
|
|
36
|
+
custom_id: string;
|
|
37
|
+
/** ≤45 chars. */
|
|
38
|
+
label: string;
|
|
39
|
+
/** `short` = single line (values cap at 1024), `paragraph` = multi-line. */
|
|
40
|
+
style: TextInputStyle;
|
|
41
|
+
/** Server default: true. */
|
|
42
|
+
required?: boolean;
|
|
43
|
+
/** ≤100 chars. */
|
|
44
|
+
placeholder?: string;
|
|
45
|
+
/** 0–4000. */
|
|
46
|
+
min_length?: number;
|
|
47
|
+
/** 1–4000 (`short` caps at 1024). */
|
|
48
|
+
max_length?: number;
|
|
49
|
+
/** Prefill (≤ max_length). */
|
|
50
|
+
value?: string;
|
|
51
|
+
}
|
|
52
|
+
/** The `modal` callback payload. */
|
|
53
|
+
export interface Modal {
|
|
54
|
+
/** ≤45 chars. */
|
|
55
|
+
title: string;
|
|
56
|
+
/** ≤100 chars — round-trips as the modal_submit interaction's `customId`. */
|
|
57
|
+
custom_id: string;
|
|
58
|
+
/** 1–5 text inputs. */
|
|
59
|
+
fields: TextInput[];
|
|
60
|
+
}
|
|
61
|
+
/** Fluent text-input builder — throws at build time where the server would 400. */
|
|
62
|
+
export declare class TextInputBuilder {
|
|
63
|
+
private readonly data;
|
|
64
|
+
/** Your opaque field identifier (≤100 chars, unique within the modal). */
|
|
65
|
+
setCustomId(customId: string): this;
|
|
66
|
+
/** ≤45 chars. */
|
|
67
|
+
setLabel(label: string): this;
|
|
68
|
+
/** `'short'` (single line) or `'paragraph'` (multi-line). */
|
|
69
|
+
setStyle(style: TextInputStyle): this;
|
|
70
|
+
/** Server default: true. */
|
|
71
|
+
setRequired(required?: boolean): this;
|
|
72
|
+
/** ≤100 chars. */
|
|
73
|
+
setPlaceholder(placeholder: string): this;
|
|
74
|
+
/** 0–4000. */
|
|
75
|
+
setMinLength(min: number): this;
|
|
76
|
+
/** 1–4000 (`short` style caps at 1024 — checked at build time). */
|
|
77
|
+
setMaxLength(max: number): this;
|
|
78
|
+
/** Prefill text (must fit max_length — checked at build time). */
|
|
79
|
+
setValue(value: string): this;
|
|
80
|
+
toJSON(): TextInput;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Fluent modal builder. Pass it straight to `interaction.showModal(...)` —
|
|
84
|
+
* no `.toJSON()` call needed.
|
|
85
|
+
*/
|
|
86
|
+
export declare class ModalBuilder {
|
|
87
|
+
private readonly data;
|
|
88
|
+
private readonly fields;
|
|
89
|
+
/** ≤45 chars. */
|
|
90
|
+
setTitle(title: string): this;
|
|
91
|
+
/** Your opaque modal identifier (≤100 chars) — comes back as the modal_submit's `customId`. */
|
|
92
|
+
setCustomId(customId: string): this;
|
|
93
|
+
/** Append text inputs (1–5 total; field custom_ids must be unique). */
|
|
94
|
+
addFields(...fields: (TextInput | TextInputBuilder)[]): this;
|
|
95
|
+
toJSON(): Modal;
|
|
96
|
+
}
|
package/dist/modals.js
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Modals (interactions v2 §4) + fluent builders — siblings of the embed and
|
|
4
|
+
* component builders. A modal is opened with `interaction.showModal(...)`
|
|
5
|
+
* (valid only from a pending interaction, once, not after `defer()`); the
|
|
6
|
+
* user's submission arrives as a fresh `interaction` event with
|
|
7
|
+
* `kind: 'modal_submit'`.
|
|
8
|
+
*
|
|
9
|
+
* Wire shape (the `modal` callback payload, exactly per spec §4):
|
|
10
|
+
* { title, custom_id, fields: [
|
|
11
|
+
* { custom_id, label, style: 'short' | 'paragraph', required?,
|
|
12
|
+
* placeholder?, min_length?, max_length?, value? },
|
|
13
|
+
* ]}
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.ModalBuilder = exports.TextInputBuilder = exports.TextInputStyle = exports.ModalLimits = void 0;
|
|
17
|
+
/** Server-enforced modal limits (mirrored client-side). */
|
|
18
|
+
exports.ModalLimits = {
|
|
19
|
+
Title: 45,
|
|
20
|
+
CustomId: 100,
|
|
21
|
+
/** Text inputs per modal. */
|
|
22
|
+
Fields: 5,
|
|
23
|
+
Label: 45,
|
|
24
|
+
Placeholder: 100,
|
|
25
|
+
/** Max `min_length`/`max_length` (paragraph style). */
|
|
26
|
+
FieldLength: 4000,
|
|
27
|
+
/** `max_length` cap for `short`-style inputs. */
|
|
28
|
+
ShortFieldLength: 1024,
|
|
29
|
+
};
|
|
30
|
+
/** discord.js-style constants for {@link TextInputStyle} — `setStyle(TextInputStyle.Short)` ports verbatim. */
|
|
31
|
+
exports.TextInputStyle = {
|
|
32
|
+
Short: 'short',
|
|
33
|
+
Paragraph: 'paragraph',
|
|
34
|
+
};
|
|
35
|
+
function assertLength(what, value, max) {
|
|
36
|
+
if (value.length === 0 || value.length > max) {
|
|
37
|
+
throw new RangeError(`Modal ${what} must be 1–${max} characters (got ${value.length}).`);
|
|
38
|
+
}
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
/** Fluent text-input builder — throws at build time where the server would 400. */
|
|
42
|
+
class TextInputBuilder {
|
|
43
|
+
constructor() {
|
|
44
|
+
this.data = {};
|
|
45
|
+
}
|
|
46
|
+
/** Your opaque field identifier (≤100 chars, unique within the modal). */
|
|
47
|
+
setCustomId(customId) {
|
|
48
|
+
this.data.custom_id = assertLength('field custom_id', customId, exports.ModalLimits.CustomId);
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
/** ≤45 chars. */
|
|
52
|
+
setLabel(label) {
|
|
53
|
+
this.data.label = assertLength('field label', label, exports.ModalLimits.Label);
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
/** `'short'` (single line) or `'paragraph'` (multi-line). */
|
|
57
|
+
setStyle(style) {
|
|
58
|
+
if (style !== 'short' && style !== 'paragraph') {
|
|
59
|
+
throw new RangeError(`Text input style must be "short" or "paragraph" (got "${style}").`);
|
|
60
|
+
}
|
|
61
|
+
this.data.style = style;
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
/** Server default: true. */
|
|
65
|
+
setRequired(required = true) {
|
|
66
|
+
this.data.required = required;
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
/** ≤100 chars. */
|
|
70
|
+
setPlaceholder(placeholder) {
|
|
71
|
+
this.data.placeholder = assertLength('field placeholder', placeholder, exports.ModalLimits.Placeholder);
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
/** 0–4000. */
|
|
75
|
+
setMinLength(min) {
|
|
76
|
+
if (!Number.isInteger(min) || min < 0 || min > exports.ModalLimits.FieldLength) {
|
|
77
|
+
throw new RangeError(`Text input min_length must be an integer between 0 and ${exports.ModalLimits.FieldLength} (got ${min}).`);
|
|
78
|
+
}
|
|
79
|
+
this.data.min_length = min;
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
/** 1–4000 (`short` style caps at 1024 — checked at build time). */
|
|
83
|
+
setMaxLength(max) {
|
|
84
|
+
if (!Number.isInteger(max) || max < 1 || max > exports.ModalLimits.FieldLength) {
|
|
85
|
+
throw new RangeError(`Text input max_length must be an integer between 1 and ${exports.ModalLimits.FieldLength} (got ${max}).`);
|
|
86
|
+
}
|
|
87
|
+
this.data.max_length = max;
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
/** Prefill text (must fit max_length — checked at build time). */
|
|
91
|
+
setValue(value) {
|
|
92
|
+
this.data.value = value;
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
toJSON() {
|
|
96
|
+
const d = this.data;
|
|
97
|
+
if (!d.custom_id)
|
|
98
|
+
throw new RangeError('Text inputs require a custom_id — call setCustomId().');
|
|
99
|
+
if (!d.label)
|
|
100
|
+
throw new RangeError('Text inputs require a label — call setLabel().');
|
|
101
|
+
if (!d.style)
|
|
102
|
+
throw new RangeError('Text inputs require a style — call setStyle("short" | "paragraph").');
|
|
103
|
+
const styleCap = d.style === 'short' ? exports.ModalLimits.ShortFieldLength : exports.ModalLimits.FieldLength;
|
|
104
|
+
if (d.max_length !== undefined && d.max_length > styleCap) {
|
|
105
|
+
throw new RangeError(`Text input max_length exceeds ${styleCap} (${d.style} style cap; got ${d.max_length}).`);
|
|
106
|
+
}
|
|
107
|
+
const effectiveMax = d.max_length ?? styleCap;
|
|
108
|
+
if (d.min_length !== undefined && d.min_length > effectiveMax) {
|
|
109
|
+
throw new RangeError(`Text input min_length (${d.min_length}) must not exceed max_length (${effectiveMax}).`);
|
|
110
|
+
}
|
|
111
|
+
if (d.value !== undefined && d.value.length > effectiveMax) {
|
|
112
|
+
throw new RangeError(`Text input prefill value exceeds max_length (${effectiveMax}; got ${d.value.length}).`);
|
|
113
|
+
}
|
|
114
|
+
return { ...d };
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
exports.TextInputBuilder = TextInputBuilder;
|
|
118
|
+
/**
|
|
119
|
+
* Fluent modal builder. Pass it straight to `interaction.showModal(...)` —
|
|
120
|
+
* no `.toJSON()` call needed.
|
|
121
|
+
*/
|
|
122
|
+
class ModalBuilder {
|
|
123
|
+
constructor() {
|
|
124
|
+
this.data = {};
|
|
125
|
+
this.fields = [];
|
|
126
|
+
}
|
|
127
|
+
/** ≤45 chars. */
|
|
128
|
+
setTitle(title) {
|
|
129
|
+
this.data.title = assertLength('title', title, exports.ModalLimits.Title);
|
|
130
|
+
return this;
|
|
131
|
+
}
|
|
132
|
+
/** Your opaque modal identifier (≤100 chars) — comes back as the modal_submit's `customId`. */
|
|
133
|
+
setCustomId(customId) {
|
|
134
|
+
this.data.custom_id = assertLength('custom_id', customId, exports.ModalLimits.CustomId);
|
|
135
|
+
return this;
|
|
136
|
+
}
|
|
137
|
+
/** Append text inputs (1–5 total; field custom_ids must be unique). */
|
|
138
|
+
addFields(...fields) {
|
|
139
|
+
for (const field of fields) {
|
|
140
|
+
const resolved = field instanceof TextInputBuilder ? field.toJSON() : field;
|
|
141
|
+
if (this.fields.length >= exports.ModalLimits.Fields) {
|
|
142
|
+
throw new RangeError(`Modals hold at most ${exports.ModalLimits.Fields} fields.`);
|
|
143
|
+
}
|
|
144
|
+
if (this.fields.some((f) => f.custom_id === resolved.custom_id)) {
|
|
145
|
+
throw new RangeError(`Modal field custom_id "${resolved.custom_id}" is duplicated — field custom_ids must be unique.`);
|
|
146
|
+
}
|
|
147
|
+
this.fields.push(resolved);
|
|
148
|
+
}
|
|
149
|
+
return this;
|
|
150
|
+
}
|
|
151
|
+
toJSON() {
|
|
152
|
+
const d = this.data;
|
|
153
|
+
if (!d.title)
|
|
154
|
+
throw new RangeError('Modals require a title — call setTitle().');
|
|
155
|
+
if (!d.custom_id)
|
|
156
|
+
throw new RangeError('Modals require a custom_id — call setCustomId().');
|
|
157
|
+
if (this.fields.length === 0)
|
|
158
|
+
throw new RangeError('Modal has no fields — add at least one with addFields().');
|
|
159
|
+
return { title: d.title, custom_id: d.custom_id, fields: this.fields.map((f) => ({ ...f })) };
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
exports.ModalBuilder = ModalBuilder;
|