seyfert 0.1.0 → 1.0.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 (193) hide show
  1. package/README.md +19 -30
  2. package/lib/api/CDN.d.ts +0 -8
  3. package/lib/api/CDN.js +7 -13
  4. package/lib/api/Router.d.ts +2 -2
  5. package/lib/api/Router.js +1 -1
  6. package/lib/api/Routes/applications.d.ts +1 -1
  7. package/lib/api/Routes/channels.d.ts +1 -1
  8. package/lib/api/Routes/gateway.d.ts +1 -1
  9. package/lib/api/Routes/guilds.d.ts +1 -1
  10. package/lib/api/Routes/interactions.d.ts +1 -1
  11. package/lib/api/Routes/invites.d.ts +1 -1
  12. package/lib/api/Routes/stage-instances.d.ts +1 -1
  13. package/lib/api/Routes/stickers.d.ts +1 -1
  14. package/lib/api/Routes/users.d.ts +1 -1
  15. package/lib/api/Routes/voice.d.ts +1 -1
  16. package/lib/api/Routes/webhooks.d.ts +1 -1
  17. package/lib/api/api.d.ts +39 -0
  18. package/lib/api/api.js +318 -0
  19. package/lib/api/bucket.d.ts +19 -0
  20. package/lib/api/bucket.js +71 -0
  21. package/lib/api/index.d.ts +1 -1
  22. package/lib/api/index.js +1 -1
  23. package/lib/api/shared.d.ts +31 -5
  24. package/lib/api/shared.js +2 -7
  25. package/lib/api/utils/constants.d.ts +1 -30
  26. package/lib/api/utils/constants.js +2 -41
  27. package/lib/api/utils/types.d.ts +1 -320
  28. package/lib/api/utils/utils.d.ts +0 -38
  29. package/lib/api/utils/utils.js +1 -139
  30. package/lib/builders/ActionRow.js +1 -1
  31. package/lib/builders/Attachment.d.ts +14 -6
  32. package/lib/builders/Attachment.js +30 -7
  33. package/lib/builders/Button.d.ts +3 -12
  34. package/lib/builders/Button.js +0 -11
  35. package/lib/builders/{MessageEmbed.d.ts → Embed.d.ts} +15 -15
  36. package/lib/builders/{MessageEmbed.js → Embed.js} +16 -16
  37. package/lib/builders/Modal.js +1 -1
  38. package/lib/builders/SelectMenu.d.ts +14 -15
  39. package/lib/builders/SelectMenu.js +19 -18
  40. package/lib/builders/index.d.ts +1 -1
  41. package/lib/builders/index.js +1 -1
  42. package/lib/builders/types.d.ts +2 -2
  43. package/lib/cache/adapters/default.js +2 -2
  44. package/lib/cache/adapters/redis.d.ts +2 -3
  45. package/lib/cache/adapters/redis.js +13 -5
  46. package/lib/cache/adapters/workeradapter.d.ts +9 -1
  47. package/lib/cache/adapters/workeradapter.js +7 -3
  48. package/lib/cache/index.d.ts +20 -6
  49. package/lib/cache/index.js +26 -10
  50. package/lib/cache/resources/channels.d.ts +6 -2
  51. package/lib/cache/resources/channels.js +12 -6
  52. package/lib/cache/resources/default/base.d.ts +17 -16
  53. package/lib/cache/resources/default/base.js +25 -24
  54. package/lib/cache/resources/default/guild-based.d.ts +22 -19
  55. package/lib/cache/resources/default/guild-based.js +32 -31
  56. package/lib/cache/resources/default/guild-related.d.ts +22 -19
  57. package/lib/cache/resources/default/guild-related.js +37 -43
  58. package/lib/cache/resources/emojis.d.ts +4 -2
  59. package/lib/cache/resources/emojis.js +8 -6
  60. package/lib/cache/resources/guilds.d.ts +4 -2
  61. package/lib/cache/resources/guilds.js +15 -8
  62. package/lib/cache/resources/members.d.ts +4 -2
  63. package/lib/cache/resources/members.js +16 -13
  64. package/lib/cache/resources/overwrites.d.ts +25 -0
  65. package/lib/cache/resources/overwrites.js +39 -0
  66. package/lib/cache/resources/presence.js +3 -4
  67. package/lib/cache/resources/roles.d.ts +4 -2
  68. package/lib/cache/resources/roles.js +8 -6
  69. package/lib/cache/resources/stickers.d.ts +4 -2
  70. package/lib/cache/resources/stickers.js +8 -6
  71. package/lib/cache/resources/threads.d.ts +4 -2
  72. package/lib/cache/resources/threads.js +8 -6
  73. package/lib/cache/resources/users.d.ts +4 -2
  74. package/lib/cache/resources/users.js +8 -6
  75. package/lib/cache/resources/voice-states.d.ts +3 -3
  76. package/lib/cache/resources/voice-states.js +6 -7
  77. package/lib/client/base.d.ts +49 -16
  78. package/lib/client/base.js +21 -17
  79. package/lib/client/client.d.ts +14 -3
  80. package/lib/client/client.js +21 -21
  81. package/lib/client/httpclient.d.ts +3 -5
  82. package/lib/client/httpclient.js +29 -16
  83. package/lib/client/{oninteraction.d.ts → oninteractioncreate.d.ts} +1 -1
  84. package/lib/client/{oninteraction.js → oninteractioncreate.js} +34 -23
  85. package/lib/client/onmessagecreate.d.ts +3 -0
  86. package/lib/client/onmessagecreate.js +337 -0
  87. package/lib/client/workerclient.d.ts +5 -1
  88. package/lib/client/workerclient.js +67 -44
  89. package/lib/collection.d.ts +1 -1
  90. package/lib/collection.js +9 -6
  91. package/lib/commands/applications/chat.d.ts +32 -25
  92. package/lib/commands/applications/chat.js +51 -34
  93. package/lib/commands/applications/chatcontext.d.ts +34 -16
  94. package/lib/commands/applications/chatcontext.js +99 -20
  95. package/lib/commands/applications/menu.d.ts +9 -8
  96. package/lib/commands/applications/menu.js +14 -5
  97. package/lib/commands/applications/menucontext.d.ts +27 -10
  98. package/lib/commands/applications/menucontext.js +51 -7
  99. package/lib/commands/applications/options.d.ts +13 -13
  100. package/lib/commands/applications/shared.d.ts +7 -2
  101. package/lib/commands/decorators.d.ts +14 -14
  102. package/lib/commands/decorators.js +9 -5
  103. package/lib/commands/handler.d.ts +2 -1
  104. package/lib/commands/handler.js +60 -14
  105. package/lib/commands/index.d.ts +1 -1
  106. package/lib/commands/index.js +2 -1
  107. package/lib/commands/optionresolver.d.ts +6 -5
  108. package/lib/commands/optionresolver.js +10 -6
  109. package/lib/common/bot/watcher.d.ts +3 -3
  110. package/lib/common/bot/watcher.js +3 -1
  111. package/lib/common/index.d.ts +1 -1
  112. package/lib/common/index.js +2 -1
  113. package/lib/common/it/logger.d.ts +11 -0
  114. package/lib/common/it/logger.js +51 -2
  115. package/lib/common/it/utils.d.ts +3 -13
  116. package/lib/common/it/utils.js +9 -30
  117. package/lib/common/shorters/channels.d.ts +55 -5
  118. package/lib/common/shorters/channels.js +59 -0
  119. package/lib/common/shorters/guilds.d.ts +5 -2
  120. package/lib/common/shorters/guilds.js +18 -0
  121. package/lib/common/shorters/messages.js +0 -2
  122. package/lib/common/shorters/overwrites.d.ts +29 -0
  123. package/lib/common/shorters/overwrites.js +63 -0
  124. package/lib/common/shorters/roles.js +3 -3
  125. package/lib/common/shorters/webhook.d.ts +2 -2
  126. package/lib/common/types/util.d.ts +2 -1
  127. package/lib/common/types/write.d.ts +3 -7
  128. package/lib/components/handler.d.ts +12 -18
  129. package/lib/components/handler.js +58 -103
  130. package/lib/components/index.d.ts +0 -1
  131. package/lib/components/index.js +0 -1
  132. package/lib/components/listener.d.ts +2 -2
  133. package/lib/components/listener.js +2 -3
  134. package/lib/events/event.d.ts +2 -2
  135. package/lib/events/handler.d.ts +3 -2
  136. package/lib/events/handler.js +14 -6
  137. package/lib/events/hooks/dispatch.d.ts +2 -1
  138. package/lib/events/hooks/dispatch.js +5 -1
  139. package/lib/events/hooks/thread.d.ts +63 -63
  140. package/lib/index.d.ts +8 -5
  141. package/lib/index.js +20 -10
  142. package/lib/langs/handler.d.ts +6 -4
  143. package/lib/langs/handler.js +10 -8
  144. package/lib/langs/router.d.ts +8 -9
  145. package/lib/langs/router.js +5 -5
  146. package/lib/structures/ClientUser.d.ts +1 -16
  147. package/lib/structures/ClientUser.js +0 -31
  148. package/lib/structures/Guild.d.ts +1 -1
  149. package/lib/structures/GuildMember.d.ts +12 -0
  150. package/lib/structures/GuildMember.js +14 -0
  151. package/lib/structures/GuildRole.d.ts +4 -2
  152. package/lib/structures/GuildRole.js +4 -1
  153. package/lib/structures/GuildTemplate.js +1 -1
  154. package/lib/structures/Interaction.d.ts +2 -0
  155. package/lib/structures/Interaction.js +12 -13
  156. package/lib/structures/Message.d.ts +7 -2
  157. package/lib/structures/Message.js +6 -3
  158. package/lib/structures/Sticker.d.ts +1 -1
  159. package/lib/structures/Sticker.js +1 -1
  160. package/lib/structures/User.d.ts +5 -0
  161. package/lib/structures/User.js +3 -0
  162. package/lib/structures/Webhook.d.ts +1 -1
  163. package/lib/structures/Webhook.js +1 -1
  164. package/lib/structures/channels.d.ts +45 -6
  165. package/lib/structures/channels.js +23 -7
  166. package/lib/structures/extra/BitField.d.ts +9 -6
  167. package/lib/structures/extra/BitField.js +27 -3
  168. package/lib/structures/extra/Permissions.d.ts +6 -1
  169. package/lib/structures/extra/Permissions.js +7 -0
  170. package/lib/websocket/discord/basesocket.js +0 -1
  171. package/lib/websocket/discord/workermanager.d.ts +9 -1
  172. package/lib/websocket/discord/workermanager.js +21 -13
  173. package/package.json +21 -20
  174. package/lib/api/REST.d.ts +0 -127
  175. package/lib/api/REST.js +0 -424
  176. package/lib/api/errors/DiscordAPIError.d.ts +0 -51
  177. package/lib/api/errors/DiscordAPIError.js +0 -81
  178. package/lib/api/errors/HTTPError.d.ts +0 -20
  179. package/lib/api/errors/HTTPError.js +0 -28
  180. package/lib/api/errors/RateLimitError.d.ts +0 -19
  181. package/lib/api/errors/RateLimitError.js +0 -37
  182. package/lib/api/handlers/BurstHandler.d.ts +0 -51
  183. package/lib/api/handlers/BurstHandler.js +0 -124
  184. package/lib/api/handlers/SequentialHandler.d.ts +0 -81
  185. package/lib/api/handlers/SequentialHandler.js +0 -365
  186. package/lib/api/handlers/Shared.d.ts +0 -14
  187. package/lib/api/handlers/Shared.js +0 -125
  188. package/lib/api/interfaces/Handler.d.ts +0 -21
  189. package/lib/api/interfaces/Handler.js +0 -2
  190. package/lib/websocket/discord/handlemessage.d.ts +0 -0
  191. package/lib/websocket/discord/handlemessage.js +0 -1
  192. package/lib/websocket/discord/memberUpdate.d.ts +0 -16
  193. package/lib/websocket/discord/memberUpdate.js +0 -47
