seyfert 1.0.0 → 1.1.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 (112) hide show
  1. package/lib/api/CDN.d.ts +1 -1
  2. package/lib/api/CDN.js +0 -2
  3. package/lib/api/Router.js +2 -2
  4. package/lib/api/Routes/applications.d.ts +29 -33
  5. package/lib/api/Routes/channels.d.ts +11 -17
  6. package/lib/api/Routes/interactions.d.ts +3 -7
  7. package/lib/api/Routes/webhooks.d.ts +4 -6
  8. package/lib/api/api.d.ts +5 -0
  9. package/lib/api/api.js +36 -0
  10. package/lib/api/shared.d.ts +5 -3
  11. package/lib/builders/Attachment.d.ts +2 -3
  12. package/lib/builders/Button.d.ts +2 -2
  13. package/lib/cache/adapters/default.d.ts +1 -0
  14. package/lib/cache/adapters/default.js +1 -0
  15. package/lib/cache/adapters/redis.d.ts +1 -0
  16. package/lib/cache/adapters/redis.js +7 -0
  17. package/lib/cache/adapters/types.d.ts +1 -0
  18. package/lib/cache/adapters/workeradapter.d.ts +5 -4
  19. package/lib/cache/adapters/workeradapter.js +11 -5
  20. package/lib/cache/index.d.ts +4 -6
  21. package/lib/cache/index.js +5 -6
  22. package/lib/cache/resources/default/base.d.ts +2 -1
  23. package/lib/cache/resources/default/guild-based.d.ts +2 -1
  24. package/lib/cache/resources/default/guild-based.js +6 -6
  25. package/lib/cache/resources/default/guild-related.d.ts +2 -1
  26. package/lib/cache/resources/default/guild-related.js +1 -1
  27. package/lib/cache/resources/guilds.js +2 -1
  28. package/lib/cache/resources/overwrites.d.ts +1 -1
  29. package/lib/cache/resources/overwrites.js +7 -1
  30. package/lib/client/base.d.ts +18 -171
  31. package/lib/client/base.js +12 -15
  32. package/lib/client/client.d.ts +6 -1
  33. package/lib/client/client.js +13 -12
  34. package/lib/client/oninteractioncreate.js +4 -4
  35. package/lib/client/onmessagecreate.js +188 -152
  36. package/lib/client/workerclient.d.ts +15 -1
  37. package/lib/client/workerclient.js +135 -27
  38. package/lib/collection.js +2 -2
  39. package/lib/commands/applications/chat.d.ts +15 -7
  40. package/lib/commands/applications/chat.js +7 -7
  41. package/lib/commands/applications/chatcontext.d.ts +6 -4
  42. package/lib/commands/applications/chatcontext.js +12 -7
  43. package/lib/commands/applications/menu.d.ts +5 -1
  44. package/lib/commands/applications/menu.js +4 -0
  45. package/lib/commands/applications/menucontext.d.ts +5 -3
  46. package/lib/commands/applications/menucontext.js +9 -4
  47. package/lib/commands/applications/options.d.ts +1 -2
  48. package/lib/commands/decorators.d.ts +17 -5
  49. package/lib/commands/decorators.js +17 -7
  50. package/lib/commands/handler.d.ts +5 -5
  51. package/lib/commands/handler.js +40 -36
  52. package/lib/commands/optionresolver.d.ts +11 -4
  53. package/lib/commands/optionresolver.js +6 -4
  54. package/lib/common/index.d.ts +7 -0
  55. package/lib/common/index.js +7 -0
  56. package/lib/common/it/utils.js +2 -0
  57. package/lib/common/shorters/channels.d.ts +67 -129
  58. package/lib/common/shorters/channels.js +119 -135
  59. package/lib/common/shorters/emojis.d.ts +47 -0
  60. package/lib/common/shorters/emojis.js +80 -0
  61. package/lib/common/shorters/guilds.d.ts +22 -249
  62. package/lib/common/shorters/guilds.js +51 -140
  63. package/lib/common/shorters/members.d.ts +82 -108
  64. package/lib/common/shorters/members.js +151 -166
  65. package/lib/common/shorters/messages.d.ts +11 -23
  66. package/lib/common/shorters/messages.js +58 -104
  67. package/lib/common/shorters/reactions.d.ts +10 -0
  68. package/lib/common/shorters/reactions.js +45 -0
  69. package/lib/common/shorters/roles.d.ts +39 -7
  70. package/lib/common/shorters/roles.js +74 -42
  71. package/lib/common/shorters/templates.d.ts +6 -8
  72. package/lib/common/shorters/templates.js +17 -21
  73. package/lib/common/shorters/users.d.ts +4 -0
  74. package/lib/common/shorters/users.js +30 -0
  75. package/lib/common/shorters/webhook.d.ts +62 -26
  76. package/lib/common/shorters/webhook.js +113 -58
  77. package/lib/common/types/options.d.ts +2 -2
  78. package/lib/common/types/util.d.ts +1 -1
  79. package/lib/components/handler.d.ts +11 -8
  80. package/lib/components/handler.js +34 -22
  81. package/lib/index.d.ts +4 -2
  82. package/lib/langs/handler.js +7 -2
  83. package/lib/structures/AutoModerationRule.d.ts +2 -2
  84. package/lib/structures/ClientUser.d.ts +2 -2
  85. package/lib/structures/Guild.d.ts +2 -2
  86. package/lib/structures/GuildEmoji.d.ts +4 -4
  87. package/lib/structures/GuildEmoji.js +7 -7
  88. package/lib/structures/GuildMember.d.ts +6 -6
  89. package/lib/structures/GuildMember.js +2 -2
  90. package/lib/structures/GuildPreview.d.ts +2 -2
  91. package/lib/structures/GuildRole.d.ts +2 -2
  92. package/lib/structures/GuildTemplate.d.ts +2 -2
  93. package/lib/structures/Interaction.d.ts +7 -8
  94. package/lib/structures/Interaction.js +1 -1
  95. package/lib/structures/Message.d.ts +7 -6
  96. package/lib/structures/Message.js +7 -4
  97. package/lib/structures/Sticker.d.ts +2 -2
  98. package/lib/structures/Webhook.d.ts +2 -2
  99. package/lib/structures/Webhook.js +3 -3
  100. package/lib/structures/channels.d.ts +19 -20
  101. package/lib/structures/channels.js +13 -25
  102. package/lib/structures/extra/Base.d.ts +1 -2
  103. package/lib/structures/extra/DiscordBase.d.ts +2 -2
  104. package/lib/websocket/constants/index.js +2 -3
  105. package/lib/websocket/discord/shard.js +4 -2
  106. package/lib/websocket/discord/sharder.d.ts +3 -0
  107. package/lib/websocket/discord/sharder.js +12 -5
  108. package/lib/websocket/discord/shared.d.ts +3 -0
  109. package/lib/websocket/discord/worker.d.ts +24 -7
  110. package/lib/websocket/discord/workermanager.d.ts +30 -6
  111. package/lib/websocket/discord/workermanager.js +160 -51
  112. package/package.json +8 -5
