@magicyan/discord 1.0.21 → 1.0.23

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.
@@ -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 };