seyfert 0.1.0 → 1.0.1

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 (198) 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 +44 -0
  18. package/lib/api/api.js +354 -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 +33 -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 +5 -14
  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.d.ts +1 -0
  44. package/lib/cache/adapters/default.js +3 -2
  45. package/lib/cache/adapters/redis.d.ts +3 -3
  46. package/lib/cache/adapters/redis.js +14 -5
  47. package/lib/cache/adapters/types.d.ts +1 -0
  48. package/lib/cache/adapters/workeradapter.d.ts +10 -1
  49. package/lib/cache/adapters/workeradapter.js +8 -3
  50. package/lib/cache/index.d.ts +18 -5
  51. package/lib/cache/index.js +23 -9
  52. package/lib/cache/resources/channels.d.ts +6 -2
  53. package/lib/cache/resources/channels.js +12 -6
  54. package/lib/cache/resources/default/base.d.ts +17 -16
  55. package/lib/cache/resources/default/base.js +25 -24
  56. package/lib/cache/resources/default/guild-based.d.ts +22 -19
  57. package/lib/cache/resources/default/guild-based.js +32 -31
  58. package/lib/cache/resources/default/guild-related.d.ts +22 -19
  59. package/lib/cache/resources/default/guild-related.js +37 -43
  60. package/lib/cache/resources/emojis.d.ts +4 -2
  61. package/lib/cache/resources/emojis.js +8 -6
  62. package/lib/cache/resources/guilds.d.ts +4 -2
  63. package/lib/cache/resources/guilds.js +15 -8
  64. package/lib/cache/resources/members.d.ts +4 -2
  65. package/lib/cache/resources/members.js +16 -13
  66. package/lib/cache/resources/overwrites.d.ts +25 -0
  67. package/lib/cache/resources/overwrites.js +39 -0
  68. package/lib/cache/resources/presence.js +3 -4
  69. package/lib/cache/resources/roles.d.ts +4 -2
  70. package/lib/cache/resources/roles.js +8 -6
  71. package/lib/cache/resources/stickers.d.ts +4 -2
  72. package/lib/cache/resources/stickers.js +8 -6
  73. package/lib/cache/resources/threads.d.ts +4 -2
  74. package/lib/cache/resources/threads.js +8 -6
  75. package/lib/cache/resources/users.d.ts +4 -2
  76. package/lib/cache/resources/users.js +8 -6
  77. package/lib/cache/resources/voice-states.d.ts +3 -3
  78. package/lib/cache/resources/voice-states.js +6 -7
  79. package/lib/client/base.d.ts +48 -16
  80. package/lib/client/base.js +19 -15
  81. package/lib/client/client.d.ts +15 -4
  82. package/lib/client/client.js +26 -28
  83. package/lib/client/httpclient.d.ts +3 -5
  84. package/lib/client/httpclient.js +29 -16
  85. package/lib/client/{oninteraction.d.ts → oninteractioncreate.d.ts} +1 -1
  86. package/lib/client/{oninteraction.js → oninteractioncreate.js} +34 -23
  87. package/lib/client/onmessagecreate.d.ts +3 -0
  88. package/lib/client/onmessagecreate.js +337 -0
  89. package/lib/client/workerclient.d.ts +19 -2
  90. package/lib/client/workerclient.js +156 -46
  91. package/lib/collection.d.ts +1 -1
  92. package/lib/collection.js +9 -6
  93. package/lib/commands/applications/chat.d.ts +32 -25
  94. package/lib/commands/applications/chat.js +51 -34
  95. package/lib/commands/applications/chatcontext.d.ts +34 -16
  96. package/lib/commands/applications/chatcontext.js +99 -20
  97. package/lib/commands/applications/menu.d.ts +9 -8
  98. package/lib/commands/applications/menu.js +14 -5
  99. package/lib/commands/applications/menucontext.d.ts +27 -10
  100. package/lib/commands/applications/menucontext.js +51 -7
  101. package/lib/commands/applications/options.d.ts +13 -13
  102. package/lib/commands/applications/shared.d.ts +7 -2
  103. package/lib/commands/decorators.d.ts +14 -14
  104. package/lib/commands/decorators.js +9 -5
  105. package/lib/commands/handler.d.ts +2 -1
  106. package/lib/commands/handler.js +60 -14
  107. package/lib/commands/index.d.ts +1 -1
  108. package/lib/commands/index.js +2 -1
  109. package/lib/commands/optionresolver.d.ts +6 -5
  110. package/lib/commands/optionresolver.js +10 -6
  111. package/lib/common/bot/watcher.d.ts +3 -3
  112. package/lib/common/bot/watcher.js +3 -1
  113. package/lib/common/index.d.ts +1 -1
  114. package/lib/common/index.js +2 -1
  115. package/lib/common/it/logger.d.ts +11 -0
  116. package/lib/common/it/logger.js +51 -2
  117. package/lib/common/it/utils.d.ts +3 -13
  118. package/lib/common/it/utils.js +9 -30
  119. package/lib/common/shorters/channels.d.ts +55 -5
  120. package/lib/common/shorters/channels.js +59 -0
  121. package/lib/common/shorters/guilds.d.ts +5 -2
  122. package/lib/common/shorters/guilds.js +18 -0
  123. package/lib/common/shorters/messages.js +0 -2
  124. package/lib/common/shorters/overwrites.d.ts +29 -0
  125. package/lib/common/shorters/overwrites.js +63 -0
  126. package/lib/common/shorters/roles.js +3 -3
  127. package/lib/common/shorters/webhook.d.ts +2 -2
  128. package/lib/common/types/util.d.ts +3 -2
  129. package/lib/common/types/write.d.ts +3 -7
  130. package/lib/components/handler.d.ts +11 -17
  131. package/lib/components/handler.js +45 -93
  132. package/lib/components/index.d.ts +0 -1
  133. package/lib/components/index.js +0 -1
  134. package/lib/components/listener.d.ts +2 -2
  135. package/lib/components/listener.js +2 -3
  136. package/lib/events/event.d.ts +2 -2
  137. package/lib/events/handler.d.ts +3 -2
  138. package/lib/events/handler.js +14 -6
  139. package/lib/events/hooks/dispatch.d.ts +2 -1
  140. package/lib/events/hooks/dispatch.js +5 -1
  141. package/lib/events/hooks/thread.d.ts +63 -63
  142. package/lib/index.d.ts +8 -5
  143. package/lib/index.js +20 -10
  144. package/lib/langs/handler.d.ts +6 -4
  145. package/lib/langs/handler.js +10 -8
  146. package/lib/langs/router.d.ts +8 -9
  147. package/lib/langs/router.js +5 -5
  148. package/lib/structures/ClientUser.d.ts +1 -16
  149. package/lib/structures/ClientUser.js +0 -31
  150. package/lib/structures/Guild.d.ts +1 -1
  151. package/lib/structures/GuildMember.d.ts +12 -0
  152. package/lib/structures/GuildMember.js +14 -0
  153. package/lib/structures/GuildRole.d.ts +4 -2
  154. package/lib/structures/GuildRole.js +4 -1
  155. package/lib/structures/GuildTemplate.js +1 -1
  156. package/lib/structures/Interaction.d.ts +2 -0
  157. package/lib/structures/Interaction.js +12 -13
  158. package/lib/structures/Message.d.ts +7 -2
  159. package/lib/structures/Message.js +6 -3
  160. package/lib/structures/Sticker.d.ts +1 -1
  161. package/lib/structures/Sticker.js +1 -1
  162. package/lib/structures/User.d.ts +5 -0
  163. package/lib/structures/User.js +3 -0
  164. package/lib/structures/Webhook.d.ts +1 -1
  165. package/lib/structures/Webhook.js +1 -1
  166. package/lib/structures/channels.d.ts +45 -6
  167. package/lib/structures/channels.js +23 -7
  168. package/lib/structures/extra/BitField.d.ts +9 -6
  169. package/lib/structures/extra/BitField.js +27 -3
  170. package/lib/structures/extra/Permissions.d.ts +6 -1
  171. package/lib/structures/extra/Permissions.js +7 -0
  172. package/lib/websocket/constants/index.js +1 -3
  173. package/lib/websocket/discord/basesocket.js +0 -1
  174. package/lib/websocket/discord/shared.d.ts +2 -0
  175. package/lib/websocket/discord/worker.d.ts +23 -7
  176. package/lib/websocket/discord/workermanager.d.ts +32 -5
  177. package/lib/websocket/discord/workermanager.js +98 -29
  178. package/package.json +23 -21
  179. package/lib/api/REST.d.ts +0 -127
  180. package/lib/api/REST.js +0 -424
  181. package/lib/api/errors/DiscordAPIError.d.ts +0 -51
  182. package/lib/api/errors/DiscordAPIError.js +0 -81
  183. package/lib/api/errors/HTTPError.d.ts +0 -20
  184. package/lib/api/errors/HTTPError.js +0 -28
  185. package/lib/api/errors/RateLimitError.d.ts +0 -19
  186. package/lib/api/errors/RateLimitError.js +0 -37
  187. package/lib/api/handlers/BurstHandler.d.ts +0 -51
  188. package/lib/api/handlers/BurstHandler.js +0 -124
  189. package/lib/api/handlers/SequentialHandler.d.ts +0 -81
  190. package/lib/api/handlers/SequentialHandler.js +0 -365
  191. package/lib/api/handlers/Shared.d.ts +0 -14
  192. package/lib/api/handlers/Shared.js +0 -125
  193. package/lib/api/interfaces/Handler.d.ts +0 -21
  194. package/lib/api/interfaces/Handler.js +0 -2
  195. package/lib/websocket/discord/handlemessage.d.ts +0 -0
  196. package/lib/websocket/discord/handlemessage.js +0 -1
  197. package/lib/websocket/discord/memberUpdate.d.ts +0 -16
  198. 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;
