@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.
@@ -59,5 +59,10 @@ function findChannel(guild, type) {
59
59
  }
60
60
  };
61
61
  }
62
+ function getChannelUrlInfo(url) {
63
+ const [channelId, guildId] = url.split("/").reverse();
64
+ return { channelId, guildId };
65
+ }
62
66
 
63
67
  exports.findChannel = findChannel;
68
+ exports.getChannelUrlInfo = getChannelUrlInfo;
@@ -57,5 +57,9 @@ function findChannel(guild, type) {
57
57
  }
58
58
  };
59
59
  }
60
+ function getChannelUrlInfo(url) {
61
+ const [channelId, guildId] = url.split("/").reverse();
62
+ return { channelId, guildId };
63
+ }
60
64
 
61
- export { findChannel };
65
+ export { findChannel, getChannelUrlInfo };
@@ -5,9 +5,6 @@ const discord_js = require('discord.js');
5
5
  function createRow(...components) {
6
6
  return new discord_js.ActionRowBuilder({ components });
7
7
  }
8
- function createModalInput(data) {
9
- return createRow(new discord_js.TextInputBuilder(data));
10
- }
11
8
  function createLinkButton(data) {
12
9
  if (!data.label)
13
10
  data.label = data.url;
@@ -64,5 +61,4 @@ function createComponentsManager(components) {
64
61
 
65
62
  exports.createComponentsManager = createComponentsManager;
66
63
  exports.createLinkButton = createLinkButton;
67
- exports.createModalInput = createModalInput;
68
64
  exports.createRow = createRow;
@@ -1,11 +1,8 @@
1
- import { ActionRowBuilder, TextInputBuilder, ButtonBuilder, ButtonStyle, ComponentType } from 'discord.js';
1
+ import { ActionRowBuilder, ButtonBuilder, ButtonStyle, ComponentType } from 'discord.js';
2
2
 
3
3
  function createRow(...components) {
4
4
  return new ActionRowBuilder({ components });
5
5
  }
6
- function createModalInput(data) {
7
- return createRow(new TextInputBuilder(data));
8
- }
9
6
  function createLinkButton(data) {
10
7
  if (!data.label)
11
8
  data.label = data.url;
@@ -60,4 +57,4 @@ function createComponentsManager(components) {
60
57
  };
61
58
  }
62
59
 
63
- export { createComponentsManager, createLinkButton, createModalInput, createRow };
60
+ export { createComponentsManager, createLinkButton, createRow };
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ const discord_js = require('discord.js');
4
+
5
+ function createEmbedAsset(source, options) {
6
+ if (source instanceof discord_js.Attachment || source instanceof discord_js.AttachmentBuilder) {
7
+ return { url: `attachment://${source.name}`, ...options };
8
+ }
9
+ if (source && typeof source === "object" && "url" in source) {
10
+ return source;
11
+ }
12
+ return source ? { url: source, ...options } : void 0;
13
+ }
14
+
15
+ exports.createEmbedAsset = createEmbedAsset;
@@ -0,0 +1,13 @@
1
+ import { Attachment, AttachmentBuilder } from 'discord.js';
2
+
3
+ function createEmbedAsset(source, options) {
4
+ if (source instanceof Attachment || source instanceof AttachmentBuilder) {
5
+ return { url: `attachment://${source.name}`, ...options };
6
+ }
7
+ if (source && typeof source === "object" && "url" in source) {
8
+ return source;
9
+ }
10
+ return source ? { url: source, ...options } : void 0;
11
+ }
12
+
13
+ export { createEmbedAsset };
@@ -0,0 +1,30 @@
1
+ 'use strict';
2
+
3
+ function createEmbedAuthor(options) {
4
+ const { prefix, suffix, url, iconURL } = options;
5
+ const { size = 512, extension, forceStatic } = options;
6
+ const avatarOptions = { size, extension, forceStatic };
7
+ if ("member" in options) {
8
+ const { member, property: property2 = "displayName" } = options;
9
+ const name = {
10
+ id: member.id,
11
+ username: member.user.username,
12
+ displayName: member.displayName,
13
+ globalName: member.user.globalName,
14
+ nickname: member.nickname
15
+ }[property2] ?? member.displayName;
16
+ return {
17
+ name: `${prefix}${name}${suffix}`,
18
+ url,
19
+ iconURL: iconURL || member.displayAvatarURL(avatarOptions)
20
+ };
21
+ }
22
+ const { property = "displayName", user } = options;
23
+ return {
24
+ name: `${prefix}${options.user[property]}${suffix}`,
25
+ url,
26
+ iconURL: iconURL || user.displayAvatarURL(avatarOptions)
27
+ };
28
+ }
29
+
30
+ exports.createEmbedAuthor = createEmbedAuthor;
@@ -0,0 +1,28 @@
1
+ function createEmbedAuthor(options) {
2
+ const { prefix, suffix, url, iconURL } = options;
3
+ const { size = 512, extension, forceStatic } = options;
4
+ const avatarOptions = { size, extension, forceStatic };
5
+ if ("member" in options) {
6
+ const { member, property: property2 = "displayName" } = options;
7
+ const name = {
8
+ id: member.id,
9
+ username: member.user.username,
10
+ displayName: member.displayName,
11
+ globalName: member.user.globalName,
12
+ nickname: member.nickname
13
+ }[property2] ?? member.displayName;
14
+ return {
15
+ name: `${prefix}${name}${suffix}`,
16
+ url,
17
+ iconURL: iconURL || member.displayAvatarURL(avatarOptions)
18
+ };
19
+ }
20
+ const { property = "displayName", user } = options;
21
+ return {
22
+ name: `${prefix}${options.user[property]}${suffix}`,
23
+ url,
24
+ iconURL: iconURL || user.displayAvatarURL(avatarOptions)
25
+ };
26
+ }
27
+
28
+ export { createEmbedAuthor };
@@ -0,0 +1,93 @@
1
+ 'use strict';
2
+
3
+ const discord_js = require('discord.js');
4
+ const chars = require('../../constants/chars.cjs');
5
+ const assets = require('./assets.cjs');
6
+ const footer = require('./footer.cjs');
7
+
8
+ class EmbedPlusBuilder extends discord_js.EmbedBuilder {
9
+ constructor(data) {
10
+ const extendsEmbed = data.extends ? new EmbedPlusBuilder(
11
+ data.extends instanceof discord_js.Embed || data.extends instanceof discord_js.EmbedBuilder ? data.extends.data : data.extends
12
+ ).data : {};
13
+ const { fields: extendsFields, ...exetendData } = extendsEmbed;
14
+ const fields = (data.mergeFields ? [extendsFields ?? [], data.fields ?? []].flat() : data.fields ?? extendsFields ?? []).map(({ name = chars.chars.invisible, value = chars.chars.invisible, inline }) => ({
15
+ name,
16
+ value,
17
+ inline
18
+ }));
19
+ const embed = new discord_js.EmbedBuilder({
20
+ ...exetendData,
21
+ ...data.title ? { title: data.title } : {},
22
+ ...data.description ? { description: data.description } : {},
23
+ ...data.url ? { url: data.url } : {},
24
+ ...data.footer ? { footer: footer.createEmbedFooter(data.footer) } : {},
25
+ ...data.author ? { author: data.author } : {},
26
+ ...data.image ? { image: assets.createEmbedAsset(data.image) } : {},
27
+ ...data.thumbnail ? { thumbnail: assets.createEmbedAsset(data.thumbnail) } : {},
28
+ ...fields.length > 0 ? { fields } : {}
29
+ });
30
+ if (data.timestamp)
31
+ embed.setTimestamp(
32
+ typeof data.timestamp === "string" ? new Date(data.timestamp) : data.timestamp
33
+ );
34
+ if (data.color)
35
+ embed.setColor(data.color);
36
+ super(embed.data);
37
+ }
38
+ has(property) {
39
+ return Boolean(this.data[property]);
40
+ }
41
+ toArray() {
42
+ return Array.from([this]);
43
+ }
44
+ toString(space = 2) {
45
+ return JSON.stringify(this, null, space);
46
+ }
47
+ updateField(index, field) {
48
+ if (this.fields.at(index)) {
49
+ const fields = Array.from(this.fields);
50
+ if (field.name)
51
+ fields[index].name = field.name;
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));
63
+ }
64
+ return this;
65
+ }
66
+ popField() {
67
+ const fields = Array.from(this.fields);
68
+ const field = fields.pop();
69
+ this.setFields(fields);
70
+ return field;
71
+ }
72
+ setAsset(asset, source) {
73
+ const assetData = assets.createEmbedAsset(source);
74
+ if (!assetData?.url)
75
+ return this;
76
+ asset === "image" ? this.setImage(assetData.url) : this.setThumbnail(assetData.url);
77
+ return this;
78
+ }
79
+ get fieldsLength() {
80
+ return this.data.fields?.length ?? 0;
81
+ }
82
+ get fields() {
83
+ return this.data.fields ?? [];
84
+ }
85
+ }
86
+ function createEmbed(options) {
87
+ const { array = false, ...data } = options;
88
+ const embed = new EmbedPlusBuilder(data);
89
+ return array ? [embed] : embed;
90
+ }
91
+
92
+ exports.EmbedPlusBuilder = EmbedPlusBuilder;
93
+ exports.createEmbed = createEmbed;
@@ -0,0 +1,90 @@
1
+ import { EmbedBuilder, Embed } from 'discord.js';
2
+ import { chars } from '../../constants/chars.mjs';
3
+ import { createEmbedAsset } from './assets.mjs';
4
+ import { createEmbedFooter } from './footer.mjs';
5
+
6
+ class EmbedPlusBuilder extends EmbedBuilder {
7
+ constructor(data) {
8
+ const extendsEmbed = data.extends ? new EmbedPlusBuilder(
9
+ data.extends instanceof Embed || data.extends instanceof EmbedBuilder ? data.extends.data : data.extends
10
+ ).data : {};
11
+ const { fields: extendsFields, ...exetendData } = extendsEmbed;
12
+ const fields = (data.mergeFields ? [extendsFields ?? [], data.fields ?? []].flat() : data.fields ?? extendsFields ?? []).map(({ name = chars.invisible, value = chars.invisible, inline }) => ({
13
+ name,
14
+ value,
15
+ inline
16
+ }));
17
+ const embed = new EmbedBuilder({
18
+ ...exetendData,
19
+ ...data.title ? { title: data.title } : {},
20
+ ...data.description ? { description: data.description } : {},
21
+ ...data.url ? { url: data.url } : {},
22
+ ...data.footer ? { footer: createEmbedFooter(data.footer) } : {},
23
+ ...data.author ? { author: data.author } : {},
24
+ ...data.image ? { image: createEmbedAsset(data.image) } : {},
25
+ ...data.thumbnail ? { thumbnail: createEmbedAsset(data.thumbnail) } : {},
26
+ ...fields.length > 0 ? { fields } : {}
27
+ });
28
+ if (data.timestamp)
29
+ embed.setTimestamp(
30
+ typeof data.timestamp === "string" ? new Date(data.timestamp) : data.timestamp
31
+ );
32
+ if (data.color)
33
+ embed.setColor(data.color);
34
+ super(embed.data);
35
+ }
36
+ has(property) {
37
+ return Boolean(this.data[property]);
38
+ }
39
+ toArray() {
40
+ return Array.from([this]);
41
+ }
42
+ toString(space = 2) {
43
+ return JSON.stringify(this, null, space);
44
+ }
45
+ updateField(index, field) {
46
+ if (this.fields.at(index)) {
47
+ const fields = Array.from(this.fields);
48
+ if (field.name)
49
+ fields[index].name = field.name;
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));
61
+ }
62
+ return this;
63
+ }
64
+ popField() {
65
+ const fields = Array.from(this.fields);
66
+ const field = fields.pop();
67
+ this.setFields(fields);
68
+ return field;
69
+ }
70
+ setAsset(asset, source) {
71
+ const assetData = createEmbedAsset(source);
72
+ if (!assetData?.url)
73
+ return this;
74
+ asset === "image" ? this.setImage(assetData.url) : this.setThumbnail(assetData.url);
75
+ return this;
76
+ }
77
+ get fieldsLength() {
78
+ return this.data.fields?.length ?? 0;
79
+ }
80
+ get fields() {
81
+ return this.data.fields ?? [];
82
+ }
83
+ }
84
+ function createEmbed(options) {
85
+ const { array = false, ...data } = options;
86
+ const embed = new EmbedPlusBuilder(data);
87
+ return array ? [embed] : embed;
88
+ }
89
+
90
+ export { EmbedPlusBuilder, createEmbed };
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ const core = require('@magicyan/core');
4
+ const chars = require('../../constants/chars.cjs');
5
+
6
+ function createEmbedFooter(options) {
7
+ const { text, iconURL } = options;
8
+ return !text && !iconURL ? void 0 : { text: text ?? chars.chars.invisible, iconURL: core.notFound(iconURL) };
9
+ }
10
+
11
+ exports.createEmbedFooter = createEmbedFooter;
@@ -0,0 +1,9 @@
1
+ import { notFound } from '@magicyan/core';
2
+ import { chars } from '../../constants/chars.mjs';
3
+
4
+ function createEmbedFooter(options) {
5
+ const { text, iconURL } = options;
6
+ return !text && !iconURL ? void 0 : { text: text ?? chars.invisible, iconURL: notFound(iconURL) };
7
+ }
8
+
9
+ export { createEmbedFooter };
@@ -40,5 +40,10 @@ function findMessage(channel) {
40
40
  }