@@ -1,7 +1,6 @@
1
- import { type APIChannelSelectComponent, type APIMentionableSelectComponent, type APIMessageComponentEmoji, type APIRoleSelectComponent, type APISelectMenuComponent, type APISelectMenuOption, type APIStringSelectComponent, type APIUserSelectComponent, type ChannelType, type RestOrArray } from '../common';
1
+ import { type APIChannelSelectComponent, type APIMentionableSelectComponent, type APIRoleSelectComponent, type APISelectMenuComponent, type APISelectMenuOption, type APIStringSelectComponent, type APIUserSelectComponent, type ChannelType, type EmojiResolvable, type RestOrArray, type ToClass } from '../common';
2
2
  import type { ChannelSelectMenuInteraction, ComponentInteraction, MentionableSelectMenuInteraction, RoleSelectMenuInteraction, StringSelectMenuInteraction, UserSelectMenuInteraction } from '../structures';
3
3
  import { BaseComponentBuilder, type OptionValuesLength } from './Base';
4
- import type { ComponentCallback } from './types';
5
4
  export type BuilderSelectMenus = RoleSelectMenu | UserSelectMenu | MentionableSelectMenu | ChannelSelectMenu | StringSelectMenu;
6
5
  /**
7
6
  * Represents a base class for building Select Menus.
@@ -40,12 +39,6 @@ export declare class SelectMenu<Select extends APISelectMenuComponent = APISelec
40
39
  * @returns The current SelectMenu instance.
41
40
  */
