@magicyan/discord 1.1.2 → 1.2.0

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.
@@ -6,8 +6,7 @@ function createRow(...components) {
6
6
  return new discord_js.ActionRowBuilder({ components });
7
7
  }
8
8
  function createLinkButton(data) {
9
- if (!data.label)
10
- data.label = data.url;
9
+ data.label ?? (data.label = data.url);
11
10
  return new discord_js.ButtonBuilder({ style: discord_js.ButtonStyle.Link, ...data });
12
11
  }
13
12
 
@@ -4,8 +4,7 @@ function createRow(...components) {
4
4
  return new ActionRowBuilder({ components });
5
5
  }
6
6
  function createLinkButton(data) {
7
- if (!data.label)
8
- data.label = data.url;
7
+ data.label ?? (data.label = data.url);
9
8
  return new ButtonBuilder({ style: ButtonStyle.Link, ...data });
10
9
  }
11
10
 
@@ -5,7 +5,7 @@ const chars = require('../../constants/chars.cjs');
5
5
 
6
6
  function createEmbedFooter(options) {
7
7
  const { text, iconURL } = options;
8
- return !text && !iconURL ? void 0 : { text: text ?? chars.chars.invisible, iconURL: core.notFound(iconURL) };
8
+ return !text && !iconURL ? void 0 : { text: text || chars.chars.invisible, iconURL: core.notFound(iconURL) };
9
9
  }
10
10
 
11
11
  exports.createEmbedFooter = createEmbedFooter;
@@ -3,7 +3,7 @@ import { chars } from '../../constants/chars.mjs';
3
3
 
4
4
  function createEmbedFooter(options) {
5
5
  const { text, iconURL } = options;
6
- return !text && !iconURL ? void 0 : { text: text ?? chars.invisible, iconURL: notFound(iconURL) };
6
+ return !text && !iconURL ? void 0 : { text: text || chars.invisible, iconURL: notFound(iconURL) };
7
7
  }
8
8
 
9
9
  export { createEmbedFooter };
@@ -17,7 +17,7 @@ function modalFieldsToRecord(fields) {
17
17
  data,
18
18
  { [customId]: value }
19
19
  );
20
- const modalFields = "fields" in fields ? fields.fields : fields;
20
+ const modalFields = fields instanceof discord_js.ModalSubmitInteraction ? fields.fields.fields : "fields" in fields ? fields.fields : fields;
21
21
  return modalFields.reduce(reduceFunction, {});
22
22
  }
23
23
 
@@ -1,4 +1,4 @@
1
- import { TextInputStyle, TextInputBuilder } from 'discord.js';
1
+ import { TextInputStyle, TextInputBuilder, ModalSubmitInteraction } from 'discord.js';
2
2
  import { createRow } from './components.mjs';
3
3
 
4
4
  function createModalInput(data) {
@@ -15,7 +15,7 @@ function modalFieldsToRecord(fields) {
15
15
  data,
16
16
  { [customId]: value }
17
17
  );
18
- const modalFields = "fields" in fields ? fields.fields : fields;
18
+ const modalFields = fields instanceof ModalSubmitInteraction ? fields.fields.fields : "fields" in fields ? fields.fields : fields;
19
19
  return modalFields.reduce(reduceFunction, {});
20
20
  }