@@ -9,11 +9,11 @@ function getCommandFromContent(commandRaw, self) {
9
9
  const groupName = commandRaw.length === 3 ? commandRaw[1] : undefined;
10
10
  const subcommandName = groupName ? commandRaw[2] : commandRaw[1];
11
11
  const parent = self.commands.values.find(x => x.name === parentName);
12
- const fullCommandName = `${parentName}${groupName ? ` ${groupName} ${subcommandName}` : ` ${subcommandName ?? ''}`}`;
12
+ const fullCommandName = `${parentName}${groupName ? ` ${groupName} ${subcommandName}` : `${subcommandName ? ` ${subcommandName}` : ''}`}`;
13
13
  if (!(parent instanceof __1.Command))
14
14
  return { fullCommandName };
15
15
  if (groupName && !parent.groups?.[groupName])
16
- return getCommandFromContent([parentName, subcommandName], self);
16
+ return getCommandFromContent([parentName, groupName], self);
17
17
  if (subcommandName && !parent.options?.some(x => x instanceof __1.SubCommand && x.name === subcommandName))
18
18
  return getCommandFromContent([parentName], self);
19
19
  const command = groupName || subcommandName
@@ -50,7 +50,8 @@ async function onMessageCreate(self, rawMessage, shardId) {
50
50
  return;
51
51
  if (!command.run)
52
52
  return self.logger.warn(`${fullCommandName} command does not have 'run' callback`);
53
- if (command.dm && !message.guildId)
53
+ if ([__1.InteractionContextTypes.BOT_DM, __1.InteractionContextTypes.PRIVATE_CHANNEL].some(i => command.contexts?.includes(i)) &&
54
+ !message.guildId)
54
55
  return;
55
56
  if (command.guild_id && !command.guild_id?.includes(message.guildId))
56
57
  return;
@@ -64,7 +65,10 @@ async function onMessageCreate(self, rawMessage, shardId) {
64
65
  const args = (self.options?.commands?.argsParser ?? defaultArgsParser)(content, command);
65
66
  const { options, errors } = await parseOptions(self, command, rawMessage, args, resolved);
66
67
  const optionsResolver = new __1.OptionResolver(self, options, parent, message.guildId, resolved);
67
- const context = new __1.CommandContext(self, message, optionsResolver, shardId);
68
+ const context = new __1.CommandContext(self, message, optionsResolver, shardId, command);
69
+ //@ts-expect-error
70
+ const extendContext = self.options?.context?.(message) ?? {};
71
+ Object.assign(context, extendContext);
68
72
  try {
69
73
  if (command.botPermissions && message.guildId) {
70
74
  const meMember = await self.cache.members?.get(self.botId, message.guildId);
@@ -128,119 +132,192 @@ async function parseOptions(self, command, message, args, resolved) {
128
132
  const options = [];
129
133
  const errors = [];
130
134
  for (const i of (command.options ?? [])) {
131
- let value;
132
- let indexAttachment = -1;
133
- switch (i.type) {
134
- case v10_1.ApplicationCommandOptionType.Attachment:
135
- if (message.attachments[++indexAttachment]) {
136
- value = message.attachments[indexAttachment].id;
137
- resolved.attachments[value] = message.attachments[indexAttachment];
138
- }
139
- break;
140
- case v10_1.ApplicationCommandOptionType.Boolean:
141
- if (args[i.name]) {
142
- value = ['yes', 'y', 'true', 'treu'].includes(args[i.name].toLowerCase());
143
- }
144
- break;
145
- case v10_1.ApplicationCommandOptionType.Channel:
146
- {
147
- const rawId = message.content.match(/(?<=<#)[0-9]{17,19}(?=>)/g)?.find(x => args[i.name]?.includes(x));
148
- if (rawId) {
149
- const channel = i.required ? await self.channels.fetch(rawId) : await self.cache.channels?.get(rawId);
150
- if (channel) {
151
- if ('channel_types' in i) {
152
- if (!i.channel_types.includes(channel.type)) {
153
- errors.push({
154
- name: i.name,
155
- error: `The entered channel type is not one of ${i
156
- .channel_types.map(t => v10_1.ChannelType[t])
157
- .join(', ')}`,
158
- });
159
- break;
135
+ try {
136
+ let value;
137
+ let indexAttachment = -1;
138
+ switch (i.type) {
139
+ case v10_1.ApplicationCommandOptionType.Attachment:
140
+ if (message.attachments[++indexAttachment]) {
141
+ value = message.attachments[indexAttachment].id;
142
+ resolved.attachments[value] = message.attachments[indexAttachment];
143
+ }
144
+ break;
145
+ case v10_1.ApplicationCommandOptionType.Boolean:
146
+ if (args[i.name]) {
147
+ value = ['yes', 'y', 'true', 'treu'].includes(args[i.name].toLowerCase());
148
+ }
149
+ break;
150
+ case v10_1.ApplicationCommandOptionType.Channel:
151
+ {
152
+ const rawId = message.content.match(/(?<=<#)[0-9]{17,19}(?=>)/g)?.find(x => args[i.name]?.includes(x)) ||
153
+ args[i.name]?.match(/[0-9]{17,19}/g)?.[0];
154
+ if (rawId) {
155
+ const channel = (await self.cache.channels?.get(rawId)) ?? (i.required ? await self.channels.fetch(rawId) : undefined);
156
+ if (channel) {
157
+ if ('channel_types' in i) {
158
+ if (!i.channel_types.includes(channel.type)) {
159
+ errors.push({
160
+ name: i.name,
161
+ error: `The entered channel type is not one of ${i
162
+ .channel_types.map(t => v10_1.ChannelType[t])
163
+ .join(', ')}`,
164
+ });
165
+ break;
166
+ }
160
167
  }
168
+ value = rawId;
169
+ resolved.channels[rawId] = channel;
161
170
  }
162
- value = rawId;
163
- //@ts-expect-error
164
- resolved.channels[rawId] = channel;
165
171
  }
166
172
  }
167
- }
168
- break;
169
- case v10_1.ApplicationCommandOptionType.Mentionable:
170
- {
171
- const matches = message.content.match(/<@[0-9]{17,19}(?=>)|<@&[0-9]{17,19}(?=>)/g) ?? [];
172
- for (const match of matches) {
173
- if (match.includes('&')) {
174
- const rawId = match.slice(3);
175
- if (rawId) {
176
- const role = i.required
177
- ? (await self.roles.list(message.guild_id)).find(x => x.id === rawId)
178
- : await self.cache.roles?.get(rawId);
179
- if (role) {
180
- value = rawId;
181
- //@ts-expect-error
182
- resolved.roles[rawId] = role;
173
+ break;
174
+ case v10_1.ApplicationCommandOptionType.Mentionable:
175
+ {
176
+ const matches = message.content.match(/<@[0-9]{17,19}(?=>)|<@&[0-9]{17,19}(?=>)/g) ?? [];
177
+ for (const match of matches) {
178
+ if (match.includes('&')) {
179
+ const rawId = match.slice(3);
180
+ if (rawId) {
181
+ const role = (await self.cache.roles?.get(rawId)) ??
182
+ (i.required ? (await self.roles.list(message.guild_id)).find(x => x.id === rawId) : undefined);
183
+ if (role) {
184
+ value = rawId;
185
+ resolved.roles[rawId] = role;
186
+ break;
187
+ }
188
+ }
189
+ }
190
+ else {
191
+ const rawId = match.slice(2);
192
+ const raw = message.mentions.find(x => rawId === x.id);
193
+ if (raw) {
194
+ const { member, ...user } = raw;
195
+ value = raw.id;
196
+ resolved.users[raw.id] = user;
197
+ if (member)
198
+ resolved.members[raw.id] = member;
183
199
  break;
184
200
  }
185
201
  }
186
202
  }
187
- else {
188
- const rawId = match.slice(2);
189
- const raw = message.mentions.find(x => rawId === x.id);
203
+ }
204
+ break;
205
+ case v10_1.ApplicationCommandOptionType.Role:
206
+ {
207
+ const rawId = message.mention_roles.find(x => args[i.name]?.includes(x)) || args[i.name]?.match(/[0-9]{17,19}/g)?.[0];
208
+ if (rawId) {
209
+ const role = (await self.cache.roles?.get(rawId)) ??
210
+ (i.required ? (await self.roles.list(message.guild_id)).find(x => x.id === rawId) : undefined);
211
+ if (role) {
212
+ value = rawId;
213
+ resolved.roles[rawId] = role;
214
+ }
215
+ }
216
+ }
217
+ break;
218
+ case v10_1.ApplicationCommandOptionType.User:
219
+ {
220
+ const rawId = message.mentions.find(x => args[i.name]?.includes(x.id))?.id || args[i.name]?.match(/[0-9]{17,19}/g)?.[0];
221
+ if (rawId) {
222
+ const raw = message.mentions.find(x => args[i.name]?.includes(x.id)) ??
223
+ (await self.cache.users?.get(rawId)) ??
224
+ (i.required ? await self.users.fetch(rawId) : undefined);
190
225
  if (raw) {
191
226
  value = raw.id;
192
- resolved.users[raw.id] = raw;
193
- break;
227
+ if (raw instanceof __1.User) {
228
+ resolved.users[raw.id] = raw;
229
+ if (message.guild_id) {
230
+ const member = message.mentions.find(x => args[i.name]?.includes(x.id))?.member ??
231
+ (await self.cache.members?.get(rawId, message.guild_id)) ??
232
+ (i.required ? await self.members.fetch(rawId, message.guild_id) : undefined);
233
+ if (member)
234
+ resolved.members[raw.id] = member;
235
+ }
236
+ }
237
+ else {
238
+ const { member, ...user } = raw;
239
+ resolved.users[user.id] = user;
240
+ if (member)
241
+ resolved.members[user.id] = member;
242
+ }
194
243
  }
195
244
  }
196
245
  }
197
- }
198
- break;
199
- case v10_1.ApplicationCommandOptionType.Role:
200
- {
201
- const rawId = message.mention_roles.find(x => args[i.name]?.includes(x));
202
- if (rawId) {
203
- const role = i.required
204
- ? (await self.roles.list(message.guild_id)).find(x => x.id === rawId) //why, discord, why
205
- : await self.cache.roles?.get(rawId);
206
- if (role) {
207
- value = rawId;
208
- //@ts-expect-error
209
- resolved.roles[rawId] = role;
246
+ break;
247
+ case v10_1.ApplicationCommandOptionType.String:
248
+ {
249
+ value = args[i.name];
250
+ const option = i;
251
+ if (value) {
252
+ if (option.min_length) {
253
+ if (value.length < option.min_length) {
254
+ value = undefined;
255
+ errors.push({
256
+ name: i.name,
257
+ error: `The entered string has less than ${option.min_length} characters. The minimum required is ${option.min_length} characters.`,
258
+ });
259
+ break;
260
+ }
261
+ }
262
+ if (option.max_length) {
263
+ if (value.length > option.max_length) {
264
+ value = undefined;
265
+ errors.push({
266
+ name: i.name,
267
+ error: `The entered string has more than ${option.max_length} characters. The maximum required is ${option.max_length} characters.`,
268
+ });
269
+ break;
270
+ }
271
+ }
272
+ if (option.choices?.length) {
273
+ if (!option.choices.some(x => x.name === value)) {
274
+ value = undefined;
275
+ errors.push({
276
+ name: i.name,
277
+ error: `The entered choice is invalid. Please choose one of the following options: ${option.choices
278
+ .map(x => x.name)
279
+ .join(', ')}.`,
280
+ });
281
+ break;
282
+ }
283
+ value = option.choices.find(x => x.name === value).value;
284
+ }
210
285
  }
211
286
  }
212
- }
213
- break;
214
- case v10_1.ApplicationCommandOptionType.User:
215
- {
216
- const raw = message.mentions.find(x => args[i.name]?.includes(x.id));
217
- if (raw) {
218
- value = raw.id;
219
- resolved.users[raw.id] = raw;
220
- }
221
- }
222
- break;
223
- case v10_1.ApplicationCommandOptionType.String:
224
- {
225
- value = args[i.name];
226
- const option = i;
227
- if (value) {
228
- if (option.min_length) {
229
- if (value.length < option.min_length) {
287
+ break;
288
+ case v10_1.ApplicationCommandOptionType.Number:
289
+ case v10_1.ApplicationCommandOptionType.Integer:
290
+ {
291
+ value = Number(args[i.name]);
292
+ if (args[i.name] === undefined) {
293
+ value = undefined;
294
+ break;
295
+ }
296
+ if (Number.isNaN(value)) {
297
+ value = undefined;
298
+ errors.push({
299
+ name: i.name,
300
+ error: 'The entered choice is an invalid number.',
301
+ });
302
+ break;
303
+ }
304
+ const option = i;
305
+ if (option.min_value) {
306
+ if (value < option.min_value) {
230
307
  value = undefined;
231
308
  errors.push({
232
309
  name: i.name,
233
- error: `The entered string has less than ${option.min_length} characters. The minimum required is ${option.min_length} characters.`,
310
+ error: `The entered number is less than ${option.min_value}. The minimum allowed is ${option.min_value}`,
234
311
  });
235
312
  break;
236
313
  }
237
314
  }
238
- if (option.max_length) {
239
- if (value.length > option.max_length) {
315
+ if (option.max_value) {
316
+ if (value > option.max_value) {
240
317
  value = undefined;
241
318
  errors.push({
242
319
  name: i.name,
243
- error: `The entered string has more than ${option.max_length} characters. The maximum required is ${option.max_length} characters.`,
320
+ error: `The entered number is greater than ${option.max_value}. The maximum allowed is ${option.max_value}`,
244
321
  });
245
322
  break;
246
323
  }
@@ -259,68 +336,27 @@ async function parseOptions(self, command, message, args, resolved) {
259
336
  value = option.choices.find(x => x.name === value).value;
260
337
  }
261
338
  }
262
- }
263
- break;
264
- case v10_1.ApplicationCommandOptionType.Number:
265
- case v10_1.ApplicationCommandOptionType.Integer:
266
- {
267
- value = Number(args[i.name]);
268
- if (args[i.name] === undefined) {
269
- value = undefined;
270
- break;
271
- }
272
- if (Number.isNaN(value)) {
273
- value = undefined;
274
- errors.push({
275
- name: i.name,
276
- error: 'The entered choice is an invalid number.',
277
- });
278
- break;
279
- }
280
- const option = i;
281
- if (option.min_value) {
282
- if (value < option.min_value) {
283
- value = undefined;
284
- errors.push({
285
- name: i.name,
286
- error: `The entered number is less than ${option.min_value}. The minimum allowed is ${option.min_value}`,
287
- });
288
- break;
289
- }
290
- }
291
- if (option.max_value) {
292
- if (value > option.max_value) {
293
- value = undefined;
294
- errors.push({
295
- name: i.name,
296
- error: `The entered number is greater than ${option.max_value}. The maximum allowed is ${option.max_value}`,
297
- });
298
- break;
299
- }
300
- }
301
- if (option.choices?.length) {
302
- if (!option.choices.some(x => x.name === value)) {
303
- value = undefined;
304
- errors.push({
305
- name: i.name,
306
- error: `The entered choice is invalid. Please choose one of the following options: ${option.choices
307
- .map(x => x.name)
308
- .join(', ')}.`,
309
- });
310
- break;
311
- }
312
- value = option.choices.find(x => x.name === value).value;
313
- }
314
- }
315
- break;
316
- default:
317
- break;
339
+ break;
340
+ default:
341
+ break;
342
+ }
343
+ if (value !== undefined) {
344
+ options.push({
345
+ name: i.name,
346
+ type: i.type,
347
+ value,
348
+ });
349
+ }
350
+ else if (i.required)
351
+ errors.push({
352
+ error: 'Option is required but returned undefined',
353
+ name: i.name,
354
+ });
318
355
  }
319
- if (value !== undefined) {
320
- options.push({
356
+ catch (e) {
357
+ errors.push({
358
+ error: e && typeof e === 'object' && 'message' in e ? e.message : `${e}`,
321
359
  name: i.name,
322
- type: i.type,
323
- value,
324
360
  });
325
361
  }
326
362
  }
@@ -1,3 +1,8 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
4
+ /// <reference types="node" />
5
+ /// <reference types="node" />
1
6
  import type { Cache } from '../cache';
2
7
  import type { GatewayDispatchPayload, When } from '../common';
3
8
  import { Logger, type DeepPartial } from '../common';
@@ -14,13 +19,22 @@ export declare class WorkerClient<Ready extends boolean = boolean> extends BaseC
14
19
  logger: Logger;
15
20
  events: EventHandler;
16
21
  me: When<Ready, ClientUser>;
22
+ promises: Map<string, {
23
+ resolve: (value: any) => void;
24
+ timeout: NodeJS.Timeout;
25
+ }>;
17
26
  shards: Map<number, Shard>;
18
27
  options: WorkerClientOptions | undefined;
19
28
  constructor(options?: WorkerClientOptions);
20
29
  get workerId(): number;
30
+ get latency(): number;
21
31
  start(options?: Omit<DeepPartial<StartOptions>, 'httpConnection' | 'token' | 'connection'>): Promise<void>;
22
32
  loadEvents(dir?: string): Promise<void>;
23
- protected handleManagerMessages(data: ManagerMessages): Promise<void>;
33
+ postMessage(body: any): boolean | void;
34
+ protected handleManagerMessages(data: ManagerMessages): Promise<any>;
35
+ private generateNonce;
36
+ private generateSendPromise;
37
+ tellWorker(workerId: number, func: (_: this) => {}): Promise<unknown>;
24
38
  protected onPacket(packet: GatewayDispatchPayload, shardId: number): Promise<void>;
25
39
  }
26
40
  export declare function generateShardInfo(shard: Shard): WorkerShardInfo;