42
41
  setDisabled(disabled?: boolean): this;
43
- /**
44
- * Sets the callback function to be executed when the select menu is interacted with.
45
- * func - The callback function.
46
- * @returns The current SelectMenu instance.
47
- */
48
- run(func: ComponentCallback<Interaction>): this;
49
42
  }
50
43
  /**
51
44
  * Represents a Select Menu for selecting users.
@@ -129,6 +122,7 @@ export declare class ChannelSelectMenu extends SelectMenu<APIChannelSelectCompon
129
122
  */
130
123
  setChannelTypes(types: ChannelType[]): this;
131
124
  }
125
+ declare const StringSelectMenu_base: ToClass<Omit<SelectMenu<APIStringSelectComponent, StringSelectMenuInteraction<string[]>>, "data" | "toJSON">, StringSelectMenu>;
132
126
  /**
133
127
  * Represents a Select Menu for selecting string options.
134
128
  * @example
@@ -140,20 +134,24 @@ export declare class ChannelSelectMenu extends SelectMenu<APIChannelSelectCompon
140
134
  * { label: "Option 3", value: "option_3" },
141
135
  * ]);
142
136
  */
143
- export declare class StringSelectMenu extends SelectMenu<APIStringSelectComponent, StringSelectMenuInteraction> {
137
+ export declare class StringSelectMenu extends StringSelectMenu_base {
138
+ data: Omit<APIStringSelectComponent, 'options'> & {
139
+ options: StringSelectOption[];
140
+ };
144
141
  constructor(data?: Partial<APIStringSelectComponent>);
145
142
  /**
146
143
  * Adds options to the string select menu.
147
- * @param {...RestOrArray<APISelectMenuOption>} options - Options to be added.
144
+ * @param options - Options to be added.
148
145
  * @returns The current StringSelectMenu instance.
149
146
  */
150
- addOption(...options: RestOrArray<APISelectMenuOption>): this;
147
+ addOption(...options: RestOrArray<StringSelectOption>): this;
151
148
  /**
152
149
  * Sets the options for the string select menu.
153
150
  * options - Options to be set.
154
151
  * @returns The current StringSelectMenu instance.
155
152
  */
156
- setOptions(options: APISelectMenuOption[]): this;
153
+ setOptions(options: StringSelectOption[]): this;
154
+ toJSON(): APIStringSelectComponent;
157
155
  }
158
156
  /**
159
157
  * Represents an individual option for a string select menu.
@@ -189,13 +187,14 @@ export declare class StringSelectOption {
189
187
  setDefault(Default?: boolean): this;
190
188
  /**
191
189
  * Sets the emoji for the option.
192
- * emoji - The emoji for the option.
193
- * @returns The current StringSelectOption instance.
190
+ * @param emoji - The emoji to set.
191
+ * @returns The modified option instance.
194
192
  */
195
- setEmoji(emoji: APIMessageComponentEmoji): this;
193
+ setEmoji(emoji: EmojiResolvable): this;
196
194
  /**
197
195
  * Converts the option to JSON format.
198
196
  * @returns The option data in JSON format.
199
197
  */
200
198
  toJSON(): APISelectMenuOption;
201
199
  }
200
+ export {};
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StringSelectOption = exports.StringSelectMenu = exports.ChannelSelectMenu = exports.MentionableSelectMenu = exports.RoleSelectMenu = exports.UserSelectMenu = exports.SelectMenu = void 0;
4
+ const __1 = require("..");
4
5
  const common_1 = require("../common");
