@magicyan/discord 1.6.3 → 1.7.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/dist/functions/components/container.cjs +54 -1
- package/dist/functions/components/container.mjs +54 -1
- package/dist/guards/components/file.cjs +10 -0
- package/dist/guards/components/file.mjs +8 -0
- package/dist/guards/components/row.cjs +1 -2
- package/dist/guards/components/row.mjs +1 -2
- package/dist/index.cjs +2 -0
- package/dist/index.d.cts +33 -3
- package/dist/index.d.mts +33 -3
- package/dist/index.d.ts +33 -3
- package/dist/index.mjs +1 -0
- package/package.json +2 -2
|
@@ -4,6 +4,13 @@ const core = require('@magicyan/core');
|
|
|
4
4
|
const discord_js = require('discord.js');
|
|
5
5
|
const components = require('./components.cjs');
|
|
6
6
|
const message = require('../../guards/message.cjs');
|
|
7
|
+
const row = require('../../guards/components/row.cjs');
|
|
8
|
+
const section = require('../../guards/components/section.cjs');
|
|
9
|
+
const button = require('../../guards/components/button.cjs');
|
|
10
|
+
const textdisplay = require('../../guards/components/textdisplay.cjs');
|
|
11
|
+
const gallery = require('../../guards/components/gallery.cjs');
|
|
12
|
+
const file = require('../../guards/components/file.cjs');
|
|
13
|
+
const separator = require('../../guards/components/separator.cjs');
|
|
7
14
|
|
|
8
15
|
class ContainerPlusBuilder extends discord_js.ContainerBuilder {
|
|
9
16
|
constructor(data) {
|
|
@@ -54,7 +61,16 @@ class ContainerPlusBuilder extends discord_js.ContainerBuilder {
|
|
|
54
61
|
* container.setComponent(1, null); // Removes the component at index 1.
|
|
55
62
|
*/
|
|
56
63
|
setComponent(index, data) {
|
|
57
|
-
|
|
64
|
+
return this._spliceComponents(index, 1, data);
|
|
65
|
+
}
|
|
66
|
+
insertComponent(argA, argB) {
|
|
67
|
+
if (typeof argA === "number") {
|
|
68
|
+
return this._spliceComponents(argA, 0, argB);
|
|
69
|
+
}
|
|
70
|
+
return this._spliceComponents(this.components.length, 0, argA);
|
|
71
|
+
}
|
|
72
|
+
_spliceComponents(index, deleteCount, data) {
|
|
73
|
+
const args = [index, deleteCount];
|
|
58
74
|
if (core.isDefined(data))
|
|
59
75
|
args.push(...components.createComponents(data));
|
|
60
76
|
return this.spliceComponents(...args);
|
|
@@ -62,6 +78,43 @@ class ContainerPlusBuilder extends discord_js.ContainerBuilder {
|
|
|
62
78
|
componentAt(index, type) {
|
|
63
79
|
return core.isDefined(type) ? this.components.filter((builder) => builder.data.type === type).at(index) : this.components.at(index);
|
|
64
80
|
}
|
|
81
|
+
get buttonComponents() {
|
|
82
|
+
return this.components.filter(
|
|
83
|
+
(comp) => row.isActionRowBuilder(comp, "buttons") || section.isSectionBuilder(comp)
|
|
84
|
+
).flatMap((comp) => {
|
|
85
|
+
if (section.isSectionBuilder(comp)) {
|
|
86
|
+
if (!comp.accessory || !button.isButtonBuilder(comp.accessory))
|
|
87
|
+
return [];
|
|
88
|
+
return [comp.accessory];
|
|
89
|
+
}
|
|
90
|
+
return comp.components;
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
get sectionComponents() {
|
|
94
|
+
return this.components.filter(section.isSectionBuilder);
|
|
95
|
+
}
|
|
96
|
+
get selectMenuComponents() {
|
|
97
|
+
return this.components.filter(
|
|
98
|
+
(comp) => row.isActionRowBuilder(comp, "selects")
|
|
99
|
+
).flatMap((comp) => comp.components);
|
|
100
|
+
}
|
|
101
|
+
get textDisplayComponents() {
|
|
102
|
+
return this.components.filter(textdisplay.isTextDisplayBuilder);
|
|
103
|
+
}
|
|
104
|
+
get actionRowComponents() {
|
|
105
|
+
return this.components.filter(
|
|
106
|
+
(row$1) => row.isActionRowBuilder(row$1, "buttons") || row.isActionRowBuilder(row$1, "selects")
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
get mediaGalleryComponents() {
|
|
110
|
+
return this.components.filter(gallery.isMediaGalleryBuilder);
|
|
111
|
+
}
|
|
112
|
+
get fileComponents() {
|
|
113
|
+
return this.components.filter(file.isFileBuilder);
|
|
114
|
+
}
|
|
115
|
+
get separatorComponents() {
|
|
116
|
+
return this.components.filter(separator.isSeparatorBuilder);
|
|
117
|
+
}
|
|
65
118
|
}
|
|
66
119
|
function createContainer(data, ...items) {
|
|
67
120
|
const isContainerData = (value) => typeof value === "object" && core.isDefined(value) && !Array.isArray(value);
|
|
@@ -2,6 +2,13 @@ import { isDefined } from '@magicyan/core';
|
|
|
2
2
|
import { ContainerBuilder, resolveColor, ComponentType } from 'discord.js';
|
|
3
3
|
import { createComponents } from './components.mjs';
|
|
4
4
|
import { isMessage } from '../../guards/message.mjs';
|
|
5
|
+
import { isActionRowBuilder } from '../../guards/components/row.mjs';
|
|
6
|
+
import { isSectionBuilder } from '../../guards/components/section.mjs';
|
|
7
|
+
import { isButtonBuilder } from '../../guards/components/button.mjs';
|
|
8
|
+
import { isTextDisplayBuilder } from '../../guards/components/textdisplay.mjs';
|
|
9
|
+
import { isMediaGalleryBuilder } from '../../guards/components/gallery.mjs';
|
|
10
|
+
import { isFileBuilder } from '../../guards/components/file.mjs';
|
|
11
|
+
import { isSeparatorBuilder } from '../../guards/components/separator.mjs';
|
|
5
12
|
|
|
6
13
|
class ContainerPlusBuilder extends ContainerBuilder {
|
|
7
14
|
constructor(data) {
|
|
@@ -52,7 +59,16 @@ class ContainerPlusBuilder extends ContainerBuilder {
|
|
|
52
59
|
* container.setComponent(1, null); // Removes the component at index 1.
|
|
53
60
|
*/
|
|
54
61
|
setComponent(index, data) {
|
|
55
|
-
|
|
62
|
+
return this._spliceComponents(index, 1, data);
|
|
63
|
+
}
|
|
64
|
+
insertComponent(argA, argB) {
|
|
65
|
+
if (typeof argA === "number") {
|
|
66
|
+
return this._spliceComponents(argA, 0, argB);
|
|
67
|
+
}
|
|
68
|
+
return this._spliceComponents(this.components.length, 0, argA);
|
|
69
|
+
}
|
|
70
|
+
_spliceComponents(index, deleteCount, data) {
|
|
71
|
+
const args = [index, deleteCount];
|
|
56
72
|
if (isDefined(data))
|
|
57
73
|
args.push(...createComponents(data));
|
|
58
74
|
return this.spliceComponents(...args);
|
|
@@ -60,6 +76,43 @@ class ContainerPlusBuilder extends ContainerBuilder {
|
|
|
60
76
|
componentAt(index, type) {
|
|
61
77
|
return isDefined(type) ? this.components.filter((builder) => builder.data.type === type).at(index) : this.components.at(index);
|
|
62
78
|
}
|
|
79
|
+
get buttonComponents() {
|
|
80
|
+
return this.components.filter(
|
|
81
|
+
(comp) => isActionRowBuilder(comp, "buttons") || isSectionBuilder(comp)
|
|
82
|
+
).flatMap((comp) => {
|
|
83
|
+
if (isSectionBuilder(comp)) {
|
|
84
|
+
if (!comp.accessory || !isButtonBuilder(comp.accessory))
|
|
85
|
+
return [];
|
|
86
|
+
return [comp.accessory];
|
|
87
|
+
}
|
|
88
|
+
return comp.components;
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
get sectionComponents() {
|
|
92
|
+
return this.components.filter(isSectionBuilder);
|
|
93
|
+
}
|
|
94
|
+
get selectMenuComponents() {
|
|
95
|
+
return this.components.filter(
|
|
96
|
+
(comp) => isActionRowBuilder(comp, "selects")
|
|
97
|
+
).flatMap((comp) => comp.components);
|
|
98
|
+
}
|
|
99
|
+
get textDisplayComponents() {
|
|
100
|
+
return this.components.filter(isTextDisplayBuilder);
|
|
101
|
+
}
|
|
102
|
+
get actionRowComponents() {
|
|
103
|
+
return this.components.filter(
|
|
104
|
+
(row) => isActionRowBuilder(row, "buttons") || isActionRowBuilder(row, "selects")
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
get mediaGalleryComponents() {
|
|
108
|
+
return this.components.filter(isMediaGalleryBuilder);
|
|
109
|
+
}
|
|
110
|
+
get fileComponents() {
|
|
111
|
+
return this.components.filter(isFileBuilder);
|
|
112
|
+
}
|
|
113
|
+
get separatorComponents() {
|
|
114
|
+
return this.components.filter(isSeparatorBuilder);
|
|
115
|
+
}
|
|
63
116
|
}
|
|
64
117
|
function createContainer(data, ...items) {
|
|
65
118
|
const isContainerData = (value) => typeof value === "object" && isDefined(value) && !Array.isArray(value);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const discord_js = require('discord.js');
|
|
4
|
+
const utils = require('../utils.cjs');
|
|
5
|
+
|
|
6
|
+
function isFileBuilder(value) {
|
|
7
|
+
return value instanceof discord_js.FileBuilder || utils.hasConstructor(value) && value.constructor.name === discord_js.FileBuilder.name;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
exports.isFileBuilder = isFileBuilder;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FileBuilder } from 'discord.js';
|
|
2
|
+
import { hasConstructor } from '../utils.mjs';
|
|
3
|
+
|
|
4
|
+
function isFileBuilder(value) {
|
|
5
|
+
return value instanceof FileBuilder || hasConstructor(value) && value.constructor.name === FileBuilder.name;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export { isFileBuilder };
|
|
@@ -4,12 +4,11 @@ const discord_js = require('discord.js');
|
|
|
4
4
|
const selectmenu = require('./selectmenu.cjs');
|
|
5
5
|
const button = require('./button.cjs');
|
|
6
6
|
const utils = require('../utils.cjs');
|
|
7
|
-
const textinput = require('./textinput.cjs');
|
|
8
7
|
|
|
9
8
|
function isActionRowBuilder(value, withComponent) {
|
|
10
9
|
const isActionRow = utils.hasConstructor(value) && value.constructor.name === discord_js.ActionRowBuilder.name && "components" in value && Array.isArray(value.components);
|
|
11
10
|
if (isActionRow && withComponent) {
|
|
12
|
-
const guard = withComponent === "selects" ? selectmenu.isAnySelectMenuBuilder :
|
|
11
|
+
const guard = withComponent === "selects" ? selectmenu.isAnySelectMenuBuilder : button.isButtonBuilder;
|
|
13
12
|
return value.components.some(guard);
|
|
14
13
|
}
|
|
15
14
|
return isActionRow;
|
|
@@ -2,12 +2,11 @@ import { ActionRowBuilder } from 'discord.js';
|
|
|
2
2
|
import { isAnySelectMenuBuilder } from './selectmenu.mjs';
|
|
3
3
|
import { isButtonBuilder } from './button.mjs';
|
|
4
4
|
import { hasConstructor } from '../utils.mjs';
|
|
5
|
-
import { isTextInputBuilder } from './textinput.mjs';
|
|
6
5
|
|
|
7
6
|
function isActionRowBuilder(value, withComponent) {
|
|
8
7
|
const isActionRow = hasConstructor(value) && value.constructor.name === ActionRowBuilder.name && "components" in value && Array.isArray(value.components);
|
|
9
8
|
if (isActionRow && withComponent) {
|
|
10
|
-
const guard = withComponent === "selects" ? isAnySelectMenuBuilder :
|
|
9
|
+
const guard = withComponent === "selects" ? isAnySelectMenuBuilder : isButtonBuilder;
|
|
11
10
|
return value.components.some(guard);
|
|
12
11
|
}
|
|
13
12
|
return isActionRow;
|
package/dist/index.cjs
CHANGED
|
@@ -41,6 +41,7 @@ const modal$1 = require('./guards/components/modal.cjs');
|
|
|
41
41
|
const row$1 = require('./guards/components/row.cjs');
|
|
42
42
|
const section$1 = require('./guards/components/section.cjs');
|
|
43
43
|
const selectmenu = require('./guards/components/selectmenu.cjs');
|
|
44
|
+
const file$1 = require('./guards/components/file.cjs');
|
|
44
45
|
const separator$2 = require('./guards/components/separator.cjs');
|
|
45
46
|
const textdisplay = require('./guards/components/textdisplay.cjs');
|
|
46
47
|
const textinput = require('./guards/components/textinput.cjs');
|
|
@@ -106,6 +107,7 @@ exports.isMentionableSelectMenuBuilder = selectmenu.isMentionableSelectMenuBuild
|
|
|
106
107
|
exports.isRoleSelectMenuBuilder = selectmenu.isRoleSelectMenuBuilder;
|
|
107
108
|
exports.isStringSelectMenuBuilder = selectmenu.isStringSelectMenuBuilder;
|
|
108
109
|
exports.isUserSelectMenuBuilder = selectmenu.isUserSelectMenuBuilder;
|
|
110
|
+
exports.isFileBuilder = file$1.isFileBuilder;
|
|
109
111
|
exports.isSeparatorBuilder = separator$2.isSeparatorBuilder;
|
|
110
112
|
exports.isTextDisplayBuilder = textdisplay.isTextDisplayBuilder;
|
|
111
113
|
exports.isTextInputBuilder = textinput.isTextInputBuilder;
|
package/dist/index.d.cts
CHANGED
|
@@ -216,7 +216,7 @@ type CreateComponentData = ComponentData | ContainerBuilder;
|
|
|
216
216
|
type ContainerComponentBuilder = Exclude<ContainerComponentBuilder$1, ActionRowBuilder> | ActionRowBuilder<MessageActionRowComponentBuilder>;
|
|
217
217
|
type CreateComponentsReturn<IsContainer> = IsContainer extends true ? ContainerComponentBuilder[] : (ContainerComponentBuilder | ContainerBuilder)[];
|
|
218
218
|
type CreateComponentsData<IsContainer> = IsContainer extends true ? ComponentData : ComponentData | ContainerBuilder;
|
|
219
|
-
declare function createComponents<IsContainer extends boolean = false, Data extends CreateComponentsData<IsContainer> = CreateComponentsData<IsContainer
|
|
219
|
+
declare function createComponents<IsContainer extends boolean = false, Data extends CreateComponentsData<IsContainer>[] = CreateComponentsData<IsContainer>[]>(...data: (Data | Data[])): CreateComponentsReturn<IsContainer>;
|
|
220
220
|
|
|
221
221
|
type ContainerColor = (string & {}) | ColorResolvable;
|
|
222
222
|
type ContainerInComponentType = ComponentType.TextDisplay | ComponentType.ActionRow | ComponentType.Section | ComponentType.Separator | ComponentType.MediaGallery | ComponentType.File;
|
|
@@ -261,6 +261,9 @@ declare class ContainerPlusBuilder extends ContainerBuilder {
|
|
|
261
261
|
* container.setComponent(1, null); // Removes the component at index 1.
|
|
262
262
|
*/
|
|
263
263
|
setComponent(index: number, data: ComponentData | null): this;
|
|
264
|
+
insertComponent(data: ComponentData): this;
|
|
265
|
+
insertComponent(index: number, data?: ComponentData): this;
|
|
266
|
+
private _spliceComponents;
|
|
264
267
|
/**
|
|
265
268
|
* Retrieves a component from the container at the specified index, optionally filtering by component type.
|
|
266
269
|
*
|
|
@@ -281,6 +284,14 @@ declare class ContainerPlusBuilder extends ContainerBuilder {
|
|
|
281
284
|
componentAt(index: number, type: ComponentType.Separator): SeparatorBuilder | undefined;
|
|
282
285
|
componentAt(index: number, type: ComponentType.MediaGallery): MediaGalleryBuilder | undefined;
|
|
283
286
|
componentAt(index: number, type: ComponentType.File): FileBuilder | undefined;
|
|
287
|
+
get buttonComponents(): ButtonBuilder[];
|
|
288
|
+
get sectionComponents(): SectionBuilder[];
|
|
289
|
+
get selectMenuComponents(): AnySelectMenuBuilder[];
|
|
290
|
+
get textDisplayComponents(): TextDisplayBuilder[];
|
|
291
|
+
get actionRowComponents(): (ActionRowBuilder<ButtonBuilder> | ActionRowBuilder<AnySelectMenuBuilder>)[];
|
|
292
|
+
get mediaGalleryComponents(): MediaGalleryBuilder[];
|
|
293
|
+
get fileComponents(): FileBuilder[];
|
|
294
|
+
get separatorComponents(): SeparatorBuilder[];
|
|
284
295
|
}
|
|
285
296
|
/**
|
|
286
297
|
* Creates one or multiple {@link ContainerPlusBuilder} components with optional accent color and child components.
|
|
@@ -1084,7 +1095,6 @@ declare function isAnySelectMenuBuilder(value: unknown): value is AnySelectMenuB
|
|
|
1084
1095
|
declare function isActionRowBuilder(value: unknown): value is ActionRowBuilder;
|
|
1085
1096
|
declare function isActionRowBuilder(value: unknown, withComponents: "selects"): value is ActionRowBuilder<AnySelectMenuBuilder>;
|
|
1086
1097
|
declare function isActionRowBuilder(value: unknown, withComponents: "buttons"): value is ActionRowBuilder<ButtonBuilder>;
|
|
1087
|
-
declare function isActionRowBuilder(value: unknown, withComponents: "inputs"): value is ActionRowBuilder<TextInputBuilder>;
|
|
1088
1098
|
|
|
1089
1099
|
/**
|
|
1090
1100
|
* Checks whether the given value is a {@link SectionBuilder}.
|
|
@@ -1106,6 +1116,26 @@ declare function isActionRowBuilder(value: unknown, withComponents: "inputs"): v
|
|
|
1106
1116
|
*/
|
|
1107
1117
|
declare function isSectionBuilder(value: unknown): value is SectionBuilder;
|
|
1108
1118
|
|
|
1119
|
+
/**
|
|
1120
|
+
* Checks whether the given value is a {@link FileBuilder}.
|
|
1121
|
+
*
|
|
1122
|
+
* This function returns `true` if the value is an instance of `FileBuilder`,
|
|
1123
|
+
* or if it structurally matches by constructor name.
|
|
1124
|
+
*
|
|
1125
|
+
* @param value - The value to check.
|
|
1126
|
+
* @returns `true` if the value is a `FileBuilder`, otherwise `false`.
|
|
1127
|
+
*
|
|
1128
|
+
* @example
|
|
1129
|
+
* import type { FileBuilder } from "discord.js";
|
|
1130
|
+
*
|
|
1131
|
+
* function handle(input: FileBuilder | unknown) {
|
|
1132
|
+
* if (FileBuilder(input)) {
|
|
1133
|
+
* input.setURL("https://example.com/image.png");
|
|
1134
|
+
* }
|
|
1135
|
+
* }
|
|
1136
|
+
*/
|
|
1137
|
+
declare function isFileBuilder(value: unknown): value is FileBuilder;
|
|
1138
|
+
|
|
1109
1139
|
/**
|
|
1110
1140
|
* Checks whether the given value is a {@link SeparatorBuilder}.
|
|
1111
1141
|
*
|
|
@@ -1187,5 +1217,5 @@ declare function isTextInputBuilder(value: unknown): value is TextInputBuilder;
|
|
|
1187
1217
|
*/
|
|
1188
1218
|
declare function isMessage(value: unknown): value is Message;
|
|
1189
1219
|
|
|
1190
|
-
export { ContainerPlusBuilder, CustomItents, CustomPartials, EmbedLimit, EmbedPlusBuilder, Separator, chars, commandMention, createComponents, createContainer, createEmbed, createEmbedAsset, createEmbedAuthor, createEmbedFiles, createEmbedFooter, createFile, createFileUpload, createLabel, createLinkButton, createMediaGallery, createModalFields, createModalInput, createRow, createSection, createSeparator, createTextDisplay, createTextInput, createThumbArea, createThumbnail, createWebhookClient, extractMentionId, fetchMessageFromURL, findChannel, findCommand, findEmoji, findMember, findMessage, findRole, getChannelUrlInfo, getMessageURLInfo, isActionRowBuilder, isAnySelectMenuBuilder, isAttachment, isButtonBuilder, isChannelSelectMenuBuilder, isContainerBuilder, isMediaGalleryBuilder, isMediaGalleryItemBuilder, isMentionableSelectMenuBuilder, isMessage, isModalBuilder, isRoleSelectMenuBuilder, isSectionBuilder, isSeparatorBuilder, isStringSelectMenuBuilder, isTextDisplayBuilder, isTextInputBuilder, isUserSelectMenuBuilder, modalFieldsToRecord, setMobileStatus, wrapButtons };
|
|
1220
|
+
export { ContainerPlusBuilder, CustomItents, CustomPartials, EmbedLimit, EmbedPlusBuilder, Separator, chars, commandMention, createComponents, createContainer, createEmbed, createEmbedAsset, createEmbedAuthor, createEmbedFiles, createEmbedFooter, createFile, createFileUpload, createLabel, createLinkButton, createMediaGallery, createModalFields, createModalInput, createRow, createSection, createSeparator, createTextDisplay, createTextInput, createThumbArea, createThumbnail, createWebhookClient, extractMentionId, fetchMessageFromURL, findChannel, findCommand, findEmoji, findMember, findMessage, findRole, getChannelUrlInfo, getMessageURLInfo, isActionRowBuilder, isAnySelectMenuBuilder, isAttachment, isButtonBuilder, isChannelSelectMenuBuilder, isContainerBuilder, isFileBuilder, isMediaGalleryBuilder, isMediaGalleryItemBuilder, isMentionableSelectMenuBuilder, isMessage, isModalBuilder, isRoleSelectMenuBuilder, isSectionBuilder, isSeparatorBuilder, isStringSelectMenuBuilder, isTextDisplayBuilder, isTextInputBuilder, isUserSelectMenuBuilder, modalFieldsToRecord, setMobileStatus, wrapButtons };
|
|
1191
1221
|
export type { AnyEmbedData, AnySelectMenuBuilder, ComponentBuildersData, ComponentData, ComponentInLabelBuilder, ContainerColor, ContainerComponentBuilder, ContainerData, ContainerInComponentType, CreateComponentData, CreateLabelData, EmbedPlusAssetData, EmbedPlusAuthorData, EmbedPlusColorData, EmbedPlusData, EmbedPlusFooterData, EmbedPlusProperty, FileUploadData, MagicComponentData, MediaGallerySource, SectionAccessory, SectionAccessoryData, SectionButtonAccessory, SectionData, SectionThumbnailAccessory, SeparatorData, ThumbAreaData, ThumbAreaThumbnail, ThumbnailData };
|
package/dist/index.d.mts
CHANGED
|
@@ -216,7 +216,7 @@ type CreateComponentData = ComponentData | ContainerBuilder;
|
|
|
216
216
|
type ContainerComponentBuilder = Exclude<ContainerComponentBuilder$1, ActionRowBuilder> | ActionRowBuilder<MessageActionRowComponentBuilder>;
|
|
217
217
|
type CreateComponentsReturn<IsContainer> = IsContainer extends true ? ContainerComponentBuilder[] : (ContainerComponentBuilder | ContainerBuilder)[];
|
|
218
218
|
type CreateComponentsData<IsContainer> = IsContainer extends true ? ComponentData : ComponentData | ContainerBuilder;
|
|
219
|
-
declare function createComponents<IsContainer extends boolean = false, Data extends CreateComponentsData<IsContainer> = CreateComponentsData<IsContainer
|
|
219
|
+
declare function createComponents<IsContainer extends boolean = false, Data extends CreateComponentsData<IsContainer>[] = CreateComponentsData<IsContainer>[]>(...data: (Data | Data[])): CreateComponentsReturn<IsContainer>;
|
|
220
220
|
|
|
221
221
|
type ContainerColor = (string & {}) | ColorResolvable;
|
|
222
222
|
type ContainerInComponentType = ComponentType.TextDisplay | ComponentType.ActionRow | ComponentType.Section | ComponentType.Separator | ComponentType.MediaGallery | ComponentType.File;
|
|
@@ -261,6 +261,9 @@ declare class ContainerPlusBuilder extends ContainerBuilder {
|
|
|
261
261
|
* container.setComponent(1, null); // Removes the component at index 1.
|
|
262
262
|
*/
|
|
263
263
|
setComponent(index: number, data: ComponentData | null): this;
|
|
264
|
+
insertComponent(data: ComponentData): this;
|
|
265
|
+
insertComponent(index: number, data?: ComponentData): this;
|
|
266
|
+
private _spliceComponents;
|
|
264
267
|
/**
|
|
265
268
|
* Retrieves a component from the container at the specified index, optionally filtering by component type.
|
|
266
269
|
*
|
|
@@ -281,6 +284,14 @@ declare class ContainerPlusBuilder extends ContainerBuilder {
|
|
|
281
284
|
componentAt(index: number, type: ComponentType.Separator): SeparatorBuilder | undefined;
|
|
282
285
|
componentAt(index: number, type: ComponentType.MediaGallery): MediaGalleryBuilder | undefined;
|
|
283
286
|
componentAt(index: number, type: ComponentType.File): FileBuilder | undefined;
|
|
287
|
+
get buttonComponents(): ButtonBuilder[];
|
|
288
|
+
get sectionComponents(): SectionBuilder[];
|
|
289
|
+
get selectMenuComponents(): AnySelectMenuBuilder[];
|
|
290
|
+
get textDisplayComponents(): TextDisplayBuilder[];
|
|
291
|
+
get actionRowComponents(): (ActionRowBuilder<ButtonBuilder> | ActionRowBuilder<AnySelectMenuBuilder>)[];
|
|
292
|
+
get mediaGalleryComponents(): MediaGalleryBuilder[];
|
|
293
|
+
get fileComponents(): FileBuilder[];
|
|
294
|
+
get separatorComponents(): SeparatorBuilder[];
|
|
284
295
|
}
|
|
285
296
|
/**
|
|
286
297
|
* Creates one or multiple {@link ContainerPlusBuilder} components with optional accent color and child components.
|
|
@@ -1084,7 +1095,6 @@ declare function isAnySelectMenuBuilder(value: unknown): value is AnySelectMenuB
|
|
|
1084
1095
|
declare function isActionRowBuilder(value: unknown): value is ActionRowBuilder;
|
|
1085
1096
|
declare function isActionRowBuilder(value: unknown, withComponents: "selects"): value is ActionRowBuilder<AnySelectMenuBuilder>;
|
|
1086
1097
|
declare function isActionRowBuilder(value: unknown, withComponents: "buttons"): value is ActionRowBuilder<ButtonBuilder>;
|
|
1087
|
-
declare function isActionRowBuilder(value: unknown, withComponents: "inputs"): value is ActionRowBuilder<TextInputBuilder>;
|
|
1088
1098
|
|
|
1089
1099
|
/**
|
|
1090
1100
|
* Checks whether the given value is a {@link SectionBuilder}.
|
|
@@ -1106,6 +1116,26 @@ declare function isActionRowBuilder(value: unknown, withComponents: "inputs"): v
|
|
|
1106
1116
|
*/
|
|
1107
1117
|
declare function isSectionBuilder(value: unknown): value is SectionBuilder;
|
|
1108
1118
|
|
|
1119
|
+
/**
|
|
1120
|
+
* Checks whether the given value is a {@link FileBuilder}.
|
|
1121
|
+
*
|
|
1122
|
+
* This function returns `true` if the value is an instance of `FileBuilder`,
|
|
1123
|
+
* or if it structurally matches by constructor name.
|
|
1124
|
+
*
|
|
1125
|
+
* @param value - The value to check.
|
|
1126
|
+
* @returns `true` if the value is a `FileBuilder`, otherwise `false`.
|
|
1127
|
+
*
|
|
1128
|
+
* @example
|
|
1129
|
+
* import type { FileBuilder } from "discord.js";
|
|
1130
|
+
*
|
|
1131
|
+
* function handle(input: FileBuilder | unknown) {
|
|
1132
|
+
* if (FileBuilder(input)) {
|
|
1133
|
+
* input.setURL("https://example.com/image.png");
|
|
1134
|
+
* }
|
|
1135
|
+
* }
|
|
1136
|
+
*/
|
|
1137
|
+
declare function isFileBuilder(value: unknown): value is FileBuilder;
|
|
1138
|
+
|
|
1109
1139
|
/**
|
|
1110
1140
|
* Checks whether the given value is a {@link SeparatorBuilder}.
|
|
1111
1141
|
*
|
|
@@ -1187,5 +1217,5 @@ declare function isTextInputBuilder(value: unknown): value is TextInputBuilder;
|
|
|
1187
1217
|
*/
|
|
1188
1218
|
declare function isMessage(value: unknown): value is Message;
|
|
1189
1219
|
|
|
1190
|
-
export { ContainerPlusBuilder, CustomItents, CustomPartials, EmbedLimit, EmbedPlusBuilder, Separator, chars, commandMention, createComponents, createContainer, createEmbed, createEmbedAsset, createEmbedAuthor, createEmbedFiles, createEmbedFooter, createFile, createFileUpload, createLabel, createLinkButton, createMediaGallery, createModalFields, createModalInput, createRow, createSection, createSeparator, createTextDisplay, createTextInput, createThumbArea, createThumbnail, createWebhookClient, extractMentionId, fetchMessageFromURL, findChannel, findCommand, findEmoji, findMember, findMessage, findRole, getChannelUrlInfo, getMessageURLInfo, isActionRowBuilder, isAnySelectMenuBuilder, isAttachment, isButtonBuilder, isChannelSelectMenuBuilder, isContainerBuilder, isMediaGalleryBuilder, isMediaGalleryItemBuilder, isMentionableSelectMenuBuilder, isMessage, isModalBuilder, isRoleSelectMenuBuilder, isSectionBuilder, isSeparatorBuilder, isStringSelectMenuBuilder, isTextDisplayBuilder, isTextInputBuilder, isUserSelectMenuBuilder, modalFieldsToRecord, setMobileStatus, wrapButtons };
|
|
1220
|
+
export { ContainerPlusBuilder, CustomItents, CustomPartials, EmbedLimit, EmbedPlusBuilder, Separator, chars, commandMention, createComponents, createContainer, createEmbed, createEmbedAsset, createEmbedAuthor, createEmbedFiles, createEmbedFooter, createFile, createFileUpload, createLabel, createLinkButton, createMediaGallery, createModalFields, createModalInput, createRow, createSection, createSeparator, createTextDisplay, createTextInput, createThumbArea, createThumbnail, createWebhookClient, extractMentionId, fetchMessageFromURL, findChannel, findCommand, findEmoji, findMember, findMessage, findRole, getChannelUrlInfo, getMessageURLInfo, isActionRowBuilder, isAnySelectMenuBuilder, isAttachment, isButtonBuilder, isChannelSelectMenuBuilder, isContainerBuilder, isFileBuilder, isMediaGalleryBuilder, isMediaGalleryItemBuilder, isMentionableSelectMenuBuilder, isMessage, isModalBuilder, isRoleSelectMenuBuilder, isSectionBuilder, isSeparatorBuilder, isStringSelectMenuBuilder, isTextDisplayBuilder, isTextInputBuilder, isUserSelectMenuBuilder, modalFieldsToRecord, setMobileStatus, wrapButtons };
|
|
1191
1221
|
export type { AnyEmbedData, AnySelectMenuBuilder, ComponentBuildersData, ComponentData, ComponentInLabelBuilder, ContainerColor, ContainerComponentBuilder, ContainerData, ContainerInComponentType, CreateComponentData, CreateLabelData, EmbedPlusAssetData, EmbedPlusAuthorData, EmbedPlusColorData, EmbedPlusData, EmbedPlusFooterData, EmbedPlusProperty, FileUploadData, MagicComponentData, MediaGallerySource, SectionAccessory, SectionAccessoryData, SectionButtonAccessory, SectionData, SectionThumbnailAccessory, SeparatorData, ThumbAreaData, ThumbAreaThumbnail, ThumbnailData };
|
package/dist/index.d.ts
CHANGED
|
@@ -216,7 +216,7 @@ type CreateComponentData = ComponentData | ContainerBuilder;
|
|
|
216
216
|
type ContainerComponentBuilder = Exclude<ContainerComponentBuilder$1, ActionRowBuilder> | ActionRowBuilder<MessageActionRowComponentBuilder>;
|
|
217
217
|
type CreateComponentsReturn<IsContainer> = IsContainer extends true ? ContainerComponentBuilder[] : (ContainerComponentBuilder | ContainerBuilder)[];
|
|
218
218
|
type CreateComponentsData<IsContainer> = IsContainer extends true ? ComponentData : ComponentData | ContainerBuilder;
|
|
219
|
-
declare function createComponents<IsContainer extends boolean = false, Data extends CreateComponentsData<IsContainer> = CreateComponentsData<IsContainer
|
|
219
|
+
declare function createComponents<IsContainer extends boolean = false, Data extends CreateComponentsData<IsContainer>[] = CreateComponentsData<IsContainer>[]>(...data: (Data | Data[])): CreateComponentsReturn<IsContainer>;
|
|
220
220
|
|
|
221
221
|
type ContainerColor = (string & {}) | ColorResolvable;
|
|
222
222
|
type ContainerInComponentType = ComponentType.TextDisplay | ComponentType.ActionRow | ComponentType.Section | ComponentType.Separator | ComponentType.MediaGallery | ComponentType.File;
|
|
@@ -261,6 +261,9 @@ declare class ContainerPlusBuilder extends ContainerBuilder {
|
|
|
261
261
|
* container.setComponent(1, null); // Removes the component at index 1.
|
|
262
262
|
*/
|
|
263
263
|
setComponent(index: number, data: ComponentData | null): this;
|
|
264
|
+
insertComponent(data: ComponentData): this;
|
|
265
|
+
insertComponent(index: number, data?: ComponentData): this;
|
|
266
|
+
private _spliceComponents;
|
|
264
267
|
/**
|
|
265
268
|
* Retrieves a component from the container at the specified index, optionally filtering by component type.
|
|
266
269
|
*
|
|
@@ -281,6 +284,14 @@ declare class ContainerPlusBuilder extends ContainerBuilder {
|
|
|
281
284
|
componentAt(index: number, type: ComponentType.Separator): SeparatorBuilder | undefined;
|
|
282
285
|
componentAt(index: number, type: ComponentType.MediaGallery): MediaGalleryBuilder | undefined;
|
|
283
286
|
componentAt(index: number, type: ComponentType.File): FileBuilder | undefined;
|
|
287
|
+
get buttonComponents(): ButtonBuilder[];
|
|
288
|
+
get sectionComponents(): SectionBuilder[];
|
|
289
|
+
get selectMenuComponents(): AnySelectMenuBuilder[];
|
|
290
|
+
get textDisplayComponents(): TextDisplayBuilder[];
|
|
291
|
+
get actionRowComponents(): (ActionRowBuilder<ButtonBuilder> | ActionRowBuilder<AnySelectMenuBuilder>)[];
|
|
292
|
+
get mediaGalleryComponents(): MediaGalleryBuilder[];
|
|
293
|
+
get fileComponents(): FileBuilder[];
|
|
294
|
+
get separatorComponents(): SeparatorBuilder[];
|
|
284
295
|
}
|
|
285
296
|
/**
|
|
286
297
|
* Creates one or multiple {@link ContainerPlusBuilder} components with optional accent color and child components.
|
|
@@ -1084,7 +1095,6 @@ declare function isAnySelectMenuBuilder(value: unknown): value is AnySelectMenuB
|
|
|
1084
1095
|
declare function isActionRowBuilder(value: unknown): value is ActionRowBuilder;
|
|
1085
1096
|
declare function isActionRowBuilder(value: unknown, withComponents: "selects"): value is ActionRowBuilder<AnySelectMenuBuilder>;
|
|
1086
1097
|
declare function isActionRowBuilder(value: unknown, withComponents: "buttons"): value is ActionRowBuilder<ButtonBuilder>;
|
|
1087
|
-
declare function isActionRowBuilder(value: unknown, withComponents: "inputs"): value is ActionRowBuilder<TextInputBuilder>;
|
|
1088
1098
|
|
|
1089
1099
|
/**
|
|
1090
1100
|
* Checks whether the given value is a {@link SectionBuilder}.
|
|
@@ -1106,6 +1116,26 @@ declare function isActionRowBuilder(value: unknown, withComponents: "inputs"): v
|
|
|
1106
1116
|
*/
|
|
1107
1117
|
declare function isSectionBuilder(value: unknown): value is SectionBuilder;
|
|
1108
1118
|
|
|
1119
|
+
/**
|
|
1120
|
+
* Checks whether the given value is a {@link FileBuilder}.
|
|
1121
|
+
*
|
|
1122
|
+
* This function returns `true` if the value is an instance of `FileBuilder`,
|
|
1123
|
+
* or if it structurally matches by constructor name.
|
|
1124
|
+
*
|
|
1125
|
+
* @param value - The value to check.
|
|
1126
|
+
* @returns `true` if the value is a `FileBuilder`, otherwise `false`.
|
|
1127
|
+
*
|
|
1128
|
+
* @example
|
|
1129
|
+
* import type { FileBuilder } from "discord.js";
|
|
1130
|
+
*
|
|
1131
|
+
* function handle(input: FileBuilder | unknown) {
|
|
1132
|
+
* if (FileBuilder(input)) {
|
|
1133
|
+
* input.setURL("https://example.com/image.png");
|
|
1134
|
+
* }
|
|
1135
|
+
* }
|
|
1136
|
+
*/
|
|
1137
|
+
declare function isFileBuilder(value: unknown): value is FileBuilder;
|
|
1138
|
+
|
|
1109
1139
|
/**
|
|
1110
1140
|
* Checks whether the given value is a {@link SeparatorBuilder}.
|
|
1111
1141
|
*
|
|
@@ -1187,5 +1217,5 @@ declare function isTextInputBuilder(value: unknown): value is TextInputBuilder;
|
|
|
1187
1217
|
*/
|
|
1188
1218
|
declare function isMessage(value: unknown): value is Message;
|
|
1189
1219
|
|
|
1190
|
-
export { ContainerPlusBuilder, CustomItents, CustomPartials, EmbedLimit, EmbedPlusBuilder, Separator, chars, commandMention, createComponents, createContainer, createEmbed, createEmbedAsset, createEmbedAuthor, createEmbedFiles, createEmbedFooter, createFile, createFileUpload, createLabel, createLinkButton, createMediaGallery, createModalFields, createModalInput, createRow, createSection, createSeparator, createTextDisplay, createTextInput, createThumbArea, createThumbnail, createWebhookClient, extractMentionId, fetchMessageFromURL, findChannel, findCommand, findEmoji, findMember, findMessage, findRole, getChannelUrlInfo, getMessageURLInfo, isActionRowBuilder, isAnySelectMenuBuilder, isAttachment, isButtonBuilder, isChannelSelectMenuBuilder, isContainerBuilder, isMediaGalleryBuilder, isMediaGalleryItemBuilder, isMentionableSelectMenuBuilder, isMessage, isModalBuilder, isRoleSelectMenuBuilder, isSectionBuilder, isSeparatorBuilder, isStringSelectMenuBuilder, isTextDisplayBuilder, isTextInputBuilder, isUserSelectMenuBuilder, modalFieldsToRecord, setMobileStatus, wrapButtons };
|
|
1220
|
+
export { ContainerPlusBuilder, CustomItents, CustomPartials, EmbedLimit, EmbedPlusBuilder, Separator, chars, commandMention, createComponents, createContainer, createEmbed, createEmbedAsset, createEmbedAuthor, createEmbedFiles, createEmbedFooter, createFile, createFileUpload, createLabel, createLinkButton, createMediaGallery, createModalFields, createModalInput, createRow, createSection, createSeparator, createTextDisplay, createTextInput, createThumbArea, createThumbnail, createWebhookClient, extractMentionId, fetchMessageFromURL, findChannel, findCommand, findEmoji, findMember, findMessage, findRole, getChannelUrlInfo, getMessageURLInfo, isActionRowBuilder, isAnySelectMenuBuilder, isAttachment, isButtonBuilder, isChannelSelectMenuBuilder, isContainerBuilder, isFileBuilder, isMediaGalleryBuilder, isMediaGalleryItemBuilder, isMentionableSelectMenuBuilder, isMessage, isModalBuilder, isRoleSelectMenuBuilder, isSectionBuilder, isSeparatorBuilder, isStringSelectMenuBuilder, isTextDisplayBuilder, isTextInputBuilder, isUserSelectMenuBuilder, modalFieldsToRecord, setMobileStatus, wrapButtons };
|
|
1191
1221
|
export type { AnyEmbedData, AnySelectMenuBuilder, ComponentBuildersData, ComponentData, ComponentInLabelBuilder, ContainerColor, ContainerComponentBuilder, ContainerData, ContainerInComponentType, CreateComponentData, CreateLabelData, EmbedPlusAssetData, EmbedPlusAuthorData, EmbedPlusColorData, EmbedPlusData, EmbedPlusFooterData, EmbedPlusProperty, FileUploadData, MagicComponentData, MediaGallerySource, SectionAccessory, SectionAccessoryData, SectionButtonAccessory, SectionData, SectionThumbnailAccessory, SeparatorData, ThumbAreaData, ThumbAreaThumbnail, ThumbnailData };
|
package/dist/index.mjs
CHANGED
|
@@ -39,6 +39,7 @@ export { isModalBuilder } from './guards/components/modal.mjs';
|
|
|
39
39
|
export { isActionRowBuilder } from './guards/components/row.mjs';
|
|
40
40
|
export { isSectionBuilder } from './guards/components/section.mjs';
|
|
41
41
|
export { isAnySelectMenuBuilder, isChannelSelectMenuBuilder, isMentionableSelectMenuBuilder, isRoleSelectMenuBuilder, isStringSelectMenuBuilder, isUserSelectMenuBuilder } from './guards/components/selectmenu.mjs';
|
|
42
|
+
export { isFileBuilder } from './guards/components/file.mjs';
|
|
42
43
|
export { isSeparatorBuilder } from './guards/components/separator.mjs';
|
|
43
44
|
export { isTextDisplayBuilder } from './guards/components/textdisplay.mjs';
|
|
44
45
|
export { isTextInputBuilder } from './guards/components/textinput.mjs';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@magicyan/discord",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
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.
|
|
52
|
+
"@magicyan/core": "^1.2.0"
|
|
53
53
|
}
|
|
54
54
|
}
|