21
21
 
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as discord_js from 'discord.js';
2
- import { GatewayIntentBits, Partials, Attachment, AttachmentBuilder, EmbedAssetData, Guild, GuildMember, User, ClientUser, ImageURLOptions, EmbedFooterData, ColorResolvable, APIEmbed, Embed, EmbedData, EmbedBuilder, AttachmentData, AnyComponentBuilder, ActionRowBuilder, ButtonBuilder, LinkButtonComponentData, ChannelType, CommandInteractionOption, Client, ApplicationCommand, TextInputBuilder, ModalSubmitFields, Collection, TextInputComponent, TextInputStyle, TextInputComponentData, GuildEmoji, GuildTextBasedChannel, Message, Role } from 'discord.js';
2
+ import { GatewayIntentBits, Partials, Attachment, AttachmentBuilder, EmbedAssetData, Guild, GuildMember, User, ClientUser, ImageURLOptions, EmbedFooterData, ColorResolvable, APIEmbed, Embed, EmbedData, EmbedBuilder, AttachmentData, AnyComponentBuilder, ActionRowBuilder, ButtonBuilder, LinkButtonComponentData, ChannelType, CommandInteractionOption, Client, ApplicationCommand, TextInputBuilder, ModalSubmitInteraction, ModalSubmitFields, Collection, TextInputComponent, TextInputStyle, TextInputComponentData, GuildEmoji, GuildTextBasedChannel, Message, Role } from 'discord.js';
3
3
  export * from '@magicyan/core';
4
4
 
