@magicyan/discord 1.4.3 → 1.4.5
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/dist/functions/components/container.cjs +21 -9
- package/dist/functions/components/container.mjs +22 -10
- package/dist/functions/components/section.cjs +23 -7
- package/dist/functions/components/section.mjs +24 -8
- package/dist/index.d.cts +48 -52
- package/dist/index.d.mts +48 -52
- package/dist/index.d.ts +48 -52
- package/package.json +2 -2
|
@@ -1,21 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const core = require('@magicyan/core');
|
|
4
3
|
const discord_js = require('discord.js');
|
|
5
|
-
const selectmenu = require('../../guards/selectmenu.cjs');
|
|
6
4
|
const attachment = require('../../guards/attachment.cjs');
|
|
5
|
+
const selectmenu = require('../../guards/selectmenu.cjs');
|
|
7
6
|
const gallery = require('./gallery.cjs');
|
|
8
|
-
const text = require('./text.cjs');
|
|
9
7
|
const row = require('./row.cjs');
|
|
8
|
+
const text = require('./text.cjs');
|
|
10
9
|
|
|
11
|
-
function createContainer(data) {
|
|
10
|
+
function createContainer(data, ...components) {
|
|
12
11
|
const container = new discord_js.ContainerBuilder();
|
|
13
|
-
|
|
14
|
-
typeof data.accentColor === "string" ? data.accentColor in discord_js.Colors ? discord_js.Colors[data.accentColor] : core.hexToRgb(data.accentColor) : data.accentColor
|
|
15
|
-
);
|
|
16
|
-
for (const component of data.components) {
|
|
12
|
+
const addComponent = (component) => {
|
|
17
13
|
if (!component)
|
|
18
|
-
|
|
14
|
+
return;
|
|
19
15
|
if (typeof component === "string") {
|
|
20
16
|
container.addTextDisplayComponents(
|
|
21
17
|
text.createTextDisplay(component)
|
|
@@ -56,7 +52,23 @@ function createContainer(data) {
|
|
|
56
52
|
if (component instanceof discord_js.SeparatorBuilder) {
|
|
57
53
|
container.addSeparatorComponents(component);
|
|
58
54
|
}
|
|
55
|
+
};
|
|
56
|
+
const setColor = (color) => {
|
|
57
|
+
container.setAccentColor(
|
|
58
|
+
discord_js.resolveColor(color)
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
const isContainerData = (value) => typeof value === "object" && "components" in value && Array.isArray(value.components);
|
|
62
|
+
if (isContainerData(data)) {
|
|
63
|
+
if (data.accentColor)
|
|
64
|
+
setColor(data.accentColor);
|
|
65
|
+
for (const component of data.components)
|
|
66
|
+
addComponent(component);
|
|
67
|
+
return container;
|
|
59
68
|
}
|
|
69
|
+
setColor(data);
|
|
70
|
+
for (const component of components)
|
|
71
|
+
addComponent(component);
|
|
60
72
|
return container;
|
|
61
73
|
}
|
|
62
74
|
|
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ContainerBuilder, Colors, TextDisplayBuilder, ActionRowBuilder, ButtonBuilder, SectionBuilder, FileBuilder, MediaGalleryBuilder, SeparatorBuilder } from 'discord.js';
|
|
3
|
-
import { isAnySelectMenuBuilder } from '../../guards/selectmenu.mjs';
|
|
1
|
+
import { ContainerBuilder, TextDisplayBuilder, ActionRowBuilder, ButtonBuilder, SectionBuilder, FileBuilder, MediaGalleryBuilder, SeparatorBuilder, resolveColor } from 'discord.js';
|
|
4
2
|
import { isAttachment } from '../../guards/attachment.mjs';
|
|
3
|
+
import { isAnySelectMenuBuilder } from '../../guards/selectmenu.mjs';
|
|
5
4
|
import { createMediaGallery } from './gallery.mjs';
|
|
6
|
-
import { createTextDisplay } from './text.mjs';
|
|
7
5
|
import { createRow } from './row.mjs';
|
|
6
|
+
import { createTextDisplay } from './text.mjs';
|
|
8
7
|
|
|
9
|
-
function createContainer(data) {
|
|
8
|
+
function createContainer(data, ...components) {
|
|
10
9
|
const container = new ContainerBuilder();
|
|
11
|
-
|
|
12
|
-
typeof data.accentColor === "string" ? data.accentColor in Colors ? Colors[data.accentColor] : hexToRgb(data.accentColor) : data.accentColor
|
|
13
|
-
);
|
|
14
|
-
for (const component of data.components) {
|
|
10
|
+
const addComponent = (component) => {
|
|
15
11
|
if (!component)
|
|
16
|
-
|
|
12
|
+
return;
|
|
17
13
|
if (typeof component === "string") {
|
|
18
14
|
container.addTextDisplayComponents(
|
|
19
15
|
createTextDisplay(component)
|
|
@@ -54,7 +50,23 @@ function createContainer(data) {
|
|
|
54
50
|
if (component instanceof SeparatorBuilder) {
|
|
55
51
|
container.addSeparatorComponents(component);
|
|
56
52
|
}
|
|
53
|
+
};
|
|
54
|
+
const setColor = (color) => {
|
|
55
|
+
container.setAccentColor(
|
|
56
|
+
resolveColor(color)
|
|
57
|
+
);
|
|
58
|
+
};
|
|
59
|
+
const isContainerData = (value) => typeof value === "object" && "components" in value && Array.isArray(value.components);
|
|
60
|
+
if (isContainerData(data)) {
|
|
61
|
+
if (data.accentColor)
|
|
62
|
+
setColor(data.accentColor);
|
|
63
|
+
for (const component of data.components)
|
|
64
|
+
addComponent(component);
|
|
65
|
+
return container;
|
|
57
66
|
}
|
|
67
|
+
setColor(data);
|
|
68
|
+
for (const component of components)
|
|
69
|
+
addComponent(component);
|
|
58
70
|
return container;
|
|
59
71
|
}
|
|
60
72
|
|
|
@@ -6,17 +6,33 @@ const thumbnail = require('./thumbnail.cjs');
|
|
|
6
6
|
|
|
7
7
|
function createSection(data) {
|
|
8
8
|
const section = new discord_js.SectionBuilder();
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
function setAccessory(data2) {
|
|
10
|
+
if (data2 instanceof discord_js.ButtonBuilder) {
|
|
11
|
+
return section.setButtonAccessory(data2);
|
|
12
|
+
}
|
|
13
|
+
if (data2 instanceof discord_js.ThumbnailBuilder) {
|
|
14
|
+
return section.setThumbnailAccessory(data2);
|
|
15
|
+
}
|
|
16
|
+
if (typeof data2 === "string") {
|
|
17
|
+
return section.setThumbnailAccessory(
|
|
18
|
+
thumbnail.createThumbnail(data2)
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
if ("media" in data2 || "description" in data2) {
|
|
22
|
+
return section.setThumbnailAccessory(
|
|
23
|
+
thumbnail.createThumbnail(data2)
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
return section.setButtonAccessory(
|
|
27
|
+
new discord_js.ButtonBuilder(data2)
|
|
15
28
|
);
|
|
16
29
|
}
|
|
30
|
+
if (data.accessory || data.button || data.thumbnail) {
|
|
31
|
+
setAccessory(data.accessory ?? data.button ?? data.thumbnail);
|
|
32
|
+
}
|
|
17
33
|
if (Array.isArray(data.content)) {
|
|
18
34
|
section.addTextDisplayComponents(
|
|
19
|
-
data.content.map(text.createTextDisplay)
|
|
35
|
+
data.content.map((text$1) => text.createTextDisplay(text$1))
|
|
20
36
|
);
|
|
21
37
|
} else {
|
|
22
38
|
section.addTextDisplayComponents(
|
|
@@ -1,20 +1,36 @@
|
|
|
1
|
-
import { SectionBuilder } from 'discord.js';
|
|
1
|
+
import { SectionBuilder, ButtonBuilder, ThumbnailBuilder } from 'discord.js';
|
|
2
2
|
import { createTextDisplay } from './text.mjs';
|
|
3
3
|
import { createThumbnail } from './thumbnail.mjs';
|
|
4
4
|
|
|
5
5
|
function createSection(data) {
|
|
6
6
|
const section = new SectionBuilder();
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
function setAccessory(data2) {
|
|
8
|
+
if (data2 instanceof ButtonBuilder) {
|
|
9
|
+
return section.setButtonAccessory(data2);
|
|
10
|
+
}
|
|
11
|
+
if (data2 instanceof ThumbnailBuilder) {
|
|
12
|
+
return section.setThumbnailAccessory(data2);
|
|
13
|
+
}
|
|
14
|
+
if (typeof data2 === "string") {
|
|
15
|
+
return section.setThumbnailAccessory(
|
|
16
|
+
createThumbnail(data2)
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
if ("media" in data2 || "description" in data2) {
|
|
20
|
+
return section.setThumbnailAccessory(
|
|
21
|
+
createThumbnail(data2)
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
return section.setButtonAccessory(
|
|
25
|
+
new ButtonBuilder(data2)
|
|
13
26
|
);
|
|
14
27
|
}
|
|
28
|
+
if (data.accessory || data.button || data.thumbnail) {
|
|
29
|
+
setAccessory(data.accessory ?? data.button ?? data.thumbnail);
|
|
30
|
+
}
|
|
15
31
|
if (Array.isArray(data.content)) {
|
|
16
32
|
section.addTextDisplayComponents(
|
|
17
|
-
data.content.map(createTextDisplay)
|
|
33
|
+
data.content.map((text) => createTextDisplay(text))
|
|
18
34
|
);
|
|
19
35
|
} else {
|
|
20
36
|
section.addTextDisplayComponents(
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as discord_js from 'discord.js';
|
|
2
|
-
import { GatewayIntentBits, Partials, Attachment, AttachmentBuilder, EmbedAssetData, Guild, GuildMember, User, ClientUser, ImageURLOptions, EmbedFooterData, ColorResolvable, APIEmbed, Embed, EmbedData, EmbedBuilder, AttachmentData, ButtonBuilder, LinkButtonComponentData, AnyComponentBuilder, ActionRowBuilder, FileBuilder, APIUnfurledMediaItem, MediaGalleryBuilder, MediaGalleryItemData, SeparatorBuilder, ThumbnailComponentData, ThumbnailBuilder, SectionBuilder, TextDisplayBuilder, MessageActionRowComponentBuilder, ContainerBuilder,
|
|
2
|
+
import { GatewayIntentBits, Partials, Attachment, AttachmentBuilder, EmbedAssetData, Guild, GuildMember, User, ClientUser, ImageURLOptions, EmbedFooterData, ColorResolvable, APIEmbed, Embed, EmbedData, EmbedBuilder, AttachmentData, ButtonBuilder, LinkButtonComponentData, AnyComponentBuilder, ActionRowBuilder, FileBuilder, APIUnfurledMediaItem, MediaGalleryBuilder, MediaGalleryItemData, SeparatorBuilder, ThumbnailComponentData, ThumbnailBuilder, ButtonComponentData, SectionBuilder, TextDisplayBuilder, MessageActionRowComponentBuilder, ContainerBuilder, ContainerComponentData, ChannelType, CommandInteractionOption, Client, ApplicationCommand, TextInputBuilder, ModalSubmitInteraction, ModalSubmitFields, Collection, TextInputComponent, TextInputStyle, TextInputComponentData, GuildEmoji, GuildTextBasedChannel, Message, Role, WebhookClientOptions, WebhookClient, WebhookClientData, StringSelectMenuBuilder, UserSelectMenuBuilder, RoleSelectMenuBuilder, ChannelSelectMenuBuilder, MentionableSelectMenuBuilder } from 'discord.js';
|
|
3
3
|
export * from '@magicyan/core';
|
|
4
4
|
|
|
5
5
|
declare const chars: {
|
|
@@ -322,14 +322,23 @@ type ThumbnailData = Partial<Omit<ThumbnailComponentData, "type">> | Attachment
|
|
|
322
322
|
*/
|
|
323
323
|
declare function createThumbnail(data: ThumbnailData): ThumbnailBuilder;
|
|
324
324
|
|
|
325
|
-
type
|
|
325
|
+
type SectionThumbnailAccessory = ThumbnailBuilder | ThumbnailData;
|
|
326
|
+
type SectionButtonAccessory = ButtonBuilder | Partial<ButtonComponentData>;
|
|
327
|
+
type SectionAccessory = SectionThumbnailAccessory | SectionButtonAccessory;
|
|
328
|
+
type SectionAccessoryData = {
|
|
329
|
+
accessory: SectionAccessory;
|
|
326
330
|
button?: never;
|
|
327
|
-
thumbnail
|
|
331
|
+
thumbnail?: never;
|
|
328
332
|
} | {
|
|
329
|
-
button:
|
|
333
|
+
button: SectionButtonAccessory;
|
|
330
334
|
thumbnail?: never;
|
|
335
|
+
accessory?: never;
|
|
336
|
+
} | {
|
|
337
|
+
thumbnail: SectionThumbnailAccessory;
|
|
338
|
+
button?: never;
|
|
339
|
+
accessory?: never;
|
|
331
340
|
};
|
|
332
|
-
type SectionData =
|
|
341
|
+
type SectionData = SectionAccessoryData & {
|
|
333
342
|
content: string | string[];
|
|
334
343
|
};
|
|
335
344
|
/**
|
|
@@ -396,71 +405,58 @@ declare function createSection(data: SectionData): SectionBuilder;
|
|
|
396
405
|
*/
|
|
397
406
|
declare function createTextDisplay(content: string, id?: number): TextDisplayBuilder;
|
|
398
407
|
|
|
399
|
-
type ComponentData = TextDisplayBuilder | SeparatorBuilder | FileBuilder | SectionBuilder | MediaGalleryBuilder | ActionRowBuilder<MessageActionRowComponentBuilder> | MessageActionRowComponentBuilder[] | MessageActionRowComponentBuilder |
|
|
400
|
-
declare function createComponents(...data: (ComponentData | ContainerBuilder)[]): (TextDisplayBuilder | SeparatorBuilder |
|
|
408
|
+
type ComponentData = TextDisplayBuilder | SeparatorBuilder | FileBuilder | SectionBuilder | MediaGalleryBuilder | ActionRowBuilder<MessageActionRowComponentBuilder> | MessageActionRowComponentBuilder[] | MessageActionRowComponentBuilder | Attachment | AttachmentBuilder | string | null | undefined;
|
|
409
|
+
declare function createComponents(...data: (ComponentData | ContainerBuilder)[]): (TextDisplayBuilder | SeparatorBuilder | FileBuilder | SectionBuilder | MediaGalleryBuilder | ActionRowBuilder<MessageActionRowComponentBuilder> | ContainerBuilder)[];
|
|
401
410
|
|
|
402
|
-
type
|
|
411
|
+
type ContainerColor = (string & {}) | ColorResolvable;
|
|
403
412
|
interface ContainerData extends Omit<ContainerComponentData, "accentColor" | "type" | "components"> {
|
|
404
|
-
accentColor?:
|
|
413
|
+
accentColor?: ContainerColor;
|
|
405
414
|
components: ComponentData[];
|
|
406
415
|
}
|
|
407
416
|
/**
|
|
408
|
-
* Creates a {@link ContainerBuilder} component with
|
|
417
|
+
* Creates a {@link ContainerBuilder} component with optional accent color and a set of child components.
|
|
409
418
|
*
|
|
410
|
-
* This function
|
|
411
|
-
*
|
|
412
|
-
*
|
|
419
|
+
* This function can be used in two ways:
|
|
420
|
+
* 1. By passing an object with `accentColor` and `components` properties.
|
|
421
|
+
* 2. By passing the `accentColor` directly followed by a list of components.
|
|
413
422
|
*
|
|
414
|
-
*
|
|
415
|
-
* - `
|
|
416
|
-
*
|
|
417
|
-
*
|
|
418
|
-
*
|
|
419
|
-
*
|
|
420
|
-
* -
|
|
421
|
-
*
|
|
422
|
-
*
|
|
423
|
-
*
|
|
423
|
+
* The container can include various types of components such as:
|
|
424
|
+
* - `string` (converted to `TextDisplayBuilder`)
|
|
425
|
+
* - {@link TextDisplayBuilder}
|
|
426
|
+
* - {@link ActionRowBuilder}
|
|
427
|
+
* - Arrays of components (converted to an action row)
|
|
428
|
+
* - {@link ButtonBuilder}
|
|
429
|
+
* - {@link SectionBuilder}
|
|
430
|
+
* - {@link MediaGalleryBuilder}
|
|
431
|
+
* - {@link FileBuilder}
|
|
432
|
+
* - {@link SeparatorBuilder}
|
|
433
|
+
* - Discord attachments (treated as media galleries)
|
|
424
434
|
*
|
|
425
|
-
* @param data -
|
|
435
|
+
* @param data - Either a `ContainerData` object containing `accentColor` and `components`, or the accent color directly.
|
|
436
|
+
* @param components - When using the overload with accent color as the first parameter, this is the list of components to include in the container.
|
|
426
437
|
*
|
|
427
|
-
* @returns A {@link ContainerBuilder} instance with
|
|
438
|
+
* @returns A {@link ContainerBuilder} instance with all components and styles applied.
|
|
428
439
|
*
|
|
429
440
|
* @example
|
|
430
|
-
* //
|
|
441
|
+
* // Using ContainerData object
|
|
431
442
|
* const container = createContainer({
|
|
432
|
-
* accentColor: "#ff5733",
|
|
433
|
-
* components: [
|
|
434
|
-
* "This is a text display component"
|
|
435
|
-
* ]
|
|
443
|
+
* accentColor: "#ff5733",
|
|
444
|
+
* components: ["Welcome to the app!"]
|
|
436
445
|
* });
|
|
437
446
|
*
|
|
438
447
|
* @example
|
|
439
|
-
* //
|
|
440
|
-
* const container = createContainer(
|
|
441
|
-
*
|
|
442
|
-
*
|
|
443
|
-
*
|
|
444
|
-
* content: "-# Increment counter",
|
|
445
|
-
* button: new ButtonBuilder({
|
|
446
|
-
* customId: `counter/increment`,
|
|
447
|
-
* label: "+",
|
|
448
|
-
* style: ButtonStyle.Success
|
|
449
|
-
* })
|
|
450
|
-
* }),
|
|
451
|
-
* ]
|
|
452
|
-
* });
|
|
448
|
+
* // Using color and components as separate arguments
|
|
449
|
+
* const container = createContainer("Red",
|
|
450
|
+
* new TextDisplayBuilder().setText("Alert!"),
|
|
451
|
+
* new SeparatorBuilder()
|
|
452
|
+
* );
|
|
453
453
|
*
|
|
454
454
|
* @example
|
|
455
|
-
* //
|
|
456
|
-
* const container = createContainer(
|
|
457
|
-
* accentColor: [255, 87, 51], // RGB tuple
|
|
458
|
-
* components: [
|
|
459
|
-
* "Here's some content."
|
|
460
|
-
* ]
|
|
461
|
-
* });
|
|
455
|
+
* // Using RGB tuple
|
|
456
|
+
* const container = createContainer([255, 0, 0], "Red alert");
|
|
462
457
|
*/
|
|
463
458
|
declare function createContainer(data: ContainerData): ContainerBuilder;
|
|
459
|
+
declare function createContainer(data: ColorResolvable | string, ...components: ComponentData[]): ContainerBuilder;
|
|
464
460
|
|
|
465
461
|
type GuildChannelType = Exclude<ChannelType, ChannelType.DM>;
|
|
466
462
|
type FindChannelFilter<T extends GuildChannelType> = (channel: GetChannelType<T>) => boolean;
|
|
@@ -598,4 +594,4 @@ declare function isAnySelectMenuBuilder(value: unknown): value is AnySelectMenuB
|
|
|
598
594
|
declare function isButtonBuilder(value: unknown): value is ButtonBuilder;
|
|
599
595
|
|
|
600
596
|
export { CustomItents, CustomPartials, EmbedLimit, EmbedPlusBuilder, chars, commandMention, createComponents, createContainer, createEmbed, createEmbedAsset, createEmbedAuthor, createEmbedFiles, createEmbedFooter, createFile, createLinkButton, createMediaGallery, createModalFields, createModalInput, createRow, createSection, createSeparator, createTextDisplay, createThumbnail, createWebhookClient, extractMentionId, findChannel, findCommand, findEmoji, findMember, findMessage, findRole, getChannelUrlInfo, getMessageUrlInfo, isAnySelectMenuBuilder, isAttachment, isButtonBuilder, modalFieldsToRecord, setMobileStatus };
|
|
601
|
-
export type { AnyEmbedData, AnySelectMenuBuilder, ComponentData, ContainerData, EmbedPlusAssetData, EmbedPlusAuthorData, EmbedPlusColorData, EmbedPlusData, EmbedPlusFooterData, EmbedPlusProperty,
|
|
597
|
+
export type { AnyEmbedData, AnySelectMenuBuilder, ComponentData, ContainerColor, ContainerData, EmbedPlusAssetData, EmbedPlusAuthorData, EmbedPlusColorData, EmbedPlusData, EmbedPlusFooterData, EmbedPlusProperty, SectionAccessory, SectionAccessoryData, SectionButtonAccessory, SectionData, SectionThumbnailAccessory, SeparatorData, ThumbnailData };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as discord_js from 'discord.js';
|
|
2
|
-
import { GatewayIntentBits, Partials, Attachment, AttachmentBuilder, EmbedAssetData, Guild, GuildMember, User, ClientUser, ImageURLOptions, EmbedFooterData, ColorResolvable, APIEmbed, Embed, EmbedData, EmbedBuilder, AttachmentData, ButtonBuilder, LinkButtonComponentData, AnyComponentBuilder, ActionRowBuilder, FileBuilder, APIUnfurledMediaItem, MediaGalleryBuilder, MediaGalleryItemData, SeparatorBuilder, ThumbnailComponentData, ThumbnailBuilder, SectionBuilder, TextDisplayBuilder, MessageActionRowComponentBuilder, ContainerBuilder,
|
|
2
|
+
import { GatewayIntentBits, Partials, Attachment, AttachmentBuilder, EmbedAssetData, Guild, GuildMember, User, ClientUser, ImageURLOptions, EmbedFooterData, ColorResolvable, APIEmbed, Embed, EmbedData, EmbedBuilder, AttachmentData, ButtonBuilder, LinkButtonComponentData, AnyComponentBuilder, ActionRowBuilder, FileBuilder, APIUnfurledMediaItem, MediaGalleryBuilder, MediaGalleryItemData, SeparatorBuilder, ThumbnailComponentData, ThumbnailBuilder, ButtonComponentData, SectionBuilder, TextDisplayBuilder, MessageActionRowComponentBuilder, ContainerBuilder, ContainerComponentData, ChannelType, CommandInteractionOption, Client, ApplicationCommand, TextInputBuilder, ModalSubmitInteraction, ModalSubmitFields, Collection, TextInputComponent, TextInputStyle, TextInputComponentData, GuildEmoji, GuildTextBasedChannel, Message, Role, WebhookClientOptions, WebhookClient, WebhookClientData, StringSelectMenuBuilder, UserSelectMenuBuilder, RoleSelectMenuBuilder, ChannelSelectMenuBuilder, MentionableSelectMenuBuilder } from 'discord.js';
|
|
3
3
|
export * from '@magicyan/core';
|
|
4
4
|
|
|
5
5
|
declare const chars: {
|
|
@@ -322,14 +322,23 @@ type ThumbnailData = Partial<Omit<ThumbnailComponentData, "type">> | Attachment
|
|
|
322
322
|
*/
|
|
323
323
|
declare function createThumbnail(data: ThumbnailData): ThumbnailBuilder;
|
|
324
324
|
|
|
325
|
-
type
|
|
325
|
+
type SectionThumbnailAccessory = ThumbnailBuilder | ThumbnailData;
|
|
326
|
+
type SectionButtonAccessory = ButtonBuilder | Partial<ButtonComponentData>;
|
|
327
|
+
type SectionAccessory = SectionThumbnailAccessory | SectionButtonAccessory;
|
|
328
|
+
type SectionAccessoryData = {
|
|
329
|
+
accessory: SectionAccessory;
|
|
326
330
|
button?: never;
|
|
327
|
-
thumbnail
|
|
331
|
+
thumbnail?: never;
|
|
328
332
|
} | {
|
|
329
|
-
button:
|
|
333
|
+
button: SectionButtonAccessory;
|
|
330
334
|
thumbnail?: never;
|
|
335
|
+
accessory?: never;
|
|
336
|
+
} | {
|
|
337
|
+
thumbnail: SectionThumbnailAccessory;
|
|
338
|
+
button?: never;
|
|
339
|
+
accessory?: never;
|
|
331
340
|
};
|
|
332
|
-
type SectionData =
|
|
341
|
+
type SectionData = SectionAccessoryData & {
|
|
333
342
|
content: string | string[];
|
|
334
343
|
};
|
|
335
344
|
/**
|
|
@@ -396,71 +405,58 @@ declare function createSection(data: SectionData): SectionBuilder;
|
|
|
396
405
|
*/
|
|
397
406
|
declare function createTextDisplay(content: string, id?: number): TextDisplayBuilder;
|
|
398
407
|
|
|
399
|
-
type ComponentData = TextDisplayBuilder | SeparatorBuilder | FileBuilder | SectionBuilder | MediaGalleryBuilder | ActionRowBuilder<MessageActionRowComponentBuilder> | MessageActionRowComponentBuilder[] | MessageActionRowComponentBuilder |
|
|
400
|
-
declare function createComponents(...data: (ComponentData | ContainerBuilder)[]): (TextDisplayBuilder | SeparatorBuilder |
|
|
408
|
+
type ComponentData = TextDisplayBuilder | SeparatorBuilder | FileBuilder | SectionBuilder | MediaGalleryBuilder | ActionRowBuilder<MessageActionRowComponentBuilder> | MessageActionRowComponentBuilder[] | MessageActionRowComponentBuilder | Attachment | AttachmentBuilder | string | null | undefined;
|
|
409
|
+
declare function createComponents(...data: (ComponentData | ContainerBuilder)[]): (TextDisplayBuilder | SeparatorBuilder | FileBuilder | SectionBuilder | MediaGalleryBuilder | ActionRowBuilder<MessageActionRowComponentBuilder> | ContainerBuilder)[];
|
|
401
410
|
|
|
402
|
-
type
|
|
411
|
+
type ContainerColor = (string & {}) | ColorResolvable;
|
|
403
412
|
interface ContainerData extends Omit<ContainerComponentData, "accentColor" | "type" | "components"> {
|
|
404
|
-
accentColor?:
|
|
413
|
+
accentColor?: ContainerColor;
|
|
405
414
|
components: ComponentData[];
|
|
406
415
|
}
|
|
407
416
|
/**
|
|
408
|
-
* Creates a {@link ContainerBuilder} component with
|
|
417
|
+
* Creates a {@link ContainerBuilder} component with optional accent color and a set of child components.
|
|
409
418
|
*
|
|
410
|
-
* This function
|
|
411
|
-
*
|
|
412
|
-
*
|
|
419
|
+
* This function can be used in two ways:
|
|
420
|
+
* 1. By passing an object with `accentColor` and `components` properties.
|
|
421
|
+
* 2. By passing the `accentColor` directly followed by a list of components.
|
|
413
422
|
*
|
|
414
|
-
*
|
|
415
|
-
* - `
|
|
416
|
-
*
|
|
417
|
-
*
|
|
418
|
-
*
|
|
419
|
-
*
|
|
420
|
-
* -
|
|
421
|
-
*
|
|
422
|
-
*
|
|
423
|
-
*
|
|
423
|
+
* The container can include various types of components such as:
|
|
424
|
+
* - `string` (converted to `TextDisplayBuilder`)
|
|
425
|
+
* - {@link TextDisplayBuilder}
|
|
426
|
+
* - {@link ActionRowBuilder}
|
|
427
|
+
* - Arrays of components (converted to an action row)
|
|
428
|
+
* - {@link ButtonBuilder}
|
|
429
|
+
* - {@link SectionBuilder}
|
|
430
|
+
* - {@link MediaGalleryBuilder}
|
|
431
|
+
* - {@link FileBuilder}
|
|
432
|
+
* - {@link SeparatorBuilder}
|
|
433
|
+
* - Discord attachments (treated as media galleries)
|
|
424
434
|
*
|
|
425
|
-
* @param data -
|
|
435
|
+
* @param data - Either a `ContainerData` object containing `accentColor` and `components`, or the accent color directly.
|
|
436
|
+
* @param components - When using the overload with accent color as the first parameter, this is the list of components to include in the container.
|
|
426
437
|
*
|
|
427
|
-
* @returns A {@link ContainerBuilder} instance with
|
|
438
|
+
* @returns A {@link ContainerBuilder} instance with all components and styles applied.
|
|
428
439
|
*
|
|
429
440
|
* @example
|
|
430
|
-
* //
|
|
441
|
+
* // Using ContainerData object
|
|
431
442
|
* const container = createContainer({
|
|
432
|
-
* accentColor: "#ff5733",
|
|
433
|
-
* components: [
|
|
434
|
-
* "This is a text display component"
|
|
435
|
-
* ]
|
|
443
|
+
* accentColor: "#ff5733",
|
|
444
|
+
* components: ["Welcome to the app!"]
|
|
436
445
|
* });
|
|
437
446
|
*
|
|
438
447
|
* @example
|
|
439
|
-
* //
|
|
440
|
-
* const container = createContainer(
|
|
441
|
-
*
|
|
442
|
-
*
|
|
443
|
-
*
|
|
444
|
-
* content: "-# Increment counter",
|
|
445
|
-
* button: new ButtonBuilder({
|
|
446
|
-
* customId: `counter/increment`,
|
|
447
|
-
* label: "+",
|
|
448
|
-
* style: ButtonStyle.Success
|
|
449
|
-
* })
|
|
450
|
-
* }),
|
|
451
|
-
* ]
|
|
452
|
-
* });
|
|
448
|
+
* // Using color and components as separate arguments
|
|
449
|
+
* const container = createContainer("Red",
|
|
450
|
+
* new TextDisplayBuilder().setText("Alert!"),
|
|
451
|
+
* new SeparatorBuilder()
|
|
452
|
+
* );
|
|
453
453
|
*
|
|
454
454
|
* @example
|
|
455
|
-
* //
|
|
456
|
-
* const container = createContainer(
|
|
457
|
-
* accentColor: [255, 87, 51], // RGB tuple
|
|
458
|
-
* components: [
|
|
459
|
-
* "Here's some content."
|
|
460
|
-
* ]
|
|
461
|
-
* });
|
|
455
|
+
* // Using RGB tuple
|
|
456
|
+
* const container = createContainer([255, 0, 0], "Red alert");
|
|
462
457
|
*/
|
|
463
458
|
declare function createContainer(data: ContainerData): ContainerBuilder;
|
|
459
|
+
declare function createContainer(data: ColorResolvable | string, ...components: ComponentData[]): ContainerBuilder;
|
|
464
460
|
|
|
465
461
|
type GuildChannelType = Exclude<ChannelType, ChannelType.DM>;
|
|
466
462
|
type FindChannelFilter<T extends GuildChannelType> = (channel: GetChannelType<T>) => boolean;
|
|
@@ -598,4 +594,4 @@ declare function isAnySelectMenuBuilder(value: unknown): value is AnySelectMenuB
|
|
|
598
594
|
declare function isButtonBuilder(value: unknown): value is ButtonBuilder;
|
|
599
595
|
|
|
600
596
|
export { CustomItents, CustomPartials, EmbedLimit, EmbedPlusBuilder, chars, commandMention, createComponents, createContainer, createEmbed, createEmbedAsset, createEmbedAuthor, createEmbedFiles, createEmbedFooter, createFile, createLinkButton, createMediaGallery, createModalFields, createModalInput, createRow, createSection, createSeparator, createTextDisplay, createThumbnail, createWebhookClient, extractMentionId, findChannel, findCommand, findEmoji, findMember, findMessage, findRole, getChannelUrlInfo, getMessageUrlInfo, isAnySelectMenuBuilder, isAttachment, isButtonBuilder, modalFieldsToRecord, setMobileStatus };
|
|
601
|
-
export type { AnyEmbedData, AnySelectMenuBuilder, ComponentData, ContainerData, EmbedPlusAssetData, EmbedPlusAuthorData, EmbedPlusColorData, EmbedPlusData, EmbedPlusFooterData, EmbedPlusProperty,
|
|
597
|
+
export type { AnyEmbedData, AnySelectMenuBuilder, ComponentData, ContainerColor, ContainerData, EmbedPlusAssetData, EmbedPlusAuthorData, EmbedPlusColorData, EmbedPlusData, EmbedPlusFooterData, EmbedPlusProperty, SectionAccessory, SectionAccessoryData, SectionButtonAccessory, SectionData, SectionThumbnailAccessory, SeparatorData, ThumbnailData };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as discord_js from 'discord.js';
|
|
2
|
-
import { GatewayIntentBits, Partials, Attachment, AttachmentBuilder, EmbedAssetData, Guild, GuildMember, User, ClientUser, ImageURLOptions, EmbedFooterData, ColorResolvable, APIEmbed, Embed, EmbedData, EmbedBuilder, AttachmentData, ButtonBuilder, LinkButtonComponentData, AnyComponentBuilder, ActionRowBuilder, FileBuilder, APIUnfurledMediaItem, MediaGalleryBuilder, MediaGalleryItemData, SeparatorBuilder, ThumbnailComponentData, ThumbnailBuilder, SectionBuilder, TextDisplayBuilder, MessageActionRowComponentBuilder, ContainerBuilder,
|
|
2
|
+
import { GatewayIntentBits, Partials, Attachment, AttachmentBuilder, EmbedAssetData, Guild, GuildMember, User, ClientUser, ImageURLOptions, EmbedFooterData, ColorResolvable, APIEmbed, Embed, EmbedData, EmbedBuilder, AttachmentData, ButtonBuilder, LinkButtonComponentData, AnyComponentBuilder, ActionRowBuilder, FileBuilder, APIUnfurledMediaItem, MediaGalleryBuilder, MediaGalleryItemData, SeparatorBuilder, ThumbnailComponentData, ThumbnailBuilder, ButtonComponentData, SectionBuilder, TextDisplayBuilder, MessageActionRowComponentBuilder, ContainerBuilder, ContainerComponentData, ChannelType, CommandInteractionOption, Client, ApplicationCommand, TextInputBuilder, ModalSubmitInteraction, ModalSubmitFields, Collection, TextInputComponent, TextInputStyle, TextInputComponentData, GuildEmoji, GuildTextBasedChannel, Message, Role, WebhookClientOptions, WebhookClient, WebhookClientData, StringSelectMenuBuilder, UserSelectMenuBuilder, RoleSelectMenuBuilder, ChannelSelectMenuBuilder, MentionableSelectMenuBuilder } from 'discord.js';
|
|
3
3
|
export * from '@magicyan/core';
|
|
4
4
|
|
|
5
5
|
declare const chars: {
|
|
@@ -322,14 +322,23 @@ type ThumbnailData = Partial<Omit<ThumbnailComponentData, "type">> | Attachment
|
|
|
322
322
|
*/
|
|
323
323
|
declare function createThumbnail(data: ThumbnailData): ThumbnailBuilder;
|
|
324
324
|
|
|
325
|
-
type
|
|
325
|
+
type SectionThumbnailAccessory = ThumbnailBuilder | ThumbnailData;
|
|
326
|
+
type SectionButtonAccessory = ButtonBuilder | Partial<ButtonComponentData>;
|
|
327
|
+
type SectionAccessory = SectionThumbnailAccessory | SectionButtonAccessory;
|
|
328
|
+
type SectionAccessoryData = {
|
|
329
|
+
accessory: SectionAccessory;
|
|
326
330
|
button?: never;
|
|
327
|
-
thumbnail
|
|
331
|
+
thumbnail?: never;
|
|
328
332
|
} | {
|
|
329
|
-
button:
|
|
333
|
+
button: SectionButtonAccessory;
|
|
330
334
|
thumbnail?: never;
|
|
335
|
+
accessory?: never;
|
|
336
|
+
} | {
|
|
337
|
+
thumbnail: SectionThumbnailAccessory;
|
|
338
|
+
button?: never;
|
|
339
|
+
accessory?: never;
|
|
331
340
|
};
|
|
332
|
-
type SectionData =
|
|
341
|
+
type SectionData = SectionAccessoryData & {
|
|
333
342
|
content: string | string[];
|
|
334
343
|
};
|
|
335
344
|
/**
|
|
@@ -396,71 +405,58 @@ declare function createSection(data: SectionData): SectionBuilder;
|
|
|
396
405
|
*/
|
|
397
406
|
declare function createTextDisplay(content: string, id?: number): TextDisplayBuilder;
|
|
398
407
|
|
|
399
|
-
type ComponentData = TextDisplayBuilder | SeparatorBuilder | FileBuilder | SectionBuilder | MediaGalleryBuilder | ActionRowBuilder<MessageActionRowComponentBuilder> | MessageActionRowComponentBuilder[] | MessageActionRowComponentBuilder |
|
|
400
|
-
declare function createComponents(...data: (ComponentData | ContainerBuilder)[]): (TextDisplayBuilder | SeparatorBuilder |
|
|
408
|
+
type ComponentData = TextDisplayBuilder | SeparatorBuilder | FileBuilder | SectionBuilder | MediaGalleryBuilder | ActionRowBuilder<MessageActionRowComponentBuilder> | MessageActionRowComponentBuilder[] | MessageActionRowComponentBuilder | Attachment | AttachmentBuilder | string | null | undefined;
|
|
409
|
+
declare function createComponents(...data: (ComponentData | ContainerBuilder)[]): (TextDisplayBuilder | SeparatorBuilder | FileBuilder | SectionBuilder | MediaGalleryBuilder | ActionRowBuilder<MessageActionRowComponentBuilder> | ContainerBuilder)[];
|
|
401
410
|
|
|
402
|
-
type
|
|
411
|
+
type ContainerColor = (string & {}) | ColorResolvable;
|
|
403
412
|
interface ContainerData extends Omit<ContainerComponentData, "accentColor" | "type" | "components"> {
|
|
404
|
-
accentColor?:
|
|
413
|
+
accentColor?: ContainerColor;
|
|
405
414
|
components: ComponentData[];
|
|
406
415
|
}
|
|
407
416
|
/**
|
|
408
|
-
* Creates a {@link ContainerBuilder} component with
|
|
417
|
+
* Creates a {@link ContainerBuilder} component with optional accent color and a set of child components.
|
|
409
418
|
*
|
|
410
|
-
* This function
|
|
411
|
-
*
|
|
412
|
-
*
|
|
419
|
+
* This function can be used in two ways:
|
|
420
|
+
* 1. By passing an object with `accentColor` and `components` properties.
|
|
421
|
+
* 2. By passing the `accentColor` directly followed by a list of components.
|
|
413
422
|
*
|
|
414
|
-
*
|
|
415
|
-
* - `
|
|
416
|
-
*
|
|
417
|
-
*
|
|
418
|
-
*
|
|
419
|
-
*
|
|
420
|
-
* -
|
|
421
|
-
*
|
|
422
|
-
*
|
|
423
|
-
*
|
|
423
|
+
* The container can include various types of components such as:
|
|
424
|
+
* - `string` (converted to `TextDisplayBuilder`)
|
|
425
|
+
* - {@link TextDisplayBuilder}
|
|
426
|
+
* - {@link ActionRowBuilder}
|
|
427
|
+
* - Arrays of components (converted to an action row)
|
|
428
|
+
* - {@link ButtonBuilder}
|
|
429
|
+
* - {@link SectionBuilder}
|
|
430
|
+
* - {@link MediaGalleryBuilder}
|
|
431
|
+
* - {@link FileBuilder}
|
|
432
|
+
* - {@link SeparatorBuilder}
|
|
433
|
+
* - Discord attachments (treated as media galleries)
|
|
424
434
|
*
|
|
425
|
-
* @param data -
|
|
435
|
+
* @param data - Either a `ContainerData` object containing `accentColor` and `components`, or the accent color directly.
|
|
436
|
+
* @param components - When using the overload with accent color as the first parameter, this is the list of components to include in the container.
|
|
426
437
|
*
|
|
427
|
-
* @returns A {@link ContainerBuilder} instance with
|
|
438
|
+
* @returns A {@link ContainerBuilder} instance with all components and styles applied.
|
|
428
439
|
*
|
|
429
440
|
* @example
|
|
430
|
-
* //
|
|
441
|
+
* // Using ContainerData object
|
|
431
442
|
* const container = createContainer({
|
|
432
|
-
* accentColor: "#ff5733",
|
|
433
|
-
* components: [
|
|
434
|
-
* "This is a text display component"
|
|
435
|
-
* ]
|
|
443
|
+
* accentColor: "#ff5733",
|
|
444
|
+
* components: ["Welcome to the app!"]
|
|
436
445
|
* });
|
|
437
446
|
*
|
|
438
447
|
* @example
|
|
439
|
-
* //
|
|
440
|
-
* const container = createContainer(
|
|
441
|
-
*
|
|
442
|
-
*
|
|
443
|
-
*
|
|
444
|
-
* content: "-# Increment counter",
|
|
445
|
-
* button: new ButtonBuilder({
|
|
446
|
-
* customId: `counter/increment`,
|
|
447
|
-
* label: "+",
|
|
448
|
-
* style: ButtonStyle.Success
|
|
449
|
-
* })
|
|
450
|
-
* }),
|
|
451
|
-
* ]
|
|
452
|
-
* });
|
|
448
|
+
* // Using color and components as separate arguments
|
|
449
|
+
* const container = createContainer("Red",
|
|
450
|
+
* new TextDisplayBuilder().setText("Alert!"),
|
|
451
|
+
* new SeparatorBuilder()
|
|
452
|
+
* );
|
|
453
453
|
*
|
|
454
454
|
* @example
|
|
455
|
-
* //
|
|
456
|
-
* const container = createContainer(
|
|
457
|
-
* accentColor: [255, 87, 51], // RGB tuple
|
|
458
|
-
* components: [
|
|
459
|
-
* "Here's some content."
|
|
460
|
-
* ]
|
|
461
|
-
* });
|
|
455
|
+
* // Using RGB tuple
|
|
456
|
+
* const container = createContainer([255, 0, 0], "Red alert");
|
|
462
457
|
*/
|
|
463
458
|
declare function createContainer(data: ContainerData): ContainerBuilder;
|
|
459
|
+
declare function createContainer(data: ColorResolvable | string, ...components: ComponentData[]): ContainerBuilder;
|
|
464
460
|
|
|
465
461
|
type GuildChannelType = Exclude<ChannelType, ChannelType.DM>;
|
|
466
462
|
type FindChannelFilter<T extends GuildChannelType> = (channel: GetChannelType<T>) => boolean;
|
|
@@ -598,4 +594,4 @@ declare function isAnySelectMenuBuilder(value: unknown): value is AnySelectMenuB
|
|
|
598
594
|
declare function isButtonBuilder(value: unknown): value is ButtonBuilder;
|
|
599
595
|
|
|
600
596
|
export { CustomItents, CustomPartials, EmbedLimit, EmbedPlusBuilder, chars, commandMention, createComponents, createContainer, createEmbed, createEmbedAsset, createEmbedAuthor, createEmbedFiles, createEmbedFooter, createFile, createLinkButton, createMediaGallery, createModalFields, createModalInput, createRow, createSection, createSeparator, createTextDisplay, createThumbnail, createWebhookClient, extractMentionId, findChannel, findCommand, findEmoji, findMember, findMessage, findRole, getChannelUrlInfo, getMessageUrlInfo, isAnySelectMenuBuilder, isAttachment, isButtonBuilder, modalFieldsToRecord, setMobileStatus };
|
|
601
|
-
export type { AnyEmbedData, AnySelectMenuBuilder, ComponentData, ContainerData, EmbedPlusAssetData, EmbedPlusAuthorData, EmbedPlusColorData, EmbedPlusData, EmbedPlusFooterData, EmbedPlusProperty,
|
|
597
|
+
export type { AnyEmbedData, AnySelectMenuBuilder, ComponentData, ContainerColor, ContainerData, EmbedPlusAssetData, EmbedPlusAuthorData, EmbedPlusColorData, EmbedPlusData, EmbedPlusFooterData, EmbedPlusProperty, SectionAccessory, SectionAccessoryData, SectionButtonAccessory, SectionData, SectionThumbnailAccessory, SeparatorData, ThumbnailData };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@magicyan/discord",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.5",
|
|
4
4
|
"description": "Simple functions to facilitate discord bot development",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -49,6 +49,6 @@
|
|
|
49
49
|
"vitest": "^2.1.9"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@magicyan/core": "^1.0
|
|
52
|
+
"@magicyan/core": "^1.1.0"
|
|
53
53
|
}
|
|
54
54
|
}
|