6
+ const functions_1 = require("../structures/extra/functions");
5
7
  const Base_1 = require("./Base");
6
8
  /**
7
9
  * Maps default values for Select Menus.
@@ -11,7 +13,7 @@ const Base_1 = require("./Base");
11
13
  * @returns An array of default values.
12
14
  */
13
15
  function mappedDefault(ids, type) {
14
- return (0, common_1.fastMap)((0, common_1.fastFlat)(ids), id => ({ id, type }));
16
+ return ids.flat().map(id => ({ id, type }));
15
17
  }
16
18
  /**
17
19
  * Represents a base class for building Select Menus.
@@ -26,8 +28,6 @@ function mappedDefault(ids, type) {
26
28
  * });
27
29
  */
28
30
  class SelectMenu extends Base_1.BaseComponentBuilder {
29
- /** @internal */
30
- __exec;
31
31
  /**
32
32
  * Sets the custom ID for the select menu.
33
33
  * @param id - The custom ID for the select menu.
@@ -65,15 +65,6 @@ class SelectMenu extends Base_1.BaseComponentBuilder {
65
65
  this.data.disabled = disabled;
66
66
  return this;
67
67
  }
68
- /**
69
- * Sets the callback function to be executed when the select menu is interacted with.
70
- * func - The callback function.
71
- * @returns The current SelectMenu instance.
72
- */
73
- run(func) {
74
- this.__exec = func;
75
- return this;
76
- }
77
68
  }
78
69
  exports.SelectMenu = SelectMenu;
79
70
  /**
@@ -205,15 +196,15 @@ exports.ChannelSelectMenu = ChannelSelectMenu;
205
196
  class StringSelectMenu extends SelectMenu {
206
197
  constructor(data = {}) {
207
198
  super({ ...data, type: common_1.ComponentType.StringSelect });
199
+ this.data.options = (data.options ?? []).map(x => new StringSelectOption(x));
208
200
  }
209
201
  /**
210
202
  * Adds options to the string select menu.
211
- * @param {...RestOrArray<APISelectMenuOption>} options - Options to be added.
203
+ * @param options - Options to be added.
212
204
  * @returns The current StringSelectMenu instance.
213
205
  */
214
206
  addOption(...options) {
215
- this.data.options ??= [];
216
- this.data.options = this.data.options.concat((0, common_1.fastFlat)(options));
207
+ this.data.options = this.data.options.concat(options.flat());
217
208
  return this;
218
209
  }
219
210
  /**
@@ -225,6 +216,13 @@ class StringSelectMenu extends SelectMenu {
225
216
  this.data.options = options;
226
217
  return this;
227
218
  }
219
+ toJSON() {
220
+ const { options, ...raw } = this.data;
221
+ return {
222
+ ...raw,
223
+ options: this.data.options.map(x => x.toJSON()),
224
+ };
225
+ }
228
226
  }
229
227
  exports.StringSelectMenu = StringSelectMenu;
230
228
  /**
@@ -275,11 +273,14 @@ class StringSelectOption {
275
273
  }
276
274
  /**
277
275
  * Sets the emoji for the option.
278
- * emoji - The emoji for the option.
279
- * @returns The current StringSelectOption instance.
276
+ * @param emoji - The emoji to set.
277
+ * @returns The modified option instance.
280
278
  */
281
279
  setEmoji(emoji) {
282
- this.data.emoji = emoji;
280
+ const resolve = (0, functions_1.resolvePartialEmoji)(emoji);
281
+ if (!resolve)
282
+ return (0, __1.throwError)('Invalid Emoji');
283
+ this.data.emoji = resolve;
283
284
  return this;
284
285
  }