41
41
  };
42
42
  }
43
+ function getMessageUrlInfo(url) {
44
+ const [messageId, channelId, guildId] = url.split("/").reverse();
45
+ return { messageId, channelId, guildId };
46
+ }
43
47
 
44
48
  exports.findMessage = findMessage;
49
+ exports.getMessageUrlInfo = getMessageUrlInfo;
@@ -38,5 +38,9 @@ function findMessage(channel) {
38
38
  }
39
39
  };
40
40
  }
41
+ function getMessageUrlInfo(url) {
42
+ const [messageId, channelId, guildId] = url.split("/").reverse();
43
+ return { messageId, channelId, guildId };
44
+ }
41
45
 
42
- export { findMessage };
46
+ export { findMessage, getMessageUrlInfo };
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ const discord_js = require('discord.js');
4
+
5
+ function setMobileStatus() {
6
+ discord_js.DefaultWebSocketManagerOptions.identifyProperties.browser = "Discord Android";
7
+ }
8
+
9
+ exports.setMobileStatus = setMobileStatus;
@@ -0,0 +1,7 @@
1
+ import { DefaultWebSocketManagerOptions } from 'discord.js';
2
+
3
+ function setMobileStatus() {
4
+ DefaultWebSocketManagerOptions.identifyProperties.browser = "Discord Android";
5
+ }
6
+
7
+ export { setMobileStatus };
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+
3
+ const discord_js = require('discord.js');
4
+ const components = require('./components.cjs');
5
+
6
+ function createModalInput(data) {
7
+ return components.createRow(new discord_js.TextInputBuilder(data));
8
+ }
9
+ function createModalFields(data) {
10
+ return Object.entries(data).map(
11
+ ([customId, data2]) => createModalInput({ customId, ...data2 })
12
+ );
13
+ }
14
+
15
+ exports.createModalFields = createModalFields;
16
+ exports.createModalInput = createModalInput;
@@ -0,0 +1,13 @@
1
+ import { TextInputBuilder } from 'discord.js';
2
+ import { createRow } from './components.mjs';
3
+
4
+ function createModalInput(data) {
5
+ return createRow(new TextInputBuilder(data));
6
+ }
7
+ function createModalFields(data) {
8
+ return Object.entries(data).map(
9
+ ([customId, data2]) => createModalInput({ customId, ...data2 })
10
+ );
11
+ }
12
+
13
+ export { createModalFields, createModalInput };
package/dist/index.cjs CHANGED
@@ -2,16 +2,21 @@
2
2
 
