seyfert 1.3.3 → 1.5.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.
Files changed (138) hide show
  1. package/README.md +7 -7
  2. package/lib/api/Router.js +3 -1
  3. package/lib/api/Routes/guilds.d.ts +4 -1
  4. package/lib/api/api.js +13 -7
  5. package/lib/builders/Attachment.d.ts +1 -4
  6. package/lib/builders/Attachment.js +4 -4
  7. package/lib/cache/adapters/workeradapter.js +7 -3
  8. package/lib/cache/index.d.ts +6 -2
  9. package/lib/cache/index.js +18 -0
  10. package/lib/cache/resources/bans.d.ts +12 -0
  11. package/lib/cache/resources/bans.js +35 -0
  12. package/lib/cache/resources/default/base.d.ts +1 -2
  13. package/lib/cache/resources/default/guild-based.d.ts +1 -2
  14. package/lib/cache/resources/members.js +4 -4
  15. package/lib/cache/resources/messages.js +8 -6
  16. package/lib/client/base.d.ts +33 -7
  17. package/lib/client/base.js +80 -21
  18. package/lib/client/client.d.ts +18 -6
  19. package/lib/client/client.js +45 -37
  20. package/lib/client/collectors.d.ts +36 -0
  21. package/lib/client/collectors.js +85 -0
  22. package/lib/client/httpclient.d.ts +7 -8
  23. package/lib/client/httpclient.js +96 -17
  24. package/lib/client/oninteractioncreate.d.ts +2 -2
  25. package/lib/client/oninteractioncreate.js +15 -7
  26. package/lib/client/onmessagecreate.d.ts +12 -2
  27. package/lib/client/onmessagecreate.js +105 -82
  28. package/lib/client/workerclient.d.ts +5 -2
  29. package/lib/client/workerclient.js +66 -63
  30. package/lib/collection.d.ts +2 -2
  31. package/lib/collection.js +2 -2
  32. package/lib/commands/applications/chat.d.ts +11 -10
  33. package/lib/commands/applications/chat.js +23 -8
  34. package/lib/commands/applications/chatcontext.d.ts +1 -1
  35. package/lib/commands/applications/chatcontext.js +2 -2
  36. package/lib/commands/applications/menu.d.ts +8 -7
  37. package/lib/commands/applications/menu.js +3 -50
  38. package/lib/commands/applications/menucontext.d.ts +1 -1
  39. package/lib/commands/applications/menucontext.js +3 -3
  40. package/lib/commands/applications/options.d.ts +3 -1
  41. package/lib/commands/applications/shared.d.ts +12 -0
  42. package/lib/commands/basecontext.d.ts +26 -0
  43. package/lib/commands/{basecontex.js → basecontext.js} +24 -0
  44. package/lib/commands/decorators.d.ts +11 -17
  45. package/lib/commands/decorators.js +7 -14
  46. package/lib/commands/handler.d.ts +6 -1
  47. package/lib/commands/handler.js +161 -29
  48. package/lib/common/bot/watcher.d.ts +1 -2
  49. package/lib/common/bot/watcher.js +9 -4
  50. package/lib/common/index.d.ts +1 -0
  51. package/lib/common/index.js +3 -1
  52. package/lib/common/it/formatter.d.ts +155 -0
  53. package/lib/common/it/formatter.js +184 -0
  54. package/lib/common/it/logger.d.ts +1 -1
  55. package/lib/common/it/logger.js +14 -13
  56. package/lib/common/it/utils.d.ts +2 -0
  57. package/lib/common/it/utils.js +21 -9
  58. package/lib/common/shorters/bans.d.ts +43 -0
  59. package/lib/common/shorters/bans.js +78 -0
  60. package/lib/common/shorters/emojis.d.ts +1 -1
  61. package/lib/common/shorters/emojis.js +4 -3
  62. package/lib/common/shorters/interaction.js +9 -7
  63. package/lib/common/shorters/messages.js +2 -2
  64. package/lib/common/shorters/webhook.js +2 -2
  65. package/lib/components/componentcommand.d.ts +22 -0
  66. package/lib/components/{command.js → componentcommand.js} +3 -5
  67. package/lib/components/componentcontext.d.ts +20 -16
  68. package/lib/components/componentcontext.js +27 -9
  69. package/lib/components/handler.d.ts +11 -6
  70. package/lib/components/handler.js +106 -32
  71. package/lib/components/index.d.ts +3 -1
  72. package/lib/components/index.js +3 -1
  73. package/lib/components/modalcommand.d.ts +16 -0
  74. package/lib/components/modalcommand.js +10 -0
  75. package/lib/components/modalcontext.d.ts +104 -0
  76. package/lib/components/modalcontext.js +132 -0
  77. package/lib/events/event.d.ts +4 -3
  78. package/lib/events/handler.d.ts +12 -6
  79. package/lib/events/handler.js +60 -20
  80. package/lib/events/hooks/application_command.d.ts +2 -2
  81. package/lib/events/hooks/auto_moderation.d.ts +5 -5
  82. package/lib/events/hooks/channel.d.ts +5 -5
  83. package/lib/events/hooks/custom.d.ts +3 -3
  84. package/lib/events/hooks/dispatch.d.ts +4 -4
  85. package/lib/events/hooks/entitlement.d.ts +4 -4
  86. package/lib/events/hooks/guild.d.ts +41 -96
  87. package/lib/events/hooks/guild.js +6 -6
  88. package/lib/events/hooks/integration.d.ts +61 -4
  89. package/lib/events/hooks/interactions.d.ts +2 -2
  90. package/lib/events/hooks/invite.d.ts +6 -3
  91. package/lib/events/hooks/message.d.ts +23 -18
  92. package/lib/events/hooks/message.js +1 -1
  93. package/lib/events/hooks/presence.d.ts +11 -3
  94. package/lib/events/hooks/presence.js +2 -2
  95. package/lib/events/hooks/stage.d.ts +7 -13
  96. package/lib/events/hooks/stage.js +2 -2
  97. package/lib/events/hooks/thread.d.ts +21 -10
  98. package/lib/events/hooks/thread.js +2 -2
  99. package/lib/events/hooks/typing.d.ts +3 -2
  100. package/lib/events/hooks/user.d.ts +2 -2
  101. package/lib/events/hooks/user.js +2 -2
  102. package/lib/events/hooks/voice.d.ts +5 -45
  103. package/lib/events/hooks/voice.js +4 -7
  104. package/lib/events/hooks/webhook.d.ts +2 -2
  105. package/lib/index.d.ts +4 -4
  106. package/lib/index.js +11 -5
  107. package/lib/langs/handler.d.ts +4 -1
  108. package/lib/langs/handler.js +3 -3
  109. package/lib/structures/Guild.d.ts +9 -1
  110. package/lib/structures/Guild.js +2 -0
  111. package/lib/structures/GuildBan.d.ts +25 -0
  112. package/lib/structures/GuildBan.js +36 -0
  113. package/lib/structures/GuildEmoji.d.ts +1 -1
  114. package/lib/structures/GuildMember.d.ts +7 -2
  115. package/lib/structures/GuildMember.js +4 -4
  116. package/lib/structures/Interaction.d.ts +4 -3
  117. package/lib/structures/Interaction.js +29 -12
  118. package/lib/structures/Message.d.ts +69 -8
  119. package/lib/structures/Message.js +59 -17
  120. package/lib/structures/Sticker.d.ts +3 -3
  121. package/lib/structures/User.d.ts +1 -0
  122. package/lib/structures/User.js +4 -1
  123. package/lib/structures/VoiceState.d.ts +6 -5
  124. package/lib/structures/VoiceState.js +6 -3
  125. package/lib/structures/channels.d.ts +4 -1
  126. package/lib/structures/channels.js +37 -6
  127. package/lib/structures/extra/functions.js +1 -1
  128. package/lib/websocket/discord/basesocket.d.ts +1 -0
  129. package/lib/websocket/discord/basesocket.js +17 -0
  130. package/lib/websocket/discord/shard.d.ts +1 -0
  131. package/lib/websocket/discord/shard.js +6 -0
  132. package/lib/websocket/discord/sharder.js +10 -3
  133. package/lib/websocket/discord/shared.d.ts +1 -0
  134. package/lib/websocket/discord/workermanager.d.ts +2 -3
  135. package/lib/websocket/discord/workermanager.js +4 -2
  136. package/package.json +7 -7
  137. package/lib/commands/basecontex.d.ts +0 -15
  138. package/lib/components/command.d.ts +0 -24
