@magicyan/discord 1.0.29 → 1.0.31

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,53 +6,53 @@ function findChannel(guild, type) {
6
6
  const channelType = type ?? discord_js.ChannelType.GuildText;
7
7
  const cache = guild.channels.cache;
8
8
  return {
9
- byName(name, filter = () => true) {
9
+ byId(id) {
10
10
  return cache.find(
11
- (c) => c.name === name && c.type === channelType && filter
11
+ (c) => c.id === id && c.type === channelType
12
12
  );
13
13
  },
14
- byId(id) {
14
+ byName(name, and = () => true) {
15
15
  return cache.find(
16
- (c) => c.id === id && c.type === channelType
16
+ (c) => c.name === name && c.type === channelType && and(c)
17
17
  );
18
18
  },
19
19
  byFilter(filter) {
20
- return cache.find((c) => c.type == type && filter);
20
+ return cache.find((c) => c.type == type && filter(c));
21
21
  },
22
22
  inCategoryId(id) {
23
23
  return {
24
- byName(name, filter = () => true) {
24
+ byId(id2) {
25
25
  return cache.find(
26
- (c) => c.name === name && c.type === channelType && c.parentId == id && filter
26
+ (c) => c.id === id2 && c.type === channelType && c.parentId == id2
27
27
  );
28
28
  },
29
- byId(id2, filter = () => true) {
29
+ byName(name, and = () => true) {
30
30
  return cache.find(
31
- (c) => c.id === id2 && c.type === channelType && c.parentId == id2 && filter
31
+ (c) => c.name === name && c.type === channelType && c.parentId == id && and(c)
32
32
  );
33
33
  },
34
34
  byFilter(filter) {
35
35
  return cache.find(
36
- (c) => c.type === channelType && c.parent?.id == id && filter
36
+ (c) => c.type === channelType && c.parent?.id == id && filter(c)
37
37
  );
38
38
  }
39
39
  };
40
40
  },
41
41
  inCategoryName(name) {
42
42
  return {
43
- byName(name2, filter = () => true) {
43
+ byId(id) {
44
44
  return cache.find(
45
- (c) => c.name === name2 && c.type === channelType && c.parent?.name == name2 && filter
45
+ (c) => c.id === id && c.type === channelType && c.parent?.name == name
46
46
  );
47
47
  },
48
- byId(id, filter = () => true) {
48
+ byName(name2, and = () => true) {
49
49
  return cache.find(
50
- (c) => c.id === id && c.type === channelType && c.parent?.name == name && filter
50
+ (c) => c.name === name2 && c.type === channelType && c.parent?.name == name2 && and(c)
51
51
  );
52
52
  },
53
53
  byFilter(filter) {
54
54
  return cache.find(
55
- (c) => c.type === channelType && c.parent?.name == name && filter
55
+ (c) => c.type === channelType && c.parent?.name == name && filter(c)
56
56
  );
57
57
  }
58
58
  };
@@ -4,53 +4,53 @@ function findChannel(guild, type) {
4
4
  const channelType = type ?? ChannelType.GuildText;
5
5
  const cache = guild.channels.cache;
6
6
  return {
7
- byName(name, filter = () => true) {
7
+ byId(id) {
8
8
  return cache.find(
9
- (c) => c.name === name && c.type === channelType && filter
9
+ (c) => c.id === id && c.type === channelType
10
10
  );
11
11
  },
12
- byId(id) {
12
+ byName(name, and = () => true) {
13
13
  return cache.find(
14
- (c) => c.id === id && c.type === channelType
14
+ (c) => c.name === name && c.type === channelType && and(c)
15
15
  );
16
16
  },
17
17
  byFilter(filter) {
18
- return cache.find((c) => c.type == type && filter);
18
+ return cache.find((c) => c.type == type && filter(c));
19
19
  },
20
20
  inCategoryId(id) {
21
21
  return {
22
- byName(name, filter = () => true) {
22
+ byId(id2) {
23
23
  return cache.find(
24
- (c) => c.name === name && c.type === channelType && c.parentId == id && filter
24
+ (c) => c.id === id2 && c.type === channelType && c.parentId == id2
25
25
  );
26
26
  },
27
- byId(id2, filter = () => true) {
27
+ byName(name, and = () => true) {
28
28
  return cache.find(
29
- (c) => c.id === id2 && c.type === channelType && c.parentId == id2 && filter
29
+ (c) => c.name === name && c.type === channelType && c.parentId == id && and(c)
30
30
  );
31
31
  },
32
32
  byFilter(filter) {
33
33
  return cache.find(
34
- (c) => c.type === channelType && c.parent?.id == id && filter
34
+ (c) => c.type === channelType && c.parent?.id == id && filter(c)
35
35
  );
36
36
  }
37
37
  };
38
38
  },
39
39
  inCategoryName(name) {
40
40
  return {
41
- byName(name2, filter = () => true) {
41
+ byId(id) {
42
42
  return cache.find(
43
- (c) => c.name === name2 && c.type === channelType && c.parent?.name == name2 && filter
43
+ (c) => c.id === id && c.type === channelType && c.parent?.name == name
44
44
  );
45
45
  },
46
- byId(id, filter = () => true) {
46
+ byName(name2, and = () => true) {
47
47
  return cache.find(
48
- (c) => c.id === id && c.type === channelType && c.parent?.name == name && filter
48
+ (c) => c.name === name2 && c.type === channelType && c.parent?.name == name2 && and(c)
49
49
  );
50
50
  },
51
51
  byFilter(filter) {
52
52
  return cache.find(
53
- (c) => c.type === channelType && c.parent?.name == name && filter
53
+ (c) => c.type === channelType && c.parent?.name == name && filter(c)
54
54
  );
55
55
  }
56
56
  };
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
3
  const discord_js = require('discord.js');
4
- const chars = require('../../constants/chars.cjs');
5
4
  const assets = require('./assets.cjs');
6
5
  const fields = require('./fields.cjs');
7
6
  const footer = require('./footer.cjs');
7
+ const chars = require('../../constants/chars.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;
@@ -51,23 +51,13 @@ class EmbedPlusBuilder extends discord_js.EmbedBuilder {
51
51
  toArray() {
52
52
  return Array.from([this]);
53
53
  }
54
- /**
55
- *
56
- * @param data
57
- * @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.
58
- * @returns AttachmentBuilder
59
- *
60
- * Create a json attachment file from this embed
61
- */
62
- toAttachment(data, space = 2) {
63
- return new discord_js.AttachmentBuilder(
64
- Buffer.from(this.toString(space), "utf-8"),
65
- data ?? (data = { name: "embed.json" })
66
- );
67
- }
68
54
  toString(space = 2) {
69
55
  return JSON.stringify(this, null, space);
70
56
  }
57
+ toAttachment(data = { name: "embed.png" }, space = 2) {
58
+ const buffer = Buffer.from(this.toString(space), "utf-8");
59
+ return new discord_js.AttachmentBuilder(buffer, data);
60
+ }
71
61
  setBorderColor(color) {
72
62
  if (color === null) {
73
63
  this.setColor("#2B2D31");
@@ -79,10 +69,32 @@ class EmbedPlusBuilder extends discord_js.EmbedBuilder {
79
69
  return this;
80
70
  }
81
71
  setAsset(asset, source) {
82
- if (source === null) {
83
- asset === "image" ? this.setImage(source) : this.setThumbnail(source);
84
- } else {
85
- this.update({ [asset]: source });
72
+ this.update({ [asset]: source });
73
+ return this;
74
+ }
75
+ setElementImageURL(element, url) {
76
+ switch (element) {
77
+ case "thumbnail":
78
+ case "image": {
79
+ this.setAsset(element, url);
80
+ break;
81
+ }
82
+ case "author": {
83
+ const author = this.data.author;
84
+ this.setAuthor({
85
+ name: author?.name ?? chars.chars.invisible,
86
+ iconURL: url ?? void 0
87
+ });
88
+ break;
89
+ }
90
+ case "footer": {
91
+ const footer = this.data.footer;
92
+ this.setFooter({
93
+ text: footer?.text ?? chars.chars.invisible,
94
+ iconURL: url ?? void 0
95
+ });
96
+ break;
97
+ }
86
98
  }
87
99
  return this;
88
100
  }
@@ -94,8 +106,8 @@ class EmbedPlusBuilder extends discord_js.EmbedBuilder {
94
106
  }
95
107
  }
96
108
  function createEmbed(options) {
97
- const { array = false, interaction, ...data } = options;
98
- const embed = interaction ? EmbedPlusBuilder.fromInteraction(interaction, 0, data) : new EmbedPlusBuilder(data);
109
+ const { array = false, from, fromIndex = 0, ...data } = options;
110
+ const embed = from ? "message" in from ? EmbedPlusBuilder.fromInteraction(from, fromIndex, data) : EmbedPlusBuilder.fromMessage(from, fromIndex, data) : new EmbedPlusBuilder(data);
99
111
  return array ? [embed] : embed;
100
112
  }
101
113
 
@@ -1,8 +1,8 @@
1
1
  import { EmbedBuilder, AttachmentBuilder } from 'discord.js';
2
- import { chars } from '../../constants/chars.mjs';
3
2
  import { createEmbedAsset } from './assets.mjs';
4
3
  import { EmbedPlusFields } from './fields.mjs';
5
4
  import { createEmbedFooter } from './footer.mjs';
5
+ import { chars } from '../../constants/chars.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;
@@ -49,23 +49,13 @@ class EmbedPlusBuilder extends EmbedBuilder {
49
49
  toArray() {
50
50
  return Array.from([this]);
51
51
  }
52
- /**
53
- *
54
- * @param data
55
- * @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.
56
- * @returns AttachmentBuilder
57
- *
58
- * Create a json attachment file from this embed
59
- */
60
- toAttachment(data, space = 2) {
61
- return new AttachmentBuilder(
62
- Buffer.from(this.toString(space), "utf-8"),
63
- data ?? (data = { name: "embed.json" })
64
- );
65
- }
66
52
  toString(space = 2) {
67
53
  return JSON.stringify(this, null, space);
68
54
  }
55
+ toAttachment(data = { name: "embed.png" }, space = 2) {
56
+ const buffer = Buffer.from(this.toString(space), "utf-8");
57
+ return new AttachmentBuilder(buffer, data);
58
+ }
69
59
  setBorderColor(color) {
70
60
  if (color === null) {
71
61
  this.setColor("#2B2D31");
@@ -77,10 +67,32 @@ class EmbedPlusBuilder extends EmbedBuilder {
77
67
  return this;
78
68
  }
79
69
  setAsset(asset, source) {
80
- if (source === null) {
81
- asset === "image" ? this.setImage(source) : this.setThumbnail(source);
82
- } else {
83
- this.update({ [asset]: source });
70
+ this.update({ [asset]: source });
71
+ return this;
72
+ }
73
+ setElementImageURL(element, url) {
74
+ switch (element) {
75
+ case "thumbnail":
76
+ case "image": {
77
+ this.setAsset(element, url);
78
+ break;
79
+ }
80
+ case "author": {
81
+ const author = this.data.author;
82
+ this.setAuthor({
83
+ name: author?.name ?? chars.invisible,
84
+ iconURL: url ?? void 0
85
+ });
86
+ break;
87
+ }
88
+ case "footer": {
89
+ const footer = this.data.footer;
90
+ this.setFooter({
91
+ text: footer?.text ?? chars.invisible,
92
+ iconURL: url ?? void 0
93
+ });
94
+ break;
95
+ }
84
96
  }
85
97
  return this;
86
98
  }
@@ -92,8 +104,8 @@ class EmbedPlusBuilder extends EmbedBuilder {
92
104
  }
93
105
  }
94
106
  function createEmbed(options) {
95
- const { array = false, interaction, ...data } = options;
96
- const embed = interaction ? EmbedPlusBuilder.fromInteraction(interaction, 0, data) : new EmbedPlusBuilder(data);
107
+ const { array = false, from, fromIndex = 0, ...data } = options;
108
+ const embed = from ? "message" in from ? EmbedPlusBuilder.fromInteraction(from, fromIndex, data) : EmbedPlusBuilder.fromMessage(from, fromIndex, data) : new EmbedPlusBuilder(data);
97
109
  return array ? [embed] : embed;
98
110
  }
99
111
 
@@ -0,0 +1,31 @@
1
+ 'use strict';
2
+
3
+ const discord_js = require('discord.js');
4
+
5
+ function createEmbedFiles(embed, options) {
6
+ const { thumbnail, image, footer, author } = embed.data;
7
+ const files = [];
8
+ const handle = (url, name, ext = "png") => {
9
+ files.push(new discord_js.AttachmentBuilder(url, { name: `${name}.${ext}` }));
10
+ return `attachment://${name}.${ext}`;
11
+ };
12
+ if (thumbnail?.url) {
13
+ const url = handle(thumbnail.url, "thumbnail", options?.extentions?.thumbnail);
14
+ embed.setThumbnail(url);
15
+ }
16
+ if (image?.url) {
17
+ const url = handle(image.url, "image", options?.extentions?.image);
18
+ embed.setImage(url);
19
+ }
20
+ if (author?.icon_url) {
21
+ const url = handle(author?.icon_url, "author", options?.extentions?.author);
22
+ embed.setAuthor({ name: author.name, iconURL: url, url: author.url });
23
+ }
24
+ if (footer?.icon_url) {
25
+ const url = handle(footer.icon_url, "footer", options?.extentions?.footer);
26
+ embed.setFooter({ text: footer.text, iconURL: url });
27
+ }
28
+ return files;
29
+ }
30
+
31
+ exports.createEmbedFiles = createEmbedFiles;
@@ -0,0 +1,29 @@
1
+ import { AttachmentBuilder } from 'discord.js';
2
+
3
+ function createEmbedFiles(embed, options) {
4
+ const { thumbnail, image, footer, author } = embed.data;
5
+ const files = [];
6
+ const handle = (url, name, ext = "png") => {
7
+ files.push(new AttachmentBuilder(url, { name: `${name}.${ext}` }));
8
+ return `attachment://${name}.${ext}`;
9
+ };
10
+ if (thumbnail?.url) {
11
+ const url = handle(thumbnail.url, "thumbnail", options?.extentions?.thumbnail);
12
+ embed.setThumbnail(url);
13
+ }
14
+ if (image?.url) {
15
+ const url = handle(image.url, "image", options?.extentions?.image);
16
+ embed.setImage(url);
17
+ }
18
+ if (author?.icon_url) {
19
+ const url = handle(author?.icon_url, "author", options?.extentions?.author);
20
+ embed.setAuthor({ name: author.name, iconURL: url, url: author.url });
21
+ }
22
+ if (footer?.icon_url) {
23
+ const url = handle(footer.icon_url, "footer", options?.extentions?.footer);
24
+ embed.setFooter({ text: footer.text, iconURL: url });
25
+ }
26
+ return files;
27
+ }
28
+
29
+ export { createEmbedFiles };
@@ -3,7 +3,9 @@
3
3
  const discord_js = require('discord.js');
4
4
 
5
5
  function setMobileStatus() {
6
- discord_js.DefaultWebSocketManagerOptions.identifyProperties.browser = "Discord Android";
6
+ Object.assign(discord_js.DefaultWebSocketManagerOptions.identifyProperties, {
7
+ browser: "Discord Android"
8
+ });
7
9
  }
8
10
 
9
11
  exports.setMobileStatus = setMobileStatus;
@@ -1,7 +1,9 @@
1
1
  import { DefaultWebSocketManagerOptions } from 'discord.js';
2
2
 
3
3
  function setMobileStatus() {
4
- DefaultWebSocketManagerOptions.identifyProperties.browser = "Discord Android";
4
+ Object.assign(DefaultWebSocketManagerOptions.identifyProperties, {
5
+ browser: "Discord Android"
6
+ });
5
7
  }
6
8
 
7
9
  export { setMobileStatus };
package/dist/index.cjs CHANGED
@@ -7,6 +7,7 @@ const assets = require('./functions/embeds/assets.cjs');
7
7
  const author = require('./functions/embeds/author.cjs');
8
8
  const embedplus = require('./functions/embeds/embedplus.cjs');
9
9
  const footer = require('./functions/embeds/footer.cjs');
10
+ const files = require('./functions/embeds/files.cjs');
10
11
  const components = require('./functions/components.cjs');
11
12
  const channels = require('./functions/channels.cjs');
12
13
  const commands = require('./functions/commands.cjs');
@@ -29,6 +30,7 @@ exports.createEmbedAuthor = author.createEmbedAuthor;
29
30
  exports.EmbedPlusBuilder = embedplus.EmbedPlusBuilder;
30
31
  exports.createEmbed = embedplus.createEmbed;
31
32
  exports.createEmbedFooter = footer.createEmbedFooter;
33
+ exports.createEmbedFiles = files.createEmbedFiles;
32
34
  exports.createLinkButton = components.createLinkButton;
33
35
  exports.createRow = components.createRow;
34
36
  exports.findChannel = channels.findChannel;
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, ImageURLOptions, EmbedFooterData, APIEmbed, Embed, EmbedData, EmbedBuilder, AttachmentData, ColorResolvable, AnyComponentBuilder, ActionRowBuilder, ButtonBuilder, LinkButtonComponentData, ChannelType, CommandInteractionOption, Client, ApplicationCommand, TextInputBuilder, ModalSubmitFields, Collection, TextInputComponent, 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, ModalSubmitFields, Collection, TextInputComponent, TextInputComponentData, GuildEmoji, GuildTextBasedChannel, Message, Role } from 'discord.js';
3
3
  export * from '@magicyan/core';
4
4
 
5
5
  declare const chars: {
@@ -23,21 +23,27 @@ type EmbedAssetOptions = Omit<EmbedAssetData, "url">;
23
23
  declare function createEmbedAsset(source: EmbedPlusAssetData, options?: EmbedAssetOptions): EmbedAssetData | undefined;
24
24
 
25
25
  interface MemberAuthor {
26
+ type: GuildMember;
26
27
  property?: "username" | "displayName" | "id" | "globalName" | "nickname";
27
28
  }
28
29
  interface UserAuthor {
30
+ type: User | ClientUser;
29
31
  property?: "username" | "displayName" | "id" | "globalName";
30
32
  }
31
33
  interface GuildAuthor {
34
+ type: Guild;
32
35
  property?: "name" | "id";
33
36
  }
34
- type AuthorType = Guild | GuildMember | User;
37
+ type AuthorOption = MemberAuthor | UserAuthor | GuildAuthor;
38
+ type AuthorType = Guild | GuildMember | User | ClientUser;
35
39
  type CreateEmbedAuthorOptions<T extends AuthorType> = {
36
40
  iconURL?: string;
37
41
  url?: string | null;
38
42
  prefix?: string;
39
43
  suffix?: string;
40
- } & ImageURLOptions & (T extends User ? UserAuthor : T extends GuildMember ? MemberAuthor : T extends Guild ? GuildAuthor : never);
44
+ } & ImageURLOptions & Omit<Extract<AuthorOption, {
45
+ type: T;
46
+ }>, "type">;
41
47
  declare function createEmbedAuthor<T extends AuthorType>(type: T, options?: CreateEmbedAuthorOptions<T>): {
42
48
  name: string;
43
49
  url: string | undefined;
@@ -125,29 +131,34 @@ declare class EmbedPlusBuilder extends EmbedBuilder {
125
131
  update(data: EmbedPlusData): this;
126
132
  has(property: keyof EmbedPlusData): boolean;
127
133
  toArray(): EmbedPlusBuilder[];
128
- /**
129
- *
130
- * @param data
131
- * @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.
132
- * @returns AttachmentBuilder
133
- *
134
- * Create a json attachment file from this embed
135
- */
136
- toAttachment(data?: AttachmentData, space?: number): AttachmentBuilder;
137
134
  toString(space?: number): string;
135
+ toAttachment(data?: AttachmentData, space?: number): AttachmentBuilder;
138
136
  setBorderColor(color: EmbedPlusColorData | null): this;
139
137
  setAsset(asset: "thumbnail" | "image", source: EmbedPlusAssetData): this;
138
+ setElementImageURL(element: "thumbnail" | "image" | "author" | "footer", url: string | null): this;
140
139
  static fromInteraction(interaction: InteractionWithEmbeds, index?: number, data?: EmbedPlusData): EmbedPlusBuilder;
141
140
  static fromMessage(message: MessageWithEmbeds, index?: number, data?: EmbedPlusData): EmbedPlusBuilder;
142
141
  }
143
142
  type EmbedPlusProperty<P extends keyof EmbedPlusData> = EmbedPlusData[P];
144
143
  interface CreateEmbedOptions<B extends boolean> extends EmbedPlusOptions {
145
144
  array?: B;
146
- interaction?: InteractionWithEmbeds;
145
+ from?: InteractionWithEmbeds | MessageWithEmbeds;
146
+ fromIndex?: number;
147
147
  }
148
148
  type CreateEmbedReturn<B> = undefined extends B ? EmbedPlusBuilder : false extends B ? EmbedPlusBuilder : EmbedPlusBuilder[];
149
149
  declare function createEmbed<B extends boolean>(options: CreateEmbedOptions<B>): CreateEmbedReturn<B>;
150
150
 
151
+ type ImageFileExtention = "png" | "jpg" | "gif" | "webp";
152
+ type ImageElementProperty = "author" | "thumbnail" | "image" | "footer";
153
+ interface CreateEmbedFilesOptions {
154
+ extentions?: Record<ImageElementProperty, ImageFileExtention>;
155
+ }
156
+ /**
157
+ *
158
+ * Turns any embed image url into an attachment and returns an attachment array
159
+ */
160
+ declare function createEmbedFiles(embed: EmbedPlusBuilder, options?: CreateEmbedFilesOptions): AttachmentBuilder[];
161
+
151
162
  declare function createRow<Component extends AnyComponentBuilder>(...components: Component[]): ActionRowBuilder<Component>;
152
163
  interface CreateLinkButtonData extends Omit<LinkButtonComponentData, "style" | "type"> {
153
164
  }
@@ -159,17 +170,17 @@ type GetChannelType<Type extends GuildChannelType> = Extract<NonNullable<Command
159
170
  type: Type extends ChannelType.PublicThread | ChannelType.AnnouncementThread ? ChannelType.PublicThread | ChannelType.AnnouncementThread : Type;
160
171
  }>;
161
172
  declare function findChannel<Type extends GuildChannelType = ChannelType.GuildText>(guild: Guild, type?: Type): {
162
- byName(name: string, filter?: FindChannelFilter<Type>): GetChannelType<Type> | undefined;
163
173
  byId(id: string): GetChannelType<Type> | undefined;
174
+ byName(name: string, and?: FindChannelFilter<Type>): GetChannelType<Type> | undefined;
164
175
  byFilter(filter: FindChannelFilter<Type>): GetChannelType<Type> | undefined;
165
176
  inCategoryId(id: string): {
166
- byName(name: string, filter?: FindChannelFilter<Type>): GetChannelType<Type> | undefined;
167
- byId(id: string, filter?: FindChannelFilter<Type>): GetChannelType<Type> | undefined;
177
+ byId(id: string): GetChannelType<Type> | undefined;
178
+ byName(name: string, and?: FindChannelFilter<Type>): GetChannelType<Type> | undefined;
168
179
  byFilter(filter: FindChannelFilter<Type>): GetChannelType<Type> | undefined;
169
180
  };
170
181
  inCategoryName(name: string): {
171
- byName(name: string, filter?: FindChannelFilter<Type>): GetChannelType<Type> | undefined;
172
- byId(id: string, filter?: FindChannelFilter<Type>): GetChannelType<Type> | undefined;
182
+ byId(id: string): GetChannelType<Type> | undefined;
183
+ byName(name: string, and?: FindChannelFilter<Type>): GetChannelType<Type> | undefined;
173
184
  byFilter(filter: FindChannelFilter<Type>): GetChannelType<Type> | undefined;
174
185
  };
175
186
  };
@@ -270,4 +281,4 @@ declare function findRole(guild: Guild): {
270
281
  */
271
282
  declare function extractMentionId(mention: string): string | null;
272
283
 
273
- export { type AnyEmbedData, 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 };
284
+ export { type AnyEmbedData, CustomItents, CustomPartials, type EmbedPlusAssetData, type EmbedPlusAuthorData, EmbedPlusBuilder, type EmbedPlusColorData, type EmbedPlusData, type EmbedPlusFooterData, type EmbedPlusProperty, chars, createEmbed, createEmbedAsset, createEmbedAuthor, createEmbedFiles, 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, Attachment, AttachmentBuilder, EmbedAssetData, Guild, GuildMember, User, ImageURLOptions, EmbedFooterData, APIEmbed, Embed, EmbedData, EmbedBuilder, AttachmentData, ColorResolvable, AnyComponentBuilder, ActionRowBuilder, ButtonBuilder, LinkButtonComponentData, ChannelType, CommandInteractionOption, Client, ApplicationCommand, TextInputBuilder, ModalSubmitFields, Collection, TextInputComponent, 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, ModalSubmitFields, Collection, TextInputComponent, TextInputComponentData, GuildEmoji, GuildTextBasedChannel, Message, Role } from 'discord.js';
3
3
  export * from '@magicyan/core';
4
4
 
5
5
  declare const chars: {
@@ -23,21 +23,27 @@ type EmbedAssetOptions = Omit<EmbedAssetData, "url">;
23
23
  declare function createEmbedAsset(source: EmbedPlusAssetData, options?: EmbedAssetOptions): EmbedAssetData | undefined;
24
24
 
25
25
  interface MemberAuthor {
26
+ type: GuildMember;
26
27
  property?: "username" | "displayName" | "id" | "globalName" | "nickname";
27
28
  }
28
29
  interface UserAuthor {
30
+ type: User | ClientUser;
29
31
  property?: "username" | "displayName" | "id" | "globalName";
30
32
  }
31
33
  interface GuildAuthor {
34
+ type: Guild;
32
35
  property?: "name" | "id";
33
36
  }
34
- type AuthorType = Guild | GuildMember | User;
37
+ type AuthorOption = MemberAuthor | UserAuthor | GuildAuthor;
38
+ type AuthorType = Guild | GuildMember | User | ClientUser;
35
39
  type CreateEmbedAuthorOptions<T extends AuthorType> = {
36
40
  iconURL?: string;
37
41
  url?: string | null;
38
42
  prefix?: string;
39
43
  suffix?: string;
40
- } & ImageURLOptions & (T extends User ? UserAuthor : T extends GuildMember ? MemberAuthor : T extends Guild ? GuildAuthor : never);
44
+ } & ImageURLOptions & Omit<Extract<AuthorOption, {
45
+ type: T;
46
+ }>, "type">;
41
47
  declare function createEmbedAuthor<T extends AuthorType>(type: T, options?: CreateEmbedAuthorOptions<T>): {
42
48
  name: string;
43
49
  url: string | undefined;
@@ -125,29 +131,34 @@ declare class EmbedPlusBuilder extends EmbedBuilder {
125
131
  update(data: EmbedPlusData): this;
126
132
  has(property: keyof EmbedPlusData): boolean;
127
133
  toArray(): EmbedPlusBuilder[];
128
- /**
129
- *
130
- * @param data
131
- * @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.
132
- * @returns AttachmentBuilder
133
- *
134
- * Create a json attachment file from this embed
135
- */
136
- toAttachment(data?: AttachmentData, space?: number): AttachmentBuilder;
137
134
  toString(space?: number): string;
135
+ toAttachment(data?: AttachmentData, space?: number): AttachmentBuilder;
138
136
  setBorderColor(color: EmbedPlusColorData | null): this;
139
137
  setAsset(asset: "thumbnail" | "image", source: EmbedPlusAssetData): this;
138
+ setElementImageURL(element: "thumbnail" | "image" | "author" | "footer", url: string | null): this;
140
139
  static fromInteraction(interaction: InteractionWithEmbeds, index?: number, data?: EmbedPlusData): EmbedPlusBuilder;
141
140
  static fromMessage(message: MessageWithEmbeds, index?: number, data?: EmbedPlusData): EmbedPlusBuilder;
142
141
  }
143
142
  type EmbedPlusProperty<P extends keyof EmbedPlusData> = EmbedPlusData[P];
144
143
  interface CreateEmbedOptions<B extends boolean> extends EmbedPlusOptions {
145
144
  array?: B;
146
- interaction?: InteractionWithEmbeds;
145
+ from?: InteractionWithEmbeds | MessageWithEmbeds;
146
+ fromIndex?: number;
147
147
  }
148
148
  type CreateEmbedReturn<B> = undefined extends B ? EmbedPlusBuilder : false extends B ? EmbedPlusBuilder : EmbedPlusBuilder[];
149
149
  declare function createEmbed<B extends boolean>(options: CreateEmbedOptions<B>): CreateEmbedReturn<B>;
150
150
 
151
+ type ImageFileExtention = "png" | "jpg" | "gif" | "webp";
152
+ type ImageElementProperty = "author" | "thumbnail" | "image" | "footer";
153
+ interface CreateEmbedFilesOptions {
154
+ extentions?: Record<ImageElementProperty, ImageFileExtention>;
155
+ }
156
+ /**
157
+ *
158
+ * Turns any embed image url into an attachment and returns an attachment array
159
+ */
160
+ declare function createEmbedFiles(embed: EmbedPlusBuilder, options?: CreateEmbedFilesOptions): AttachmentBuilder[];
161
+
151
162
  declare function createRow<Component extends AnyComponentBuilder>(...components: Component[]): ActionRowBuilder<Component>;
152
163
  interface CreateLinkButtonData extends Omit<LinkButtonComponentData, "style" | "type"> {
153
164
  }
@@ -159,17 +170,17 @@ type GetChannelType<Type extends GuildChannelType> = Extract<NonNullable<Command
159
170
  type: Type extends ChannelType.PublicThread | ChannelType.AnnouncementThread ? ChannelType.PublicThread | ChannelType.AnnouncementThread : Type;
160
171
  }>;
161
172
  declare function findChannel<Type extends GuildChannelType = ChannelType.GuildText>(guild: Guild, type?: Type): {
162
- byName(name: string, filter?: FindChannelFilter<Type>): GetChannelType<Type> | undefined;
163
173
  byId(id: string): GetChannelType<Type> | undefined;
174
+ byName(name: string, and?: FindChannelFilter<Type>): GetChannelType<Type> | undefined;
164
175
  byFilter(filter: FindChannelFilter<Type>): GetChannelType<Type> | undefined;
165
176
  inCategoryId(id: string): {
166
- byName(name: string, filter?: FindChannelFilter<Type>): GetChannelType<Type> | undefined;
167
- byId(id: string, filter?: FindChannelFilter<Type>): GetChannelType<Type> | undefined;
177
+ byId(id: string): GetChannelType<Type> | undefined;
178
+ byName(name: string, and?: FindChannelFilter<Type>): GetChannelType<Type> | undefined;
168
179
  byFilter(filter: FindChannelFilter<Type>): GetChannelType<Type> | undefined;
169
180
  };
170
181
  inCategoryName(name: string): {
171
- byName(name: string, filter?: FindChannelFilter<Type>): GetChannelType<Type> | undefined;
172
- byId(id: string, filter?: FindChannelFilter<Type>): GetChannelType<Type> | undefined;
182
+ byId(id: string): GetChannelType<Type> | undefined;
183
+ byName(name: string, and?: FindChannelFilter<Type>): GetChannelType<Type> | undefined;
173
184
  byFilter(filter: FindChannelFilter<Type>): GetChannelType<Type> | undefined;
174
185
  };
175
186
  };
@@ -270,4 +281,4 @@ declare function findRole(guild: Guild): {
270
281
  */
271
282
  declare function extractMentionId(mention: string): string | null;
272
283
 
273
- export { type AnyEmbedData, 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 };
284
+ export { type AnyEmbedData, CustomItents, CustomPartials, type EmbedPlusAssetData, type EmbedPlusAuthorData, EmbedPlusBuilder, type EmbedPlusColorData, type EmbedPlusData, type EmbedPlusFooterData, type EmbedPlusProperty, chars, createEmbed, createEmbedAsset, createEmbedAuthor, createEmbedFiles, 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, Attachment, AttachmentBuilder, EmbedAssetData, Guild, GuildMember, User, ImageURLOptions, EmbedFooterData, APIEmbed, Embed, EmbedData, EmbedBuilder, AttachmentData, ColorResolvable, AnyComponentBuilder, ActionRowBuilder, ButtonBuilder, LinkButtonComponentData, ChannelType, CommandInteractionOption, Client, ApplicationCommand, TextInputBuilder, ModalSubmitFields, Collection, TextInputComponent, 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, ModalSubmitFields, Collection, TextInputComponent, TextInputComponentData, GuildEmoji, GuildTextBasedChannel, Message, Role } from 'discord.js';
3
3
  export * from '@magicyan/core';
4
4
 
5
5
  declare const chars: {
@@ -23,21 +23,27 @@ type EmbedAssetOptions = Omit<EmbedAssetData, "url">;
23
23
  declare function createEmbedAsset(source: EmbedPlusAssetData, options?: EmbedAssetOptions): EmbedAssetData | undefined;
24
24
 
25
25
  interface MemberAuthor {
26
+ type: GuildMember;
26
27
  property?: "username" | "displayName" | "id" | "globalName" | "nickname";
27
28
  }
28
29
  interface UserAuthor {
30
+ type: User | ClientUser;
29
31
  property?: "username" | "displayName" | "id" | "globalName";
30
32
  }
31
33
  interface GuildAuthor {
34
+ type: Guild;
32
35
  property?: "name" | "id";
33
36
  }
34
- type AuthorType = Guild | GuildMember | User;
37
+ type AuthorOption = MemberAuthor | UserAuthor | GuildAuthor;
38
+ type AuthorType = Guild | GuildMember | User | ClientUser;
35
39
  type CreateEmbedAuthorOptions<T extends AuthorType> = {
36
40
  iconURL?: string;
37
41
  url?: string | null;
38
42
  prefix?: string;
39
43
  suffix?: string;
40
- } & ImageURLOptions & (T extends User ? UserAuthor : T extends GuildMember ? MemberAuthor : T extends Guild ? GuildAuthor : never);
44
+ } & ImageURLOptions & Omit<Extract<AuthorOption, {
45
+ type: T;
46
+ }>, "type">;
41
47
  declare function createEmbedAuthor<T extends AuthorType>(type: T, options?: CreateEmbedAuthorOptions<T>): {
42
48
  name: string;
43
49
  url: string | undefined;
@@ -125,29 +131,34 @@ declare class EmbedPlusBuilder extends EmbedBuilder {
125
131
  update(data: EmbedPlusData): this;
126
132
  has(property: keyof EmbedPlusData): boolean;
127
133
  toArray(): EmbedPlusBuilder[];
128
- /**
129
- *
130
- * @param data
131
- * @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.
132
- * @returns AttachmentBuilder
133
- *
134
- * Create a json attachment file from this embed
135
- */
136
- toAttachment(data?: AttachmentData, space?: number): AttachmentBuilder;
137
134
  toString(space?: number): string;
135
+ toAttachment(data?: AttachmentData, space?: number): AttachmentBuilder;
138
136
  setBorderColor(color: EmbedPlusColorData | null): this;
139
137
  setAsset(asset: "thumbnail" | "image", source: EmbedPlusAssetData): this;
138
+ setElementImageURL(element: "thumbnail" | "image" | "author" | "footer", url: string | null): this;
140
139
  static fromInteraction(interaction: InteractionWithEmbeds, index?: number, data?: EmbedPlusData): EmbedPlusBuilder;
141
140
  static fromMessage(message: MessageWithEmbeds, index?: number, data?: EmbedPlusData): EmbedPlusBuilder;
142
141
  }
143
142
  type EmbedPlusProperty<P extends keyof EmbedPlusData> = EmbedPlusData[P];
144
143
  interface CreateEmbedOptions<B extends boolean> extends EmbedPlusOptions {
145
144
  array?: B;
146
- interaction?: InteractionWithEmbeds;
145
+ from?: InteractionWithEmbeds | MessageWithEmbeds;
146
+ fromIndex?: number;
147
147
  }
148
148
  type CreateEmbedReturn<B> = undefined extends B ? EmbedPlusBuilder : false extends B ? EmbedPlusBuilder : EmbedPlusBuilder[];
149
149
  declare function createEmbed<B extends boolean>(options: CreateEmbedOptions<B>): CreateEmbedReturn<B>;
150
150
 
151
+ type ImageFileExtention = "png" | "jpg" | "gif" | "webp";
152
+ type ImageElementProperty = "author" | "thumbnail" | "image" | "footer";
153
+ interface CreateEmbedFilesOptions {
154
+ extentions?: Record<ImageElementProperty, ImageFileExtention>;
155
+ }
156
+ /**
157
+ *
158
+ * Turns any embed image url into an attachment and returns an attachment array
159
+ */
160
+ declare function createEmbedFiles(embed: EmbedPlusBuilder, options?: CreateEmbedFilesOptions): AttachmentBuilder[];
161
+
151
162
  declare function createRow<Component extends AnyComponentBuilder>(...components: Component[]): ActionRowBuilder<Component>;
152
163
  interface CreateLinkButtonData extends Omit<LinkButtonComponentData, "style" | "type"> {
153
164
  }
@@ -159,17 +170,17 @@ type GetChannelType<Type extends GuildChannelType> = Extract<NonNullable<Command
159
170
  type: Type extends ChannelType.PublicThread | ChannelType.AnnouncementThread ? ChannelType.PublicThread | ChannelType.AnnouncementThread : Type;
160
171
  }>;
161
172
  declare function findChannel<Type extends GuildChannelType = ChannelType.GuildText>(guild: Guild, type?: Type): {
162
- byName(name: string, filter?: FindChannelFilter<Type>): GetChannelType<Type> | undefined;
163
173
  byId(id: string): GetChannelType<Type> | undefined;
174
+ byName(name: string, and?: FindChannelFilter<Type>): GetChannelType<Type> | undefined;
164
175
  byFilter(filter: FindChannelFilter<Type>): GetChannelType<Type> | undefined;
165
176
  inCategoryId(id: string): {
166
- byName(name: string, filter?: FindChannelFilter<Type>): GetChannelType<Type> | undefined;
167
- byId(id: string, filter?: FindChannelFilter<Type>): GetChannelType<Type> | undefined;
177
+ byId(id: string): GetChannelType<Type> | undefined;
178
+ byName(name: string, and?: FindChannelFilter<Type>): GetChannelType<Type> | undefined;
168
179
  byFilter(filter: FindChannelFilter<Type>): GetChannelType<Type> | undefined;
169
180
  };
170
181
  inCategoryName(name: string): {
171
- byName(name: string, filter?: FindChannelFilter<Type>): GetChannelType<Type> | undefined;
172
- byId(id: string, filter?: FindChannelFilter<Type>): GetChannelType<Type> | undefined;
182
+ byId(id: string): GetChannelType<Type> | undefined;
183
+ byName(name: string, and?: FindChannelFilter<Type>): GetChannelType<Type> | undefined;
173
184
  byFilter(filter: FindChannelFilter<Type>): GetChannelType<Type> | undefined;
174
185
  };
175
186
  };
@@ -270,4 +281,4 @@ declare function findRole(guild: Guild): {
270
281
  */
271
282
  declare function extractMentionId(mention: string): string | null;
272
283
 
273
- export { type AnyEmbedData, 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 };
284
+ export { type AnyEmbedData, CustomItents, CustomPartials, type EmbedPlusAssetData, type EmbedPlusAuthorData, EmbedPlusBuilder, type EmbedPlusColorData, type EmbedPlusData, type EmbedPlusFooterData, type EmbedPlusProperty, chars, createEmbed, createEmbedAsset, createEmbedAuthor, createEmbedFiles, createEmbedFooter, createLinkButton, createModalFields, createModalInput, createRow, extractMentionId, findChannel, findCommand, findEmoji, findMember, findMessage, findRole, getChannelUrlInfo, getMessageUrlInfo, modalFieldsToRecord, setMobileStatus };
package/dist/index.mjs CHANGED
@@ -5,6 +5,7 @@ export { createEmbedAsset } from './functions/embeds/assets.mjs';
5
5
  export { createEmbedAuthor } from './functions/embeds/author.mjs';
6
6
  export { EmbedPlusBuilder, createEmbed } from './functions/embeds/embedplus.mjs';
7
7
  export { createEmbedFooter } from './functions/embeds/footer.mjs';
8
+ export { createEmbedFiles } from './functions/embeds/files.mjs';
8
9
  export { createLinkButton, createRow } from './functions/components.mjs';
9
10
  export { findChannel, getChannelUrlInfo } from './functions/channels.mjs';
10
11
  export { findCommand } from './functions/commands.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magicyan/discord",
3
- "version": "1.0.29",
3
+ "version": "1.0.31",
4
4
  "description": "Simple functions to facilitate discord bot development",
5
5
  "license": "MIT",
6
6
  "type": "module",