@@ -1,5 +1,6 @@
1
1
  import type { Adapter } from './types';
2
2
  export declare class MemoryAdapter implements Adapter {
3
+ isAsync: boolean;
3
4
  readonly storage: Map<string, string>;
4
5
  readonly relationships: Map<string, string[]>;
5
6
  scan(query: string, keys?: false): any[];
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MemoryAdapter = void 0;
4
4
  class MemoryAdapter {
5
+ isAsync = false;
5
6
  storage = new Map();
6
7
  relationships = new Map();
7
8
  scan(query, keys = false) {
@@ -43,7 +44,7 @@ class MemoryAdapter {
43
44
  if (updateOnly && !oldData) {
44
45
  continue;
45
46
  }
46
- this.storage.set(key, JSON.stringify({ ...(oldData ?? {}), ...value }));
47
+ this.storage.set(key, Array.isArray(value) ? JSON.stringify(value) : JSON.stringify({ ...(oldData ?? {}), ...value }));
47
48
  }
48
49
  }
49
50
  else {
@@ -51,7 +52,7 @@ class MemoryAdapter {
51
52
  if (updateOnly && !oldData) {
52
53
  return;
53
54
  }
54
- this.storage.set(keys, JSON.stringify({ ...(oldData ?? {}), ...data }));
55
+ this.storage.set(keys, Array.isArray(data) ? JSON.stringify(data) : JSON.stringify({ ...(oldData ?? {}), ...data }));
55
56
  }
56
57
  }
57
58
  values(to) {
@@ -1,14 +1,14 @@
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
+ isAsync: boolean;
8
+ client: import('ioredis').Redis;
9
9
  namespace: string;
10
10
  constructor(data: ({
11
- client: Redis;
11
+ client: import('ioredis').Redis;
12
12
  } | {
13
13
  redisOptions: RedisOptions;
14
14
  }) & RedisAdapterOptions);
@@ -1,13 +1,22 @@
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 {
12
+ isAsync = true;
7
13
  client;
8
14
  namespace;
9
15
  constructor(data) {
10
- this.client = 'client' in data ? data.client : new ioredis_1.Redis(data.redisOptions);
16
+ if (!Redis) {
17
+ throw new Error('No ioredis installed');
18
+ }
19
+ this.client = 'client' in data ? data.client : new Redis(data.redisOptions);
11
20
  this.namespace = data.namespace ?? 'seyfert';
12
21
  }
13
22
  scan(query, returnKeys = false) {
@@ -53,7 +62,7 @@ class RedisAdapter {
53
62
  async patch(updateOnly, id, data) {
54
63
  if (!Array.isArray(id)) {
55
64
  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))));
65
+ 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
66
  }
58
67
  else {
59
68
  await this.client.hset(this.buildKey(id), toDb(data));
@@ -63,7 +72,7 @@ class RedisAdapter {
63
72
  const pipeline = this.client.pipeline();
64
73
  for (const [k, v] of id) {
65
74
  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))));
75
+ 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
76
  }
68
77
  else {
69
78
  pipeline.hset(this.buildKey(k), toDb(v));
@@ -1,4 +1,5 @@
1
1
  export interface Adapter {
2
+ isAsync: boolean;
2
3
  scan(query: string, keys?: false): RPV<any[]>;
3
4
  scan(query: string, keys: true): RPV<string[]>;
4
5
  scan(query: string, keys?: boolean): RPV<(any | string)[]>;
@@ -1,10 +1,19 @@
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
+ isAsync: boolean;
13
+ promises: Map<string, {
14
+ resolve: (value: unknown) => void;
15
+ timeout: NodeJS.Timeout;
16
+ }>;
8
17
  constructor(parent: MessagePort);
9
18
  protected send(method: WorkerSendCacheRequest['method'], ...args: any[]): Promise<any>;
10
19
  scan(...rest: any[]): Promise<any>;
@@ -5,12 +5,15 @@ const node_crypto_1 = require("node:crypto");
5
5
  const node_worker_threads_1 = require("node:worker_threads");
6
6
  class WorkerAdapter {
7
7
  parent;
8
+ isAsync = true;
8
9
  promises = new Map();
9
10
  constructor(parent) {
10
11
  this.parent = parent;
11
12
  }
12
13
  send(method, ...args) {
13
14
  const nonce = (0, node_crypto_1.randomUUID)();
15
+ if (this.promises.has(nonce))
16
+ return this.send(method, ...args);
14
17
  node_worker_threads_1.parentPort.postMessage({
15
18
  type: 'CACHE_REQUEST',
16
19
  args,
@@ -21,13 +24,15 @@ class WorkerAdapter {
21
24
  let resolve = (_) => {
22
25
  /**/
23
26
  };
27
+ let timeout = -1;
24
28
  const promise = new Promise((res, rej) => {
25
29
  resolve = res;
26
- setTimeout(() => {
30
+ timeout = setTimeout(() => {
31
+ this.promises.delete(nonce);
27
32
  rej(new Error('Timeout cache request'));
28
- }, 3e3);
33
+ }, 60e3);
29
34
  });
30
- this.promises.set(nonce, resolve);
35
+ this.promises.set(nonce, { resolve, timeout });
31
36
  return promise;
32
37
  }
33
38
  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,9 +12,15 @@ 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';
@@ -25,6 +31,7 @@ export declare class Cache {
25
31
  users?: Users;
26
32
  guilds?: Guilds;
27
33
  members?: Members;
34
+ overwrites?: Overwrites;
28
35
  roles?: Roles;
29
36
  emojis?: Emojis;
30
37
  threads?: Threads;
@@ -55,9 +62,9 @@ export declare class Cache {
55
62
  roles: import("..").GuildRole[];
56
63
  emojis: import("..").GuildEmoji[];
57
64
  stickers: import("..").Sticker[];
58
- channels: NonNullable<import("..").AllChannels | undefined>[];
59
- users: import("..").User[];
65
+ channels: NonNullable<ReturnCache<import("..").AllChannels | undefined>>[];
60
66
  members: import("..").GuildMember[];
67
+ users: import("..").User[];
61
68
  presences: (Omit<import("discord-api-types/payloads/v10/gateway").GatewayPresenceUpdate, "user"> & {
62
69
  id: string;
63
70
  } & {
@@ -72,6 +79,12 @@ export declare class Cache {
72
79
  stageInstances: (import("discord-api-types/payloads/v10/stageInstance").APIStageInstance & {
73
80
  guild_id: string;
74
81
  })[];
82
+ overwrites: {
83
+ type: number;
84
+ id: string;
85
+ deny: import("../structures/extra/Permissions").PermissionsBitField;
86
+ allow: import("../structures/extra/Permissions").PermissionsBitField;
87
+ }[][];
75
88
  }>>;
76
89
  bulkPatch(keys: (readonly [
77
90
  NonGuildBased,
@@ -27,6 +27,7 @@ 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;
@@ -38,6 +39,7 @@ class Cache {
38
39
  // guild based
39
40
  members;
40
41
  // guild related
42
+ overwrites;
41
43
  roles;
42
44
  emojis;
43
45
  threads;
@@ -61,10 +63,16 @@ class Cache {
61
63
  if (!this.disabledCache.includes('members')) {
62
64
  this.members = new members_1.Members(this, client);
63
65
  }
66
+ if (!this.disabledCache.includes('voiceStates')) {
67
+ this.voiceStates = new voice_states_1.VoiceStates(this, client);
68
+ }
64
69
  // guild based
65
70
  if (!this.disabledCache.includes('roles')) {
66
71
  this.roles = new roles_1.Roles(this, client);
67
72
  }
73
+ if (!this.disabledCache.includes('overwrites')) {
74
+ this.overwrites = new overwrites_1.Overwrites(this, client);
75
+ }
68
76
  if (!this.disabledCache.includes('channels')) {
69
77
  this.channels = new channels_1.Channels(this, client);
70
78
  }
@@ -77,9 +85,6 @@ class Cache {
77
85
  if (!this.disabledCache.includes('presences')) {
78
86
  this.presences = new presence_1.Presences(this, client);
79
87
  }
80
- if (!this.disabledCache.includes('voiceStates')) {
81
- this.voiceStates = new voice_states_1.VoiceStates(this, client);
82
- }
83
88
  if (!this.disabledCache.includes('threads')) {
84
89
  this.threads = new threads_1.Threads(this, client);
85
90
  }
@@ -92,12 +97,12 @@ class Cache {
92
97
  this.users?.__setClient(client);
93
98
  this.guilds?.__setClient(client);
94
99
  this.members?.__setClient(client);
100
+ this.voiceStates?.__setClient(client);
95
101
  this.roles?.__setClient(client);
96
102
  this.channels?.__setClient(client);
97
103
  this.emojis?.__setClient(client);
98
104
  this.stickers?.__setClient(client);
99
105
  this.presences?.__setClient(client);
100
- this.voiceStates?.__setClient(client);
101
106
  this.threads?.__setClient(client);
102
107
  this.stageInstances?.__setClient(client);
103
108
  }
@@ -133,6 +138,7 @@ class Cache {
133
138
  const allData = {};
134
139
  for (const [type, id, guildId] of keys) {
135
140
  switch (type) {
141
+ case 'voiceStates':
136
142
  case 'members':
137
143
  {
138
144
  if (!allData[type]) {
@@ -146,11 +152,11 @@ class Cache {
146
152
  case 'stickers':
147
153
  case 'channels':
148
154
  case 'presences':
149
- case 'voiceStates':
150
155
  case 'stageInstances':
151
156
  case 'emojis':
152
157
  case 'users':
153
158
  case 'guilds':
159
+ case 'overwrites':
154
160
  {
155
161
  if (!allData[type]) {
156
162
  allData[type] = [];
@@ -187,9 +193,9 @@ class Cache {
187
193
  case 'stickers':
188
194
  case 'channels':
189
195
  case 'presences':
190
- case 'voiceStates':
191
196
  case 'stageInstances':
192
197
  case 'emojis':
198
+ case 'overwrites':
193
199
  {
194
200
  const hashId = this[type]?.hashId(guildId);
195
201
  if (!hashId) {
@@ -199,10 +205,13 @@ class Cache {
199
205
  relationshipsData[hashId] = [];
200
206
  }
201
207
  relationshipsData[hashId].push(id);
202
- data.guild_id = guildId;
208
+ if (type !== 'overwrites') {
209
+ data.guild_id = guildId;
210
+ }
203
211
  allData.push([this[type].hashId(id), this[type].parse(data, id, guildId)]);
204
212
  }
205
213
  break;
214
+ case 'voiceStates':
206
215
  case 'members':
207
216
  {
208
217
  const hashId = this[type]?.hashId(guildId);
@@ -248,9 +257,9 @@ class Cache {
248
257
  case 'stickers':
249
258
  case 'channels':
250
259
  case 'presences':
251
- case 'voiceStates':
252
260
  case 'stageInstances':
253
261
  case 'emojis':
262
+ case 'overwrites':
254
263
  {
255
264
  const hashId = this[type]?.hashId(guildId);
256
265
  if (!hashId) {
@@ -260,10 +269,13 @@ class Cache {
260
269
  relationshipsData[hashId] = [];
261
270
  }
262
271
  relationshipsData[hashId].push(id);
263
- data.guild_id = guildId;
272
+ if (type !== 'overwrites') {
273
+ data.guild_id = guildId;
274
+ }
264
275
  allData.push([this[type].hashId(id), this[type].parse(data, id, guildId)]);
265
276
  }
266
277
  break;
278
+ case 'voiceStates':
267
279
  case 'members':
268
280
  {
269
281
  const hashId = this[type]?.hashId(guildId);
@@ -323,6 +335,8 @@ class Cache {
323
335
  case 'CHANNEL_UPDATE':
324
336
  if ('guild_id' in event.d) {
325
337
  await this.channels?.set(event.d.id, event.d.guild_id, event.d);
338
+ if (event.d.permission_overwrites?.length)
339
+ await this.overwrites?.set(event.d.id, event.d.guild_id, event.d.permission_overwrites);
326
340
  break;
327
341
  }
328
342
  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
  }