seyfert 1.3.3 → 1.4.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 (94) hide show
  1. package/lib/api/api.js +13 -7
  2. package/lib/builders/Attachment.d.ts +1 -4
  3. package/lib/builders/Attachment.js +4 -4
  4. package/lib/cache/adapters/workeradapter.js +7 -3
  5. package/lib/cache/resources/default/base.d.ts +1 -2
  6. package/lib/cache/resources/default/guild-based.d.ts +1 -2
  7. package/lib/client/base.d.ts +26 -4
  8. package/lib/client/base.js +42 -2
  9. package/lib/client/client.d.ts +3 -3
  10. package/lib/client/client.js +18 -6
  11. package/lib/client/httpclient.d.ts +7 -8
  12. package/lib/client/httpclient.js +92 -13
  13. package/lib/client/oninteractioncreate.d.ts +2 -2
  14. package/lib/client/oninteractioncreate.js +15 -7
  15. package/lib/client/onmessagecreate.js +74 -66
  16. package/lib/client/workerclient.d.ts +1 -1
  17. package/lib/client/workerclient.js +18 -7
  18. package/lib/commands/applications/chat.d.ts +1 -1
  19. package/lib/commands/applications/chat.js +2 -1
  20. package/lib/commands/applications/chatcontext.d.ts +1 -1
  21. package/lib/commands/applications/chatcontext.js +2 -2
  22. package/lib/commands/applications/menu.js +0 -48
  23. package/lib/commands/applications/menucontext.d.ts +1 -1
  24. package/lib/commands/applications/menucontext.js +3 -3
  25. package/lib/commands/applications/options.d.ts +3 -1
  26. package/lib/commands/basecontext.d.ts +26 -0
  27. package/lib/commands/{basecontex.js → basecontext.js} +24 -0
  28. package/lib/commands/handler.d.ts +6 -1
  29. package/lib/commands/handler.js +125 -3
  30. package/lib/common/bot/watcher.d.ts +1 -2
  31. package/lib/common/bot/watcher.js +9 -4
  32. package/lib/common/it/logger.d.ts +1 -1
  33. package/lib/common/it/logger.js +9 -8
  34. package/lib/common/it/utils.d.ts +2 -0
  35. package/lib/common/it/utils.js +19 -5
  36. package/lib/common/shorters/interaction.js +3 -3
  37. package/lib/common/shorters/messages.js +2 -2
  38. package/lib/common/shorters/webhook.js +2 -2
  39. package/lib/components/componentcommand.d.ts +21 -0
  40. package/lib/components/{command.js → componentcommand.js} +2 -5
  41. package/lib/components/componentcontext.d.ts +20 -16
  42. package/lib/components/componentcontext.js +27 -9
  43. package/lib/components/handler.d.ts +10 -5
  44. package/lib/components/handler.js +94 -17
  45. package/lib/components/index.d.ts +3 -1
  46. package/lib/components/index.js +3 -1
  47. package/lib/components/modalcommand.d.ts +15 -0
  48. package/lib/components/modalcommand.js +9 -0
  49. package/lib/components/modalcontext.d.ts +104 -0
  50. package/lib/components/modalcontext.js +132 -0
  51. package/lib/events/handler.d.ts +4 -1
  52. package/lib/events/handler.js +2 -7
  53. package/lib/events/hooks/application_command.d.ts +2 -2
  54. package/lib/events/hooks/auto_moderation.d.ts +5 -5
  55. package/lib/events/hooks/channel.d.ts +5 -5
  56. package/lib/events/hooks/custom.d.ts +3 -3
  57. package/lib/events/hooks/dispatch.d.ts +4 -4
  58. package/lib/events/hooks/entitlement.d.ts +4 -4
  59. package/lib/events/hooks/guild.d.ts +23 -23
  60. package/lib/events/hooks/guild.js +6 -6
  61. package/lib/events/hooks/integration.d.ts +4 -4
  62. package/lib/events/hooks/interactions.d.ts +2 -2
  63. package/lib/events/hooks/invite.d.ts +3 -3
  64. package/lib/events/hooks/message.d.ts +13 -13
  65. package/lib/events/hooks/message.js +1 -1
  66. package/lib/events/hooks/presence.d.ts +7 -3
  67. package/lib/events/hooks/presence.js +2 -2
  68. package/lib/events/hooks/stage.d.ts +7 -13
  69. package/lib/events/hooks/stage.js +2 -2
  70. package/lib/events/hooks/thread.d.ts +7 -7
  71. package/lib/events/hooks/thread.js +2 -2
  72. package/lib/events/hooks/typing.d.ts +2 -2
  73. package/lib/events/hooks/user.d.ts +2 -2
  74. package/lib/events/hooks/user.js +2 -2
  75. package/lib/events/hooks/voice.d.ts +5 -45
  76. package/lib/events/hooks/voice.js +4 -7
  77. package/lib/events/hooks/webhook.d.ts +2 -2
  78. package/lib/index.d.ts +1 -1
  79. package/lib/index.js +9 -4
  80. package/lib/langs/handler.d.ts +4 -1
  81. package/lib/langs/handler.js +3 -3
  82. package/lib/structures/Interaction.d.ts +3 -3
  83. package/lib/structures/Interaction.js +11 -6
  84. package/lib/structures/VoiceState.d.ts +6 -5
  85. package/lib/structures/VoiceState.js +6 -3
  86. package/lib/structures/channels.d.ts +1 -1
  87. package/lib/structures/channels.js +2 -1
  88. package/lib/websocket/discord/sharder.js +10 -3
  89. package/lib/websocket/discord/shared.d.ts +1 -0
  90. package/lib/websocket/discord/workermanager.d.ts +2 -3
  91. package/lib/websocket/discord/workermanager.js +4 -2
  92. package/package.json +3 -3
  93. package/lib/commands/basecontex.d.ts +0 -15
  94. package/lib/components/command.d.ts +0 -24