5
5
  declare const chars: {
@@ -154,8 +154,8 @@ type ImageFileExtention = "png" | "jpg" | "gif" | "webp";
154
154
  type ImageElementProperty = "author" | "thumbnail" | "image" | "footer";
155
155
  interface CreateEmbedFilesOptions {
156
156
  ignore?: ImageElementProperty[];
157
- extentions?: Record<ImageElementProperty, ImageFileExtention>;
158
- names?: Record<ImageElementProperty, ImageFileExtention>;
157
+ extentions?: Partial<Record<ImageElementProperty, ImageFileExtention>>;
158
+ names?: Partial<Record<ImageElementProperty, string>>;
159
159
  }
160
160
  /**
161
161
  * Turns any embed image url into an attachment and returns an attachment array
@@ -213,16 +213,14 @@ declare function commandMention(command: CommandMentionData, group?: string, sub
213
213
  declare function commandMention(command: CommandMentionData, subcommand?: string): string;
214
214
 
215
215
  type TextInputData = Omit<TextInputComponentData, "type">;
216
- interface ModalFieldData extends Omit<TextInputData, "customId" | "style"> {
216
+ interface ModalFieldData extends Omit<TextInputData, "style"> {
217
217
  style?: TextInputStyle;
218
218
  }
219
- declare function createModalInput(data: ModalFieldData & {
220
- customId: string;
221
- }): ActionRowBuilder<TextInputBuilder>;
222
- type ModalFieldsData = Record<string, ModalFieldData>;
219
+ declare function createModalInput(data: ModalFieldData): ActionRowBuilder<TextInputBuilder>;
220
+ type ModalFieldsData = Record<string, Omit<ModalFieldData, "customId">>;
223
221
  declare function createModalFields(data: ModalFieldsData): ActionRowBuilder<TextInputBuilder>[];
224
222
  type ModalFieldsRecord<K extends string> = Record<K, string>;
225
- declare function modalFieldsToRecord<K extends string = string>(fields: ModalSubmitFields | Collection<string, TextInputComponent>): ModalFieldsRecord<K>;
223
+ declare function modalFieldsToRecord<K extends string = string>(fields: ModalSubmitInteraction | ModalSubmitFields | Collection<string, TextInputComponent>): ModalFieldsRecord<K>;
226
224
 
227
225
  type FindEmojiFilter = (emoji: GuildEmoji) => boolean;
228
226
  declare function findEmoji(guildOrClient: Guild | Client): {
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as discord_js from 'discord.js';
2
- import { GatewayIntentBits, Partials, Attachment, AttachmentBuilder, EmbedAssetData, Guild, GuildMember, User, ClientUser, ImageURLOptions, EmbedFooterData, ColorResolvable, APIEmbed, Embed, EmbedData, EmbedBuilder, AttachmentData, AnyComponentBuilder, ActionRowBuilder, ButtonBuilder, LinkButtonComponentData, ChannelType, CommandInteractionOption, Client, ApplicationCommand, TextInputBuilder, ModalSubmitFields, Collection, TextInputComponent, TextInputStyle, TextInputComponentData, GuildEmoji, GuildTextBasedChannel, Message, Role } from 'discord.js';
2
+ import { GatewayIntentBits, Partials, Attachment, AttachmentBuilder, EmbedAssetData, Guild, GuildMember, User, ClientUser, ImageURLOptions, EmbedFooterData, ColorResolvable, APIEmbed, Embed, EmbedData, EmbedBuilder, AttachmentData, AnyComponentBuilder, ActionRowBuilder, ButtonBuilder, LinkButtonComponentData, ChannelType, CommandInteractionOption, Client, ApplicationCommand, TextInputBuilder, ModalSubmitInteraction, ModalSubmitFields, Collection, TextInputComponent, TextInputStyle, TextInputComponentData, GuildEmoji, GuildTextBasedChannel, Message, Role } from 'discord.js';
3
3
  export * from '@magicyan/core';
4
4
 
5
5
  declare const chars: {
@@ -154,8 +154,8 @@ type ImageFileExtention = "png" | "jpg" | "gif" | "webp";
154
154
  type ImageElementProperty = "author" | "thumbnail" | "image" | "footer";
155
155
  interface CreateEmbedFilesOptions {
156
156
  ignore?: ImageElementProperty[];
157
- extentions?: Record<ImageElementProperty, ImageFileExtention>;
158
- names?: Record<ImageElementProperty, ImageFileExtention>;
157
+ extentions?: Partial<Record<ImageElementProperty, ImageFileExtention>>;
158
+ names?: Partial<Record<ImageElementProperty, string>>;
159
159
  }
160
160
  /**
161
161
  * Turns any embed image url into an attachment and returns an attachment array
@@ -213,16 +213,14 @@ declare function commandMention(command: CommandMentionData, group?: string, sub
213
213
  declare function commandMention(command: CommandMentionData, subcommand?: string): string;
214
214
 
215
215
  type TextInputData = Omit<TextInputComponentData, "type">;
216
- interface ModalFieldData extends Omit<TextInputData, "customId" | "style"> {
216
+ interface ModalFieldData extends Omit<TextInputData, "style"> {
217
217
  style?: TextInputStyle;
218
218
  }
219
- declare function createModalInput(data: ModalFieldData & {
220
- customId: string;
221
- }): ActionRowBuilder<TextInputBuilder>;
222
- type ModalFieldsData = Record<string, ModalFieldData>;
219
+ declare function createModalInput(data: ModalFieldData): ActionRowBuilder<TextInputBuilder>;
220
+ type ModalFieldsData = Record<string, Omit<ModalFieldData, "customId">>;
223
221
  declare function createModalFields(data: ModalFieldsData): ActionRowBuilder<TextInputBuilder>[];
224
222
  type ModalFieldsRecord<K extends string> = Record<K, string>;
225
- declare function modalFieldsToRecord<K extends string = string>(fields: ModalSubmitFields | Collection<string, TextInputComponent>): ModalFieldsRecord<K>;
223
+ declare function modalFieldsToRecord<K extends string = string>(fields: ModalSubmitInteraction | ModalSubmitFields | Collection<string, TextInputComponent>): ModalFieldsRecord<K>;
226
224
 
227
225
  type FindEmojiFilter = (emoji: GuildEmoji) => boolean;
228
226
  declare function findEmoji(guildOrClient: Guild | Client): {
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as discord_js from 'discord.js';
2
- import { GatewayIntentBits, Partials, Attachment, AttachmentBuilder, EmbedAssetData, Guild, GuildMember, User, ClientUser, ImageURLOptions, EmbedFooterData, ColorResolvable, APIEmbed, Embed, EmbedData, EmbedBuilder, AttachmentData, AnyComponentBuilder, ActionRowBuilder, ButtonBuilder, LinkButtonComponentData, ChannelType, CommandInteractionOption, Client, ApplicationCommand, TextInputBuilder, ModalSubmitFields, Collection, TextInputComponent, TextInputStyle, TextInputComponentData, GuildEmoji, GuildTextBasedChannel, Message, Role } from 'discord.js';
2
+ import { GatewayIntentBits, Partials, Attachment, AttachmentBuilder, EmbedAssetData, Guild, GuildMember, User, ClientUser, ImageURLOptions, EmbedFooterData, ColorResolvable, APIEmbed, Embed, EmbedData, EmbedBuilder, AttachmentData, AnyComponentBuilder, ActionRowBuilder, ButtonBuilder, LinkButtonComponentData, ChannelType, CommandInteractionOption, Client, ApplicationCommand, TextInputBuilder, ModalSubmitInteraction, ModalSubmitFields, Collection, TextInputComponent, TextInputStyle, TextInputComponentData, GuildEmoji, GuildTextBasedChannel, Message, Role } from 'discord.js';
3
3
  export * from '@magicyan/core';
4
4
 
5
5
  declare const chars: {
@@ -154,8 +154,8 @@ type ImageFileExtention = "png" | "jpg" | "gif" | "webp";
154
154
  type ImageElementProperty = "author" | "thumbnail" | "image" | "footer";
155
155
  interface CreateEmbedFilesOptions {
156
156
  ignore?: ImageElementProperty[];
157
- extentions?: Record<ImageElementProperty, ImageFileExtention>;
158
- names?: Record<ImageElementProperty, ImageFileExtention>;
157
+ extentions?: Partial<Record<ImageElementProperty, ImageFileExtention>>;
158
+ names?: Partial<Record<ImageElementProperty, string>>;
159
159
  }
160
160
  /**
161
161
  * Turns any embed image url into an attachment and returns an attachment array
@@ -213,16 +213,14 @@ declare function commandMention(command: CommandMentionData, group?: string, sub
213
213
  declare function commandMention(command: CommandMentionData, subcommand?: string): string;
214
214
 
215
215
  type TextInputData = Omit<TextInputComponentData, "type">;
216
- interface ModalFieldData extends Omit<TextInputData, "customId" | "style"> {
216
+ interface ModalFieldData extends Omit<TextInputData, "style"> {
217
217
  style?: TextInputStyle;
218
218
  }
219
- declare function createModalInput(data: ModalFieldData & {
220
- customId: string;
221
- }): ActionRowBuilder<TextInputBuilder>;
222
- type ModalFieldsData = Record<string, ModalFieldData>;
219
+ declare function createModalInput(data: ModalFieldData): ActionRowBuilder<TextInputBuilder>;
220
+ type ModalFieldsData = Record<string, Omit<ModalFieldData, "customId">>;
223
221
  declare function createModalFields(data: ModalFieldsData): ActionRowBuilder<TextInputBuilder>[];
224
222
  type ModalFieldsRecord<K extends string> = Record<K, string>;
225
- declare function modalFieldsToRecord<K extends string = string>(fields: ModalSubmitFields | Collection<string, TextInputComponent>): ModalFieldsRecord<K>;
223
+ declare function modalFieldsToRecord<K extends string = string>(fields: ModalSubmitInteraction | ModalSubmitFields | Collection<string, TextInputComponent>): ModalFieldsRecord<K>;
226
224
 
227
225
  type FindEmojiFilter = (emoji: GuildEmoji) => boolean;
228
226
  declare function findEmoji(guildOrClient: Guild | Client): {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magicyan/discord",
3
- "version": "1.1.2",
3
+ "version": "1.2.0",
4
4
  "description": "Simple functions to facilitate discord bot development",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -35,13 +35,13 @@
35
35
  "dev": "tsx --env-file .env playground/index.ts"
36
36
  },
37
37
  "devDependencies": {
38
- "tsx": "^4.10.0",
38
+ "tsx": "^4.19.1",
39
39
  "unbuild": "^2.0.0"
40
40
  },
41
41
  "dependencies": {
42
42
  "@magicyan/core": "^1.0.19"
43
43
  },
44
44
  "peerDependencies": {
45
- "discord.js": "^14.15.2"
45
+ "discord.js": "^14.16.3"
46
46
  }
47
- }
47
+ }