@magicyan/discord 1.0.24 → 1.0.26
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.cjs +1 -1
- package/dist/functions/components.mjs +1 -1
- package/dist/functions/embeds/author.cjs +1 -1
- package/dist/functions/embeds/author.mjs +1 -1
- package/dist/functions/embeds/embedplus.cjs +45 -52
- package/dist/functions/embeds/embedplus.mjs +46 -53
- package/dist/functions/embeds/fields.cjs +97 -0
- package/dist/functions/embeds/fields.mjs +95 -0
- package/dist/functions/members.cjs +7 -6
- package/dist/functions/members.mjs +7 -6
- package/dist/functions/modals.cjs +10 -1
- package/dist/functions/modals.mjs +10 -2
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +60 -25
- package/dist/index.d.mts +60 -25
- package/dist/index.d.ts +60 -25
- package/dist/index.mjs +1 -1
- package/package.json +2 -2
|
@@ -27,7 +27,7 @@ function createComponentsManager(components) {
|
|
|
27
27
|
(row) => row.components.filter((c) => c.type === discord_js.ComponentType.RoleSelect)
|
|
28
28
|
);
|
|
29
29
|
const mentionableSelects = components.flatMap(
|
|
30
|
-
(row) => row.components.filter((c) => c.type === discord_js.ComponentType.
|
|
30
|
+
(row) => row.components.filter((c) => c.type === discord_js.ComponentType.MentionableSelect)
|
|
31
31
|
);
|
|
32
32
|
return {
|
|
33
33
|
getButton(customId) {
|
|
@@ -25,7 +25,7 @@ function createComponentsManager(components) {
|
|
|
25
25
|
(row) => row.components.filter((c) => c.type === ComponentType.RoleSelect)
|
|
26
26
|
);
|
|
27
27
|
const mentionableSelects = components.flatMap(
|
|
28
|
-
(row) => row.components.filter((c) => c.type === ComponentType.
|
|
28
|
+
(row) => row.components.filter((c) => c.type === ComponentType.MentionableSelect)
|
|
29
29
|
);
|
|
30
30
|
return {
|
|
31
31
|
getButton(customId) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
function createEmbedAuthor(options) {
|
|
4
|
-
const { prefix, suffix, url, iconURL } = options;
|
|
4
|
+
const { prefix = "", suffix = "", url, iconURL } = options;
|
|
5
5
|
const { size = 512, extension, forceStatic } = options;
|
|
6
6
|
const avatarOptions = { size, extension, forceStatic };
|
|
7
7
|
if ("member" in options) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
function createEmbedAuthor(options) {
|
|
2
|
-
const { prefix, suffix, url, iconURL } = options;
|
|
2
|
+
const { prefix = "", suffix = "", url, iconURL } = options;
|
|
3
3
|
const { size = 512, extension, forceStatic } = options;
|
|
4
4
|
const avatarOptions = { size, extension, forceStatic };
|
|
5
5
|
if ("member" in options) {
|
|
@@ -4,36 +4,46 @@ const discord_js = require('discord.js');
|
|
|
4
4
|
const chars = require('../../constants/chars.cjs');
|
|
5
5
|
const assets = require('./assets.cjs');
|
|
6
6
|
const footer = require('./footer.cjs');
|
|
7
|
+
const fields = require('./fields.cjs');
|
|
7
8
|
|
|
9
|
+
var __defProp = Object.defineProperty;
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
+
var __publicField = (obj, key, value) => {
|
|
12
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
13
|
+
return value;
|
|
14
|
+
};
|
|
8
15
|
class EmbedPlusBuilder extends discord_js.EmbedBuilder {
|
|
9
16
|
constructor(data) {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
...data.thumbnail ? { thumbnail: assets.createEmbedAsset(data.thumbnail) } : {},
|
|
28
|
-
...fields.length > 0 ? { fields } : {}
|
|
29
|
-
});
|
|
30
|
-
if (data.timestamp)
|
|
17
|
+
const { mergeFields = false, extends: extendsEmbed, ...embedData } = data;
|
|
18
|
+
const extendsEmbedData = extendsEmbed ? "data" in extendsEmbed ? extendsEmbed.data : data : {};
|
|
19
|
+
const { fields: extendsFields, ...extendsData } = extendsEmbedData;
|
|
20
|
+
const fields$1 = (mergeFields ? [extendsFields ?? [], data.fields ?? []].flat() : data.fields ?? extendsFields ?? []).map((field) => Object.assign(
|
|
21
|
+
{ name: field.name ?? chars.chars.invisible, value: field.name ?? chars.chars.invisible },
|
|
22
|
+
field.inline !== void 0 ? { inline: field.inline } : {}
|
|
23
|
+
));
|
|
24
|
+
const builderData = Object.assign({}, extendsData, embedData, { fields: fields$1 });
|
|
25
|
+
const { color, footer: footer$1, image, thumbnail, timestamp } = embedData;
|
|
26
|
+
if (footer$1)
|
|
27
|
+
Object.assign(builderData, { footer: footer.createEmbedFooter(footer$1) });
|
|
28
|
+
if (image)
|
|
29
|
+
Object.assign(builderData, { image: assets.createEmbedAsset(image) });
|
|
30
|
+
if (thumbnail)
|
|
31
|
+
Object.assign(builderData, { thumbnail: assets.createEmbedAsset(thumbnail) });
|
|
32
|
+
const embed = new discord_js.EmbedBuilder(builderData);
|
|
33
|
+
if (timestamp)
|
|
31
34
|
embed.setTimestamp(
|
|
32
|
-
typeof
|
|
35
|
+
typeof timestamp === "string" ? new Date(timestamp) : timestamp
|
|
33
36
|
);
|
|
34
|
-
if (
|
|
35
|
-
embed.setColor(
|
|
37
|
+
if (color)
|
|
38
|
+
embed.setColor(color);
|
|
36
39
|
super(embed.data);
|
|
40
|
+
__publicField(this, "fields");
|
|
41
|
+
this.fields = new fields.EmbedPlusFields(this);
|
|
42
|
+
}
|
|
43
|
+
update(data) {
|
|
44
|
+
const updated = createEmbed({ mergeFields: true, extends: this, ...data });
|
|
45
|
+
Object.assign(this.data, updated.data);
|
|
46
|
+
return this;
|
|
37
47
|
}
|
|
38
48
|
has(property) {
|
|
39
49
|
return Boolean(this.data[property]);
|
|
@@ -44,31 +54,14 @@ class EmbedPlusBuilder extends discord_js.EmbedBuilder {
|
|
|
44
54
|
toString(space = 2) {
|
|
45
55
|
return JSON.stringify(this, null, space);
|
|
46
56
|
}
|
|
47
|
-
|
|
48
|
-
if (
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if (field.value)
|
|
53
|
-
fields[index].value = field.value;
|
|
54
|
-
if (field.inline)
|
|
55
|
-
fields[index].inline = field.inline;
|
|
56
|
-
this.setFields(fields);
|
|
57
|
-
}
|
|
58
|
-
return this;
|
|
59
|
-
}
|
|
60
|
-
deleteField(index) {
|
|
61
|
-
if (this.fields.at(index)) {
|
|
62
|
-
this.setFields(this.fields.toSpliced(index, 1));
|
|
57
|
+
setBorderColor(color) {
|
|
58
|
+
if (color === null) {
|
|
59
|
+
this.setColor("#2B2D31");
|
|
60
|
+
} else {
|
|
61
|
+
this.setColor(color);
|
|
63
62
|
}
|
|
64
63
|
return this;
|
|
65
64
|
}
|
|
66
|
-
popField() {
|
|
67
|
-
const fields = Array.from(this.fields);
|
|
68
|
-
const field = fields.pop();
|
|
69
|
-
this.setFields(fields);
|
|
70
|
-
return field;
|
|
71
|
-
}
|
|
72
65
|
setAsset(asset, source) {
|
|
73
66
|
const assetData = assets.createEmbedAsset(source);
|
|
74
67
|
if (!assetData?.url)
|
|
@@ -76,16 +69,16 @@ class EmbedPlusBuilder extends discord_js.EmbedBuilder {
|
|
|
76
69
|
asset === "image" ? this.setImage(assetData.url) : this.setThumbnail(assetData.url);
|
|
77
70
|
return this;
|
|
78
71
|
}
|
|
79
|
-
|
|
80
|
-
return
|
|
72
|
+
static fromInteraction(interaction, index = 0, data = {}) {
|
|
73
|
+
return EmbedPlusBuilder.fromMessage(interaction.message, index, data);
|
|
81
74
|
}
|
|
82
|
-
|
|
83
|
-
return
|
|
75
|
+
static fromMessage(message, index = 0, data = {}) {
|
|
76
|
+
return new EmbedPlusBuilder(Object.assign({ extends: message.embeds[index] }, data));
|
|
84
77
|
}
|
|
85
78
|
}
|
|
86
79
|
function createEmbed(options) {
|
|
87
|
-
const { array = false, ...data } = options;
|
|
88
|
-
const embed = new EmbedPlusBuilder(data);
|
|
80
|
+
const { array = false, interaction, ...data } = options;
|
|
81
|
+
const embed = interaction ? EmbedPlusBuilder.fromInteraction(interaction, 0, data) : new EmbedPlusBuilder(data);
|
|
89
82
|
return array ? [embed] : embed;
|
|
90
83
|
}
|
|
91
84
|
|
|
@@ -1,37 +1,47 @@
|
|
|
1
|
-
import { EmbedBuilder
|
|
1
|
+
import { EmbedBuilder } from 'discord.js';
|
|
2
2
|
import { chars } from '../../constants/chars.mjs';
|
|
3
3
|
import { createEmbedAsset } from './assets.mjs';
|
|
4
4
|
import { createEmbedFooter } from './footer.mjs';
|
|
5
|
+
import { EmbedPlusFields } from './fields.mjs';
|
|
5
6
|
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __publicField = (obj, key, value) => {
|
|
10
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
11
|
+
return value;
|
|
12
|
+
};
|
|
6
13
|
class EmbedPlusBuilder extends EmbedBuilder {
|
|
7
14
|
constructor(data) {
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
...data.thumbnail ? { thumbnail: createEmbedAsset(data.thumbnail) } : {},
|
|
26
|
-
...fields.length > 0 ? { fields } : {}
|
|
27
|
-
});
|
|
28
|
-
if (data.timestamp)
|
|
15
|
+
const { mergeFields = false, extends: extendsEmbed, ...embedData } = data;
|
|
16
|
+
const extendsEmbedData = extendsEmbed ? "data" in extendsEmbed ? extendsEmbed.data : data : {};
|
|
17
|
+
const { fields: extendsFields, ...extendsData } = extendsEmbedData;
|
|
18
|
+
const fields = (mergeFields ? [extendsFields ?? [], data.fields ?? []].flat() : data.fields ?? extendsFields ?? []).map((field) => Object.assign(
|
|
19
|
+
{ name: field.name ?? chars.invisible, value: field.name ?? chars.invisible },
|
|
20
|
+
field.inline !== void 0 ? { inline: field.inline } : {}
|
|
21
|
+
));
|
|
22
|
+
const builderData = Object.assign({}, extendsData, embedData, { fields });
|
|
23
|
+
const { color, footer, image, thumbnail, timestamp } = embedData;
|
|
24
|
+
if (footer)
|
|
25
|
+
Object.assign(builderData, { footer: createEmbedFooter(footer) });
|
|
26
|
+
if (image)
|
|
27
|
+
Object.assign(builderData, { image: createEmbedAsset(image) });
|
|
28
|
+
if (thumbnail)
|
|
29
|
+
Object.assign(builderData, { thumbnail: createEmbedAsset(thumbnail) });
|
|
30
|
+
const embed = new EmbedBuilder(builderData);
|
|
31
|
+
if (timestamp)
|
|
29
32
|
embed.setTimestamp(
|
|
30
|
-
typeof
|
|
33
|
+
typeof timestamp === "string" ? new Date(timestamp) : timestamp
|
|
31
34
|
);
|
|
32
|
-
if (
|
|
33
|
-
embed.setColor(
|
|
35
|
+
if (color)
|
|
36
|
+
embed.setColor(color);
|
|
34
37
|
super(embed.data);
|
|
38
|
+
__publicField(this, "fields");
|
|
39
|
+
this.fields = new EmbedPlusFields(this);
|
|
40
|
+
}
|
|
41
|
+
update(data) {
|
|
42
|
+
const updated = createEmbed({ mergeFields: true, extends: this, ...data });
|
|
43
|
+
Object.assign(this.data, updated.data);
|
|
44
|
+
return this;
|
|
35
45
|
}
|
|
36
46
|
has(property) {
|
|
37
47
|
return Boolean(this.data[property]);
|
|
@@ -42,31 +52,14 @@ class EmbedPlusBuilder extends EmbedBuilder {
|
|
|
42
52
|
toString(space = 2) {
|
|
43
53
|
return JSON.stringify(this, null, space);
|
|
44
54
|
}
|
|
45
|
-
|
|
46
|
-
if (
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (field.value)
|
|
51
|
-
fields[index].value = field.value;
|
|
52
|
-
if (field.inline)
|
|
53
|
-
fields[index].inline = field.inline;
|
|
54
|
-
this.setFields(fields);
|
|
55
|
-
}
|
|
56
|
-
return this;
|
|
57
|
-
}
|
|
58
|
-
deleteField(index) {
|
|
59
|
-
if (this.fields.at(index)) {
|
|
60
|
-
this.setFields(this.fields.toSpliced(index, 1));
|
|
55
|
+
setBorderColor(color) {
|
|
56
|
+
if (color === null) {
|
|
57
|
+
this.setColor("#2B2D31");
|
|
58
|
+
} else {
|
|
59
|
+
this.setColor(color);
|
|
61
60
|
}
|
|
62
61
|
return this;
|
|
63
62
|
}
|
|
64
|
-
popField() {
|
|
65
|
-
const fields = Array.from(this.fields);
|
|
66
|
-
const field = fields.pop();
|
|
67
|
-
this.setFields(fields);
|
|
68
|
-
return field;
|
|
69
|
-
}
|
|
70
63
|
setAsset(asset, source) {
|
|
71
64
|
const assetData = createEmbedAsset(source);
|
|
72
65
|
if (!assetData?.url)
|
|
@@ -74,16 +67,16 @@ class EmbedPlusBuilder extends EmbedBuilder {
|
|
|
74
67
|
asset === "image" ? this.setImage(assetData.url) : this.setThumbnail(assetData.url);
|
|
75
68
|
return this;
|
|
76
69
|
}
|
|
77
|
-
|
|
78
|
-
return
|
|
70
|
+
static fromInteraction(interaction, index = 0, data = {}) {
|
|
71
|
+
return EmbedPlusBuilder.fromMessage(interaction.message, index, data);
|
|
79
72
|
}
|
|
80
|
-
|
|
81
|
-
return
|
|
73
|
+
static fromMessage(message, index = 0, data = {}) {
|
|
74
|
+
return new EmbedPlusBuilder(Object.assign({ extends: message.embeds[index] }, data));
|
|
82
75
|
}
|
|
83
76
|
}
|
|
84
77
|
function createEmbed(options) {
|
|
85
|
-
const { array = false, ...data } = options;
|
|
86
|
-
const embed = new EmbedPlusBuilder(data);
|
|
78
|
+
const { array = false, interaction, ...data } = options;
|
|
79
|
+
const embed = interaction ? EmbedPlusBuilder.fromInteraction(interaction, 0, data) : new EmbedPlusBuilder(data);
|
|
87
80
|
return array ? [embed] : embed;
|
|
88
81
|
}
|
|
89
82
|
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
5
|
+
var __publicField = (obj, key, value) => {
|
|
6
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
7
|
+
return value;
|
|
8
|
+
};
|
|
9
|
+
class EmbedPlusFields {
|
|
10
|
+
constructor(embed) {
|
|
11
|
+
__publicField(this, "embed");
|
|
12
|
+
Object.defineProperty(this, "embed", {
|
|
13
|
+
enumerable: false,
|
|
14
|
+
value: embed
|
|
15
|
+
});
|
|
16
|
+
this.embed = embed;
|
|
17
|
+
}
|
|
18
|
+
set fields(fields) {
|
|
19
|
+
this.embed.setFields(fields);
|
|
20
|
+
}
|
|
21
|
+
get fields() {
|
|
22
|
+
return this.embed.data.fields ?? [];
|
|
23
|
+
}
|
|
24
|
+
[Symbol.iterator]() {
|
|
25
|
+
let pointer = 0;
|
|
26
|
+
const fields = this.fields;
|
|
27
|
+
return {
|
|
28
|
+
next() {
|
|
29
|
+
return {
|
|
30
|
+
done: pointer >= fields.length,
|
|
31
|
+
value: fields[pointer++] ?? null
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
get length() {
|
|
37
|
+
return this.fields.length;
|
|
38
|
+
}
|
|
39
|
+
get record() {
|
|
40
|
+
return this.fields.reduce(
|
|
41
|
+
(record, { name, value }) => Object.assign(record, { [name]: value }),
|
|
42
|
+
{}
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
get(query) {
|
|
46
|
+
const isIndex = typeof query == "number";
|
|
47
|
+
if (isIndex)
|
|
48
|
+
return this.fields[query];
|
|
49
|
+
return this.fields.find((f) => f.name === query);
|
|
50
|
+
}
|
|
51
|
+
find(predicate) {
|
|
52
|
+
return this.fields.find(predicate);
|
|
53
|
+
}
|
|
54
|
+
push(...fields) {
|
|
55
|
+
this.embed.addFields(fields);
|
|
56
|
+
}
|
|
57
|
+
set(...fields) {
|
|
58
|
+
this.embed.setFields(fields);
|
|
59
|
+
}
|
|
60
|
+
update(predicate, field) {
|
|
61
|
+
const index = this.getPredicateIndex(predicate);
|
|
62
|
+
if (index == -1)
|
|
63
|
+
return false;
|
|
64
|
+
const embedField = this.get(index);
|
|
65
|
+
if (!embedField)
|
|
66
|
+
return false;
|
|
67
|
+
this.embed.spliceFields(index, 1, Object.assign(embedField, field));
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
delete(predicate) {
|
|
71
|
+
const index = this.getPredicateIndex(predicate);
|
|
72
|
+
if (index == -1)
|
|
73
|
+
return false;
|
|
74
|
+
const embedField = this.get(index);
|
|
75
|
+
if (!embedField)
|
|
76
|
+
return false;
|
|
77
|
+
this.embed.spliceFields(index, 1);
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
toArray() {
|
|
81
|
+
return Array.from(this);
|
|
82
|
+
}
|
|
83
|
+
getPredicateIndex(predicate) {
|
|
84
|
+
switch (typeof predicate) {
|
|
85
|
+
case "function":
|
|
86
|
+
return this.fields.findIndex(predicate);
|
|
87
|
+
case "string":
|
|
88
|
+
return this.fields.findIndex((f) => f.name == predicate);
|
|
89
|
+
case "number":
|
|
90
|
+
return predicate;
|
|
91
|
+
default:
|
|
92
|
+
return -1;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
exports.EmbedPlusFields = EmbedPlusFields;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => {
|
|
4
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
return value;
|
|
6
|
+
};
|
|
7
|
+
class EmbedPlusFields {
|
|
8
|
+
constructor(embed) {
|
|
9
|
+
__publicField(this, "embed");
|
|
10
|
+
Object.defineProperty(this, "embed", {
|
|
11
|
+
enumerable: false,
|
|
12
|
+
value: embed
|
|
13
|
+
});
|
|
14
|
+
this.embed = embed;
|
|
15
|
+
}
|
|
16
|
+
set fields(fields) {
|
|
17
|
+
this.embed.setFields(fields);
|
|
18
|
+
}
|
|
19
|
+
get fields() {
|
|
20
|
+
return this.embed.data.fields ?? [];
|
|
21
|
+
}
|
|
22
|
+
[Symbol.iterator]() {
|
|
23
|
+
let pointer = 0;
|
|
24
|
+
const fields = this.fields;
|
|
25
|
+
return {
|
|
26
|
+
next() {
|
|
27
|
+
return {
|
|
28
|
+
done: pointer >= fields.length,
|
|
29
|
+
value: fields[pointer++] ?? null
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
get length() {
|
|
35
|
+
return this.fields.length;
|
|
36
|
+
}
|
|
37
|
+
get record() {
|
|
38
|
+
return this.fields.reduce(
|
|
39
|
+
(record, { name, value }) => Object.assign(record, { [name]: value }),
|
|
40
|
+
{}
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
get(query) {
|
|
44
|
+
const isIndex = typeof query == "number";
|
|
45
|
+
if (isIndex)
|
|
46
|
+
return this.fields[query];
|
|
47
|
+
return this.fields.find((f) => f.name === query);
|
|
48
|
+
}
|
|
49
|
+
find(predicate) {
|
|
50
|
+
return this.fields.find(predicate);
|
|
51
|
+
}
|
|
52
|
+
push(...fields) {
|
|
53
|
+
this.embed.addFields(fields);
|
|
54
|
+
}
|
|
55
|
+
set(...fields) {
|
|
56
|
+
this.embed.setFields(fields);
|
|
57
|
+
}
|
|
58
|
+
update(predicate, field) {
|
|
59
|
+
const index = this.getPredicateIndex(predicate);
|
|
60
|
+
if (index == -1)
|
|
61
|
+
return false;
|
|
62
|
+
const embedField = this.get(index);
|
|
63
|
+
if (!embedField)
|
|
64
|
+
return false;
|
|
65
|
+
this.embed.spliceFields(index, 1, Object.assign(embedField, field));
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
delete(predicate) {
|
|
69
|
+
const index = this.getPredicateIndex(predicate);
|
|
70
|
+
if (index == -1)
|
|
71
|
+
return false;
|
|
72
|
+
const embedField = this.get(index);
|
|
73
|
+
if (!embedField)
|
|
74
|
+
return false;
|
|
75
|
+
this.embed.spliceFields(index, 1);
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
toArray() {
|
|
79
|
+
return Array.from(this);
|
|
80
|
+
}
|
|
81
|
+
getPredicateIndex(predicate) {
|
|
82
|
+
switch (typeof predicate) {
|
|
83
|
+
case "function":
|
|
84
|
+
return this.fields.findIndex(predicate);
|
|
85
|
+
case "string":
|
|
86
|
+
return this.fields.findIndex((f) => f.name == predicate);
|
|
87
|
+
case "number":
|
|
88
|
+
return predicate;
|
|
89
|
+
default:
|
|
90
|
+
return -1;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export { EmbedPlusFields };
|
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
function findMember(guild) {
|
|
4
|
+
const cache = guild.members.cache;
|
|
4
5
|
return {
|
|
5
6
|
byGlobalName(globalName, and = () => true) {
|
|
6
|
-
return
|
|
7
|
+
return cache.find((member) => member.user.globalName == globalName && and(member));
|
|
7
8
|
},
|
|
8
9
|
byNickname(nickname, and = () => true) {
|
|
9
|
-
return
|
|
10
|
+
return cache.find((member) => member.nickname && member.nickname == nickname && and(member));
|
|
10
11
|
},
|
|
11
12
|
byUsername(username, and = () => true) {
|
|
12
|
-
return
|
|
13
|
+
return cache.find((member) => member.user.username === username && and(member));
|
|
13
14
|
},
|
|
14
15
|
byDisplayName(displayName, and = () => true) {
|
|
15
|
-
return
|
|
16
|
+
return cache.find((member) => member.displayName === displayName && and(member));
|
|
16
17
|
},
|
|
17
18
|
byId(id) {
|
|
18
|
-
return
|
|
19
|
+
return cache.get(id);
|
|
19
20
|
},
|
|
20
21
|
byFilter(filter) {
|
|
21
|
-
return
|
|
22
|
+
return cache.find(filter);
|
|
22
23
|
}
|
|
23
24
|
};
|
|
24
25
|
}
|
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
function findMember(guild) {
|
|
2
|
+
const cache = guild.members.cache;
|
|
2
3
|
return {
|
|
3
4
|
byGlobalName(globalName, and = () => true) {
|
|
4
|
-
return
|
|
5
|
+
return cache.find((member) => member.user.globalName == globalName && and(member));
|
|
5
6
|
},
|
|
6
7
|
byNickname(nickname, and = () => true) {
|
|
7
|
-
return
|
|
8
|
+
return cache.find((member) => member.nickname && member.nickname == nickname && and(member));
|
|
8
9
|
},
|
|
9
10
|
byUsername(username, and = () => true) {
|
|
10
|
-
return
|
|
11
|
+
return cache.find((member) => member.user.username === username && and(member));
|
|
11
12
|
},
|
|
12
13
|
byDisplayName(displayName, and = () => true) {
|
|
13
|
-
return
|
|
14
|
+
return cache.find((member) => member.displayName === displayName && and(member));
|
|
14
15
|
},
|
|
15
16
|
byId(id) {
|
|
16
|
-
return
|
|
17
|
+
return cache.get(id);
|
|
17
18
|
},
|
|
18
19
|
byFilter(filter) {
|
|
19
|
-
return
|
|
20
|
+
return cache.find(filter);
|
|
20
21
|
}
|
|
21
22
|
};
|
|
22
23
|
}
|
|
@@ -8,9 +8,18 @@ function createModalInput(data) {
|
|
|
8
8
|
}
|
|
9
9
|
function createModalFields(data) {
|
|
10
10
|
return Object.entries(data).map(
|
|
11
|
-
([customId, data2]) => createModalInput({ customId,
|
|
11
|
+
([customId, data2]) => createModalInput(Object.assign({ customId }, data2))
|
|
12
12
|
);
|
|
13
13
|
}
|
|
14
|
+
function modalFieldsToRecord(fields) {
|
|
15
|
+
const reduceFunction = (data, { customId, value }) => Object.assign(
|
|
16
|
+
data,
|
|
17
|
+
{ [customId]: value }
|
|
18
|
+
);
|
|
19
|
+
const modalFields = "fields" in fields ? fields.fields : fields;
|
|
20
|
+
return modalFields.reduce(reduceFunction, {});
|
|
21
|
+
}
|
|
14
22
|
|
|
15
23
|
exports.createModalFields = createModalFields;
|
|
16
24
|
exports.createModalInput = createModalInput;
|
|
25
|
+
exports.modalFieldsToRecord = modalFieldsToRecord;
|
|
@@ -6,8 +6,16 @@ function createModalInput(data) {
|
|
|
6
6
|
}
|
|
7
7
|
function createModalFields(data) {
|
|
8
8
|
return Object.entries(data).map(
|
|
9
|
-
([customId, data2]) => createModalInput({ customId,
|
|
9
|
+
([customId, data2]) => createModalInput(Object.assign({ customId }, data2))
|
|
10
10
|
);
|
|
11
11
|
}
|
|
12
|
+
function modalFieldsToRecord(fields) {
|
|
13
|
+
const reduceFunction = (data, { customId, value }) => Object.assign(
|
|
14
|
+
data,
|
|
15
|
+
{ [customId]: value }
|
|
16
|
+
);
|
|
17
|
+
const modalFields = "fields" in fields ? fields.fields : fields;
|
|
18
|
+
return modalFields.reduce(reduceFunction, {});
|
|
19
|
+
}
|
|
12
20
|
|
|
13
|
-
export { createModalFields, createModalInput };
|
|
21
|
+
export { createModalFields, createModalInput, modalFieldsToRecord };
|
package/dist/index.cjs
CHANGED
|
@@ -33,6 +33,7 @@ exports.createLinkButton = components.createLinkButton;
|
|
|
33
33
|
exports.createRow = components.createRow;
|
|
34
34
|
exports.createModalFields = modals.createModalFields;
|
|
35
35
|
exports.createModalInput = modals.createModalInput;
|
|
36
|
+
exports.modalFieldsToRecord = modals.modalFieldsToRecord;
|
|
36
37
|
exports.findEmoji = emojis.findEmoji;
|
|
37
38
|
exports.formatedMention = format.formatedMention;
|
|
38
39
|
exports.findMember = members.findMember;
|
package/dist/index.d.cts
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, ButtonBuilder, ActionRow, MessageActionRowComponent, LinkButtonComponentData, ButtonComponent, StringSelectMenuComponent, UserSelectMenuComponent, ChannelSelectMenuComponent, RoleSelectMenuComponent, MentionableSelectMenuComponent, TextInputBuilder, TextInputComponentData, GuildEmoji, GuildBasedChannel, Role, User, GuildMember, GuildTextBasedChannel, Message, Attachment, AttachmentBuilder, EmbedAssetData, EmbedAuthorData, ImageURLOptions,
|
|
2
|
+
import { GatewayIntentBits, Partials, ChannelType, Guild, CommandInteractionOption, Client, ApplicationCommand, AnyComponentBuilder, ActionRowBuilder, ButtonBuilder, ActionRow, MessageActionRowComponent, LinkButtonComponentData, ButtonComponent, StringSelectMenuComponent, UserSelectMenuComponent, ChannelSelectMenuComponent, RoleSelectMenuComponent, MentionableSelectMenuComponent, TextInputBuilder, ModalSubmitFields, Collection, TextInputComponent, TextInputComponentData, GuildEmoji, GuildBasedChannel, Role, User, GuildMember, GuildTextBasedChannel, Message, Attachment, AttachmentBuilder, EmbedAssetData, EmbedAuthorData, ImageURLOptions, EmbedFooterData, APIEmbed, Embed, EmbedBuilder, EmbedData, ColorResolvable } from 'discord.js';
|
|
3
3
|
export * from '@magicyan/core';
|
|
4
4
|
|
|
5
5
|
declare const chars: {
|
|
@@ -90,6 +90,8 @@ type CreateModalInputData = TextInputData;
|
|
|
90
90
|
declare function createModalInput(data: CreateModalInputData): ActionRowBuilder<TextInputBuilder>;
|
|
91
91
|
type ModalFieldsData = Record<string, Omit<TextInputData, "customId">>;
|
|
92
92
|
declare function createModalFields(data: ModalFieldsData): ActionRowBuilder<TextInputBuilder>[];
|
|
93
|
+
type ModalFieldsRecord = Record<string, string>;
|
|
94
|
+
declare function modalFieldsToRecord(fields: ModalSubmitFields | Collection<string, TextInputComponent>): ModalFieldsRecord;
|
|
93
95
|
|
|
94
96
|
type FindEmojiFilter = (emoji: GuildEmoji) => boolean;
|
|
95
97
|
declare function findEmoji(guildOrClient: Guild | Client): {
|
|
@@ -163,9 +165,9 @@ declare function findRole(guild: Guild): {
|
|
|
163
165
|
*/
|
|
164
166
|
declare function extractMentionId(mention: string): string | null;
|
|
165
167
|
|
|
168
|
+
type EmbedPlusAssetData = string | Attachment | AttachmentBuilder | EmbedAssetData | undefined | null;
|
|
166
169
|
type EmbedAssetOptions = Omit<EmbedAssetData, "url">;
|
|
167
|
-
|
|
168
|
-
declare function createEmbedAsset(source: AssetSource, options?: EmbedAssetOptions): EmbedAssetData | undefined;
|
|
170
|
+
declare function createEmbedAsset(source: EmbedPlusAssetData, options?: EmbedAssetOptions): EmbedAssetData | undefined;
|
|
169
171
|
|
|
170
172
|
interface UserAuthorOption {
|
|
171
173
|
user: User;
|
|
@@ -184,17 +186,48 @@ type CreateEmbedAuthorOptions = AuthorOption & ImageURLOptions & {
|
|
|
184
186
|
};
|
|
185
187
|
declare function createEmbedAuthor(options: CreateEmbedAuthorOptions): EmbedAuthorData;
|
|
186
188
|
|
|
187
|
-
type
|
|
188
|
-
|
|
189
|
+
type EmbedPlusFooterData = {
|
|
190
|
+
text?: string | null;
|
|
191
|
+
iconURL?: string | null;
|
|
192
|
+
};
|
|
193
|
+
declare function createEmbedFooter(options: EmbedPlusFooterData): EmbedFooterData | undefined;
|
|
194
|
+
|
|
189
195
|
type EmbedPlusFieldData = {
|
|
190
196
|
name: string;
|
|
191
197
|
value: string;
|
|
192
198
|
inline?: boolean;
|
|
193
199
|
};
|
|
194
|
-
type
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
200
|
+
type FieldPredicate = (field: EmbedPlusFieldData, index: number, obj: EmbedPlusFieldData[]) => boolean;
|
|
201
|
+
declare class EmbedPlusFields {
|
|
202
|
+
private embed;
|
|
203
|
+
private set fields(value);
|
|
204
|
+
private get fields();
|
|
205
|
+
constructor(embed: EmbedPlusBuilder);
|
|
206
|
+
[Symbol.iterator](): {
|
|
207
|
+
next(): IteratorResult<EmbedPlusFieldData>;
|
|
208
|
+
};
|
|
209
|
+
get length(): number;
|
|
210
|
+
get record(): Record<string, string | undefined>;
|
|
211
|
+
/**
|
|
212
|
+
* Get a filed by index
|
|
213
|
+
* @param name Field name
|
|
214
|
+
*/
|
|
215
|
+
get(name: string): EmbedPlusFieldData | undefined;
|
|
216
|
+
/**
|
|
217
|
+
* Get a field by name
|
|
218
|
+
* @param index Field index
|
|
219
|
+
*/
|
|
220
|
+
get(index: number): EmbedPlusFieldData | undefined;
|
|
221
|
+
find(predicate: FieldPredicate): EmbedPlusFieldData | undefined;
|
|
222
|
+
push(...fields: EmbedPlusFieldData[]): void;
|
|
223
|
+
set(...fields: EmbedPlusFieldData[]): void;
|
|
224
|
+
update(predicate: string | number | FieldPredicate, field: Partial<EmbedPlusFieldData>): boolean;
|
|
225
|
+
delete(predicate: string | number | FieldPredicate): boolean;
|
|
226
|
+
toArray(): EmbedPlusFieldData[];
|
|
227
|
+
private getPredicateIndex;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
type EmbedPlusColorData = string & {} | ColorResolvable | null;
|
|
198
231
|
type EmbedPlusAuthorData = {
|
|
199
232
|
name: string;
|
|
200
233
|
url?: string;
|
|
@@ -205,40 +238,42 @@ interface EmbedPlusData {
|
|
|
205
238
|
color?: EmbedPlusColorData | null;
|
|
206
239
|
description?: string | null;
|
|
207
240
|
url?: string | null;
|
|
208
|
-
thumbnail?: EmbedPlusAssetData
|
|
209
|
-
image?: EmbedPlusAssetData
|
|
241
|
+
thumbnail?: EmbedPlusAssetData;
|
|
242
|
+
image?: EmbedPlusAssetData;
|
|
210
243
|
fields?: Partial<EmbedPlusFieldData>[] | null;
|
|
211
244
|
timestamp?: string | number | Date | null;
|
|
212
245
|
footer?: EmbedPlusFooterData;
|
|
213
246
|
author?: EmbedPlusAuthorData;
|
|
214
247
|
}
|
|
248
|
+
type AnyEmbed = APIEmbed | Embed | EmbedBuilder | EmbedData;
|
|
249
|
+
interface MessageWithEmbeds {
|
|
250
|
+
embeds: Array<Embed>;
|
|
251
|
+
}
|
|
252
|
+
interface InteractionWithEmbeds {
|
|
253
|
+
message: MessageWithEmbeds;
|
|
254
|
+
}
|
|
215
255
|
interface EmbedPlusOptions extends EmbedPlusData {
|
|
216
|
-
extends?: Omit<EmbedPlusData, keyof EmbedPlusOptions> |
|
|
256
|
+
extends?: Omit<EmbedPlusData, keyof EmbedPlusOptions> | AnyEmbed;
|
|
217
257
|
mergeFields?: boolean;
|
|
218
258
|
}
|
|
219
259
|
declare class EmbedPlusBuilder extends EmbedBuilder {
|
|
260
|
+
fields: EmbedPlusFields;
|
|
220
261
|
constructor(data: EmbedPlusOptions);
|
|
262
|
+
update(data: EmbedPlusData): this;
|
|
221
263
|
has(property: keyof Omit<EmbedPlusData, keyof EmbedPlusOptions>): boolean;
|
|
222
|
-
toArray():
|
|
264
|
+
toArray(): EmbedPlusBuilder[];
|
|
223
265
|
toString(space?: number): string;
|
|
224
|
-
|
|
225
|
-
deleteField(index: number): this;
|
|
226
|
-
popField(): discord_js.APIEmbedField | undefined;
|
|
266
|
+
setBorderColor(color: EmbedPlusColorData | null): this;
|
|
227
267
|
setAsset(asset: "thumbnail" | "image", source: EmbedPlusAssetData): this;
|
|
228
|
-
|
|
229
|
-
|
|
268
|
+
static fromInteraction(interaction: InteractionWithEmbeds, index?: number, data?: EmbedPlusData): EmbedPlusBuilder;
|
|
269
|
+
static fromMessage(message: MessageWithEmbeds, index?: number, data?: EmbedPlusData): EmbedPlusBuilder;
|
|
230
270
|
}
|
|
231
271
|
type EmbedPlusProperty<P extends keyof EmbedPlusData> = EmbedPlusData[P];
|
|
232
272
|
interface CreateEmbedOptions<B extends boolean> extends EmbedPlusOptions {
|
|
233
273
|
array?: B;
|
|
274
|
+
interaction?: InteractionWithEmbeds;
|
|
234
275
|
}
|
|
235
276
|
type CreateEmbedReturn<B> = undefined extends B ? EmbedPlusBuilder : false extends B ? EmbedPlusBuilder : EmbedPlusBuilder[];
|
|
236
277
|
declare function createEmbed<B extends boolean>(options: CreateEmbedOptions<B>): CreateEmbedReturn<B>;
|
|
237
278
|
|
|
238
|
-
|
|
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 };
|
|
279
|
+
export { type AnyEmbed, CustomItents, CustomPartials, type EmbedPlusAssetData, EmbedPlusBuilder, type EmbedPlusData, type EmbedPlusFooterData, type EmbedPlusProperty, chars, createComponentsManager, createEmbed, createEmbedAsset, createEmbedAuthor, createEmbedFooter, createLinkButton, createModalFields, createModalInput, createRow, extractMentionId, findChannel, findCommand, findEmoji, findMember, findMessage, findRole, formatedMention, getChannelUrlInfo, getMessageUrlInfo, modalFieldsToRecord, setMobileStatus };
|
package/dist/index.d.mts
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, ButtonBuilder, ActionRow, MessageActionRowComponent, LinkButtonComponentData, ButtonComponent, StringSelectMenuComponent, UserSelectMenuComponent, ChannelSelectMenuComponent, RoleSelectMenuComponent, MentionableSelectMenuComponent, TextInputBuilder, TextInputComponentData, GuildEmoji, GuildBasedChannel, Role, User, GuildMember, GuildTextBasedChannel, Message, Attachment, AttachmentBuilder, EmbedAssetData, EmbedAuthorData, ImageURLOptions,
|
|
2
|
+
import { GatewayIntentBits, Partials, ChannelType, Guild, CommandInteractionOption, Client, ApplicationCommand, AnyComponentBuilder, ActionRowBuilder, ButtonBuilder, ActionRow, MessageActionRowComponent, LinkButtonComponentData, ButtonComponent, StringSelectMenuComponent, UserSelectMenuComponent, ChannelSelectMenuComponent, RoleSelectMenuComponent, MentionableSelectMenuComponent, TextInputBuilder, ModalSubmitFields, Collection, TextInputComponent, TextInputComponentData, GuildEmoji, GuildBasedChannel, Role, User, GuildMember, GuildTextBasedChannel, Message, Attachment, AttachmentBuilder, EmbedAssetData, EmbedAuthorData, ImageURLOptions, EmbedFooterData, APIEmbed, Embed, EmbedBuilder, EmbedData, ColorResolvable } from 'discord.js';
|
|
3
3
|
export * from '@magicyan/core';
|
|
4
4
|
|
|
5
5
|
declare const chars: {
|
|
@@ -90,6 +90,8 @@ type CreateModalInputData = TextInputData;
|
|
|
90
90
|
declare function createModalInput(data: CreateModalInputData): ActionRowBuilder<TextInputBuilder>;
|
|
91
91
|
type ModalFieldsData = Record<string, Omit<TextInputData, "customId">>;
|
|
92
92
|
declare function createModalFields(data: ModalFieldsData): ActionRowBuilder<TextInputBuilder>[];
|
|
93
|
+
type ModalFieldsRecord = Record<string, string>;
|
|
94
|
+
declare function modalFieldsToRecord(fields: ModalSubmitFields | Collection<string, TextInputComponent>): ModalFieldsRecord;
|
|
93
95
|
|
|
94
96
|
type FindEmojiFilter = (emoji: GuildEmoji) => boolean;
|
|
95
97
|
declare function findEmoji(guildOrClient: Guild | Client): {
|
|
@@ -163,9 +165,9 @@ declare function findRole(guild: Guild): {
|
|
|
163
165
|
*/
|
|
164
166
|
declare function extractMentionId(mention: string): string | null;
|
|
165
167
|
|
|
168
|
+
type EmbedPlusAssetData = string | Attachment | AttachmentBuilder | EmbedAssetData | undefined | null;
|
|
166
169
|
type EmbedAssetOptions = Omit<EmbedAssetData, "url">;
|
|
167
|
-
|
|
168
|
-
declare function createEmbedAsset(source: AssetSource, options?: EmbedAssetOptions): EmbedAssetData | undefined;
|
|
170
|
+
declare function createEmbedAsset(source: EmbedPlusAssetData, options?: EmbedAssetOptions): EmbedAssetData | undefined;
|
|
169
171
|
|
|
170
172
|
interface UserAuthorOption {
|
|
171
173
|
user: User;
|
|
@@ -184,17 +186,48 @@ type CreateEmbedAuthorOptions = AuthorOption & ImageURLOptions & {
|
|
|
184
186
|
};
|
|
185
187
|
declare function createEmbedAuthor(options: CreateEmbedAuthorOptions): EmbedAuthorData;
|
|
186
188
|
|
|
187
|
-
type
|
|
188
|
-
|
|
189
|
+
type EmbedPlusFooterData = {
|
|
190
|
+
text?: string | null;
|
|
191
|
+
iconURL?: string | null;
|
|
192
|
+
};
|
|
193
|
+
declare function createEmbedFooter(options: EmbedPlusFooterData): EmbedFooterData | undefined;
|
|
194
|
+
|
|
189
195
|
type EmbedPlusFieldData = {
|
|
190
196
|
name: string;
|
|
191
197
|
value: string;
|
|
192
198
|
inline?: boolean;
|
|
193
199
|
};
|
|
194
|
-
type
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
200
|
+
type FieldPredicate = (field: EmbedPlusFieldData, index: number, obj: EmbedPlusFieldData[]) => boolean;
|
|
201
|
+
declare class EmbedPlusFields {
|
|
202
|
+
private embed;
|
|
203
|
+
private set fields(value);
|
|
204
|
+
private get fields();
|
|
205
|
+
constructor(embed: EmbedPlusBuilder);
|
|
206
|
+
[Symbol.iterator](): {
|
|
207
|
+
next(): IteratorResult<EmbedPlusFieldData>;
|
|
208
|
+
};
|
|
209
|
+
get length(): number;
|
|
210
|
+
get record(): Record<string, string | undefined>;
|
|
211
|
+
/**
|
|
212
|
+
* Get a filed by index
|
|
213
|
+
* @param name Field name
|
|
214
|
+
*/
|
|
215
|
+
get(name: string): EmbedPlusFieldData | undefined;
|
|
216
|
+
/**
|
|
217
|
+
* Get a field by name
|
|
218
|
+
* @param index Field index
|
|
219
|
+
*/
|
|
220
|
+
get(index: number): EmbedPlusFieldData | undefined;
|
|
221
|
+
find(predicate: FieldPredicate): EmbedPlusFieldData | undefined;
|
|
222
|
+
push(...fields: EmbedPlusFieldData[]): void;
|
|
223
|
+
set(...fields: EmbedPlusFieldData[]): void;
|
|
224
|
+
update(predicate: string | number | FieldPredicate, field: Partial<EmbedPlusFieldData>): boolean;
|
|
225
|
+
delete(predicate: string | number | FieldPredicate): boolean;
|
|
226
|
+
toArray(): EmbedPlusFieldData[];
|
|
227
|
+
private getPredicateIndex;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
type EmbedPlusColorData = string & {} | ColorResolvable | null;
|
|
198
231
|
type EmbedPlusAuthorData = {
|
|
199
232
|
name: string;
|
|
200
233
|
url?: string;
|
|
@@ -205,40 +238,42 @@ interface EmbedPlusData {
|
|
|
205
238
|
color?: EmbedPlusColorData | null;
|
|
206
239
|
description?: string | null;
|
|
207
240
|
url?: string | null;
|
|
208
|
-
thumbnail?: EmbedPlusAssetData
|
|
209
|
-
image?: EmbedPlusAssetData
|
|
241
|
+
thumbnail?: EmbedPlusAssetData;
|
|
242
|
+
image?: EmbedPlusAssetData;
|
|
210
243
|
fields?: Partial<EmbedPlusFieldData>[] | null;
|
|
211
244
|
timestamp?: string | number | Date | null;
|
|
212
245
|
footer?: EmbedPlusFooterData;
|
|
213
246
|
author?: EmbedPlusAuthorData;
|
|
214
247
|
}
|
|
248
|
+
type AnyEmbed = APIEmbed | Embed | EmbedBuilder | EmbedData;
|
|
249
|
+
interface MessageWithEmbeds {
|
|
250
|
+
embeds: Array<Embed>;
|
|
251
|
+
}
|
|
252
|
+
interface InteractionWithEmbeds {
|
|
253
|
+
message: MessageWithEmbeds;
|
|
254
|
+
}
|
|
215
255
|
interface EmbedPlusOptions extends EmbedPlusData {
|
|
216
|
-
extends?: Omit<EmbedPlusData, keyof EmbedPlusOptions> |
|
|
256
|
+
extends?: Omit<EmbedPlusData, keyof EmbedPlusOptions> | AnyEmbed;
|
|
217
257
|
mergeFields?: boolean;
|
|
218
258
|
}
|
|
219
259
|
declare class EmbedPlusBuilder extends EmbedBuilder {
|
|
260
|
+
fields: EmbedPlusFields;
|
|
220
261
|
constructor(data: EmbedPlusOptions);
|
|
262
|
+
update(data: EmbedPlusData): this;
|
|
221
263
|
has(property: keyof Omit<EmbedPlusData, keyof EmbedPlusOptions>): boolean;
|
|
222
|
-
toArray():
|
|
264
|
+
toArray(): EmbedPlusBuilder[];
|
|
223
265
|
toString(space?: number): string;
|
|
224
|
-
|
|
225
|
-
deleteField(index: number): this;
|
|
226
|
-
popField(): discord_js.APIEmbedField | undefined;
|
|
266
|
+
setBorderColor(color: EmbedPlusColorData | null): this;
|
|
227
267
|
setAsset(asset: "thumbnail" | "image", source: EmbedPlusAssetData): this;
|
|
228
|
-
|
|
229
|
-
|
|
268
|
+
static fromInteraction(interaction: InteractionWithEmbeds, index?: number, data?: EmbedPlusData): EmbedPlusBuilder;
|
|
269
|
+
static fromMessage(message: MessageWithEmbeds, index?: number, data?: EmbedPlusData): EmbedPlusBuilder;
|
|
230
270
|
}
|
|
231
271
|
type EmbedPlusProperty<P extends keyof EmbedPlusData> = EmbedPlusData[P];
|
|
232
272
|
interface CreateEmbedOptions<B extends boolean> extends EmbedPlusOptions {
|
|
233
273
|
array?: B;
|
|
274
|
+
interaction?: InteractionWithEmbeds;
|
|
234
275
|
}
|
|
235
276
|
type CreateEmbedReturn<B> = undefined extends B ? EmbedPlusBuilder : false extends B ? EmbedPlusBuilder : EmbedPlusBuilder[];
|
|
236
277
|
declare function createEmbed<B extends boolean>(options: CreateEmbedOptions<B>): CreateEmbedReturn<B>;
|
|
237
278
|
|
|
238
|
-
|
|
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 };
|
|
279
|
+
export { type AnyEmbed, CustomItents, CustomPartials, type EmbedPlusAssetData, EmbedPlusBuilder, type EmbedPlusData, type EmbedPlusFooterData, type EmbedPlusProperty, chars, createComponentsManager, createEmbed, createEmbedAsset, createEmbedAuthor, createEmbedFooter, createLinkButton, createModalFields, createModalInput, createRow, extractMentionId, findChannel, findCommand, findEmoji, findMember, findMessage, findRole, formatedMention, getChannelUrlInfo, getMessageUrlInfo, modalFieldsToRecord, setMobileStatus };
|
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, ButtonBuilder, ActionRow, MessageActionRowComponent, LinkButtonComponentData, ButtonComponent, StringSelectMenuComponent, UserSelectMenuComponent, ChannelSelectMenuComponent, RoleSelectMenuComponent, MentionableSelectMenuComponent, TextInputBuilder, TextInputComponentData, GuildEmoji, GuildBasedChannel, Role, User, GuildMember, GuildTextBasedChannel, Message, Attachment, AttachmentBuilder, EmbedAssetData, EmbedAuthorData, ImageURLOptions,
|
|
2
|
+
import { GatewayIntentBits, Partials, ChannelType, Guild, CommandInteractionOption, Client, ApplicationCommand, AnyComponentBuilder, ActionRowBuilder, ButtonBuilder, ActionRow, MessageActionRowComponent, LinkButtonComponentData, ButtonComponent, StringSelectMenuComponent, UserSelectMenuComponent, ChannelSelectMenuComponent, RoleSelectMenuComponent, MentionableSelectMenuComponent, TextInputBuilder, ModalSubmitFields, Collection, TextInputComponent, TextInputComponentData, GuildEmoji, GuildBasedChannel, Role, User, GuildMember, GuildTextBasedChannel, Message, Attachment, AttachmentBuilder, EmbedAssetData, EmbedAuthorData, ImageURLOptions, EmbedFooterData, APIEmbed, Embed, EmbedBuilder, EmbedData, ColorResolvable } from 'discord.js';
|
|
3
3
|
export * from '@magicyan/core';
|
|
4
4
|
|
|
5
5
|
declare const chars: {
|
|
@@ -90,6 +90,8 @@ type CreateModalInputData = TextInputData;
|
|
|
90
90
|
declare function createModalInput(data: CreateModalInputData): ActionRowBuilder<TextInputBuilder>;
|
|
91
91
|
type ModalFieldsData = Record<string, Omit<TextInputData, "customId">>;
|
|
92
92
|
declare function createModalFields(data: ModalFieldsData): ActionRowBuilder<TextInputBuilder>[];
|
|
93
|
+
type ModalFieldsRecord = Record<string, string>;
|
|
94
|
+
declare function modalFieldsToRecord(fields: ModalSubmitFields | Collection<string, TextInputComponent>): ModalFieldsRecord;
|
|
93
95
|
|
|
94
96
|
type FindEmojiFilter = (emoji: GuildEmoji) => boolean;
|
|
95
97
|
declare function findEmoji(guildOrClient: Guild | Client): {
|
|
@@ -163,9 +165,9 @@ declare function findRole(guild: Guild): {
|
|
|
163
165
|
*/
|
|
164
166
|
declare function extractMentionId(mention: string): string | null;
|
|
165
167
|
|
|
168
|
+
type EmbedPlusAssetData = string | Attachment | AttachmentBuilder | EmbedAssetData | undefined | null;
|
|
166
169
|
type EmbedAssetOptions = Omit<EmbedAssetData, "url">;
|
|
167
|
-
|
|
168
|
-
declare function createEmbedAsset(source: AssetSource, options?: EmbedAssetOptions): EmbedAssetData | undefined;
|
|
170
|
+
declare function createEmbedAsset(source: EmbedPlusAssetData, options?: EmbedAssetOptions): EmbedAssetData | undefined;
|
|
169
171
|
|
|
170
172
|
interface UserAuthorOption {
|
|
171
173
|
user: User;
|
|
@@ -184,17 +186,48 @@ type CreateEmbedAuthorOptions = AuthorOption & ImageURLOptions & {
|
|
|
184
186
|
};
|
|
185
187
|
declare function createEmbedAuthor(options: CreateEmbedAuthorOptions): EmbedAuthorData;
|
|
186
188
|
|
|
187
|
-
type
|
|
188
|
-
|
|
189
|
+
type EmbedPlusFooterData = {
|
|
190
|
+
text?: string | null;
|
|
191
|
+
iconURL?: string | null;
|
|
192
|
+
};
|
|
193
|
+
declare function createEmbedFooter(options: EmbedPlusFooterData): EmbedFooterData | undefined;
|
|
194
|
+
|
|
189
195
|
type EmbedPlusFieldData = {
|
|
190
196
|
name: string;
|
|
191
197
|
value: string;
|
|
192
198
|
inline?: boolean;
|
|
193
199
|
};
|
|
194
|
-
type
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
200
|
+
type FieldPredicate = (field: EmbedPlusFieldData, index: number, obj: EmbedPlusFieldData[]) => boolean;
|
|
201
|
+
declare class EmbedPlusFields {
|
|
202
|
+
private embed;
|
|
203
|
+
private set fields(value);
|
|
204
|
+
private get fields();
|
|
205
|
+
constructor(embed: EmbedPlusBuilder);
|
|
206
|
+
[Symbol.iterator](): {
|
|
207
|
+
next(): IteratorResult<EmbedPlusFieldData>;
|
|
208
|
+
};
|
|
209
|
+
get length(): number;
|
|
210
|
+
get record(): Record<string, string | undefined>;
|
|
211
|
+
/**
|
|
212
|
+
* Get a filed by index
|
|
213
|
+
* @param name Field name
|
|
214
|
+
*/
|
|
215
|
+
get(name: string): EmbedPlusFieldData | undefined;
|
|
216
|
+
/**
|
|
217
|
+
* Get a field by name
|
|
218
|
+
* @param index Field index
|
|
219
|
+
*/
|
|
220
|
+
get(index: number): EmbedPlusFieldData | undefined;
|
|
221
|
+
find(predicate: FieldPredicate): EmbedPlusFieldData | undefined;
|
|
222
|
+
push(...fields: EmbedPlusFieldData[]): void;
|
|
223
|
+
set(...fields: EmbedPlusFieldData[]): void;
|
|
224
|
+
update(predicate: string | number | FieldPredicate, field: Partial<EmbedPlusFieldData>): boolean;
|
|
225
|
+
delete(predicate: string | number | FieldPredicate): boolean;
|
|
226
|
+
toArray(): EmbedPlusFieldData[];
|
|
227
|
+
private getPredicateIndex;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
type EmbedPlusColorData = string & {} | ColorResolvable | null;
|
|
198
231
|
type EmbedPlusAuthorData = {
|
|
199
232
|
name: string;
|
|
200
233
|
url?: string;
|
|
@@ -205,40 +238,42 @@ interface EmbedPlusData {
|
|
|
205
238
|
color?: EmbedPlusColorData | null;
|
|
206
239
|
description?: string | null;
|
|
207
240
|
url?: string | null;
|
|
208
|
-
thumbnail?: EmbedPlusAssetData
|
|
209
|
-
image?: EmbedPlusAssetData
|
|
241
|
+
thumbnail?: EmbedPlusAssetData;
|
|
242
|
+
image?: EmbedPlusAssetData;
|
|
210
243
|
fields?: Partial<EmbedPlusFieldData>[] | null;
|
|
211
244
|
timestamp?: string | number | Date | null;
|
|
212
245
|
footer?: EmbedPlusFooterData;
|
|
213
246
|
author?: EmbedPlusAuthorData;
|
|
214
247
|
}
|
|
248
|
+
type AnyEmbed = APIEmbed | Embed | EmbedBuilder | EmbedData;
|
|
249
|
+
interface MessageWithEmbeds {
|
|
250
|
+
embeds: Array<Embed>;
|
|
251
|
+
}
|
|
252
|
+
interface InteractionWithEmbeds {
|
|
253
|
+
message: MessageWithEmbeds;
|
|
254
|
+
}
|
|
215
255
|
interface EmbedPlusOptions extends EmbedPlusData {
|
|
216
|
-
extends?: Omit<EmbedPlusData, keyof EmbedPlusOptions> |
|
|
256
|
+
extends?: Omit<EmbedPlusData, keyof EmbedPlusOptions> | AnyEmbed;
|
|
217
257
|
mergeFields?: boolean;
|
|
218
258
|
}
|
|
219
259
|
declare class EmbedPlusBuilder extends EmbedBuilder {
|
|
260
|
+
fields: EmbedPlusFields;
|
|
220
261
|
constructor(data: EmbedPlusOptions);
|
|
262
|
+
update(data: EmbedPlusData): this;
|
|
221
263
|
has(property: keyof Omit<EmbedPlusData, keyof EmbedPlusOptions>): boolean;
|
|
222
|
-
toArray():
|
|
264
|
+
toArray(): EmbedPlusBuilder[];
|
|
223
265
|
toString(space?: number): string;
|
|
224
|
-
|
|
225
|
-
deleteField(index: number): this;
|
|
226
|
-
popField(): discord_js.APIEmbedField | undefined;
|
|
266
|
+
setBorderColor(color: EmbedPlusColorData | null): this;
|
|
227
267
|
setAsset(asset: "thumbnail" | "image", source: EmbedPlusAssetData): this;
|
|
228
|
-
|
|
229
|
-
|
|
268
|
+
static fromInteraction(interaction: InteractionWithEmbeds, index?: number, data?: EmbedPlusData): EmbedPlusBuilder;
|
|
269
|
+
static fromMessage(message: MessageWithEmbeds, index?: number, data?: EmbedPlusData): EmbedPlusBuilder;
|
|
230
270
|
}
|
|
231
271
|
type EmbedPlusProperty<P extends keyof EmbedPlusData> = EmbedPlusData[P];
|
|
232
272
|
interface CreateEmbedOptions<B extends boolean> extends EmbedPlusOptions {
|
|
233
273
|
array?: B;
|
|
274
|
+
interaction?: InteractionWithEmbeds;
|
|
234
275
|
}
|
|
235
276
|
type CreateEmbedReturn<B> = undefined extends B ? EmbedPlusBuilder : false extends B ? EmbedPlusBuilder : EmbedPlusBuilder[];
|
|
236
277
|
declare function createEmbed<B extends boolean>(options: CreateEmbedOptions<B>): CreateEmbedReturn<B>;
|
|
237
278
|
|
|
238
|
-
|
|
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 };
|
|
279
|
+
export { type AnyEmbed, CustomItents, CustomPartials, type EmbedPlusAssetData, EmbedPlusBuilder, type EmbedPlusData, type EmbedPlusFooterData, type EmbedPlusProperty, chars, createComponentsManager, createEmbed, createEmbedAsset, createEmbedAuthor, createEmbedFooter, createLinkButton, createModalFields, createModalInput, createRow, extractMentionId, findChannel, findCommand, findEmoji, findMember, findMessage, findRole, formatedMention, getChannelUrlInfo, getMessageUrlInfo, modalFieldsToRecord, setMobileStatus };
|
package/dist/index.mjs
CHANGED
|
@@ -4,7 +4,7 @@ export { setMobileStatus } from './functions/misc.mjs';
|
|
|
4
4
|
export { findChannel, getChannelUrlInfo } from './functions/channels.mjs';
|
|
5
5
|
export { findCommand } from './functions/commands.mjs';
|
|
6
6
|
export { createComponentsManager, createLinkButton, createRow } from './functions/components.mjs';
|
|
7
|
-
export { createModalFields, createModalInput } from './functions/modals.mjs';
|
|
7
|
+
export { createModalFields, createModalInput, modalFieldsToRecord } from './functions/modals.mjs';
|
|
8
8
|
export { findEmoji } from './functions/emojis.mjs';
|
|
9
9
|
export { formatedMention } from './functions/format.mjs';
|
|
10
10
|
export { findMember } from './functions/members.mjs';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@magicyan/discord",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.26",
|
|
4
4
|
"description": "Simple functions to facilitate discord bot development",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"unbuild": "^2.0.0"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@magicyan/core": "^1.0.
|
|
42
|
+
"@magicyan/core": "^1.0.18"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"discord.js": "^14.14.1"
|