@@ -48,7 +48,7 @@ class BaseInteraction extends DiscordBase_1.DiscordBase {
48
48
  }
49
49
  this.user = this.member?.user ?? new User_1.User(client, interaction.user);
50
50
  }
51
- static transformBodyRequest(body) {
51
+ static transformBodyRequest(body, self) {
52
52
  switch (body.type) {
53
53
  case v10_1.InteractionResponseType.ApplicationCommandAutocompleteResult:
54
54
  case v10_1.InteractionResponseType.DeferredMessageUpdate:
@@ -61,6 +61,8 @@ class BaseInteraction extends DiscordBase_1.DiscordBase {
61
61
  type: body.type,
62
62
  //@ts-ignore
63
63
  data: {
64
+ //@ts-ignore
65
+ allowed_mentions: self.options?.allowedMentions,
64
66
  ...(body.data ?? {}),
65
67
  //@ts-ignore
66
68
  components: body.data?.components?.map(x => (x instanceof builders_1.ActionRow ? x.toJSON() : x)) ?? undefined,
@@ -88,9 +90,10 @@ class BaseInteraction extends DiscordBase_1.DiscordBase {
88
90
  return body;
89
91
  }
90
92
  }
91
- static transformBody(body) {
93
+ static transformBody(body, self) {
92
94
  const poll = body.poll;
93
95
  return {
96
+ allowed_mentions: self.options?.allowedMentions,
94
97
  ...body,
95
98
  components: body.components?.map(x => (x instanceof builders_1.ActionRow ? x.toJSON() : x)) ?? undefined,
96
99
  embeds: body?.embeds?.map(x => (x instanceof builders_1.Embed ? x.toJSON() : x)) ?? undefined,
@@ -104,7 +107,7 @@ class BaseInteraction extends DiscordBase_1.DiscordBase {
104
107
  //@ts-expect-error
105
108
  const data = body.data instanceof builders_1.Modal ? body.data : rest;
106
109
  return (this.replied = this.__reply({
107
- body: BaseInteraction.transformBodyRequest({ data, type: body.type }),
110
+ body: BaseInteraction.transformBodyRequest({ data, type: body.type }, this.client),
108
111
  files: files ? await (0, builders_1.resolveFiles)(files) : undefined,
109
112
  }).then(() => (this.replied = true)));
110
113
  }
@@ -131,7 +134,7 @@ class BaseInteraction extends DiscordBase_1.DiscordBase {
131
134
  static from(client, gateway, __reply) {
132
135
  switch (gateway.type) {
133
136
  case v10_1.InteractionType.ApplicationCommandAutocomplete:
134
- return new AutocompleteInteraction(client, gateway, __reply);
137
+ return new AutocompleteInteraction(client, gateway, undefined, __reply);
135
138
  // biome-ignore lint/suspicious/noFallthroughSwitchClause: bad interaction between biome and ts-server
136
139
  case v10_1.InteractionType.ApplicationCommand:
137
140
  switch (gateway.data.type) {
@@ -172,10 +175,12 @@ exports.BaseInteraction = BaseInteraction;
172
175
  class AutocompleteInteraction extends BaseInteraction {
173
176
  __reply;
174
177
  options;
175
- constructor(client, interaction, __reply) {
178
+ constructor(client, interaction, resolver, __reply) {
176
179
  super(client, interaction);
177
180
  this.__reply = __reply;
178
- this.options = new commands_1.OptionResolver(client, interaction.data.options, undefined, interaction.guild_id, interaction.data.resolved);
181
+ this.options =
182
+ resolver ??
183
+ new commands_1.OptionResolver(client, interaction.data.options, undefined, interaction.guild_id, interaction.data.resolved);
179
184
  }
180
185
  getInput() {
181
186
  return this.options.getAutocompleteValue() ?? '';
@@ -1,16 +1,17 @@
1
- import type { GuildMember, UsingClient } from '../';
1
+ import { GuildMember, type UsingClient } from '../';
2
2
  import type { VoiceStateResource } from '../cache/resources/voice-states';
3
3
  import type { ObjectToLower } from '../common';
4
+ import type { GatewayVoiceState } from '../types';
4
5
  import { Base } from './extra/Base';
5
- export interface VoiceState extends Base, ObjectToLower<VoiceStateResource> {
6
+ export interface VoiceState extends Base, ObjectToLower<Omit<VoiceStateResource, 'member'>> {
6
7
  }
7
8
  export declare class VoiceState extends Base {
8
- private withMember?;
9
- constructor(client: UsingClient, data: VoiceStateResource, withMember?: GuildMember | undefined);
9
+ protected withMember?: GuildMember;
10
+ constructor(client: UsingClient, data: GatewayVoiceState);
10
11
  isMuted(): boolean;
11
12
  member(force?: boolean): Promise<GuildMember>;
12
13
  user(force?: boolean): Promise<import("./User").User>;
13
- channel(force?: boolean): Promise<import("./channels").BaseChannel<import("discord-api-types/v10").ChannelType> | import("./channels").DMChannel | import("./channels").CategoryChannel | undefined>;
14
+ channel(force?: boolean): Promise<import("./channels").BaseChannel<import("discord-api-types/payloads/v10/channel").ChannelType> | import("./channels").DMChannel | import("./channels").CategoryChannel | undefined>;
14
15
  setMute(mute?: boolean, reason?: string): Promise<GuildMember>;
15
16
  setDeaf(deaf?: boolean, reason?: string): Promise<GuildMember>;
16
17
  disconnect(reason?: string): Promise<GuildMember>;
@@ -1,13 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VoiceState = void 0;
4
+ const __1 = require("../");
4
5
  const Base_1 = require("./extra/Base");
5
6
  class VoiceState extends Base_1.Base {
6
7
  withMember;
7
- constructor(client, data, withMember) {
8
+ constructor(client, data) {
8
9
  super(client);
9
- this.withMember = withMember;
10
- this.__patchThis(data);
10
+ const { member, ...rest } = data;
11
+ this.__patchThis(rest);
12
+ if (member?.user && data.guild_id)
13
+ this.withMember = new __1.GuildMember(client, member, member.user, data.guild_id);
11
14
  }
12
15
  isMuted() {
13
16
  return this.mute || this.selfMute;
@@ -153,7 +153,7 @@ export declare class MessagesMethods extends DiscordBase {
153
153
  set: (messageId: string, reason?: string) => Promise<never>;
154
154
  delete: (messageId: string, reason?: string) => Promise<never>;
155
155
  };
156
- static transformMessageBody<T>(body: MessageCreateBodyRequest | MessageUpdateBodyRequest): T;
156
+ static transformMessageBody<T>(body: MessageCreateBodyRequest | MessageUpdateBodyRequest, self: UsingClient): T;
157
157
  }
158
158
  export interface TextBaseGuildChannel extends ObjectToLower<Omit<APITextChannel, 'type' | 'permission_overwrites'>>, MessagesMethods {
159
159
  }
@@ -159,9 +159,10 @@ class MessagesMethods extends DiscordBase_1.DiscordBase {
159
159
  delete: (messageId, reason) => ctx.client.channels.deletePin(messageId, ctx.channelId, reason),
160
160
  };
161
161
  }
162
- static transformMessageBody(body) {
162
+ static transformMessageBody(body, self) {
163
163
  const poll = body.poll;
164
164
  return {
165
+ allowed_mentions: self.options?.allowedMentions,
165
166
  ...body,
166
167
  components: body.components?.map(x => (x instanceof builders_1.ActionRow ? x.toJSON() : x)) ?? undefined,
167
168
  embeds: body.embeds?.map(x => (x instanceof builders_1.Embed ? x.toJSON() : x)) ?? undefined,
@@ -2,12 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ShardManager = void 0;
4
4
  const v10_1 = require("discord-api-types/v10");
5
- const node_worker_threads_1 = require("node:worker_threads");
6
5
  const common_1 = require("../../common");
7
6
  const constants_1 = require("../constants");
8
7
  const structures_1 = require("../structures");
9
8
  const timeout_1 = require("../structures/timeout");
10
9
  const shard_js_1 = require("./shard.js");
10
+ let parentPort;
11
+ let workerData;
11
12
  class ShardManager extends Map {
12
13
  connectQueue;
13
14
  options;
@@ -23,6 +24,12 @@ class ShardManager extends Map {
23
24
  logLevel: common_1.LogLevels.Debug,
24
25
  });
25
26
  }
27
+ const worker_threads = (0, common_1.lazyLoadPackage)('node:worker_threads');
28
+ if (worker_threads) {
29
+ workerData = worker_threads.workerData;
30
+ if (worker_threads.parentPort)
31
+ parentPort = worker_threads.parentPort;
32
+ }
26
33
  }
27
34
  get totalShards() {
28
35
  return this.options.totalShards ?? this.options.info.shards;
@@ -148,8 +155,8 @@ class ShardManager extends Map {
148
155
  });
149
156
  }
150
157
  send(shardId, payload) {
151
- if (node_worker_threads_1.workerData?.__USING_WATCHER__) {
152
- return node_worker_threads_1.parentPort?.postMessage({
158
+ if (workerData?.__USING_WATCHER__) {
159
+ return parentPort?.postMessage({
153
160
  type: 'SEND_TO_SHARD',
154
161
  shardId,
155
162
  payload,
@@ -100,4 +100,5 @@ export interface WorkerData {
100
100
  workerId: number;
101
101
  debug: boolean;
102
102
  workerProxy: boolean;
103
+ __USING_WATCHER__?: boolean;
103
104
  }
@@ -7,7 +7,6 @@
7
7
  /// <reference types="node" />
8
8
  import type { GatewayPresenceUpdateData, GatewaySendPayload } from 'discord-api-types/v10';
9
9
  import { type Worker as ClusterWorker } from 'node:cluster';
10
- import { Worker as ThreadWorker } from 'node:worker_threads';
11
10
  import { ApiHandler, Logger } from '../..';
12
11
  import { type Adapter } from '../../cache';
13
12
  import { type MakePartial } from '../../common';
@@ -16,7 +15,7 @@ import { MemberUpdateHandler } from './events/memberUpdate';
16
15
  import { PresenceUpdateHandler } from './events/presenceUpdate';
17
16
  import type { ShardOptions, WorkerData, WorkerManagerOptions } from './shared';
18
17
  import type { WorkerInfo, WorkerMessage, WorkerShardInfo } from './worker';
19
- export declare class WorkerManager extends Map<number, (ClusterWorker | ThreadWorker) & {
18
+ export declare class WorkerManager extends Map<number, (ClusterWorker | import('node:worker_threads').Worker) & {
20
19
  ready?: boolean;
21
20
  }> {
22
21
  options: Required<WorkerManagerOptions>;
@@ -50,7 +49,7 @@ export declare class WorkerManager extends Map<number, (ClusterWorker | ThreadWo
50
49
  prepareSpaces(): number[][];
51
50
  postMessage(id: number, body: any): void;
52
51
  prepareWorkers(shards: number[][]): Promise<void>;
53
- createWorker(workerData: WorkerData): ClusterWorker | ThreadWorker;
52
+ createWorker(workerData: WorkerData): ClusterWorker | import("worker_threads").Worker;
54
53
  spawn(workerId: number, shardId: number): void;
55
54
  handleWorkerMessage(message: WorkerMessage): Promise<void>;
56
55
  private generateNonce;
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.WorkerManager = void 0;
7
7
  const node_cluster_1 = __importDefault(require("node:cluster"));
8
8
  const node_crypto_1 = require("node:crypto");
9
- const node_worker_threads_1 = require("node:worker_threads");
10
9
  const __1 = require("../..");
11
10
  const cache_1 = require("../../cache");
12
11
  const base_1 = require("../../client/base");
@@ -139,6 +138,9 @@ class WorkerManager extends Map {
139
138
  }
140
139
  }
141
140
  createWorker(workerData) {
141
+ const worker_threads = (0, common_1.lazyLoadPackage)('node:worker_threads');
142
+ if (!worker_threads)
143
+ throw new Error('Cannot create worker without worker_threads.');
142
144
  const env = {
143
145
  SEYFERT_SPAWNING: 'true',
144
146
  };
@@ -147,7 +149,7 @@ class WorkerManager extends Map {
147
149
  }
148
150
  switch (this.options.mode) {
149
151
  case 'threads': {
150
- const worker = new node_worker_threads_1.Worker(workerData.path, {
152
+ const worker = new worker_threads.Worker(workerData.path, {
151
153
  env,
152
154
  });
153
155
  worker.on('message', data => this.handleWorkerMessage(data));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "seyfert",
3
- "version": "1.3.3",
3
+ "version": "1.4.0",
4
4
  "description": "The most advanced framework for discord bots",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",
@@ -21,7 +21,7 @@
21
21
  "license": "Apache-2.0",
22
22
  "dependencies": {
23
23
  "chokidar": "^3.6.0",
24
- "discord-api-types": "^0.37.81",
24
+ "discord-api-types": "^0.37.83",
25
25
  "magic-bytes.js": "^1.10.0",
26
26
  "ts-mixer": "^6.0.4",
27
27
  "ws": "^8.16.0"
@@ -71,4 +71,4 @@
71
71
  "url": "https://github.com/socram03"
72
72
  }
73
73
  ]
74
- }
74
+ }
@@ -1,15 +0,0 @@
1
- import type { ComponentCommandInteractionMap, ComponentContext } from '../components/componentcontext';
2
- import type { MessageCommandInteraction, UserCommandInteraction } from '../structures';
3
- import type { CommandContext } from './applications/chatcontext';
4
- import type { MenuCommandContext } from './applications/menucontext';
5
- import type { UsingClient } from './applications/shared';
6
- export declare class BaseContext {
7
- readonly client: UsingClient;
8
- constructor(client: UsingClient);
9
- get proxy(): import("..").APIRoutes;
10
- isChat(): this is CommandContext;
11
- isMenu(): this is MenuCommandContext<UserCommandInteraction | MessageCommandInteraction>;
12
- isMenuUser(): this is MenuCommandContext<UserCommandInteraction>;
13
- isMenuMessage(): this is MenuCommandContext<MessageCommandInteraction>;
14
- isComponent(): this is ComponentContext<keyof ComponentCommandInteractionMap>;
15
- }
@@ -1,24 +0,0 @@
1
- import type { ModalSubmitInteraction } from '../structures';
2
- import type { ComponentCommandInteractionMap, ComponentContext } from './componentcontext';
3
- export declare const InteractionCommandType: {
4
- readonly COMPONENT: 0;
5
- readonly MODAL: 1;
6
- };
7
- export interface ComponentCommand {
8
- __filePath?: string;
9
- }
10
- export declare abstract class ComponentCommand {
11
- type: 0;
12
- abstract componentType: keyof ComponentCommandInteractionMap;
13
- abstract filter(interaction: ComponentContext<typeof this.componentType>): Promise<boolean> | boolean;
14
- abstract run(interaction: ComponentContext<typeof this.componentType>): any;
15
- get cType(): number;
16
- }
17
- export interface ModalCommand {
18
- __filePath?: string;
19
- }
20
- export declare abstract class ModalCommand {
21
- type: 1;
22
- abstract filter(interaction: ModalSubmitInteraction): Promise<boolean> | boolean;
23
- abstract run(interaction: ModalSubmitInteraction): any;
24
- }