@magicyan/discord 1.0.22 → 1.0.24
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/channels.cjs +5 -0
- package/dist/functions/channels.mjs +5 -1
- package/dist/functions/components.cjs +0 -4
- package/dist/functions/components.mjs +2 -5
- package/dist/functions/embeds/assets.cjs +15 -0
- package/dist/functions/embeds/assets.mjs +13 -0
- package/dist/functions/embeds/author.cjs +30 -0
- package/dist/functions/embeds/author.mjs +28 -0
- package/dist/functions/embeds/embedplus.cjs +93 -0
- package/dist/functions/embeds/embedplus.mjs +90 -0
- package/dist/functions/embeds/footer.cjs +11 -0
- package/dist/functions/embeds/footer.mjs +9 -0
- package/dist/functions/message.cjs +5 -0
- package/dist/functions/message.mjs +5 -1
- package/dist/functions/misc.cjs +9 -0
- package/dist/functions/misc.mjs +7 -0
- package/dist/functions/modals.cjs +16 -0
- package/dist/functions/modals.mjs +13 -0
- package/dist/index.cjs +16 -7
- package/dist/index.d.cts +115 -76
- package/dist/index.d.mts +115 -76
- package/dist/index.d.ts +115 -76
- package/dist/index.mjs +9 -4
- package/package.json +2 -2
- package/dist/functions/embeds.cjs +0 -136
- package/dist/functions/embeds.mjs +0 -130
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as discord_js from 'discord.js';
|
|
2
|
-
import { GatewayIntentBits, Partials, ChannelType, Guild, CommandInteractionOption, Client, ApplicationCommand, AnyComponentBuilder, ActionRowBuilder,
|
|
2
|
+
import { GatewayIntentBits, Partials, ChannelType, Guild, CommandInteractionOption, Client, ApplicationCommand, AnyComponentBuilder, ActionRowBuilder, ButtonBuilder, ActionRow, MessageActionRowComponent, LinkButtonComponentData, ButtonComponent, StringSelectMenuComponent, UserSelectMenuComponent, ChannelSelectMenuComponent, RoleSelectMenuComponent, MentionableSelectMenuComponent, TextInputBuilder, TextInputComponentData, GuildEmoji, GuildBasedChannel, Role, User, GuildMember, GuildTextBasedChannel, Message, Attachment, AttachmentBuilder, EmbedAssetData, EmbedAuthorData, ImageURLOptions, EmbedBuilder, EmbedData, APIEmbed, Embed, ColorResolvable, EmbedFooterData } from 'discord.js';
|
|
3
3
|
export * from '@magicyan/core';
|
|
4
4
|
|
|
5
5
|
declare const chars: {
|
|
@@ -16,25 +16,33 @@ declare const CustomPartials: {
|
|
|
16
16
|
All: Partials[];
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
declare function setMobileStatus(): void;
|
|
20
|
+
|
|
21
|
+
type GuildChannelType = Exclude<ChannelType, ChannelType.DM>;
|
|
22
|
+
type FindChannelFilter<T extends GuildChannelType> = (channel: GetChannelType<T>) => boolean;
|
|
23
|
+
type GetChannelType<Type extends GuildChannelType> = Extract<NonNullable<CommandInteractionOption<"cached">["channel"]>, {
|
|
21
24
|
type: Type extends ChannelType.PublicThread | ChannelType.AnnouncementThread ? ChannelType.PublicThread | ChannelType.AnnouncementThread : Type;
|
|
22
25
|
}>;
|
|
23
|
-
declare function findChannel<Type extends
|
|
26
|
+
declare function findChannel<Type extends GuildChannelType = ChannelType.GuildText>(guild: Guild, type?: Type): {
|
|
24
27
|
byName(name: string, filter?: FindChannelFilter<Type>): GetChannelType<Type> | undefined;
|
|
25
28
|
byId(id: string): GetChannelType<Type> | undefined;
|
|
26
|
-
byFilter(filter: FindChannelFilter<Type>):
|
|
29
|
+
byFilter(filter: FindChannelFilter<Type>): GetChannelType<Type> | undefined;
|
|
27
30
|
inCategoryId(id: string): {
|
|
28
31
|
byName(name: string, filter?: FindChannelFilter<Type>): GetChannelType<Type> | undefined;
|
|
29
32
|
byId(id: string, filter?: FindChannelFilter<Type>): GetChannelType<Type> | undefined;
|
|
30
|
-
byFilter(filter: FindChannelFilter<Type>):
|
|
33
|
+
byFilter(filter: FindChannelFilter<Type>): GetChannelType<Type> | undefined;
|
|
31
34
|
};
|
|
32
35
|
inCategoryName(name: string): {
|
|
33
36
|
byName(name: string, filter?: FindChannelFilter<Type>): GetChannelType<Type> | undefined;
|
|
34
37
|
byId(id: string, filter?: FindChannelFilter<Type>): GetChannelType<Type> | undefined;
|
|
35
|
-
byFilter(filter: FindChannelFilter<Type>):
|
|
38
|
+
byFilter(filter: FindChannelFilter<Type>): GetChannelType<Type> | undefined;
|
|
36
39
|
};
|
|
37
40
|
};
|
|
41
|
+
interface ChannelUrlInfo {
|
|
42
|
+
channelId?: string;
|
|
43
|
+
guildId?: string;
|
|
44
|
+
}
|
|
45
|
+
declare function getChannelUrlInfo(url: string): ChannelUrlInfo;
|
|
38
46
|
|
|
39
47
|
type FindCommandFilter = (command: ApplicationCommand) => boolean;
|
|
40
48
|
declare function findCommand(guildOrClient: Guild | Client<true>): {
|
|
@@ -50,9 +58,6 @@ declare function findCommand(guildOrClient: Guild | Client<true>): {
|
|
|
50
58
|
};
|
|
51
59
|
|
|
52
60
|
declare function createRow<Component extends AnyComponentBuilder>(...components: Component[]): ActionRowBuilder<Component>;
|
|
53
|
-
interface CreateModalInputData extends Omit<TextInputComponentData, "type"> {
|
|
54
|
-
}
|
|
55
|
-
declare function createModalInput(data: CreateModalInputData): ActionRowBuilder<TextInputBuilder>;
|
|
56
61
|
interface CreateLinkButtonData extends Omit<LinkButtonComponentData, "style" | "type"> {
|
|
57
62
|
}
|
|
58
63
|
declare function createLinkButton(data: CreateLinkButtonData): ButtonBuilder;
|
|
@@ -80,71 +85,11 @@ interface MessageComponentsManager {
|
|
|
80
85
|
}
|
|
81
86
|
declare function createComponentsManager(components: ActionRow<MessageActionRowComponent>[]): MessageComponentsManager;
|
|
82
87
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
url?: string;
|
|
89
|
-
prefix?: string;
|
|
90
|
-
suffix?: string;
|
|
91
|
-
}
|
|
92
|
-
declare function createEmbedAuthor(options: CreateEmbedAuthorOptions): EmbedAuthorData;
|
|
93
|
-
interface CreateEmbedFooterOptions {
|
|
94
|
-
text?: string | null;
|
|
95
|
-
iconURL?: string | null;
|
|
96
|
-
}
|
|
97
|
-
declare function createEmbedFooter(options: CreateEmbedFooterOptions): EmbedFooterData | undefined;
|
|
98
|
-
type EmbedAssetOptions = Omit<EmbedAssetData, "url">;
|
|
99
|
-
type AssetSource = string | Attachment | AttachmentBuilder | EmbedAssetData | undefined | null;
|
|
100
|
-
declare function createEmbedAsset(source: AssetSource, options?: EmbedAssetOptions): EmbedAssetData | undefined;
|
|
101
|
-
type EmbedBuilderPlusAssetData = AssetSource;
|
|
102
|
-
type EmbedBuilderPlusColorData = string & {} | ColorResolvable | null;
|
|
103
|
-
type EmbedBuilderPlusFieldData = {
|
|
104
|
-
name: string;
|
|
105
|
-
value: string;
|
|
106
|
-
inline?: boolean;
|
|
107
|
-
};
|
|
108
|
-
type EmbedBuilderPlusFooterData = {
|
|
109
|
-
text?: string | null;
|
|
110
|
-
iconURL?: string | null;
|
|
111
|
-
};
|
|
112
|
-
type EmbedBuilderPlusAuthorData = {
|
|
113
|
-
name: string;
|
|
114
|
-
url?: string;
|
|
115
|
-
iconURL?: string;
|
|
116
|
-
};
|
|
117
|
-
interface EmbedBuilderPlusOptions {
|
|
118
|
-
extend?: Omit<EmbedBuilderPlusData, keyof EmbedBuilderPlusOptions> | EmbedData | APIEmbed | Embed;
|
|
119
|
-
mergeFields?: boolean;
|
|
120
|
-
}
|
|
121
|
-
interface EmbedBuilderPlusData extends EmbedBuilderPlusOptions {
|
|
122
|
-
title?: string | null;
|
|
123
|
-
color?: EmbedBuilderPlusColorData | null;
|
|
124
|
-
description?: string | null;
|
|
125
|
-
url?: string | null;
|
|
126
|
-
thumbnail?: EmbedBuilderPlusAssetData | null;
|
|
127
|
-
image?: EmbedBuilderPlusAssetData | null;
|
|
128
|
-
fields?: Partial<EmbedBuilderPlusFieldData>[] | null;
|
|
129
|
-
timestamp?: string | number | Date | null;
|
|
130
|
-
footer?: EmbedBuilderPlusFooterData;
|
|
131
|
-
author?: EmbedBuilderPlusAuthorData;
|
|
132
|
-
}
|
|
133
|
-
declare class EmbedBuilderPlus extends EmbedBuilder {
|
|
134
|
-
constructor(data: EmbedBuilderPlusData);
|
|
135
|
-
has(property: keyof Omit<EmbedBuilderPlusData, keyof EmbedBuilderPlusOptions>): boolean;
|
|
136
|
-
toArray(): this[];
|
|
137
|
-
toString(space?: number): string;
|
|
138
|
-
updateField(index: number, field: Partial<EmbedBuilderPlusFieldData>): this;
|
|
139
|
-
deleteField(index: number): this;
|
|
140
|
-
popField(): discord_js.APIEmbedField | undefined;
|
|
141
|
-
setAsset(asset: "thumbnail" | "image", source: EmbedBuilderPlusAssetData): this;
|
|
142
|
-
get fieldsLength(): number;
|
|
143
|
-
get fields(): discord_js.APIEmbedField[];
|
|
144
|
-
createFromThis(data?: EmbedBuilderPlusData): EmbedBuilderPlus;
|
|
145
|
-
}
|
|
146
|
-
type EmbedPropery<T extends keyof EmbedBuilderPlusData> = EmbedBuilderPlusData[T];
|
|
147
|
-
declare function createEmbed(data: EmbedBuilderPlusData): EmbedBuilderPlus;
|
|
88
|
+
type TextInputData = Omit<TextInputComponentData, "type">;
|
|
89
|
+
type CreateModalInputData = TextInputData;
|
|
90
|
+
declare function createModalInput(data: CreateModalInputData): ActionRowBuilder<TextInputBuilder>;
|
|
91
|
+
type ModalFieldsData = Record<string, Omit<TextInputData, "customId">>;
|
|
92
|
+
declare function createModalFields(data: ModalFieldsData): ActionRowBuilder<TextInputBuilder>[];
|
|
148
93
|
|
|
149
94
|
type FindEmojiFilter = (emoji: GuildEmoji) => boolean;
|
|
150
95
|
declare function findEmoji(guildOrClient: Guild | Client): {
|
|
@@ -175,8 +120,24 @@ declare function findMessage(channel: GuildTextBasedChannel): {
|
|
|
175
120
|
};
|
|
176
121
|
byFilter(filter: FindMessageFilter): Message<true> | undefined;
|
|
177
122
|
};
|
|
123
|
+
interface MessageUrlInfo {
|
|
124
|
+
messageId?: string;
|
|
125
|
+
channelId?: string;
|
|
126
|
+
guildId?: string;
|
|
127
|
+
}
|
|
128
|
+
declare function getMessageUrlInfo(url: string): MessageUrlInfo;
|
|
178
129
|
|
|
179
130
|
type FindRoleFilter = (role: Role) => boolean;
|
|
131
|
+
/**
|
|
132
|
+
*
|
|
133
|
+
* @param guild Discord guild
|
|
134
|
+
*
|
|
135
|
+
* ```ts
|
|
136
|
+
* const memberRole = findRole(guild).byName("Member");
|
|
137
|
+
* const adminRole = findRole(guild).byHexColor("#ff5454");
|
|
138
|
+
* const leaderRole = findRole(guild).byId("537818031728885771");
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
180
141
|
declare function findRole(guild: Guild): {
|
|
181
142
|
byColor(color: number, and?: FindRoleFilter): Role | undefined;
|
|
182
143
|
byHexColor(hexColor: string, and?: FindRoleFilter): Role | undefined;
|
|
@@ -202,4 +163,82 @@ declare function findRole(guild: Guild): {
|
|
|
202
163
|
*/
|
|
203
164
|
declare function extractMentionId(mention: string): string | null;
|
|
204
165
|
|
|
205
|
-
|
|
166
|
+
type EmbedAssetOptions = Omit<EmbedAssetData, "url">;
|
|
167
|
+
type AssetSource = string | Attachment | AttachmentBuilder | EmbedAssetData | undefined | null;
|
|
168
|
+
declare function createEmbedAsset(source: AssetSource, options?: EmbedAssetOptions): EmbedAssetData | undefined;
|
|
169
|
+
|
|
170
|
+
interface UserAuthorOption {
|
|
171
|
+
user: User;
|
|
172
|
+
property?: "username" | "displayName" | "id" | "globalName";
|
|
173
|
+
}
|
|
174
|
+
interface MemberAuthorOption {
|
|
175
|
+
member: GuildMember;
|
|
176
|
+
property?: "username" | "displayName" | "id" | "globalName" | "nickname";
|
|
177
|
+
}
|
|
178
|
+
type AuthorOption = UserAuthorOption | MemberAuthorOption;
|
|
179
|
+
type CreateEmbedAuthorOptions = AuthorOption & ImageURLOptions & {
|
|
180
|
+
iconURL?: string;
|
|
181
|
+
url?: string;
|
|
182
|
+
prefix?: string;
|
|
183
|
+
suffix?: string;
|
|
184
|
+
};
|
|
185
|
+
declare function createEmbedAuthor(options: CreateEmbedAuthorOptions): EmbedAuthorData;
|
|
186
|
+
|
|
187
|
+
type EmbedPlusAssetData = AssetSource;
|
|
188
|
+
type EmbedPlusColorData = string & {} | ColorResolvable | null;
|
|
189
|
+
type EmbedPlusFieldData = {
|
|
190
|
+
name: string;
|
|
191
|
+
value: string;
|
|
192
|
+
inline?: boolean;
|
|
193
|
+
};
|
|
194
|
+
type EmbedPlusFooterData = {
|
|
195
|
+
text?: string | null;
|
|
196
|
+
iconURL?: string | null;
|
|
197
|
+
};
|
|
198
|
+
type EmbedPlusAuthorData = {
|
|
199
|
+
name: string;
|
|
200
|
+
url?: string;
|
|
201
|
+
iconURL?: string;
|
|
202
|
+
};
|
|
203
|
+
interface EmbedPlusData {
|
|
204
|
+
title?: string | null;
|
|
205
|
+
color?: EmbedPlusColorData | null;
|
|
206
|
+
description?: string | null;
|
|
207
|
+
url?: string | null;
|
|
208
|
+
thumbnail?: EmbedPlusAssetData | null;
|
|
209
|
+
image?: EmbedPlusAssetData | null;
|
|
210
|
+
fields?: Partial<EmbedPlusFieldData>[] | null;
|
|
211
|
+
timestamp?: string | number | Date | null;
|
|
212
|
+
footer?: EmbedPlusFooterData;
|
|
213
|
+
author?: EmbedPlusAuthorData;
|
|
214
|
+
}
|
|
215
|
+
interface EmbedPlusOptions extends EmbedPlusData {
|
|
216
|
+
extends?: Omit<EmbedPlusData, keyof EmbedPlusOptions> | EmbedData | APIEmbed | Embed;
|
|
217
|
+
mergeFields?: boolean;
|
|
218
|
+
}
|
|
219
|
+
declare class EmbedPlusBuilder extends EmbedBuilder {
|
|
220
|
+
constructor(data: EmbedPlusOptions);
|
|
221
|
+
has(property: keyof Omit<EmbedPlusData, keyof EmbedPlusOptions>): boolean;
|
|
222
|
+
toArray(): this[];
|
|
223
|
+
toString(space?: number): string;
|
|
224
|
+
updateField(index: number, field: Partial<EmbedPlusFieldData>): this;
|
|
225
|
+
deleteField(index: number): this;
|
|
226
|
+
popField(): discord_js.APIEmbedField | undefined;
|
|
227
|
+
setAsset(asset: "thumbnail" | "image", source: EmbedPlusAssetData): this;
|
|
228
|
+
get fieldsLength(): number;
|
|
229
|
+
get fields(): discord_js.APIEmbedField[];
|
|
230
|
+
}
|
|
231
|
+
type EmbedPlusProperty<P extends keyof EmbedPlusData> = EmbedPlusData[P];
|
|
232
|
+
interface CreateEmbedOptions<B extends boolean> extends EmbedPlusOptions {
|
|
233
|
+
array?: B;
|
|
234
|
+
}
|
|
235
|
+
type CreateEmbedReturn<B> = undefined extends B ? EmbedPlusBuilder : false extends B ? EmbedPlusBuilder : EmbedPlusBuilder[];
|
|
236
|
+
declare function createEmbed<B extends boolean>(options: CreateEmbedOptions<B>): CreateEmbedReturn<B>;
|
|
237
|
+
|
|
238
|
+
interface CreateEmbedFooterOptions {
|
|
239
|
+
text?: string | null;
|
|
240
|
+
iconURL?: string | null;
|
|
241
|
+
}
|
|
242
|
+
declare function createEmbedFooter(options: CreateEmbedFooterOptions): EmbedFooterData | undefined;
|
|
243
|
+
|
|
244
|
+
export { type AssetSource, CustomItents, CustomPartials, EmbedPlusBuilder, type EmbedPlusProperty, chars, createComponentsManager, createEmbed, createEmbedAsset, createEmbedAuthor, createEmbedFooter, createLinkButton, createModalFields, createModalInput, createRow, extractMentionId, findChannel, findCommand, findEmoji, findMember, findMessage, findRole, formatedMention, getChannelUrlInfo, getMessageUrlInfo, setMobileStatus };
|
package/dist/index.mjs
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
export { chars } from './constants/chars.mjs';
|
|
2
2
|
export { CustomItents, CustomPartials } from './constants/client.mjs';
|
|
3
|
-
export {
|
|
3
|
+
export { setMobileStatus } from './functions/misc.mjs';
|
|
4
|
+
export { findChannel, getChannelUrlInfo } from './functions/channels.mjs';
|
|
4
5
|
export { findCommand } from './functions/commands.mjs';
|
|
5
|
-
export { createComponentsManager, createLinkButton,
|
|
6
|
-
export {
|
|
6
|
+
export { createComponentsManager, createLinkButton, createRow } from './functions/components.mjs';
|
|
7
|
+
export { createModalFields, createModalInput } from './functions/modals.mjs';
|
|
7
8
|
export { findEmoji } from './functions/emojis.mjs';
|
|
8
9
|
export { formatedMention } from './functions/format.mjs';
|
|
9
10
|
export { findMember } from './functions/members.mjs';
|
|
10
|
-
export { findMessage } from './functions/message.mjs';
|
|
11
|
+
export { findMessage, getMessageUrlInfo } from './functions/message.mjs';
|
|
11
12
|
export { findRole } from './functions/roles.mjs';
|
|
12
13
|
export { extractMentionId } from './functions/regex.mjs';
|
|
14
|
+
export { createEmbedAsset } from './functions/embeds/assets.mjs';
|
|
15
|
+
export { createEmbedAuthor } from './functions/embeds/author.mjs';
|
|
16
|
+
export { EmbedPlusBuilder, createEmbed } from './functions/embeds/embedplus.mjs';
|
|
17
|
+
export { createEmbedFooter } from './functions/embeds/footer.mjs';
|
|
13
18
|
export * from '@magicyan/core';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@magicyan/discord",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.24",
|
|
4
4
|
"description": "Simple functions to facilitate discord bot development",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
],
|
|
33
33
|
"scripts": {
|
|
34
34
|
"build": "unbuild",
|
|
35
|
-
"dev": "tsx playground/index.ts"
|
|
35
|
+
"dev": "tsx --env-file .env playground/index.ts"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"tsx": "^4.7.0",
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const discord_js = require('discord.js');
|
|
4
|
-
const chars = require('../constants/chars.cjs');
|
|
5
|
-
const core = require('@magicyan/core');
|
|
6
|
-
|
|
7
|
-
function createEmbedAuthor(options) {
|
|
8
|
-
const {
|
|
9
|
-
user,
|
|
10
|
-
property = "displayName",
|
|
11
|
-
imageSize: size = 512,
|
|
12
|
-
iconURL,
|
|
13
|
-
url,
|
|
14
|
-
prefix = "",
|
|
15
|
-
suffix = ""
|
|
16
|
-
} = options;
|
|
17
|
-
return {
|
|
18
|
-
name: prefix + user[property] + suffix,
|
|
19
|
-
url,
|
|
20
|
-
iconURL: iconURL || user.displayAvatarURL({ size })
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
function createEmbedFooter(options) {
|
|
24
|
-
const { text, iconURL } = options;
|
|
25
|
-
return !text && !iconURL ? void 0 : { text: text ?? "\u200B", iconURL: core.notFound(iconURL) };
|
|
26
|
-
}
|
|
27
|
-
function createEmbedAsset(source, options) {
|
|
28
|
-
if (source instanceof discord_js.Attachment || source instanceof discord_js.AttachmentBuilder) {
|
|
29
|
-
return { url: `attachment://${source.name}`, ...options };
|
|
30
|
-
}
|
|
31
|
-
if (source && typeof source === "object" && "url" in source) {
|
|
32
|
-
return source;
|
|
33
|
-
}
|
|
34
|
-
return source ? { url: source, ...options } : void 0;
|
|
35
|
-
}
|
|
36
|
-
class EmbedBuilderPlus extends discord_js.EmbedBuilder {
|
|
37
|
-
constructor(data) {
|
|
38
|
-
const fields = (data.mergeFields ? [data.extend?.fields ?? [], data.fields ?? []].flat() : data.fields ?? data.extend?.fields ?? []).map(({ name = chars.chars.invisible, value = chars.chars.invisible, inline }) => ({
|
|
39
|
-
name,
|
|
40
|
-
value,
|
|
41
|
-
inline
|
|
42
|
-
}));
|
|
43
|
-
const extend = data.extend ? new EmbedBuilderPlus(
|
|
44
|
-
data.extend instanceof discord_js.Embed ? data.extend.data : data.extend instanceof discord_js.EmbedBuilder ? data.extend.data : data.extend
|
|
45
|
-
).data : {};
|
|
46
|
-
const { fields: _, ...exetendData } = extend;
|
|
47
|
-
const embed = new discord_js.EmbedBuilder({
|
|
48
|
-
...exetendData,
|
|
49
|
-
...data.title ? { title: data.title } : {},
|
|
50
|
-
...data.description ? { description: data.description } : {},
|
|
51
|
-
...data.url ? { url: data.url } : {},
|
|
52
|
-
...data.footer ? { footer: createEmbedFooter(data.footer) } : {},
|
|
53
|
-
...data.author ? { author: data.author } : {},
|
|
54
|
-
...data.image ? { image: createEmbedAsset(data.image) } : {},
|
|
55
|
-
...data.thumbnail ? { thumbnail: createEmbedAsset(data.thumbnail) } : {},
|
|
56
|
-
...fields.length > 0 ? { fields } : {}
|
|
57
|
-
});
|
|
58
|
-
if (data.timestamp)
|
|
59
|
-
embed.setTimestamp(
|
|
60
|
-
typeof data.timestamp === "string" ? new Date(data.timestamp) : data.timestamp
|
|
61
|
-
);
|
|
62
|
-
if (data.color)
|
|
63
|
-
embed.setColor(data.color);
|
|
64
|
-
super(embed.data);
|
|
65
|
-
}
|
|
66
|
-
has(property) {
|
|
67
|
-
return Boolean(this.data[property]);
|
|
68
|
-
}
|
|
69
|
-
toArray() {
|
|
70
|
-
return [this];
|
|
71
|
-
}
|
|
72
|
-
toString(space = 2) {
|
|
73
|
-
return JSON.stringify(this, null, space);
|
|
74
|
-
}
|
|
75
|
-
updateField(index, field) {
|
|
76
|
-
if (this.fields.at(index)) {
|
|
77
|
-
const fields = Array.from(this.fields);
|
|
78
|
-
if (field.name)
|
|
79
|
-
fields[index].name = field.name;
|
|
80
|
-
if (field.value)
|
|
81
|
-
fields[index].value = field.value;
|
|
82
|
-
if (field.inline)
|
|
83
|
-
fields[index].inline = field.inline;
|
|
84
|
-
this.setFields(fields);
|
|
85
|
-
}
|
|
86
|
-
return this;
|
|
87
|
-
}
|
|
88
|
-
deleteField(index) {
|
|
89
|
-
if (this.fields.at(index)) {
|
|
90
|
-
this.setFields(this.fields.toSpliced(index, 1));
|
|
91
|
-
}
|
|
92
|
-
return this;
|
|
93
|
-
}
|
|
94
|
-
popField() {
|
|
95
|
-
const fields = Array.from(this.fields);
|
|
96
|
-
const field = fields.pop();
|
|
97
|
-
this.setFields(fields);
|
|
98
|
-
return field;
|
|
99
|
-
}
|
|
100
|
-
setAsset(asset, source) {
|
|
101
|
-
let url = void 0;
|
|
102
|
-
if (source instanceof discord_js.Attachment || source instanceof discord_js.AttachmentBuilder) {
|
|
103
|
-
url = `attachment://${source.name}`;
|
|
104
|
-
}
|
|
105
|
-
if (source && typeof source === "object" && "url" in source) {
|
|
106
|
-
url = source.url;
|
|
107
|
-
}
|
|
108
|
-
if (!url)
|
|
109
|
-
return this;
|
|
110
|
-
if (asset === "thumbnail") {
|
|
111
|
-
this.setImage(url);
|
|
112
|
-
} else {
|
|
113
|
-
this.setThumbnail(url);
|
|
114
|
-
}
|
|
115
|
-
return this;
|
|
116
|
-
}
|
|
117
|
-
get fieldsLength() {
|
|
118
|
-
return this.data.fields?.length ?? 0;
|
|
119
|
-
}
|
|
120
|
-
get fields() {
|
|
121
|
-
return this.data.fields ?? [];
|
|
122
|
-
}
|
|
123
|
-
createFromThis(data = {}) {
|
|
124
|
-
data.extend = this;
|
|
125
|
-
return new EmbedBuilderPlus(data);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
function createEmbed(data) {
|
|
129
|
-
return new EmbedBuilderPlus(data);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
exports.EmbedBuilderPlus = EmbedBuilderPlus;
|
|
133
|
-
exports.createEmbed = createEmbed;
|
|
134
|
-
exports.createEmbedAsset = createEmbedAsset;
|
|
135
|
-
exports.createEmbedAuthor = createEmbedAuthor;
|
|
136
|
-
exports.createEmbedFooter = createEmbedFooter;
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { Attachment, AttachmentBuilder, EmbedBuilder, Embed } from 'discord.js';
|
|
2
|
-
import { chars } from '../constants/chars.mjs';
|
|
3
|
-
import { notFound } from '@magicyan/core';
|
|
4
|
-
|
|
5
|
-
function createEmbedAuthor(options) {
|
|
6
|
-
const {
|
|
7
|
-
user,
|
|
8
|
-
property = "displayName",
|
|
9
|
-
imageSize: size = 512,
|
|
10
|
-
iconURL,
|
|
11
|
-
url,
|
|
12
|
-
prefix = "",
|
|
13
|
-
suffix = ""
|
|
14
|
-
} = options;
|
|
15
|
-
return {
|
|
16
|
-
name: prefix + user[property] + suffix,
|
|
17
|
-
url,
|
|
18
|
-
iconURL: iconURL || user.displayAvatarURL({ size })
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
function createEmbedFooter(options) {
|
|
22
|
-
const { text, iconURL } = options;
|
|
23
|
-
return !text && !iconURL ? void 0 : { text: text ?? "\u200B", iconURL: notFound(iconURL) };
|
|
24
|
-
}
|
|
25
|
-
function createEmbedAsset(source, options) {
|
|
26
|
-
if (source instanceof Attachment || source instanceof AttachmentBuilder) {
|
|
27
|
-
return { url: `attachment://${source.name}`, ...options };
|
|
28
|
-
}
|
|
29
|
-
if (source && typeof source === "object" && "url" in source) {
|
|
30
|
-
return source;
|
|
31
|
-
}
|
|
32
|
-
return source ? { url: source, ...options } : void 0;
|
|
33
|
-
}
|
|
34
|
-
class EmbedBuilderPlus extends EmbedBuilder {
|
|
35
|
-
constructor(data) {
|
|
36
|
-
const fields = (data.mergeFields ? [data.extend?.fields ?? [], data.fields ?? []].flat() : data.fields ?? data.extend?.fields ?? []).map(({ name = chars.invisible, value = chars.invisible, inline }) => ({
|
|
37
|
-
name,
|
|
38
|
-
value,
|
|
39
|
-
inline
|
|
40
|
-
}));
|
|
41
|
-
const extend = data.extend ? new EmbedBuilderPlus(
|
|
42
|
-
data.extend instanceof Embed ? data.extend.data : data.extend instanceof EmbedBuilder ? data.extend.data : data.extend
|
|
43
|
-
).data : {};
|
|
44
|
-
const { fields: _, ...exetendData } = extend;
|
|
45
|
-
const embed = new EmbedBuilder({
|
|
46
|
-
...exetendData,
|
|
47
|
-
...data.title ? { title: data.title } : {},
|
|
48
|
-
...data.description ? { description: data.description } : {},
|
|
49
|
-
...data.url ? { url: data.url } : {},
|
|
50
|
-
...data.footer ? { footer: createEmbedFooter(data.footer) } : {},
|
|
51
|
-
...data.author ? { author: data.author } : {},
|
|
52
|
-
...data.image ? { image: createEmbedAsset(data.image) } : {},
|
|
53
|
-
...data.thumbnail ? { thumbnail: createEmbedAsset(data.thumbnail) } : {},
|
|
54
|
-
...fields.length > 0 ? { fields } : {}
|
|
55
|
-
});
|
|
56
|
-
if (data.timestamp)
|
|
57
|
-
embed.setTimestamp(
|
|
58
|
-
typeof data.timestamp === "string" ? new Date(data.timestamp) : data.timestamp
|
|
59
|
-
);
|
|
60
|
-
if (data.color)
|
|
61
|
-
embed.setColor(data.color);
|
|
62
|
-
super(embed.data);
|
|
63
|
-
}
|
|
64
|
-
has(property) {
|
|
65
|
-
return Boolean(this.data[property]);
|
|
66
|
-
}
|
|
67
|
-
toArray() {
|
|
68
|
-
return [this];
|
|
69
|
-
}
|
|
70
|
-
toString(space = 2) {
|
|
71
|
-
return JSON.stringify(this, null, space);
|
|
72
|
-
}
|
|
73
|
-
updateField(index, field) {
|
|
74
|
-
if (this.fields.at(index)) {
|
|
75
|
-
const fields = Array.from(this.fields);
|
|
76
|
-
if (field.name)
|
|
77
|
-
fields[index].name = field.name;
|
|
78
|
-
if (field.value)
|
|
79
|
-
fields[index].value = field.value;
|
|
80
|
-
if (field.inline)
|
|
81
|
-
fields[index].inline = field.inline;
|
|
82
|
-
this.setFields(fields);
|
|
83
|
-
}
|
|
84
|
-
return this;
|
|
85
|
-
}
|
|
86
|
-
deleteField(index) {
|
|
87
|
-
if (this.fields.at(index)) {
|
|
88
|
-
this.setFields(this.fields.toSpliced(index, 1));
|
|
89
|
-
}
|
|
90
|
-
return this;
|
|
91
|
-
}
|
|
92
|
-
popField() {
|
|
93
|
-
const fields = Array.from(this.fields);
|
|
94
|
-
const field = fields.pop();
|
|
95
|
-
this.setFields(fields);
|
|
96
|
-
return field;
|
|
97
|
-
}
|
|
98
|
-
setAsset(asset, source) {
|
|
99
|
-
let url = void 0;
|
|
100
|
-
if (source instanceof Attachment || source instanceof AttachmentBuilder) {
|
|
101
|
-
url = `attachment://${source.name}`;
|
|
102
|
-
}
|
|
103
|
-
if (source && typeof source === "object" && "url" in source) {
|
|
104
|
-
url = source.url;
|
|
105
|
-
}
|
|
106
|
-
if (!url)
|
|
107
|
-
return this;
|
|
108
|
-
if (asset === "thumbnail") {
|
|
109
|
-
this.setImage(url);
|
|
110
|
-
} else {
|
|
111
|
-
this.setThumbnail(url);
|
|
112
|
-
}
|
|
113
|
-
return this;
|
|
114
|
-
}
|
|
115
|
-
get fieldsLength() {
|
|
116
|
-
return this.data.fields?.length ?? 0;
|
|
117
|
-
}
|
|
118
|
-
get fields() {
|
|
119
|
-
return this.data.fields ?? [];
|
|
120
|
-
}
|
|
121
|
-
createFromThis(data = {}) {
|
|
122
|
-
data.extend = this;
|
|
123
|
-
return new EmbedBuilderPlus(data);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
function createEmbed(data) {
|
|
127
|
-
return new EmbedBuilderPlus(data);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export { EmbedBuilderPlus, createEmbed, createEmbedAsset, createEmbedAuthor, createEmbedFooter };
|