285
286
  /**
@@ -5,7 +5,7 @@ export * from './ActionRow';
5
5
  export * from './Attachment';
6
6
  export * from './Base';
7
7
  export * from './Button';
8
- export * from './MessageEmbed';
8
+ export * from './Embed';
9
9
  export * from './Modal';
10
10
  export * from './SelectMenu';
11
11
  export * from './types';
@@ -24,7 +24,7 @@ __exportStar(require("./ActionRow"), exports);
24
24
  __exportStar(require("./Attachment"), exports);
25
25
  __exportStar(require("./Base"), exports);
26
26
  __exportStar(require("./Button"), exports);
27
- __exportStar(require("./MessageEmbed"), exports);
27
+ __exportStar(require("./Embed"), exports);
28
28
  __exportStar(require("./Modal"), exports);
29
29
  __exportStar(require("./SelectMenu"), exports);
30
30
  __exportStar(require("./types"), exports);
@@ -1,8 +1,8 @@
1
- import type { ComponentInteraction, ModalSubmitInteraction } from '../structures/Interaction';
1
+ import type { ComponentInteraction, ModalSubmitInteraction, StringSelectMenuInteraction } from '../structures/Interaction';
2
2
  import type { Button } from './Button';
3
3
  import type { TextInput } from './Modal';
4
4
  import type { BuilderSelectMenus } from './SelectMenu';
5
- export type ComponentCallback<T = ComponentInteraction> = (interaction: T, stop: ComponentStopCallback, refresh: ComponentRefreshCallback) => any;
5
+ export type ComponentCallback = (interaction: ComponentInteraction | StringSelectMenuInteraction, stop: ComponentStopCallback, refresh: ComponentRefreshCallback) => any;
6
6
  export type ComponentFilterCallback<T = ComponentInteraction> = (interaction: T) => any;
7
7
  export type ComponentStopCallback = (reason?: string, refresh?: ComponentRefreshCallback) => any;
8
8
  export type ComponentRefreshCallback = () => any;
@@ -43,7 +43,7 @@ class MemoryAdapter {
43
43
  if (updateOnly && !oldData) {
44
44
  continue;
45
45
  }
46
- this.storage.set(key, JSON.stringify({ ...(oldData ?? {}), ...value }));
46
+ this.storage.set(key, Array.isArray(value) ? JSON.stringify(value) : JSON.stringify({ ...(oldData ?? {}), ...value }));
47
47
  }
48
48
  }
49
49
  else {
@@ -51,7 +51,7 @@ class MemoryAdapter {
51
51
  if (updateOnly && !oldData) {
52
52
  return;
53
53
  }
54
- this.storage.set(keys, JSON.stringify({ ...(oldData ?? {}), ...data }));
54
+ this.storage.set(keys, Array.isArray(data) ? JSON.stringify(data) : JSON.stringify({ ...(oldData ?? {}), ...data }));
55
55
  }
56
56
  }
57
57
  values(to) {
@@ -1,14 +1,13 @@
1
1
  import type { RedisOptions } from 'ioredis';
2
- import { Redis } from 'ioredis';
3
2
  import type { Adapter } from './types';
4
3
  interface RedisAdapterOptions {
5
4
  namespace?: string;
6
5
  }
7
6
  export declare class RedisAdapter implements Adapter {
8
- client: Redis;
7
+ client: import('ioredis').Redis;
9
8
  namespace: string;
10
9
  constructor(data: ({
11
- client: Redis;
10
+ client: import('ioredis').Redis;
12
11
  } | {
13
12
  redisOptions: RedisOptions;
14
13
  }) & RedisAdapterOptions);
@@ -1,13 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RedisAdapter = void 0;
4
- const ioredis_1 = require("ioredis");
5
- const common_1 = require("../../common");
4
+ let Redis;
5
+ try {
6
+ Redis = require('ioredis').Redis;
7
+ }
8
+ catch {
9
+ // potocuit > seyfert
10
+ }
6
11
  class RedisAdapter {
7
12
  client;
8
13
  namespace;
9
14
  constructor(data) {
10
- this.client = 'client' in data ? data.client : new ioredis_1.Redis(data.redisOptions);
15
+ if (!Redis) {
16
+ throw new Error('No ioredis installed');
17
+ }
18
+ this.client = 'client' in data ? data.client : new Redis(data.redisOptions);
11
19
  this.namespace = data.namespace ?? 'seyfert';
12
20
  }
13
21
  scan(query, returnKeys = false) {
@@ -53,7 +61,7 @@ class RedisAdapter {
53
61
  async patch(updateOnly, id, data) {
54
62
  if (!Array.isArray(id)) {
55
63
  if (updateOnly) {
56
- await this.client.eval(`if redis.call('exists',KEYS[1]) == 1 then redis.call('hset', KEYS[1], ${Array.from({ length: Object.keys(data).length * 2 }, (_, i) => `ARGV[${i + 1}]`)}) end`, 1, this.buildKey(id), ...(0, common_1.fastFlat)(Object.entries(toDb(data))));
64
+ await this.client.eval(`if redis.call('exists',KEYS[1]) == 1 then redis.call('hset', KEYS[1], ${Array.from({ length: Object.keys(data).length * 2 }, (_, i) => `ARGV[${i + 1}]`)}) end`, 1, this.buildKey(id), ...Object.entries(toDb(data)).flat());
57
65
  }
58
66
  else {
59
67
  await this.client.hset(this.buildKey(id), toDb(data));
@@ -63,7 +71,7 @@ class RedisAdapter {
63
71
  const pipeline = this.client.pipeline();
64
72
  for (const [k, v] of id) {
65
73
  if (updateOnly) {
66
- pipeline.eval(`if redis.call('exists',KEYS[1]) == 1 then redis.call('hset', KEYS[1], ${Array.from({ length: Object.keys(v).length * 2 }, (_, i) => `ARGV[${i + 1}]`)}) end`, 1, this.buildKey(k), ...(0, common_1.fastFlat)(Object.entries(toDb(v))));
74
+ pipeline.eval(`if redis.call('exists',KEYS[1]) == 1 then redis.call('hset', KEYS[1], ${Array.from({ length: Object.keys(v).length * 2 }, (_, i) => `ARGV[${i + 1}]`)}) end`, 1, this.buildKey(k), ...Object.entries(toDb(v)).flat());
67
75
  }
68
76
  else {
69
77
  pipeline.hset(this.buildKey(k), toDb(v));
@@ -1,10 +1,18 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
4
+ /// <reference types="node" />
5
+ /// <reference types="node" />
6
+ /// <reference types="node" />
2
7
  import { type MessagePort } from 'node:worker_threads';
3
8
  import type { WorkerSendCacheRequest } from '../../websocket/discord/worker';
4
9
  import type { Adapter } from './types';
5
10
  export declare class WorkerAdapter implements Adapter {
6
11
  readonly parent: MessagePort;
7
- promises: Map<string, (value: unknown) => void>;
12
+ promises: Map<string, {
13
+ resolve: (value: unknown) => void;
14
+ timeout: NodeJS.Timeout;
15
+ }>;
8
16
  constructor(parent: MessagePort);
9
17
  protected send(method: WorkerSendCacheRequest['method'], ...args: any[]): Promise<any>;
10
18
  scan(...rest: any[]): Promise<any>;
@@ -11,6 +11,8 @@ class WorkerAdapter {
11
11
  }
12
12
  send(method, ...args) {
13
13
  const nonce = (0, node_crypto_1.randomUUID)();
14
+ if (this.promises.has(nonce))
15
+ return this.send(method, ...args);
14
16
  node_worker_threads_1.parentPort.postMessage({
15
17
  type: 'CACHE_REQUEST',
16
18
  args,
@@ -21,13 +23,15 @@ class WorkerAdapter {
21
23
  let resolve = (_) => {
22
24
  /**/
