@magicyan/discord 1.0.26 → 1.0.28

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/README.md CHANGED
@@ -16,121 +16,239 @@ Install with
16
16
  npm install @magicyan/discord
17
17
  ```
18
18
 
19
- Some functions summarize the way we create things with discord.js
19
+ ## Components
20
+ Easily create action rows
20
21
 
21
22
  ```ts
22
- // Create an action row of buttons with discord.js
23
- new ActionRowBuilder<ButtonBuilder>({
24
- components: [
25
- new ButtonBuilder({
26
- customId: "click-me-button",
27
- label: "Click me", style: ButtonStyle.Success,
28
- })
29
- new ButtonBuilder({
30
- customId: "dont-click-me-button",
31
- label: "Don't click me", style: ButtonStyle.Danger,
32
- })
33
- ]
34
- })
23
+ import { createRow } from "@magicyan/discord";
24
+
25
+ const row = createRow(
26
+ new ButtonBuilder(/* button data... */),
27
+ new ButtonBuilder(/* button data... */),
28
+ new ButtonBuilder(/* button data... */),
29
+ );
30
+ const selectRow = createRow(
31
+ new StringSelectMenuBuilder(/* select data... */)
32
+ );
33
+ interaction.reply({ components: [row, selectRow] });
34
+ ```
35
+ Create a link button quickly
36
+ ```ts
37
+ import { createRow, createLinkButton } from "@magicyan/discord";
35
38
 
36
- // Create an action row of buttons with @magicyan/dicord
37
- createRow(
38
- new ButtonBuilder({
39
- customId: "click-me-button", label: "Click me",
40
- style: ButtonStyle.Success,
41
- })
42
- new ButtonBuilder({
43
- customId: "dont-click-me-button", label: "Don't click me",
44
- style: ButtonStyle.Danger,
45
- })
46
- )
39
+ const row = createRow(
40
+ createLinkButton({ label: "Github", url: "https://github.com/rinckodev" })
41
+ createLinkButton({ label: "Youtube", url: "https://youtube.com/@rinckodev" })
42
+ );
43
+ interaction.reply({ components: [row] });
44
+ ```
47
45
 
48
- // Add inputs to the modal with discord.js
49
- new ModalBuilder({
50
- customId: "my-modal",
51
- title: "Modal Title",
52
- components: [
53
- new ActionRowBuilder<TextInputBuilder>({components: [
54
- new TextInputBuilder({
55
- customId: "name-input",
56
- label: "Name",
57
- placeholder: "Enter your name",
58
- style: TextInputStyle.Short,
59
- required: true
60
- }),
61
- new TextInputBuilder({
62
- customId: "nio-modal",
63
- label: "Bio",
64
- placeholder: "Enter your bio",
65
- style: TextInputStyle.Paragraph,
66
- required: true
67
- })
68
- ]})
69
- ]
70
- })
46
+ ## Modals
47
+ A row only supports a single input, so use this function that already creates it within a row
48
+ ```ts
49
+ import { createModalInput } from "@magicyan/discord";
71
50
 