3
3
  const chars = require('./constants/chars.cjs');
4
4
  const client = require('./constants/client.cjs');
5
+ const misc = require('./functions/misc.cjs');
5
6
  const channels = require('./functions/channels.cjs');
6
7
  const commands = require('./functions/commands.cjs');
7
8
  const components = require('./functions/components.cjs');
8
- const embeds = require('./functions/embeds.cjs');
9
+ const modals = require('./functions/modals.cjs');
9
10
  const emojis = require('./functions/emojis.cjs');
10
11
  const format = require('./functions/format.cjs');
11
12
  const members = require('./functions/members.cjs');
12
13
  const message = require('./functions/message.cjs');
13
14
  const roles = require('./functions/roles.cjs');
14
15
  const regex = require('./functions/regex.cjs');
16
+ const assets = require('./functions/embeds/assets.cjs');
17
+ const author = require('./functions/embeds/author.cjs');
18
+ const embedplus = require('./functions/embeds/embedplus.cjs');
19
+ const footer = require('./functions/embeds/footer.cjs');
15
20
  const core = require('@magicyan/core');
16
21
 
17
22
 
@@ -19,23 +24,27 @@ const core = require('@magicyan/core');
19
24
  exports.chars = chars.chars;
20
25
  exports.CustomItents = client.CustomItents;