@@ -0,0 +1,155 @@
1
+ /**
2
+ * Represents heading levels.
3
+ */
4
+ export declare enum HeadingLevel {
5
+ /**
6
+ * Represents a level 1 heading. (#)
7
+ */
8
+ H1 = 1,
9
+ /**
10
+ * Represents a level 2 heading. (##)
11
+ */
12
+ H2 = 2,
13
+ /**
14
+ * Represents a level 3 heading. (###)
15
+ */
16
+ H3 = 3
17
+ }
18
+ /**
19
+ * Represents timestamp styles.
20
+ */
21
+ export declare enum TimestampStyle {
22
+ /**
23
+ * Represents a short timestamp style.
24
+ */
25
+ ShortTime = "t",
26
+ /**
27
+ * Represents a long timestamp style.
28
+ */
29
+ LongTime = "T",
30
+ /**
31
+ * Represents a short date style.
32
+ */
33
+ ShortDate = "d",
34
+ /**
35
+ * Represents a long date style.
36
+ */
37
+ LongDate = "D",
38
+ /**
39
+ * Represents a short time style.
40
+ */
41
+ ShortDateTime = "f",
42
+ /**
43
+ * Represents a long time style.
44
+ */
45
+ LongDateTime = "F",
46
+ /**
47
+ * Represents a relative time style.
48
+ */
49
+ RelativeTime = "R"
50
+ }
51
+ /**
52
+ * Represents a message link.
53
+ */
54
+ type MessageLink = `https://discord.com/channels/${string}/${string}/${string}`;
55
+ /**
56
+ * Represents a timestamp.
57
+ */
58
+ type Timestamp = `<t:${number}:${TimestampStyle}>`;
59
+ /**
60
+ * Represents a formatter utility for formatting content.
61
+ */
62
+ export declare class Formatter {
63
+ /**
64
+ * Formats a code block.
65
+ * @param content The content of the code block.
66
+ * @param language The language of the code block. Defaults to 'txt'.
67
+ * @returns The formatted code block.
68
+ */
69
+ static codeBlock(content: string, language?: string): string;
70
+ /**
71
+ * Formats content into inline code.
72
+ * @param content The content to format.
73
+ * @returns The formatted content.
74
+ */
75
+ static inlineCode(content: string): `\`${string}\``;
76
+ /**
77
+ * Formats content into bold text.
78
+ * @param content The content to format.
79
+ * @returns The formatted content.
80
+ */
81
+ static bold(content: string): `**${string}**`;
82
+ /**
83
+ * Formats content into italic text.
84
+ * @param content The content to format.
85
+ * @returns The formatted content.
86
+ */
87
+ static italic(content: string): `*${string}*`;
88
+ /**
89
+ * Formats content into underlined text.
90
+ * @param content The content to format.
91
+ * @returns The formatted content.
92
+ */
93
+ static underline(content: string): `__${string}__`;
94
+ /**
95
+ * Formats content into strikethrough text.
96
+ * @param content The content to format.
97
+ * @returns The formatted content.
98
+ */
99
+ static strikeThrough(content: string): `~~${string}~~`;
100
+ /**
101
+ * Formats content into a hyperlink.
102
+ * @param content The content to format.
103
+ * @param url The URL to hyperlink to.
104
+ * @returns The formatted content.
105
+ */
106
+ static hyperlink(content: string, url: string): `[${string}](${string})`;
107
+ /**
108
+ * Formats content into a spoiler.
109
+ * @param content The content to format.
110
+ * @returns The formatted content.
111
+ */
112
+ static spoiler(content: string): `||${string}||`;
113
+ /**
114
+ * Formats content into a quote.
115
+ * @param content The content to format.
116
+ * @returns The formatted content.
117
+ */
118
+ static blockQuote(content: string): string;
119
+ /**
120
+ * Formats content into a quote.
121
+ * @param content The content to format.
122
+ * @returns The formatted content.
123
+ */
124
+ static quote(content: string): string;
125
+ /**
126
+ * Formats a message link.
127
+ * @param guildId The ID of the guild.
128
+ * @param channelId The ID of the channel.
129
+ * @param messageId The ID of the message.
130
+ * @returns The formatted message link.
131
+ */
132
+ static messageLink(guildId: string, channelId: string, messageId: string): MessageLink;
133
+ /**
134
+ * Formats a header.
135
+ * @param content The content of the header.
136
+ * @param level The level of the header. Defaults to 1.
137
+ * @returns The formatted header.
138
+ */
139
+ static header(content: string, level?: HeadingLevel): string;
140
+ /**
141
+ * Formats a list.
142
+ * @param items The items of the list.
143
+ * @param ordered Whether the list is ordered. Defaults to false.
144
+ * @returns The formatted list.
145
+ */
146
+ static list(items: string[], ordered?: boolean): string;
147
+ /**
148
+ * Formats the given timestamp into discord unix timestamp format.
149
+ * @param timestamp The timestamp to format.
150
+ * @param style The style of the timestamp. Defaults to 't'.
151
+ * @returns The formatted timestamp.
152
+ */
153
+ static timestamp(timestamp: Date, style?: TimestampStyle): Timestamp;
154
+ }
155
+ export {};
@@ -0,0 +1,184 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Formatter = exports.TimestampStyle = exports.HeadingLevel = void 0;
4
+ /**
5
+ * Represents heading levels.
6
+ */
7
+ var HeadingLevel;
8
+ (function (HeadingLevel) {
9
+ /**
10
+ * Represents a level 1 heading. (#)
11
+ */
12
+ HeadingLevel[HeadingLevel["H1"] = 1] = "H1";
13
+ /**
14
+ * Represents a level 2 heading. (##)
15
+ */
16
+ HeadingLevel[HeadingLevel["H2"] = 2] = "H2";
17
+ /**
18
+ * Represents a level 3 heading. (###)
19
+ */
20
+ HeadingLevel[HeadingLevel["H3"] = 3] = "H3";
21
+ })(HeadingLevel || (exports.HeadingLevel = HeadingLevel = {}));
22
+ /**
23
+ * Represents timestamp styles.
24
+ */
25
+ var TimestampStyle;
26
+ (function (TimestampStyle) {
27
+ /**
28
+ * Represents a short timestamp style.
29
+ */
30
+ TimestampStyle["ShortTime"] = "t";
31
+ /**
32
+ * Represents a long timestamp style.
33
+ */
34
+ TimestampStyle["LongTime"] = "T";
35
+ /**
36
+ * Represents a short date style.
37
+ */
38
+ TimestampStyle["ShortDate"] = "d";
39
+ /**
40
+ * Represents a long date style.
41
+ */
42
+ TimestampStyle["LongDate"] = "D";
43
+ /**
44
+ * Represents a short time style.
45
+ */
46
+ TimestampStyle["ShortDateTime"] = "f";
47
+ /**
48
+ * Represents a long time style.
49
+ */
50
+ TimestampStyle["LongDateTime"] = "F";
51
+ /**
52
+ * Represents a relative time style.
53
+ */
54
+ TimestampStyle["RelativeTime"] = "R";
55
+ })(TimestampStyle || (exports.TimestampStyle = TimestampStyle = {}));
56
+ /**
57
+ * Represents a formatter utility for formatting content.
58
+ */
59
+ class Formatter {
60
+ /**
61
+ * Formats a code block.
62
+ * @param content The content of the code block.
63
+ * @param language The language of the code block. Defaults to 'txt'.
64
+ * @returns The formatted code block.
65
+ */
66
+ static codeBlock(content, language = 'txt') {
67
+ return `\`\`\`${language}\n${content}\n\`\`\``;
68
+ }
69
+ /**
70
+ * Formats content into inline code.
71
+ * @param content The content to format.
72
+ * @returns The formatted content.
73
+ */
74
+ static inlineCode(content) {
75
+ return `\`${content}\``;
76
+ }
77
+ /**
78
+ * Formats content into bold text.
79
+ * @param content The content to format.
80
+ * @returns The formatted content.
81
+ */
82
+ static bold(content) {
83
+ return `**${content}**`;
84
+ }
85
+ /**
86
+ * Formats content into italic text.
87
+ * @param content The content to format.
88
+ * @returns The formatted content.
89
+ */
90
+ static italic(content) {
91
+ return `*${content}*`;
92
+ }
93
+ /**
94
+ * Formats content into underlined text.
95
+ * @param content The content to format.
96
+ * @returns The formatted content.
97
+ */
98
+ static underline(content) {
99
+ return `__${content}__`;
100
+ }
101
+ /**
102
+ * Formats content into strikethrough text.
103
+ * @param content The content to format.
104
+ * @returns The formatted content.
105
+ */
106
+ static strikeThrough(content) {
107
+ return `~~${content}~~`;
108
+ }
109
+ /**
110
+ * Formats content into a hyperlink.
111
+ * @param content The content to format.
112
+ * @param url The URL to hyperlink to.
113
+ * @returns The formatted content.
114
+ */
115
+ static hyperlink(content, url) {
116
+ return `[${content}](${url})`;
117
+ }
118
+ /**
119
+ * Formats content into a spoiler.
120
+ * @param content The content to format.
121
+ * @returns The formatted content.
122
+ */
123
+ static spoiler(content) {
124
+ return `||${content}||`;
125
+ }
126
+ /**
127
+ * Formats content into a quote.
128
+ * @param content The content to format.
129
+ * @returns The formatted content.
130
+ */
131
+ static blockQuote(content) {
132
+ return `>>> ${content}`;
133
+ }
134
+ /**
135
+ * Formats content into a quote.
136
+ * @param content The content to format.
137
+ * @returns The formatted content.
138
+ */
139
+ static quote(content) {
140
+ return `> ${content}`;
141
+ }
142
+ /**
143
+ * Formats a message link.
144
+ * @param guildId The ID of the guild.
145
+ * @param channelId The ID of the channel.
146
+ * @param messageId The ID of the message.
147
+ * @returns The formatted message link.
148
+ */
149
+ static messageLink(guildId, channelId, messageId) {
150
+ return `https://discord.com/channels/${guildId}/${channelId}/${messageId}`;
151
+ }
152
+ /**
153
+ * Formats a header.
154
+ * @param content The content of the header.
155
+ * @param level The level of the header. Defaults to 1.
156
+ * @returns The formatted header.
157
+ */
158
+ static header(content, level = HeadingLevel.H1) {
159
+ return `${'#'.repeat(level)} ${content}`;
160
+ }
161
+ /**
162
+ * Formats a list.
163
+ * @param items The items of the list.
164
+ * @param ordered Whether the list is ordered. Defaults to false.
165
+ * @returns The formatted list.
166
+ */
167
+ static list(items, ordered = false) {
168
+ return items
169
+ .map((item, index) => {
170
+ return (ordered ? `${index + 1}. ` : '- ') + item;
171
+ })
172
+ .join('\n');
173
+ }
174
+ /**
175
+ * Formats the given timestamp into discord unix timestamp format.
176
+ * @param timestamp The timestamp to format.
177
+ * @param style The style of the timestamp. Defaults to 't'.
178
+ * @returns The formatted timestamp.
179
+ */
180
+ static timestamp(timestamp, style = TimestampStyle.RelativeTime) {
181
+ return `<t:${Math.floor(timestamp.getTime() / 1000)}:${style}>`;
182
+ }
183
+ }
184
+ exports.Formatter = Formatter;
@@ -13,7 +13,7 @@ export type LoggerOptions = {
13
13
  active?: boolean;
14
14
  saveOnFile?: boolean;
15
15
  };