23
25
  };
26
+ let timeout = -1;
24
27
  const promise = new Promise((res, rej) => {
25
28
  resolve = res;
26
- setTimeout(() => {
29
+ timeout = setTimeout(() => {
30
+ this.promises.delete(nonce);
27
31
  rej(new Error('Timeout cache request'));
28
- }, 3e3);
32
+ }, 60e3);
29
33
  });
30
- this.promises.set(nonce, resolve);
34
+ this.promises.set(nonce, { resolve, timeout });
31
35
  return promise;
32
36
  }
33
37
  scan(...rest) {
@@ -1,4 +1,4 @@
1
- import type { GatewayDispatchPayload } from '../common';
1
+ import type { GatewayDispatchPayload, If } from '../common';
2
2
  import type { Adapter } from './adapters';
3
3
  import { Guilds } from './resources/guilds';
4
4
  import { Users } from './resources/users';
@@ -12,19 +12,27 @@ import { Stickers } from './resources/stickers';
12
12
  import { Threads } from './resources/threads';
13
13
  import { VoiceStates } from './resources/voice-states';
14
14
  import type { BaseClient } from '../client/base';
15
+ import type { InternalOptions } from '../commands';
15
16
  import { GatewayIntentBits } from '../common';
16
- export type GuildBased = 'members';
17
- export type GuildRelated = 'emojis' | 'roles' | 'threads' | 'channels' | 'stickers' | 'presences' | 'voiceStates' | 'stageInstances';
17
+ import { Overwrites } from './resources/overwrites';
18
+ export type InferAsyncCache = InternalOptions extends {
19
+ asyncCache: infer P;
20
+ } ? P : false;
21
+ export type ReturnCache<T> = If<InferAsyncCache, Promise<T>, T>;
22
+ export type GuildBased = 'members' | 'voiceStates';
23
+ export type GuildRelated = 'emojis' | 'roles' | 'threads' | 'channels' | 'stickers' | 'presences' | 'stageInstances' | 'overwrites';
18
24
  export type NonGuildBased = 'users' | 'guilds';
19
25
  export * from './adapters/index';
20
26
  export type CachedEvents = 'READY' | 'GUILD_CREATE' | 'GUILD_UPDATE' | 'GUILD_DELETE' | 'CHANNEL_CREATE' | 'CHANNEL_UPDATE' | 'CHANNEL_DELETE' | 'GUILD_ROLE_CREATE' | 'GUILD_ROLE_UPDATE' | 'GUILD_ROLE_DELETE' | 'GUILD_EMOJIS_UPDATE' | 'GUILD_STICKERS_UPDATE' | 'GUILD_MEMBER_ADD' | 'GUILD_MEMBER_UPDATE' | 'GUILD_MEMBER_REMOVE' | 'MESSAGE_CREATE' | 'PRESENCE_UPDATE' | 'THREAD_DELETE' | 'THREAD_CREATE' | 'THREAD_UPDATE' | 'USER_UPDATE' | 'VOICE_STATE_UPDATE' | 'STAGE_INSTANCE_CREATE' | 'STAGE_INSTANCE_UPDATE' | 'STAGE_INSTANCE_DELETE';
21
27
  export declare class Cache {
22
28
  intents: number;
23
29
  adapter: Adapter;
30
+ asyncCache: boolean;
24
31
  readonly disabledCache: (NonGuildBased | GuildBased | GuildRelated)[];
25
32
  users?: Users;
26
33
  guilds?: Guilds;
27
34
  members?: Members;
35
+ overwrites?: Overwrites;
28
36
  roles?: Roles;
29
37
  emojis?: Emojis;
30
38
  threads?: Threads;
@@ -33,7 +41,7 @@ export declare class Cache {
33
41
  presences?: Presences;
34
42
  voiceStates?: VoiceStates;
35
43
  stageInstances?: StageInstances;
36
- constructor(intents: number, adapter: Adapter, disabledCache?: (NonGuildBased | GuildBased | GuildRelated)[], client?: BaseClient);
44
+ constructor(intents: number, adapter: Adapter, asyncCache?: boolean, disabledCache?: (NonGuildBased | GuildBased | GuildRelated)[], client?: BaseClient);
37
45
  hasIntent(intent: keyof typeof GatewayIntentBits): boolean;
38
46
  get hasGuildsIntent(): boolean;
39
47
  get hasRolesIntent(): boolean;
@@ -55,9 +63,9 @@ export declare class Cache {
55
63
  roles: import("..").GuildRole[];
56
64
  emojis: import("..").GuildEmoji[];
57
65
  stickers: import("..").Sticker[];
58
- channels: NonNullable<import("..").AllChannels | undefined>[];
59
- users: import("..").User[];
66
+ channels: NonNullable<ReturnCache<import("..").AllChannels | undefined>>[];
60
67
  members: import("..").GuildMember[];
68
+ users: import("..").User[];
61
69
  presences: (Omit<import("discord-api-types/payloads/v10/gateway").GatewayPresenceUpdate, "user"> & {
62
70
  id: string;
63
71
  } & {
@@ -72,6 +80,12 @@ export declare class Cache {
72
80
  stageInstances: (import("discord-api-types/payloads/v10/stageInstance").APIStageInstance & {
73
81
  guild_id: string;
74
82
  })[];
83
+ overwrites: {
84
+ type: number;
85
+ id: string;
86
+ deny: import("../structures/extra/Permissions").PermissionsBitField;
87
+ allow: import("../structures/extra/Permissions").PermissionsBitField;
88
+ }[][];
75
89
  }>>;
76
90
  bulkPatch(keys: (readonly [
77
91
  NonGuildBased,
@@ -27,10 +27,12 @@ const stickers_1 = require("./resources/stickers");
27
27
  const threads_1 = require("./resources/threads");
28
28
  const voice_states_1 = require("./resources/voice-states");
29
29
  const common_1 = require("../common");
30
+ const overwrites_1 = require("./resources/overwrites");
30
31
  __exportStar(require("./adapters/index"), exports);
31
32
  class Cache {
32
33
  intents;
33
34
  adapter;
35
+ asyncCache;
34
36
  disabledCache;
35
37
  // non-guild based
36
38
  users;
@@ -38,6 +40,7 @@ class Cache {
38
40
  // guild based
39
41
  members;
40
42
  // guild related
43
+ overwrites;
41
44
  roles;
42
45
  emojis;
43
46
  threads;
@@ -46,9 +49,10 @@ class Cache {
46
49
  presences;
47
50
  voiceStates;
48
51
  stageInstances;
49
- constructor(intents, adapter, disabledCache = [], client) {
52
+ constructor(intents, adapter, asyncCache = false, disabledCache = [], client) {
50
53
  this.intents = intents;
51
54
  this.adapter = adapter;
55
+ this.asyncCache = asyncCache;
52
56
  this.disabledCache = disabledCache;
53
57
  // non-guild based
54
58
  if (!this.disabledCache.includes('users')) {
@@ -61,10 +65,16 @@ class Cache {
61
65
  if (!this.disabledCache.includes('members')) {
62
66
  this.members = new members_1.Members(this, client);
63
67
  }
68
+ if (!this.disabledCache.includes('voiceStates')) {
69
+ this.voiceStates = new voice_states_1.VoiceStates(this, client);
70
+ }
64
71
  // guild based
65
72
  if (!this.disabledCache.includes('roles')) {
66
73
  this.roles = new roles_1.Roles(this, client);
67
74
  }
75
+ if (!this.disabledCache.includes('overwrites')) {
76
+ this.overwrites = new overwrites_1.Overwrites(this, client);
77
+ }
68
78
  if (!this.disabledCache.includes('channels')) {
69
79
  this.channels = new channels_1.Channels(this, client);
70
80
  }
@@ -77,9 +87,6 @@ class Cache {
77
87
  if (!this.disabledCache.includes('presences')) {
78
88
  this.presences = new presence_1.Presences(this, client);
79
89
  }
80
- if (!this.disabledCache.includes('voiceStates')) {
81
- this.voiceStates = new voice_states_1.VoiceStates(this, client);
82
- }
83
90
  if (!this.disabledCache.includes('threads')) {
84
91
  this.threads = new threads_1.Threads(this, client);
85
92
  }
@@ -92,12 +99,12 @@ class Cache {
92
99
  this.users?.__setClient(client);
93
100
  this.guilds?.__setClient(client);
94
101
  this.members?.__setClient(client);
102
+ this.voiceStates?.__setClient(client);
95
103
  this.roles?.__setClient(client);
96
104
  this.channels?.__setClient(client);
97
105
  this.emojis?.__setClient(client);
98
106
  this.stickers?.__setClient(client);
99
107
  this.presences?.__setClient(client);
100
- this.voiceStates?.__setClient(client);
101
108
  this.threads?.__setClient(client);
102
109
  this.stageInstances?.__setClient(client);
103
110
  }
@@ -133,6 +140,7 @@ class Cache {
133
140
  const allData = {};
134
141
  for (const [type, id, guildId] of keys) {
135
142
  switch (type) {
143
+ case 'voiceStates':
136
144
  case 'members':
137
145
  {
138
146
  if (!allData[type]) {
@@ -146,11 +154,11 @@ class Cache {
146
154
  case 'stickers':
147
155
  case 'channels':
148
156
  case 'presences':
149
- case 'voiceStates':
150
157
  case 'stageInstances':
151
158
  case 'emojis':
152
159
  case 'users':
153
160
  case 'guilds':
161
+ case 'overwrites':
154
162
  {
155
163
  if (!allData[type]) {
156
164
  allData[type] = [];
@@ -187,9 +195,9 @@ class Cache {
187
195
  case 'stickers':
188
196
  case 'channels':
189
197
  case 'presences':
190
- case 'voiceStates':
191
198
  case 'stageInstances':
192
199
  case 'emojis':
200
+ case 'overwrites':
193
201
  {
194
202
  const hashId = this[type]?.hashId(guildId);
195
203
  if (!hashId) {
@@ -199,10 +207,13 @@ class Cache {
199
207
  relationshipsData[hashId] = [];
200
208
  }
201
209
  relationshipsData[hashId].push(id);
202
- data.guild_id = guildId;
210
+ if (type !== 'overwrites') {
211
+ data.guild_id = guildId;
212
+ }
203
213
  allData.push([this[type].hashId(id), this[type].parse(data, id, guildId)]);
204
214
  }
205
215
  break;
216
+ case 'voiceStates':
206
217
  case 'members':
207
218
  {
208
219
  const hashId = this[type]?.hashId(guildId);
@@ -248,9 +259,9 @@ class Cache {
248
259
  case 'stickers':
249
260
  case 'channels':
250
261
  case 'presences':
251
- case 'voiceStates':
252
262
  case 'stageInstances':
253
263
  case 'emojis':
264
+ case 'overwrites':
254
265
  {
255
266
  const hashId = this[type]?.hashId(guildId);
256
267
  if (!hashId) {
@@ -260,10 +271,13 @@ class Cache {
260
271
  relationshipsData[hashId] = [];
261
272
  }
262
273
  relationshipsData[hashId].push(id);
263
- data.guild_id = guildId;
274
+ if (type !== 'overwrites') {
275
+ data.guild_id = guildId;
276
+ }
264
277
  allData.push([this[type].hashId(id), this[type].parse(data, id, guildId)]);
265
278
  }
266
279
  break;
280
+ case 'voiceStates':
267
281
  case 'members':
268
282
  {
269
283
  const hashId = this[type]?.hashId(guildId);
@@ -323,6 +337,8 @@ class Cache {
323
337
  case 'CHANNEL_UPDATE':
324
338
  if ('guild_id' in event.d) {
325
339
  await this.channels?.set(event.d.id, event.d.guild_id, event.d);
340
+ if (event.d.permission_overwrites?.length)
341
+ await this.overwrites?.set(event.d.id, event.d.guild_id, event.d.permission_overwrites);
326
342
  break;
327
343
  }
328
344
  if (event.d.type === common_1.ChannelType.DM) {
@@ -1,7 +1,11 @@
1
1
  import type { AllChannels } from '../../structures';
2
+ import channelFrom from '../../structures/channels';
3
+ import type { ReturnCache } from '../index';
2
4
  import { GuildRelatedResource } from './default/guild-related';
3
5
  export declare class Channels extends GuildRelatedResource {
4
6
  namespace: string;
5
- get(id: string): Promise<AllChannels | undefined>;
6
- values(guild: string): Promise<AllChannels[]>;
7
+ parse(data: any, id: string, guild_id: string): any;
8
+ get(id: string): ReturnCache<AllChannels | undefined>;
9
+ bulk(ids: string[]): ReturnCache<ReturnType<typeof channelFrom>[]>;
10
+ values(guild: string): ReturnCache<ReturnType<typeof channelFrom>[]>;
7
11
  }
@@ -4,17 +4,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Channels = void 0;
7
+ const common_1 = require("../../common");
7
8
  const channels_1 = __importDefault(require("../../structures/channels"));
8
9
  const guild_related_1 = require("./default/guild-related");
9
10
  class Channels extends guild_related_1.GuildRelatedResource {
10
11
  namespace = 'channel';
11
- async get(id) {
12
- const rawChannel = await super.get(id);
13
- return rawChannel ? (0, channels_1.default)(rawChannel, this.client) : undefined;
12
+ parse(data, id, guild_id) {
13
+ const { permission_overwrites, ...rest } = super.parse(data, id, guild_id);
14
+ return rest;
14
15
  }
15
- async values(guild) {
16
- const channels = await super.values(guild);
17
- return channels.map(rawChannel => (0, channels_1.default)(rawChannel, this.client));
16
+ get(id) {
17
+ return (0, common_1.fakePromise)(super.get(id)).then(rawChannel => rawChannel ? (0, channels_1.default)(rawChannel, this.client) : undefined);
18
+ }
19
+ bulk(ids) {
20
+ return (0, common_1.fakePromise)(super.bulk(ids)).then(channels => channels.map(rawChannel => (0, channels_1.default)(rawChannel, this.client)));
21
+ }
22
+ values(guild) {
23
+ return (0, common_1.fakePromise)(super.values(guild)).then(channels => channels.map(rawChannel => (0, channels_1.default)(rawChannel, this.client)));
18
24
  }
19
25
  }
20
26
  exports.Channels = Channels;
@@ -1,25 +1,26 @@
1
1
  import type { BaseClient } from '../../../client/base';
2
- import type { GatewayIntentBits } from '../../../common';
3
- import type { Cache } from '../../index';
2
+ import { type GatewayIntentBits } from '../../../common';
3
+ import type { Cache, ReturnCache } from '../../index';
4
4
  export declare class BaseResource<T = any> {
5
5
  protected cache: Cache;
6
6
  client: BaseClient;
7
7
  namespace: string;
8
8
  constructor(cache: Cache, client?: BaseClient);
9
- get rest(): import("../../..").REST;
9
+ get rest(): import("../../..").ApiHandler;
10
10
  get adapter(): import("../../index").Adapter;
11
- removeIfNI(intent: keyof typeof GatewayIntentBits, id: string): Promise<void>;
12
- setIfNI(intent: keyof typeof GatewayIntentBits, id: string, data: any): Promise<any>;
13
- get(id: string): Promise<T | undefined>;
14
- set(id: string, data: any): Promise<void>;
15
- patch<T extends Record<any, any> = Record<any, any>>(id: string, data: T): Promise<void>;
16
- remove(id: string): Promise<void>;
17
- keys(): Promise<string[]>;
18
- values(): Promise<T[]>;
19
- count(): Promise<number>;
20
- contains(id: string): Promise<boolean>;
21
- getToRelationship(): Promise<string[]>;
22
- addToRelationship(id: string | string[]): Promise<void>;
23
- removeToRelationship(id: string | string[]): Promise<void>;
11
+ removeIfNI(intent: keyof typeof GatewayIntentBits, id: string): import("../../index").RPV<void>;
12
+ setIfNI(intent: keyof typeof GatewayIntentBits, id: string, data: any): any;
13
+ get(id: string): ReturnCache<T | undefined>;
14
+ bulk(ids: string[]): ReturnCache<T[]>;
15
+ set(id: string, data: any): import("../../index").RPV<void>;
16
+ patch<T extends Record<any, any> = Record<any, any>>(id: string, data: T): import("../../index").RPV<void>;
17
+ remove(id: string): import("../../index").RPV<void>;
18
+ keys(): ReturnCache<string[]>;
19
+ values(): ReturnCache<T[]>;
20
+ count(): import("../../index").RPV<number>;
21
+ contains(id: string): import("../../index").RPV<boolean>;
22
+ getToRelationship(): import("../../index").RPV<string[]>;
23
+ addToRelationship(id: string | string[]): import("../../index").RPV<void>;
24
+ removeToRelationship(id: string | string[]): import("../../index").RPV<void>;
24
25
  hashId(id: string): string;
25
26
  }