21
26
  exports.CustomPartials = client.CustomPartials;
27
+ exports.setMobileStatus = misc.setMobileStatus;
22
28
  exports.findChannel = channels.findChannel;
29
+ exports.getChannelUrlInfo = channels.getChannelUrlInfo;
23
30
  exports.findCommand = commands.findCommand;
24
31
  exports.createComponentsManager = components.createComponentsManager;
25
32
  exports.createLinkButton = components.createLinkButton;
26
- exports.createModalInput = components.createModalInput;
27
33
  exports.createRow = components.createRow;
28
- exports.EmbedBuilderPlus = embeds.EmbedBuilderPlus;
29
- exports.createEmbed = embeds.createEmbed;
30
- exports.createEmbedAsset = embeds.createEmbedAsset;
31
- exports.createEmbedAuthor = embeds.createEmbedAuthor;
32
- exports.createEmbedFooter = embeds.createEmbedFooter;
34
+ exports.createModalFields = modals.createModalFields;
35
+ exports.createModalInput = modals.createModalInput;
33
36
  exports.findEmoji = emojis.findEmoji;
34
37
  exports.formatedMention = format.formatedMention;
35
38
  exports.findMember = members.findMember;
36
39
  exports.findMessage = message.findMessage;
40
+ exports.getMessageUrlInfo = message.getMessageUrlInfo;
37
41
  exports.findRole = roles.findRole;
38
42
  exports.extractMentionId = regex.extractMentionId;
43
+ exports.createEmbedAsset = assets.createEmbedAsset;
44
+ exports.createEmbedAuthor = author.createEmbedAuthor;
45
+ exports.EmbedPlusBuilder = embedplus.EmbedPlusBuilder;
46
+ exports.createEmbed = embedplus.createEmbed;
47
+ exports.createEmbedFooter = footer.createEmbedFooter;
39
48
  Object.keys(core).forEach(function (k) {
40
49
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) exports[k] = core[k];
41
50
  });