16
- export type CustomCallback = (self: Logger, level: LogLevels, args: unknown[]) => unknown[];
16
+ export type CustomCallback = (self: Logger, level: LogLevels, args: unknown[]) => unknown[] | undefined;
17
17
  /**
18
18
  * Represents a logger utility for logging messages with various log levels.
19
19
  */
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Logger = exports.LogLevels = void 0;
4
4
  const node_fs_1 = require("node:fs");
5
- const promises_1 = require("node:fs/promises");
6
5
  const node_path_1 = require("node:path");
7
6
  const colors_1 = require("./colors");
8
7
  const utils_1 = require("./utils");
@@ -42,11 +41,11 @@ class Logger {
42
41
  Logger.__callback = cb;
43
42
  }
44
43
  static async clearLogs() {
45
- for (const i of await (0, promises_1.readdir)((0, node_path_1.join)(process.cwd(), Logger.dirname))) {
46
- if (this.streams[i])
47
- await new Promise(res => this.streams[i].close(res));
48
- await (0, promises_1.unlink)((0, node_path_1.join)(process.cwd(), Logger.dirname, i)).catch(() => { });
49
- delete this.streams[i];
44
+ for (const i of await node_fs_1.promises.readdir((0, node_path_1.join)(process.cwd(), Logger.dirname), { withFileTypes: true })) {
45
+ if (this.streams[i.name])
46
+ await new Promise(res => this.streams[i.name].close(res));
47
+ await node_fs_1.promises.unlink((0, node_path_1.join)(process.cwd(), Logger.dirname, i.name)).catch(() => { });
48
+ delete this.streams[i.name];
50
49
  }
51
50
  }
52
51
  /**
@@ -110,21 +109,23 @@ class Logger {
110
109
  if (level < this.level)
111
110
  return;
112
111
  let log;
113
- if (!Logger.__callback) {
112
+ if (Logger.__callback) {
113
+ log = Logger.__callback(this, level, args);
114
+ }
115
+ else {
114
116
  const color = Logger.colorFunctions.get(level) ?? Logger.noColor;
115
- const memoryData = process.memoryUsage();
117
+ const memoryData = process.memoryUsage?.();
116
118
  const date = new Date();
117
119
  log = [
118
- (0, colors_1.brightBlack)(formatMemoryUsage(memoryData.rss)),
120
+ (0, colors_1.brightBlack)(formatMemoryUsage(memoryData?.rss ?? 0)),
119
121
  (0, colors_1.bgBrightWhite)((0, colors_1.black)(`[${date.toLocaleDateString()} ${date.toLocaleTimeString()}]`)),
120
122
  color(Logger.prefixes.get(level) ?? 'DEBUG'),
121
123
  this.name ? `${this.name} >` : '>',
122
124
  ...args,
123
125
  ];
124
126
  }
125
- else {
126
- log = Logger.__callback(this, level, args);
127
- }
127
+ if (!log)
128
+ return;
128
129
  this.__write(log);
129
130
  return console.log(...log);
130
131
  }
@@ -165,7 +166,7 @@ class Logger {
165
166
  }
166
167
  __write(log) {
167
168
  if (this.saveOnFile || Logger.saveOnFile === 'all' || Logger.saveOnFile?.includes(this.name)) {
168
- if (!Logger.createdDir && !(0, node_fs_1.existsSync)((0, node_path_1.join)(process.cwd(), Logger.dirname))) {
169
+ if (!(Logger.createdDir || (0, node_fs_1.existsSync)((0, node_path_1.join)(process.cwd(), Logger.dirname)))) {
169
170
  Logger.createdDir = true;
170
171
  (0, node_fs_1.mkdirSync)((0, node_path_1.join)(process.cwd(), Logger.dirname), { recursive: true });
171
172
  }
@@ -95,3 +95,5 @@ export type OnFailCallback = (error: unknown) => any;
95
95
  export declare function fakePromise<T = unknown | Promise<unknown>>(value: T): {
96
96
  then<R>(callback: (arg: Awaited<T>) => R): R;
97
97
  };
98
+ export declare function lazyLoadPackage<T>(mod: string): T | undefined;
99
+ export declare function isCloudfareWorker(): boolean;
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fakePromise = exports.magicImport = exports.ReplaceRegex = exports.toCamelCase = exports.toSnakeCase = exports.BaseHandler = exports.filterSplit = exports.MergeOptions = exports.isObject = exports.delay = exports.resolveColor = void 0;
4
- const promises_1 = require("node:fs/promises");
3
+ exports.isCloudfareWorker = exports.lazyLoadPackage = exports.fakePromise = exports.magicImport = exports.ReplaceRegex = exports.toCamelCase = exports.toSnakeCase = exports.BaseHandler = exports.filterSplit = exports.MergeOptions = exports.isObject = exports.delay = exports.resolveColor = void 0;
4
+ const node_fs_1 = require("node:fs");
5
5
  const node_path_1 = require("node:path");
6
- const promises_2 = require("node:timers/promises");
7
6
  const __1 = require("..");
8
7
  /**
9
8
  * Resolves the color to a numeric representation.
@@ -39,7 +38,7 @@ exports.resolveColor = resolveColor;
39
38
  * @returns A Promise that resolves after the specified time with the provided result.
40
39
  */
41
40
  function delay(time, result) {
42
- return (0, promises_2.setTimeout)(time, result);
41
+ return new Promise(r => setTimeout(r, time, result));
43
42
  }
44
43
  exports.delay = delay;
45
44
  /**
@@ -115,14 +114,12 @@ class BaseHandler {
115
114
  */
116
115
  async getFiles(dir) {
117
116
  const files = [];
118
- for (const i of await (0, promises_1.readdir)(dir, { withFileTypes: true })) {
117
+ for (const i of await node_fs_1.promises.readdir(dir, { withFileTypes: true })) {
119
118
  if (i.isDirectory()) {
120
119
  files.push(...(await this.getFiles((0, node_path_1.join)(dir, i.name))));
121
120
  }
122
- else {
123
- if (this.filter((0, node_path_1.join)(dir, i.name))) {
124
- files.push((0, node_path_1.join)(dir, i.name));
125
- }
121
+ else if (this.filter((0, node_path_1.join)(dir, i.name))) {
122
+ files.push((0, node_path_1.join)(dir, i.name));
126
123
  }
127
124
  }
128
125
  return files;
@@ -254,3 +251,18 @@ function fakePromise(value) {
254
251
  };
255
252
  }
256
253
  exports.fakePromise = fakePromise;
254
+ function lazyLoadPackage(mod) {
255
+ try {
256
+ return require(mod);
257
+ }
258
+ catch (e) {
259
+ console.log(`Cannot import ${mod}`);
260
+ return;
261
+ }
262
+ }
263
+ exports.lazyLoadPackage = lazyLoadPackage;
264
+ function isCloudfareWorker() {
265
+ //@ts-expect-error
266
+ return process.platform === 'browser';
267
+ }
268
+ exports.isCloudfareWorker = isCloudfareWorker;
@@ -0,0 +1,43 @@
1
+ import type { RESTGetAPIGuildBansQuery, RESTPostAPIGuildBulkBanJSONBody, RESTPutAPIGuildBanJSONBody } from 'discord-api-types/v10';
2
+ import { BaseShorter } from './base';
3
+ import { GuildBan } from '../../structures/GuildBan';
4
+ export declare class BanShorter extends BaseShorter {
5
+ /**
6
+ * Bulk creates bans in the guild.
7
+ * @param guildId The ID of the guild.
8
+ * @param body The request body for bulk banning members.
9
+ * @param reason The reason for bulk banning members.
10
+ */
11
+ bulkCreate(guildId: string, body: RESTPostAPIGuildBulkBanJSONBody, reason?: string): Promise<import("discord-api-types/v10").RESTPostAPIGuildBulkBanResult>;
12
+ /**
13
+ * Unbans a member from the guild.
14
+ * @param guildId The ID of the guild.
15
+ * @param memberId The ID of the member to unban.
16
+ * @param reason The reason for unbanning the member.
17
+ */
18
+ remove(guildId: string, memberId: string, reason?: string): Promise<void>;
19
+ /**
20
+ * Bans a member from the guild.
21
+ * @param guildId The ID of the guild.
22
+ * @param memberId The ID of the member to ban.
23
+ * @param body The request body for banning the member.
24
+ * @param reason The reason for banning the member.
25
+ */
26
+ create(guildId: string, memberId: string, body?: RESTPutAPIGuildBanJSONBody, reason?: string): Promise<void>;
27
+ /**
28
+ * Fetches a ban from the guild.
29
+ * @param guildId The ID of the guild.
30
+ * @param userId The ID of the user to fetch.
31
+ * @param force Whether to force fetching the ban from the API even if it exists in the cache.
32
+ * @returns A Promise that resolves to the fetched ban.
33
+ */
34
+ fetch(guildId: string, userId: string, force?: boolean): Promise<GuildBan>;
35
+ /**
36
+ * Lists bans in the guild based on the provided query.
37
+ * @param guildId The ID of the guild.
38
+ * @param query The query parameters for listing bans.
39
+ * @param force Whether to force listing bans from the API even if they exist in the cache.
40
+ * @returns A Promise that resolves to an array of listed bans.
41
+ */
42
+ list(guildId: string, query?: RESTGetAPIGuildBansQuery, force?: boolean): Promise<GuildBan[]>;
43
+ }
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BanShorter = void 0;
4
+ const base_1 = require("./base");
5
+ const GuildBan_1 = require("../../structures/GuildBan");
6
+ class BanShorter extends base_1.BaseShorter {
7
+ /**
8
+ * Bulk creates bans in the guild.
9
+ * @param guildId The ID of the guild.
10
+ * @param body The request body for bulk banning members.
11
+ * @param reason The reason for bulk banning members.
12
+ */
13
+ async bulkCreate(guildId, body, reason) {
14
+ const bans = await this.client.proxy.guilds(guildId)['bulk-bans'].post({ reason, body });
15
+ for (const id of bans.banned_users)
16
+ this.client.cache.members?.removeIfNI('GuildBans', id, guildId);
17
+ return bans;
18
+ }
19
+ /**
20
+ * Unbans a member from the guild.
21
+ * @param guildId The ID of the guild.
22
+ * @param memberId The ID of the member to unban.
23
+ * @param reason The reason for unbanning the member.
24
+ */
25
+ async remove(guildId, memberId, reason) {
26
+ await this.client.proxy.guilds(guildId).bans(memberId).delete({ reason });
27
+ }
28
+ /**
29
+ * Bans a member from the guild.
30
+ * @param guildId The ID of the guild.
31
+ * @param memberId The ID of the member to ban.
32
+ * @param body The request body for banning the member.
33
+ * @param reason The reason for banning the member.
34
+ */
35
+ async create(guildId, memberId, body, reason) {
36
+ await this.client.proxy.guilds(guildId).bans(memberId).put({ reason, body });
37
+ await this.client.cache.members?.removeIfNI('GuildBans', memberId, guildId);
38
+ }
39
+ /**
40
+ * Fetches a ban from the guild.
41
+ * @param guildId The ID of the guild.
42
+ * @param userId The ID of the user to fetch.
43
+ * @param force Whether to force fetching the ban from the API even if it exists in the cache.
44
+ * @returns A Promise that resolves to the fetched ban.
45
+ */
46
+ async fetch(guildId, userId, force = false) {
47
+ let ban;
48
+ if (!force) {
49
+ ban = await this.client.cache.bans?.get(userId, guildId);
50
+ if (ban)
51
+ return ban;
52
+ }
53
+ ban = await this.client.proxy.guilds(guildId).bans(userId).get();
54
+ await this.client.cache.members?.set(ban.user.id, guildId, ban);
55
+ return new GuildBan_1.GuildBan(this.client, ban, guildId);
56
+ }
57
+ /**
58
+ * Lists bans in the guild based on the provided query.
59
+ * @param guildId The ID of the guild.
60
+ * @param query The query parameters for listing bans.
61
+ * @param force Whether to force listing bans from the API even if they exist in the cache.
62
+ * @returns A Promise that resolves to an array of listed bans.
63
+ */
64
+ async list(guildId, query, force = false) {
65
+ let bans;
66
+ if (!force) {
67
+ bans = (await this.client.cache.bans?.values(guildId)) ?? [];
68
+ if (bans.length)
69
+ return bans;
70
+ }
71
+ bans = await this.client.proxy.guilds(guildId).bans.get({
72
+ query,
73
+ });
74
+ await this.client.cache.bans?.set(bans.map(x => [x.user.id, x]), guildId);
75
+ return bans.map(m => new GuildBan_1.GuildBan(this.client, m, guildId));
76
+ }
77
+ }
78
+ exports.BanShorter = BanShorter;
@@ -19,7 +19,7 @@ export declare class EmojiShorter extends BaseShorter {
19
19
  */
20
20
  create(guildId: string, body: OmitInsert<RESTPostAPIGuildEmojiJSONBody, 'image', {
21
21
  image: ImageResolvable;
22
- }>): Promise<void>;
22
+ }>): Promise<GuildEmoji>;
23
23
  /**
24
24
  * Fetches an emoji by its ID.
25
25
  * @param guildId The ID of the guild.
@@ -34,7 +34,8 @@ class EmojiShorter extends base_1.BaseShorter {
34
34
  const emoji = await this.client.proxy.guilds(guildId).emojis.post({
35
35
  body: bodyResolved,
36
36
  });
37
- await this.client.cache.channels?.setIfNI('GuildEmojisAndStickers', emoji.id, guildId, emoji);
37
+ await this.client.cache.emojis?.setIfNI('GuildEmojisAndStickers', emoji.id, guildId, emoji);
38
+ return new __1.GuildEmoji(this.client, emoji, guildId);
38
39
  }
39
40
  /**
40
41
  * Fetches an emoji by its ID.
@@ -61,7 +62,7 @@ class EmojiShorter extends base_1.BaseShorter {
61
62
  */
62
63
  async delete(guildId, emojiId, reason) {
63
64
  await this.client.proxy.guilds(guildId).emojis(emojiId).delete({ reason });
64
- await this.client.cache.channels?.removeIfNI('GuildEmojisAndStickers', emojiId, guildId);
65
+ await this.client.cache.emojis?.removeIfNI('GuildEmojisAndStickers', emojiId, guildId);
65
66
  }
66
67
  /**
67
68
  * Edits an emoji in the guild.
@@ -73,7 +74,7 @@ class EmojiShorter extends base_1.BaseShorter {
73
74
  */
74
75
  async edit(guildId, emojiId, body, reason) {
75
76
  const emoji = await this.client.proxy.guilds(guildId).emojis(emojiId).patch({ body, reason });
76
- await this.client.cache.channels?.setIfNI('GuildEmojisAndStickers', emoji.id, guildId, emoji);
77
+ await this.client.cache.emojis?.setIfNI('GuildEmojisAndStickers', emoji.id, guildId, emoji);
77
78
  return new __1.GuildEmoji(this.client, emoji, guildId);
78
79
  }
79
80
  }
@@ -9,14 +9,15 @@ class InteractionShorter extends base_1.BaseShorter {
9
9
  const { files, ...rest } = body.data ?? {};
10
10
  //@ts-expect-error
11
11
  const data = body.data instanceof __1.Modal ? body.data : rest;
12
+ const parsedFiles = files ? await (0, __1.resolveFiles)(files) : undefined;
12
13
  return this.client.proxy
13
14
  .interactions(id)(token)
14
15
  .callback.post({
15
16
  body: __1.BaseInteraction.transformBodyRequest({
16
17
  type: body.type,
17
18
  data,
18
- }),
19
- files: files ? await (0, __1.resolveFiles)(files) : undefined,
19
+ }, parsedFiles, this.client),
20
+ files: parsedFiles,
20
21
  });