72
- // Add inputs to the modal with @magicyan/dicord
73
- new ModalBuilder({
74
- customId: "my-modal", title: "Modal Title",
51
+ const modal = new ModalBuilder({
52
+ customId: "my/modal",
53
+ title: "My modal",
75
54
  components: [
76
55
  createModalInput({
77
- customId: "name-input", placeholder: "Enter your name",
78
- label: "Name", style: TextInputStyle.Short, required: true
56
+ customId: "name",
57
+ label: "Name",
58
+ style: TextInputStyle.Short,
79
59
  }),
80
60
  createModalInput({
81
- customId: "nio-modal", placeholder: "Enter your bio",
82
- label: "Bio", style: TextInputStyle.Paragraph, required: true
61
+ customId: "age",
62
+ label: "Age",
63
+ style: TextInputStyle.Short,
83
64
  }),
84
65
  ]
66
+ });
67
+ interaction.showModal(modal);
68
+ ```
69
+ Or if you prefer, you can create a record where the key is the customId
70
+ ```ts
71
+ import { createModalFields } from "@magicyan/discord";
72
+
73
+ const modal = new ModalBuilder({
74
+ customId: "my/modal",
75
+ title: "My modal",
76
+ components: createModalFields({
77
+ name: {
78
+ label: "Name",
79
+ style: TextInputStyle.Short,
80
+ },
81
+ age:{
82
+ label: "Age",
83
+ style: TextInputStyle.Short,
84
+ },
85
+ })
86
+ });
87
+ ```
88
+ Don't forget that you can define the custom id however you want
89
+ ```ts
90
+ createModalFields({
91
+ ["my-custom-input-name"]: {
92
+ label: "Name",
93
+ style: TextInputStyle.Short,
94
+ }
85
95
  })
86
96
  ```
87
-
88
- You can create a link button quickly
97
+ You can transform the fields received from the interaction into a record
89
98
  ```ts
90
- const url = "https://github.com/rinckodev";
99
+ import { modalFieldsToRecord } from "@magicyan/discord";
91
100
 
92
- createLinkButton({ url, label: "My github" });
101
+ function run(interaction: ModalSubmitInteraction){
102
+ const fields = modalFieldsToRecord(interaction.fields);
103
+ console.log(fields["my-custom-input-name"]);
104
+ console.log(fields.age);
105
+ }
93
106
  ```
107
+ It is also possible to pass a union type in the function generic
108
+ ```ts
109
+ type FormFields = "id" | "nickname" | "bio";
110
+ function run(interaction: ModalSubmitInteraction){
111
+ const fields = modalFieldsToRecord<FormFields>(interaction.fields);
112
+ console.log(fields.id);
113
+ console.log(fields.nickname);
114
+ console.log(fields.bio);
115
+ }
116
+ ```
117
+ ## Embeds
118
+ > soon
94
119
 
95
- You can create an embed author easily with a User object
120
+ ## Channels
121
+ You can try to get information from a channel url
96
122
  ```ts
97
- const { user } = interaction
123
+ import { getChannelUrlInfo } from "@magicyan/discord";
98
124
 
99
- new EmbedBuilder({
100
- author: createEmbedAuthor({ user }),
101
- description: "My embed description"
102
- })
125
+ const url = "https://discord.com/channels/537817462272557057/832829213651763210";
126
+ const { guildId, channelId } = getChannelUrlInfo(url);
127
+ console.log(guildId); // 537817462272557057
128
+ console.log(channelId); // 832829213651763210
129
+ ```
130
+ If the url does not follow the pattern of a discord channel url, the return will be an empty object
131
+ ```ts
132
+ const url = "https://github.com/rinckodev";
133
+ const { guildId, channelId } = getChannelUrlInfo(url);
134
+ console.log(guildId); // undefined
135
+ console.log(channelId); // undefined
103
136
  ```
137
+ Find a guild channel easily with the findChannel function
138
+ ```ts
139
+ import { findChannel } from "@magicyan/discord";
104
140
 
105
- Function to find a channel from the guild cache
141
+ function run(interaction: ChatInputCommandInteraction<"cached">){
142
+ const { guild } = interaction;
143
+ const channel = findChannel(guild).byId("832829213651763210");
144
+ channel // TextChannel | undefined
145
+ }
146
+ ```
147
+ This function searches for channels in the guild cache, by default it tries to find channels of the GuildText type, but you can change it to any type of guild channel
106
148
  ```ts
107
- const { guild } = interaction
149
+ const channel = findChannel(guild, ChannelType.GuildVoice).byId("832829213651763210");
150
+ // VoiceChannel | undefined
151
+ ```
152
+ You can find channels in other ways
153
+ ```ts
154
+ const general = findChannel(guild).byName("general");
155
+ const updates = findChannel(guild, ChannelType.GuildAnnouncement).byName("updates");
156
+ const lounge = findChannel(guild, ChannelType.GuildVoice).byName("Lounge 01");
157
+ const popular = findChannel(guild, ChannelType.GuildStageVoice).byFilter(f => f.members.size >= 12);
158
+ const hotforum = findChannel(guild, ChannelType.GuildForum).byFilter(f => f.threads.cache.size >= 100);
159
+
160
+ general; // TextChannel | undefined
161
+ updates; // NewsChannel | undefined
162
+ lounge; // VoiceChannel | undefined
163
+ popular; // StageChannel | undefined
164
+ hotforum; // ForumChannel | undefined
165
+ ```
166
+ Find a channel in a category easily
167
+ ```ts
168
+ const ticket = findChannel(guild)
169
+ .inCategoryName("Tickets")
170
+ .byName(`ticket-${member.id}`);
108
171
 
109
- const channel = findChannel(guild, ChannelType.GuildVoice).byName("Lounge 01") // VoiceChannel | undefined
172
+ ticket; // TextChannel | undefined
173
+ ```
174
+ ## Roles
175
+ Find guild roles easily
176
+ ```ts
177
+ import { findRole } from "@magicyan/discord";
178
+
179
+ function run(interaction: ChatInputCommandInteraction<"cached">){
180
+ const { guild } = interaction;
181
+
182
+ const memberRole = findRole(guild).byName("Member");
183
+ const adminRole = findRole(guild).byHexColor("#ff5454");
184
+ const leaderRole = findRole(guild).byId("537818031728885771");
185
+
186
+ memberRole // Role | undefined
187
+ adminRole // Role | undefined
188
+ leaderRole // Role | undefined
189
+ }
190
+ ```
191
+ ## Members
192
+ Find guild members easily
193
+ ```ts
194
+ import { findMember } from "@magicyan/discord";
195
+
196
+ function run(interaction: ChatInputCommandInteraction<"cached">){
197
+ const { guild } = interaction;
198
+ const finder = findMember(guild);
199
+ const member = finder.byId("264620632644255745")
200
+ ?? finder.byUsername("rincko")
201
+ ?? finder.byGlobalName("Rincko")
202
+ ?? finder.byNickname("RinckoZ_");
203
+
204
+ member; // GuildMember | undefined
205
+ }
110
206
  ```
207
+ ## Messages
208
+ You can try to get information from a channel url
209
+ ```ts
210
+ import { getMessageUrlInfo } from "@magicyan/discord";
111
211
 
112
- Function to find a role from the guild cache
212
+ const url = "https://discord.com/channels/537817462272557057/1101949941712171078/1101950570035691530";
213
+ const { guildId, channelId, messageId } = getMessageUrlInfo(url);
214
+ console.log(guildId); // 537817462272557057
215
+ console.log(channelId); // 1101949941712171078
216
+ console.log(messageId); // 1101950570035691530
217
+ ```
218
+ ## Commands
219
+ Find a command easily
113
220
  ```ts
114
- const { guild } = interaction
221
+ import { findCommand } from "@magicyan/discord";
115
222
 
116
- const role = findChannel(guild).byName("Administrator") // Role | undefined
223
+ function run(interaction: ChatInputCommandInteraction<"cached">){
224
+ const { client } = interaction;
225
+ const command = findCommand(client).byName("register");
226
+ command; // ApplicationCommand | undefined
227
+ }
117
228
  ```
118
229
 
119
- Function to create embed asset
120
- If the method used to obtain a url returns null or undefined the function will set undefined in the image property
230
+ ## Emojis
231
+ Find a emoji easily
121
232
  ```ts
122
- const embed = new EmbedBuilder({
123
- image: createEmbedAsset(guild.iconURL()) // { url: guild.iconUrl() } | undefined
124
- })
233
+ import { findEmoji } from "@magicyan/discord";
234
+
235
+ function run(interaction: ChatInputCommandInteraction<"cached">){
236
+ const { client } = interaction;
237
+ const emoji = findEmoji(client).byName("discord");
238
+ emoji; // GuildEmoji | undefined
239
+ }
125
240
  ```
126
241
 
127
- When passing an attachment to the function, it will return the url with local attachments
242
+ ## Regex
243
+ Extract the id of any mention
128
244
  ```ts
129
- const image = new AttachmentBuilder(buffer, { name: "myImage.png" });
245
+ import { extractMentionId } from "@magicyan/discord";
130
246
 
131
- const embed = new EmbedBuilder({
132
- image: createEmbedAsset(image) // { url: attachment://myImage.png }
133
- });
247
+ const user = "<@264620632644255745>";
248
+ const channel = "<#1068689068256403457>";
249
+ const role = "<@&929925182796226632>";
134
250
 
135
- channel.send({ embeds: [embed], files: [image]})
251
+ extractMentionId(user) // 264620632644255745
252
+ extractMentionId(channel) // 1068689068256403457
253
+ extractMentionId(role) // 929925182796226632
136
254
  ```
@@ -60,6 +60,9 @@ function findChannel(guild, type) {
60
60
  };
61
61
  }
62
62
  function getChannelUrlInfo(url) {
63
+ const regex = new RegExp(/^https:\/\/discord\.com\/channels\/\d+\/\d+$/);
64
+ if (!regex.test(url))
65
+ return {};
63
66
  const [channelId, guildId] = url.split("/").reverse();
64
67
  return { channelId, guildId };
65
68
  }
@@ -58,6 +58,9 @@ function findChannel(guild, type) {
58
58
  };
59
59
  }
60
60
  function getChannelUrlInfo(url) {
61
+ const regex = new RegExp(/^https:\/\/discord\.com\/channels\/\d+\/\d+$/);
62
+ if (!regex.test(url))
63
+ return {};
61
64
  const [channelId, guildId] = url.split("/").reverse();
62
65
  return { channelId, guildId };
63
66
  }
@@ -10,55 +10,6 @@ function createLinkButton(data) {
10
10
  data.label = data.url;
11
11
  return new discord_js.ButtonBuilder({ style: discord_js.ButtonStyle.Link, ...data });
12
12
  }
13
- function createComponentsManager(components) {
14
- const buttons = components.flatMap(
15
- (row) => row.components.filter((c) => c.type === discord_js.ComponentType.Button)
16
- );
17
- const stringSelects = components.flatMap(
18
- (row) => row.components.filter((c) => c.type === discord_js.ComponentType.StringSelect)
19
- );
20
- const userSelects = components.flatMap(
21
- (row) => row.components.filter((c) => c.type === discord_js.ComponentType.UserSelect)
22
- );
23
- const channelSelects = components.flatMap(
24
- (row) => row.components.filter((c) => c.type === discord_js.ComponentType.ChannelSelect)
25
- );
26
- const roleSelects = components.flatMap(
27
- (row) => row.components.filter((c) => c.type === discord_js.ComponentType.RoleSelect)
28
- );
29
- const mentionableSelects = components.flatMap(
30
- (row) => row.components.filter((c) => c.type === discord_js.ComponentType.MentionableSelect)
31
- );
32
- return {
33
- getButton(customId) {
34
- return buttons.find((b) => b.customId === customId);
35
- },
36
- getStringSelect(customId) {
37
- return stringSelects.find((b) => b.customId === customId);
38
- },
39
- getUserSelect(customId) {
40
- return userSelects.find((b) => b.customId === customId);
41
- },
42
- getChannelSelect(customId) {
43
- return channelSelects.find((b) => b.customId === customId);
44
- },
45
- getRoleSelect(customId) {
46
- return roleSelects.find((b) => b.customId === customId);
47
- },
48
- getMentionableSelect(customId) {
49
- return mentionableSelects.find((b) => b.customId === customId);
50
- },
51
- resolved: {
52
- buttons,
53
- stringSelects,
54
- userSelects,
55
- channelSelects,
56
- roleSelects,
57
- mentionableSelects
58
- }
59
- };
60
- }
61
13
 
62
- exports.createComponentsManager = createComponentsManager;
63
14
  exports.createLinkButton = createLinkButton;
64
15
  exports.createRow = createRow;
@@ -1,4 +1,4 @@
1
- import { ActionRowBuilder, ButtonBuilder, ButtonStyle, ComponentType } from 'discord.js';
1
+ import { ActionRowBuilder, ButtonBuilder, ButtonStyle } from 'discord.js';
2
2
 
3
3
  function createRow(...components) {
4
4
  return new ActionRowBuilder({ components });
@@ -8,53 +8,5 @@ function createLinkButton(data) {
8
8
  data.label = data.url;
9
9
  return new ButtonBuilder({ style: ButtonStyle.Link, ...data });
10
10
  }
11
- function createComponentsManager(components) {
12
- const buttons = components.flatMap(
13
- (row) => row.components.filter((c) => c.type === ComponentType.Button)
14
- );
15
- const stringSelects = components.flatMap(
16
- (row) => row.components.filter((c) => c.type === ComponentType.StringSelect)
17
- );
18
- const userSelects = components.flatMap(
19
- (row) => row.components.filter((c) => c.type === ComponentType.UserSelect)
20
- );
21
- const channelSelects = components.flatMap(
22
- (row) => row.components.filter((c) => c.type === ComponentType.ChannelSelect)
23
- );
24
- const roleSelects = components.flatMap(
25
- (row) => row.components.filter((c) => c.type === ComponentType.RoleSelect)
26
- );
27
- const mentionableSelects = components.flatMap(
28
- (row) => row.components.filter((c) => c.type === ComponentType.MentionableSelect)
29
- );
30
- return {
31
- getButton(customId) {
32
- return buttons.find((b) => b.customId === customId);
33
- },
34
- getStringSelect(customId) {
35
- return stringSelects.find((b) => b.customId === customId);
36
- },
37
- getUserSelect(customId) {
38
- return userSelects.find((b) => b.customId === customId);
39
- },
40
- getChannelSelect(customId) {
41
- return channelSelects.find((b) => b.customId === customId);
42
- },
43
- getRoleSelect(customId) {
44
- return roleSelects.find((b) => b.customId === customId);
45
- },
46
- getMentionableSelect(customId) {
47
- return mentionableSelects.find((b) => b.customId === customId);
48
- },
49
- resolved: {
50
- buttons,
51
- stringSelects,
52
- userSelects,
53
- channelSelects,
54
- roleSelects,
55
- mentionableSelects
56
- }
57
- };
58
- }
59
11
 
60
- export { createComponentsManager, createLinkButton, createRow };
12
+ export { createLinkButton, createRow };
@@ -3,8 +3,8 @@
3
3
  const discord_js = require('discord.js');
4
4
  const chars = require('../../constants/chars.cjs');
5
5
  const assets = require('./assets.cjs');
6
- const footer = require('./footer.cjs');
7
6
  const fields = require('./fields.cjs');
7
+ const footer = require('./footer.cjs');
8
8
 
9
9
  var __defProp = Object.defineProperty;
10
10
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
@@ -18,7 +18,7 @@ class EmbedPlusBuilder extends discord_js.EmbedBuilder {
18
18
  const extendsEmbedData = extendsEmbed ? "data" in extendsEmbed ? extendsEmbed.data : data : {};
19
19
  const { fields: extendsFields, ...extendsData } = extendsEmbedData;
20
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 },
21
+ { name: field.name ?? chars.chars.invisible, value: field.value ?? chars.chars.invisible },
22
22
  field.inline !== void 0 ? { inline: field.inline } : {}
23
23
  ));
24
24
  const builderData = Object.assign({}, extendsData, embedData, { fields: fields$1 });
@@ -1,8 +1,8 @@
1
1
  import { EmbedBuilder } from 'discord.js';
2
2
  import { chars } from '../../constants/chars.mjs';
3
3
  import { createEmbedAsset } from './assets.mjs';
4
- import { createEmbedFooter } from './footer.mjs';
5
4
  import { EmbedPlusFields } from './fields.mjs';
5
+ import { createEmbedFooter } from './footer.mjs';
6
6
 
7
7
  var __defProp = Object.defineProperty;
8
8
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
@@ -16,7 +16,7 @@ class EmbedPlusBuilder extends EmbedBuilder {
16
16
  const extendsEmbedData = extendsEmbed ? "data" in extendsEmbed ? extendsEmbed.data : data : {};
17
17
  const { fields: extendsFields, ...extendsData } = extendsEmbedData;
18
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 },
19
+ { name: field.name ?? chars.invisible, value: field.value ?? chars.invisible },
20
20
  field.inline !== void 0 ? { inline: field.inline } : {}
21
21
  ));
22
22
  const builderData = Object.assign({}, extendsData, embedData, { fields });
@@ -41,6 +41,9 @@ function findMessage(channel) {
41
41
  };
42
42
  }
43
43
  function getMessageUrlInfo(url) {
44
+ const regex = new RegExp(/^https:\/\/discord\.com\/channels\/\d+\/\d+\/\d+$/);
45
+ if (!regex.test(url))
46
+ return {};
44
47
  const [messageId, channelId, guildId] = url.split("/").reverse();
45
48
  return { messageId, channelId, guildId };
46
49
  }
@@ -39,6 +39,9 @@ function findMessage(channel) {
39
39
  };
40
40
  }
41
41
  function getMessageUrlInfo(url) {
42
+ const regex = new RegExp(/^https:\/\/discord\.com\/channels\/\d+\/\d+\/\d+$/);
43
+ if (!regex.test(url))
44
+ return {};
42
45
  const [messageId, channelId, guildId] = url.split("/").reverse();
43
46
  return { messageId, channelId, guildId };
44
47
  }
package/dist/index.cjs CHANGED
@@ -8,7 +8,6 @@ const commands = require('./functions/commands.cjs');
8
8
  const components = require('./functions/components.cjs');
9
9
  const modals = require('./functions/modals.cjs');
10
10
  const emojis = require('./functions/emojis.cjs');
11
- const format = require('./functions/format.cjs');
12
11
  const members = require('./functions/members.cjs');
13
12
  const message = require('./functions/message.cjs');
14
13
  const roles = require('./functions/roles.cjs');
@@ -28,14 +27,12 @@ exports.setMobileStatus = misc.setMobileStatus;
28
27
  exports.findChannel = channels.findChannel;
29
28
  exports.getChannelUrlInfo = channels.getChannelUrlInfo;
30
29
  exports.findCommand = commands.findCommand;
31
- exports.createComponentsManager = components.createComponentsManager;
32
30
  exports.createLinkButton = components.createLinkButton;
33
31
  exports.createRow = components.createRow;
34
32
  exports.createModalFields = modals.createModalFields;
35
33
  exports.createModalInput = modals.createModalInput;
36
34
  exports.modalFieldsToRecord = modals.modalFieldsToRecord;
37
35
  exports.findEmoji = emojis.findEmoji;
38
- exports.formatedMention = format.formatedMention;
39
36
  exports.findMember = members.findMember;
40
37
  exports.findMessage = message.findMessage;
41
38
  exports.getMessageUrlInfo = message.getMessageUrlInfo;
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, 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';
2
+ import { GatewayIntentBits, Partials, ChannelType, Guild, CommandInteractionOption, Client, ApplicationCommand, AnyComponentBuilder, ActionRowBuilder, ButtonBuilder, LinkButtonComponentData, TextInputBuilder, ModalSubmitFields, Collection, TextInputComponent, TextInputComponentData, GuildEmoji, GuildMember, GuildTextBasedChannel, Message, Role, Attachment, AttachmentBuilder, EmbedAssetData, EmbedAuthorData, ImageURLOptions, User, EmbedFooterData, APIEmbed, Embed, EmbedBuilder, EmbedData, ColorResolvable } from 'discord.js';
3
3
  export * from '@magicyan/core';
4
4
 
5
5
  declare const chars: {
@@ -61,37 +61,14 @@ declare function createRow<Component extends AnyComponentBuilder>(...components:
61
61
  interface CreateLinkButtonData extends Omit<LinkButtonComponentData, "style" | "type"> {
62
62
  }
63
63
  declare function createLinkButton(data: CreateLinkButtonData): ButtonBuilder;
64
- interface MessageComponentsManager {
65
- getButton(customId: string): ButtonComponent | undefined;
66
- getButton(customId: string, required: true): ButtonComponent;
67
- getStringSelect(customId: string): StringSelectMenuComponent | undefined;
68
- getStringSelect(customId: string, required: true): StringSelectMenuComponent;
69
- getUserSelect(customId: string): UserSelectMenuComponent | undefined;
70
- getUserSelect(customId: string, required: true): UserSelectMenuComponent;
71
- getChannelSelect(customId: string): ChannelSelectMenuComponent | undefined;
72
- getChannelSelect(customId: string, required: true): ChannelSelectMenuComponent;
73
- getRoleSelect(customId: string): RoleSelectMenuComponent | undefined;
74
- getRoleSelect(customId: string, required: true): RoleSelectMenuComponent;
75
- getMentionableSelect(customId: string): MentionableSelectMenuComponent | undefined;
76
- getMentionableSelect(customId: string, required: true): MentionableSelectMenuComponent;
77
- resolved: {
78
- buttons: ButtonComponent[];
79
- stringSelects: StringSelectMenuComponent[];
80
- userSelects: UserSelectMenuComponent[];
81
- channelSelects: ChannelSelectMenuComponent[];
82
- roleSelects: RoleSelectMenuComponent[];
83
- mentionableSelects: MentionableSelectMenuComponent[];
84
- };
85
- }
86
- declare function createComponentsManager(components: ActionRow<MessageActionRowComponent>[]): MessageComponentsManager;
87
64
 
88
65
  type TextInputData = Omit<TextInputComponentData, "type">;
89
66
  type CreateModalInputData = TextInputData;
90
67
  declare function createModalInput(data: CreateModalInputData): ActionRowBuilder<TextInputBuilder>;
91
68
  type ModalFieldsData = Record<string, Omit<TextInputData, "customId">>;
92
69
  declare function createModalFields(data: ModalFieldsData): ActionRowBuilder<TextInputBuilder>[];
93
- type ModalFieldsRecord = Record<string, string>;
94
- declare function modalFieldsToRecord(fields: ModalSubmitFields | Collection<string, TextInputComponent>): ModalFieldsRecord;
70
+ type ModalFieldsRecord<K extends string> = Record<K, string>;
71
+ declare function modalFieldsToRecord<K extends string = string>(fields: ModalSubmitFields | Collection<string, TextInputComponent>): ModalFieldsRecord<K>;
95
72
 
96
73
  type FindEmojiFilter = (emoji: GuildEmoji) => boolean;
97
74
  declare function findEmoji(guildOrClient: Guild | Client): {
@@ -100,8 +77,6 @@ declare function findEmoji(guildOrClient: Guild | Client): {
100
77
  byFilter(filter: FindEmojiFilter): GuildEmoji | undefined;
101
78
  };
102
79
 
103
- declare function formatedMention(ref: GuildBasedChannel | Role | User | undefined | null, alt?: string): string;
104
-
105
80
  type FindMemberFilter = (member: GuildMember) => boolean;
106
81
  declare function findMember(guild: Guild): {
107
82
  byGlobalName(globalName: string, and?: FindMemberFilter): GuildMember | undefined;
@@ -186,12 +161,6 @@ type CreateEmbedAuthorOptions = AuthorOption & ImageURLOptions & {
186
161
  };
187
162
  declare function createEmbedAuthor(options: CreateEmbedAuthorOptions): EmbedAuthorData;
188
163
 
189
- type EmbedPlusFooterData = {
190
- text?: string | null;
191
- iconURL?: string | null;
192
- };
193
- declare function createEmbedFooter(options: EmbedPlusFooterData): EmbedFooterData | undefined;
194
-
195
164
  type EmbedPlusFieldData = {
196
165
  name: string;
197
166
  value: string;
@@ -227,6 +196,12 @@ declare class EmbedPlusFields {
227
196
  private getPredicateIndex;
228
197
  }
229
198
 
199
+ type EmbedPlusFooterData = {
200
+ text?: string | null;
201
+ iconURL?: string | null;
202
+ };
203
+ declare function createEmbedFooter(options: EmbedPlusFooterData): EmbedFooterData | undefined;
204
+
230
205
  type EmbedPlusColorData = string & {} | ColorResolvable | null;
231
206
  type EmbedPlusAuthorData = {
232
207
  name: string;
@@ -276,4 +251,4 @@ interface CreateEmbedOptions<B extends boolean> extends EmbedPlusOptions {
276
251
  type CreateEmbedReturn<B> = undefined extends B ? EmbedPlusBuilder : false extends B ? EmbedPlusBuilder : EmbedPlusBuilder[];
277
252
  declare function createEmbed<B extends boolean>(options: CreateEmbedOptions<B>): CreateEmbedReturn<B>;
278
253
 
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 };
254
+ export { type AnyEmbed, CustomItents, CustomPartials, type EmbedPlusAssetData, EmbedPlusBuilder, type EmbedPlusData, type EmbedPlusFooterData, type EmbedPlusProperty, chars, createEmbed, createEmbedAsset, createEmbedAuthor, createEmbedFooter, createLinkButton, createModalFields, createModalInput, createRow, extractMentionId, findChannel, findCommand, findEmoji, findMember, findMessage, findRole, 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, 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';
2
+ import { GatewayIntentBits, Partials, ChannelType, Guild, CommandInteractionOption, Client, ApplicationCommand, AnyComponentBuilder, ActionRowBuilder, ButtonBuilder, LinkButtonComponentData, TextInputBuilder, ModalSubmitFields, Collection, TextInputComponent, TextInputComponentData, GuildEmoji, GuildMember, GuildTextBasedChannel, Message, Role, Attachment, AttachmentBuilder, EmbedAssetData, EmbedAuthorData, ImageURLOptions, User, EmbedFooterData, APIEmbed, Embed, EmbedBuilder, EmbedData, ColorResolvable } from 'discord.js';
3
3
  export * from '@magicyan/core';
4
4
 
5
5
  declare const chars: {
@@ -61,37 +61,14 @@ declare function createRow<Component extends AnyComponentBuilder>(...components:
61
61
  interface CreateLinkButtonData extends Omit<LinkButtonComponentData, "style" | "type"> {
62
62
  }
63
63
  declare function createLinkButton(data: CreateLinkButtonData): ButtonBuilder;
64
- interface MessageComponentsManager {
65
- getButton(customId: string): ButtonComponent | undefined;
66
- getButton(customId: string, required: true): ButtonComponent;
67
- getStringSelect(customId: string): StringSelectMenuComponent | undefined;
68
- getStringSelect(customId: string, required: true): StringSelectMenuComponent;
69
- getUserSelect(customId: string): UserSelectMenuComponent | undefined;
70
- getUserSelect(customId: string, required: true): UserSelectMenuComponent;
71
- getChannelSelect(customId: string): ChannelSelectMenuComponent | undefined;
72
- getChannelSelect(customId: string, required: true): ChannelSelectMenuComponent;
73
- getRoleSelect(customId: string): RoleSelectMenuComponent | undefined;
74
- getRoleSelect(customId: string, required: true): RoleSelectMenuComponent;
75
- getMentionableSelect(customId: string): MentionableSelectMenuComponent | undefined;
76
- getMentionableSelect(customId: string, required: true): MentionableSelectMenuComponent;
77
- resolved: {
78
- buttons: ButtonComponent[];
79
- stringSelects: StringSelectMenuComponent[];
80
- userSelects: UserSelectMenuComponent[];
81
- channelSelects: ChannelSelectMenuComponent[];
82
- roleSelects: RoleSelectMenuComponent[];
83
- mentionableSelects: MentionableSelectMenuComponent[];
84
- };
85
- }
86
- declare function createComponentsManager(components: ActionRow<MessageActionRowComponent>[]): MessageComponentsManager;
87
64
 
88
65
  type TextInputData = Omit<TextInputComponentData, "type">;
89
66
  type CreateModalInputData = TextInputData;
90
67
  declare function createModalInput(data: CreateModalInputData): ActionRowBuilder<TextInputBuilder>;
91
68
  type ModalFieldsData = Record<string, Omit<TextInputData, "customId">>;
92
69
  declare function createModalFields(data: ModalFieldsData): ActionRowBuilder<TextInputBuilder>[];
93
- type ModalFieldsRecord = Record<string, string>;
94
- declare function modalFieldsToRecord(fields: ModalSubmitFields | Collection<string, TextInputComponent>): ModalFieldsRecord;
70
+ type ModalFieldsRecord<K extends string> = Record<K, string>;
71
+ declare function modalFieldsToRecord<K extends string = string>(fields: ModalSubmitFields | Collection<string, TextInputComponent>): ModalFieldsRecord<K>;
95
72
 
96
73
  type FindEmojiFilter = (emoji: GuildEmoji) => boolean;
97
74
  declare function findEmoji(guildOrClient: Guild | Client): {
@@ -100,8 +77,6 @@ declare function findEmoji(guildOrClient: Guild | Client): {
100
77
  byFilter(filter: FindEmojiFilter): GuildEmoji | undefined;
101
78
  };
102
79
 
103
- declare function formatedMention(ref: GuildBasedChannel | Role | User | undefined | null, alt?: string): string;
104
-
105
80
  type FindMemberFilter = (member: GuildMember) => boolean;
106
81
  declare function findMember(guild: Guild): {
107
82
  byGlobalName(globalName: string, and?: FindMemberFilter): GuildMember | undefined;
@@ -186,12 +161,6 @@ type CreateEmbedAuthorOptions = AuthorOption & ImageURLOptions & {
186
161
  };
187
162
  declare function createEmbedAuthor(options: CreateEmbedAuthorOptions): EmbedAuthorData;
188
163
 
189
- type EmbedPlusFooterData = {
190
- text?: string | null;
191
- iconURL?: string | null;
192
- };
193
- declare function createEmbedFooter(options: EmbedPlusFooterData): EmbedFooterData | undefined;
194
-
195
164
  type EmbedPlusFieldData = {
196
165
  name: string;
197
166
  value: string;
@@ -227,6 +196,12 @@ declare class EmbedPlusFields {
227
196
  private getPredicateIndex;
228
197
  }
229
198
 
199
+ type EmbedPlusFooterData = {
200
+ text?: string | null;
201
+ iconURL?: string | null;
202
+ };
203
+ declare function createEmbedFooter(options: EmbedPlusFooterData): EmbedFooterData | undefined;
204
+
230
205
  type EmbedPlusColorData = string & {} | ColorResolvable | null;
231
206
  type EmbedPlusAuthorData = {
232
207
  name: string;
@@ -276,4 +251,4 @@ interface CreateEmbedOptions<B extends boolean> extends EmbedPlusOptions {
276
251
  type CreateEmbedReturn<B> = undefined extends B ? EmbedPlusBuilder : false extends B ? EmbedPlusBuilder : EmbedPlusBuilder[];
277
252
  declare function createEmbed<B extends boolean>(options: CreateEmbedOptions<B>): CreateEmbedReturn<B>;
278
253
 
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 };
254
+ export { type AnyEmbed, CustomItents, CustomPartials, type EmbedPlusAssetData, EmbedPlusBuilder, type EmbedPlusData, type EmbedPlusFooterData, type EmbedPlusProperty, chars, createEmbed, createEmbedAsset, createEmbedAuthor, createEmbedFooter, createLinkButton, createModalFields, createModalInput, createRow, extractMentionId, findChannel, findCommand, findEmoji, findMember, findMessage, findRole, 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, 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';
2
+ import { GatewayIntentBits, Partials, ChannelType, Guild, CommandInteractionOption, Client, ApplicationCommand, AnyComponentBuilder, ActionRowBuilder, ButtonBuilder, LinkButtonComponentData, TextInputBuilder, ModalSubmitFields, Collection, TextInputComponent, TextInputComponentData, GuildEmoji, GuildMember, GuildTextBasedChannel, Message, Role, Attachment, AttachmentBuilder, EmbedAssetData, EmbedAuthorData, ImageURLOptions, User, EmbedFooterData, APIEmbed, Embed, EmbedBuilder, EmbedData, ColorResolvable } from 'discord.js';
3
3
  export * from '@magicyan/core';
4
4
 
5
5
  declare const chars: {
@@ -61,37 +61,14 @@ declare function createRow<Component extends AnyComponentBuilder>(...components:
61
61
  interface CreateLinkButtonData extends Omit<LinkButtonComponentData, "style" | "type"> {
62
62
  }
63
63
  declare function createLinkButton(data: CreateLinkButtonData): ButtonBuilder;
64
- interface MessageComponentsManager {
65
- getButton(customId: string): ButtonComponent | undefined;
66
- getButton(customId: string, required: true): ButtonComponent;
67
- getStringSelect(customId: string): StringSelectMenuComponent | undefined;
68
- getStringSelect(customId: string, required: true): StringSelectMenuComponent;
69
- getUserSelect(customId: string): UserSelectMenuComponent | undefined;
70
- getUserSelect(customId: string, required: true): UserSelectMenuComponent;
71
- getChannelSelect(customId: string): ChannelSelectMenuComponent | undefined;
72
- getChannelSelect(customId: string, required: true): ChannelSelectMenuComponent;
73
- getRoleSelect(customId: string): RoleSelectMenuComponent | undefined;
74
- getRoleSelect(customId: string, required: true): RoleSelectMenuComponent;
75
- getMentionableSelect(customId: string): MentionableSelectMenuComponent | undefined;
76
- getMentionableSelect(customId: string, required: true): MentionableSelectMenuComponent;
77
- resolved: {
78
- buttons: ButtonComponent[];
79
- stringSelects: StringSelectMenuComponent[];
80
- userSelects: UserSelectMenuComponent[];
81
- channelSelects: ChannelSelectMenuComponent[];
82
- roleSelects: RoleSelectMenuComponent[];
83
- mentionableSelects: MentionableSelectMenuComponent[];
84
- };
85
- }
86
- declare function createComponentsManager(components: ActionRow<MessageActionRowComponent>[]): MessageComponentsManager;
87
64
 
88
65
  type TextInputData = Omit<TextInputComponentData, "type">;
89
66
  type CreateModalInputData = TextInputData;
90
67
  declare function createModalInput(data: CreateModalInputData): ActionRowBuilder<TextInputBuilder>;
91
68
  type ModalFieldsData = Record<string, Omit<TextInputData, "customId">>;
92
69
  declare function createModalFields(data: ModalFieldsData): ActionRowBuilder<TextInputBuilder>[];
93
- type ModalFieldsRecord = Record<string, string>;
94
- declare function modalFieldsToRecord(fields: ModalSubmitFields | Collection<string, TextInputComponent>): ModalFieldsRecord;
70
+ type ModalFieldsRecord<K extends string> = Record<K, string>;
71
+ declare function modalFieldsToRecord<K extends string = string>(fields: ModalSubmitFields | Collection<string, TextInputComponent>): ModalFieldsRecord<K>;
95
72
 
96
73
  type FindEmojiFilter = (emoji: GuildEmoji) => boolean;
97
74
  declare function findEmoji(guildOrClient: Guild | Client): {
@@ -100,8 +77,6 @@ declare function findEmoji(guildOrClient: Guild | Client): {
100
77
  byFilter(filter: FindEmojiFilter): GuildEmoji | undefined;
101
78
  };
102
79
 
103
- declare function formatedMention(ref: GuildBasedChannel | Role | User | undefined | null, alt?: string): string;
104
-
105
80
  type FindMemberFilter = (member: GuildMember) => boolean;
106
81
  declare function findMember(guild: Guild): {
107
82
  byGlobalName(globalName: string, and?: FindMemberFilter): GuildMember | undefined;
@@ -186,12 +161,6 @@ type CreateEmbedAuthorOptions = AuthorOption & ImageURLOptions & {
186
161
  };
187
162
  declare function createEmbedAuthor(options: CreateEmbedAuthorOptions): EmbedAuthorData;
188
163
 
189
- type EmbedPlusFooterData = {
190
- text?: string | null;
191
- iconURL?: string | null;
192
- };
193
- declare function createEmbedFooter(options: EmbedPlusFooterData): EmbedFooterData | undefined;
194
-
195
164
  type EmbedPlusFieldData = {
196
165
  name: string;
197
166
  value: string;
@@ -227,6 +196,12 @@ declare class EmbedPlusFields {
227
196
  private getPredicateIndex;
228
197
  }
229
198
 
199
+ type EmbedPlusFooterData = {
200
+ text?: string | null;
201
+ iconURL?: string | null;
202
+ };
203
+ declare function createEmbedFooter(options: EmbedPlusFooterData): EmbedFooterData | undefined;
204
+
230
205
  type EmbedPlusColorData = string & {} | ColorResolvable | null;
231
206
  type EmbedPlusAuthorData = {
232
207
  name: string;
@@ -276,4 +251,4 @@ interface CreateEmbedOptions<B extends boolean> extends EmbedPlusOptions {
276
251
  type CreateEmbedReturn<B> = undefined extends B ? EmbedPlusBuilder : false extends B ? EmbedPlusBuilder : EmbedPlusBuilder[];
277
252
  declare function createEmbed<B extends boolean>(options: CreateEmbedOptions<B>): CreateEmbedReturn<B>;
278
253
 
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 };
254
+ export { type AnyEmbed, CustomItents, CustomPartials, type EmbedPlusAssetData, EmbedPlusBuilder, type EmbedPlusData, type EmbedPlusFooterData, type EmbedPlusProperty, chars, createEmbed, createEmbedAsset, createEmbedAuthor, createEmbedFooter, createLinkButton, createModalFields, createModalInput, createRow, extractMentionId, findChannel, findCommand, findEmoji, findMember, findMessage, findRole, getChannelUrlInfo, getMessageUrlInfo, modalFieldsToRecord, setMobileStatus };
package/dist/index.mjs CHANGED
@@ -3,10 +3,9 @@ export { CustomItents, CustomPartials } from './constants/client.mjs';
3
3
  export { setMobileStatus } from './functions/misc.mjs';
4
4
  export { findChannel, getChannelUrlInfo } from './functions/channels.mjs';
5
5
  export { findCommand } from './functions/commands.mjs';
6
- export { createComponentsManager, createLinkButton, createRow } from './functions/components.mjs';
6
+ export { createLinkButton, createRow } from './functions/components.mjs';
7
7
  export { createModalFields, createModalInput, modalFieldsToRecord } from './functions/modals.mjs';
8
8
  export { findEmoji } from './functions/emojis.mjs';
9
- export { formatedMention } from './functions/format.mjs';
10
9
  export { findMember } from './functions/members.mjs';
11
10
  export { findMessage, getMessageUrlInfo } from './functions/message.mjs';
12
11
  export { findRole } from './functions/roles.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magicyan/discord",
3
- "version": "1.0.26",
3
+ "version": "1.0.28",
4
4
  "description": "Simple functions to facilitate discord bot development",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,9 +0,0 @@
1
- 'use strict';
2
-
3
- const discord_js = require('discord.js');
4
-
5
- function formatedMention(ref, alt = "") {
6
- return ref instanceof discord_js.Role ? discord_js.roleMention(ref.id) : ref instanceof discord_js.User ? discord_js.userMention(ref.id) : ref ? discord_js.channelMention(ref.id) : alt;
7
- }
8
-
9
- exports.formatedMention = formatedMention;
@@ -1,7 +0,0 @@
1
- import { Role, roleMention, User, userMention, channelMention } from 'discord.js';
2
-
3
- function formatedMention(ref, alt = "") {
4
- return ref instanceof Role ? roleMention(ref.id) : ref instanceof User ? userMention(ref.id) : ref ? channelMention(ref.id) : alt;
5
- }
6
-
7
- export { formatedMention };