21
22
  }
22
23
  fetchResponse(token, messageId) {
@@ -27,12 +28,13 @@ class InteractionShorter extends base_1.BaseShorter {
27
28
  }
28
29
  async editMessage(token, messageId, body) {
29
30
  const { files, ...data } = body;
31
+ const parsedFiles = files ? await (0, __1.resolveFiles)(files) : undefined;
30
32
  const apiMessage = await this.client.proxy
31
33
  .webhooks(this.client.applicationId)(token)
32
34
  .messages(messageId)
33
35
  .patch({
34
- body: __1.BaseInteraction.transformBody(data),
35
- files: files ? await (0, __1.resolveFiles)(files) : undefined,
36
+ body: __1.BaseInteraction.transformBody(data, parsedFiles, this.client),
37
+ files: parsedFiles,
36
38
  });
37
39
  return new __1.WebhookMessage(this.client, apiMessage, this.client.applicationId, token);
38
40
  }
@@ -50,12 +52,12 @@ class InteractionShorter extends base_1.BaseShorter {
50
52
  return this.deleteResponse(interactionId, token, '@original');
51
53
  }
52
54
  async followup(token, { files, ...body }) {
53
- files = files ? await (0, __1.resolveFiles)(files) : undefined;
55
+ const parsedFiles = files ? await (0, __1.resolveFiles)(files) : undefined;
54
56
  const apiMessage = await this.client.proxy
55
57
  .webhooks(this.client.applicationId)(token)
56
58
  .post({
57
- body: __1.BaseInteraction.transformBody(body),
58
- files: files,
59
+ body: __1.BaseInteraction.transformBody(body, parsedFiles, this.client),
60
+ files: parsedFiles,
59
61
  });
60
62
  return new __1.WebhookMessage(this.client, apiMessage, this.client.applicationId, token);
61
63
  }