seyfert 1.2.0 → 1.2.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.
@@ -112,41 +112,43 @@ class HttpClient extends base_1.BaseClient {
112
112
  break;
113
113
  default:
114
114
  await (0, oninteractioncreate_1.onInteractionCreate)(this, rawBody, -1, async ({ body, files }) => {
115
- let response;
116
- const headers = {};
117
- if (files) {
118
- response = new FormData();
119
- for (const [index, file] of files.entries()) {
120
- const fileKey = file.key ?? `files[${index}]`;
121
- if ((0, utils_1.isBufferLike)(file.data)) {
122
- let contentType = file.contentType;
123
- if (!contentType) {
124
- const [parsedType] = (0, magic_bytes_js_1.filetypeinfo)(file.data);
125
- if (parsedType) {
126
- contentType =
127
- api_1.OverwrittenMimeTypes[parsedType.mime] ??
128
- parsedType.mime ??
129
- 'application/octet-stream';
115
+ res.cork(() => {
116
+ let response;
117
+ const headers = {};
118
+ if (files) {
119
+ response = new FormData();
120
+ for (const [index, file] of files.entries()) {
121
+ const fileKey = file.key ?? `files[${index}]`;
122
+ if ((0, utils_1.isBufferLike)(file.data)) {
123
+ let contentType = file.contentType;
124
+ if (!contentType) {
125
+ const [parsedType] = (0, magic_bytes_js_1.filetypeinfo)(file.data);
126
+ if (parsedType) {
127
+ contentType =
128
+ api_1.OverwrittenMimeTypes[parsedType.mime] ??
129
+ parsedType.mime ??
130
+ 'application/octet-stream';
131
+ }
130
132
  }
133
+ response.append(fileKey, new Blob([file.data], { type: contentType }), file.name);
134
+ }
135
+ else {
136
+ response.append(fileKey, new Blob([`${file.data}`], { type: file.contentType }), file.name);
131
137
  }
132
- response.append(fileKey, new Blob([file.data], { type: contentType }), file.name);
133
138
  }
134
- else {
135
- response.append(fileKey, new Blob([`${file.data}`], { type: file.contentType }), file.name);
139
+ if (body) {
140
+ response.append('payload_json', JSON.stringify(body));
136
141
  }
137
142
  }
138
- if (body) {
139
- response.append('payload_json', JSON.stringify(body));
143
+ else {
144
+ response = body ?? {};
145
+ headers['Content-Type'] = 'application/json';
146
+ }
147
+ for (const i in headers) {
148
+ res.writeHeader(i, headers[i]);
140
149
  }
141
- }
142
- else {
143
- response = body ?? {};
144
- headers['Content-Type'] = 'application/json';
145
- }
146
- for (const i in headers) {
147
- res.writeHeader(i, headers[i]);
148
- }
149
- return res.end(JSON.stringify(response));
150
+ return res.end(JSON.stringify(response));
151
+ });
150
152
  });
151
153
  break;
152
154
  }
@@ -1,5 +1,5 @@
1
1
  import type { ContextMenuCommand, ReturnCache, WebhookMessage } from '../..';
2
- import { type InteractionCreateBodyRequest, type InteractionMessageUpdateBodyRequest, type UnionToTuple, type When } from '../../common';
2
+ import { type InteractionCreateBodyRequest, type InteractionMessageUpdateBodyRequest, type UnionToTuple, type When, type ModalCreateBodyRequest } from '../../common';
3
3
  import { Message, User, type AllChannels, type Guild, type GuildMember, type MessageCommandInteraction, type UserCommandInteraction } from '../../structures';
4
4
  import { BaseContext } from '../basecontex';
5
5
  import type { RegisteredMiddlewares } from '../decorators';
@@ -21,7 +21,7 @@ export declare class MenuCommandContext<T extends MessageCommandInteraction | Us
21
21
  };
22
22
  get fullCommandName(): string;
23
23
  write<FR extends boolean = false>(body: InteractionCreateBodyRequest, fetchReply?: FR): Promise<When<FR, WebhookMessage, void | WebhookMessage>>;
24
- get modal(): ((body: import("../../common").ModalCreateBodyRequest) => Promise<void>) | ((body: import("../../common").ModalCreateBodyRequest) => Promise<void>);
24
+ modal(body: ModalCreateBodyRequest): Promise<void>;
25
25
  deferReply(ephemeral?: boolean): Promise<void>;
26
26
  editResponse(body: InteractionMessageUpdateBodyRequest): Promise<Message>;
27
27
  deleteResponse(): Promise<void | undefined>;
@@ -41,8 +41,8 @@ class MenuCommandContext extends basecontex_1.BaseContext {
41
41
  write(body, fetchReply) {
42
42
  return this.interaction.write(body, fetchReply);
43
43
  }
44
- get modal() {
45
- return this.interaction.modal;
44
+ modal(body) {
45
+ return this.interaction.modal(body);
46
46
  }
47
47
  deferReply(ephemeral = false) {
48
48
  return this.interaction.deferReply(ephemeral ? v10_1.MessageFlags.Ephemeral : undefined);
@@ -1,33 +1,104 @@
1
1
  import type { AllChannels, ButtonInteraction, ChannelSelectMenuInteraction, ComponentInteraction, Guild, GuildMember, MentionableSelectMenuInteraction, Message, ReturnCache, RoleSelectMenuInteraction, StringSelectMenuInteraction, UserSelectMenuInteraction, WebhookMessage } from '..';
2
2
  import type { ExtendContext, UsingClient } from '../commands';
3
3
  import { BaseContext } from '../commands/basecontex';
4
- import type { InteractionCreateBodyRequest, InteractionMessageUpdateBodyRequest, When } from '../common';
4
+ import type { ComponentInteractionMessageUpdate, InteractionCreateBodyRequest, InteractionMessageUpdateBodyRequest, When } from '../common';
5
5
  export interface ComponentContext<Type extends keyof ComponentCommandInteractionMap> extends BaseContext, ExtendContext {
6
6
  }
7
+ /**
8
+ * Represents a context for interacting with components in a Discord bot.
9
+ * @template Type - The type of component interaction.
10
+ */
7
11
  export declare class ComponentContext<Type extends keyof ComponentCommandInteractionMap> extends BaseContext {
8
12
  readonly client: UsingClient;
9
13
  interaction: ComponentCommandInteractionMap[Type] | ComponentInteraction;
14
+ /**
15
+ * Creates a new instance of the ComponentContext class.
16
+ * @param client - The UsingClient instance.
17
+ * @param interaction - The component interaction object.
18
+ */
10
19
  constructor(client: UsingClient, interaction: ComponentCommandInteractionMap[Type] | ComponentInteraction);
20
+ /**
21
+ * Gets the proxy object.
22
+ */
11
23
  get proxy(): import("..").APIRoutes;
24
+ /**
25
+ * Gets the language object for the interaction's locale.
26
+ */
12
27
  get t(): import("..").__InternalParseLocale<import("..").DefaultLocale> & {
13
28
  get(locale?: string | undefined): import("..").DefaultLocale;
14
29
  };
30
+ /**
31
+ * Gets the custom ID of the interaction.
32
+ */
15
33
  get customId(): string;
16
- get write(): <FR extends boolean = false>(body: Omit<import("discord-api-types/v10").APIInteractionResponseCallbackData, "components" | "embeds"> & import("../common").ResolverProps, fetchReply?: FR | undefined) => Promise<When<FR, WebhookMessage, void>>;
34
+ /**
35
+ * Writes a response to the interaction.
36
+ * @param body - The body of the response.
37
+ * @param fetchReply - Whether to fetch the reply or not.
38
+ */
39
+ write<FR extends boolean = false>(body: InteractionCreateBodyRequest, fetchReply?: FR): Promise<When<FR, WebhookMessage, void>>;
40
+ /**
41
+ * Defers the reply to the interaction.
42
+ * @param ephemeral - Whether the reply should be ephemeral or not.
43
+ */
17
44
  deferReply(ephemeral?: boolean): Promise<void>;
18
- get editResponse(): ((body: Omit<import("discord-api-types/v10").RESTPatchAPIWebhookWithTokenMessageJSONBody, "components" | "embeds"> & import("../common").ResolverProps) => Promise<Message>) | ((body: Omit<import("discord-api-types/v10").RESTPatchAPIWebhookWithTokenMessageJSONBody, "components" | "embeds"> & import("../common").ResolverProps) => Promise<Message>) | ((body: Omit<import("discord-api-types/v10").RESTPatchAPIWebhookWithTokenMessageJSONBody, "components" | "embeds"> & import("../common").ResolverProps) => Promise<Message>) | ((body: Omit<import("discord-api-types/v10").RESTPatchAPIWebhookWithTokenMessageJSONBody, "components" | "embeds"> & import("../common").ResolverProps) => Promise<Message>) | ((body: Omit<import("discord-api-types/v10").RESTPatchAPIWebhookWithTokenMessageJSONBody, "components" | "embeds"> & import("../common").ResolverProps) => Promise<Message>) | ((body: Omit<import("discord-api-types/v10").RESTPatchAPIWebhookWithTokenMessageJSONBody, "components" | "embeds"> & import("../common").ResolverProps) => Promise<Message>) | ((body: Omit<import("discord-api-types/v10").RESTPatchAPIWebhookWithTokenMessageJSONBody, "components" | "embeds"> & import("../common").ResolverProps) => Promise<Message>);
19
- get update(): ((data: Omit<import("discord-api-types/v10").APIInteractionResponseCallbackData, "components" | "embeds"> & import("../common").ResolverProps) => Promise<void>) | ((data: Omit<import("discord-api-types/v10").APIInteractionResponseCallbackData, "components" | "embeds"> & import("../common").ResolverProps) => Promise<void>) | ((data: Omit<import("discord-api-types/v10").APIInteractionResponseCallbackData, "components" | "embeds"> & import("../common").ResolverProps) => Promise<void>) | ((data: Omit<import("discord-api-types/v10").APIInteractionResponseCallbackData, "components" | "embeds"> & import("../common").ResolverProps) => Promise<void>) | ((data: Omit<import("discord-api-types/v10").APIInteractionResponseCallbackData, "components" | "embeds"> & import("../common").ResolverProps) => Promise<void>) | ((data: Omit<import("discord-api-types/v10").APIInteractionResponseCallbackData, "components" | "embeds"> & import("../common").ResolverProps) => Promise<void>) | ((data: Omit<import("discord-api-types/v10").APIInteractionResponseCallbackData, "components" | "embeds"> & import("../common").ResolverProps) => Promise<void>);
45
+ /**
46
+ * Edits the response of the interaction.
47
+ * @param body - The updated body of the response.
48
+ */
49
+ editResponse(body: InteractionMessageUpdateBodyRequest): Promise<Message>;
50
+ /**
51
+ * Updates the interaction with new data.
52
+ * @param body - The updated body of the interaction.
53
+ */
54
+ update(body: ComponentInteractionMessageUpdate): Promise<void>;
55
+ /**
56
+ * Edits the response or replies to the interaction.
57
+ * @param body - The body of the response or updated body of the interaction.
58
+ * @param fetchReply - Whether to fetch the reply or not.
59
+ */
20
60
  editOrReply<FR extends boolean = false>(body: InteractionCreateBodyRequest | InteractionMessageUpdateBodyRequest, fetchReply?: FR): Promise<When<FR, WebhookMessage | Message, void | WebhookMessage | Message>>;
61
+ /**
62
+ * Deletes the response of the interaction.
63
+ * @returns A promise that resolves when the response is deleted.
64
+ */
21
65
  deleteResponse(): Promise<void | undefined>;
66
+ /**
67
+ * Gets the channel of the interaction.
68
+ * @param mode - The mode to fetch the channel.
69
+ * @returns A promise that resolves to the channel.
70
+ */
22
71
  channel(mode?: 'rest' | 'flow'): Promise<AllChannels>;
23
72
  channel(mode?: 'cache'): ReturnCache<AllChannels>;
73
+ /**
74
+ * Gets the bot member in the guild of the interaction.
75
+ * @param mode - The mode to fetch the member.
76
+ * @returns A promise that resolves to the bot member.
77
+ */
24
78
  me(mode?: 'rest' | 'flow'): Promise<GuildMember>;
25
79
  me(mode?: 'cache'): ReturnCache<GuildMember | undefined>;
80
+ /**
81
+ * Gets the guild of the interaction.
82
+ * @param mode - The mode to fetch the guild.
83
+ * @returns A promise that resolves to the guild.
84
+ */
26
85
  guild(mode?: 'rest' | 'flow'): Promise<Guild<'cached' | 'api'> | undefined>;
27
86
  guild(mode?: 'cache'): ReturnCache<Guild<'cached'> | undefined>;
87
+ /**
88
+ * Gets the ID of the guild of the interaction.
89
+ */
28
90
  get guildId(): string | undefined;
91
+ /**
92
+ * Gets the ID of the channel of the interaction.
93
+ */
29
94
  get channelId(): string;
95
+ /**
96
+ * Gets the author of the interaction.
97
+ */
30
98
  get author(): import("..").User;
99
+ /**
100
+ * Gets the member of the interaction.
101
+ */
31
102
  get member(): import("..").InteractionGuildMember | undefined;
32
103
  }
33
104
  export interface ComponentCommandInteractionMap {
@@ -3,38 +3,82 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ComponentContext = void 0;
4
4
  const v10_1 = require("discord-api-types/v10");
5
5
  const basecontex_1 = require("../commands/basecontex");
6
+ /**
7
+ * Represents a context for interacting with components in a Discord bot.
8
+ * @template Type - The type of component interaction.
9
+ */
6
10
  class ComponentContext extends basecontex_1.BaseContext {
7
11
  client;
8
12
  interaction;
13
+ /**
14
+ * Creates a new instance of the ComponentContext class.
15
+ * @param client - The UsingClient instance.
16
+ * @param interaction - The component interaction object.
17
+ */
9
18
  constructor(client, interaction) {
10
19
  super(client);
11
20
  this.client = client;
12
21
  this.interaction = interaction;
13
22
  }
23
+ /**
24
+ * Gets the proxy object.
25
+ */
14
26
  get proxy() {
15
27
  return this.client.proxy;
16
28
  }
29
+ /**
30
+ * Gets the language object for the interaction's locale.
31
+ */
17
32
  get t() {
18
33
  return this.client.langs.get(this.interaction?.locale ?? this.client.langs?.defaultLang ?? 'en-US');
19
34
  }
35
+ /**
36
+ * Gets the custom ID of the interaction.
37
+ */
20
38
  get customId() {
21
39
  return this.interaction.customId;
22
40
  }
23
- get write() {
24
- return this.interaction.write;
25
- }
41
+ /**
42
+ * Writes a response to the interaction.
43
+ * @param body - The body of the response.
44
+ * @param fetchReply - Whether to fetch the reply or not.
45
+ */
46
+ write(body, fetchReply) {
47
+ return this.interaction.write(body, fetchReply);
48
+ }
49
+ /**
50
+ * Defers the reply to the interaction.
51
+ * @param ephemeral - Whether the reply should be ephemeral or not.
52
+ */
26
53
  deferReply(ephemeral = false) {
27
54
  return this.interaction.deferReply(ephemeral ? v10_1.MessageFlags.Ephemeral : undefined);
28
55
  }
29
- get editResponse() {
30
- return this.interaction.editResponse;
31
- }
32
- get update() {
33
- return this.interaction.update;
34
- }
56
+ /**
57
+ * Edits the response of the interaction.
58
+ * @param body - The updated body of the response.
59
+ */
60
+ editResponse(body) {
61
+ return this.interaction.editResponse(body);
62
+ }
63
+ /**
64
+ * Updates the interaction with new data.
65
+ * @param body - The updated body of the interaction.
66
+ */
67
+ update(body) {
68
+ return this.interaction.update(body);
69
+ }
70
+ /**
71
+ * Edits the response or replies to the interaction.
72
+ * @param body - The body of the response or updated body of the interaction.
73
+ * @param fetchReply - Whether to fetch the reply or not.
74
+ */
35
75
  editOrReply(body, fetchReply) {
36
76
  return this.interaction.editOrReply(body, fetchReply);
37
77
  }
78
+ /**
79
+ * Deletes the response of the interaction.
80
+ * @returns A promise that resolves when the response is deleted.
81
+ */
38
82
  deleteResponse() {
39
83
  return this.interaction.deleteResponse();
40
84
  }
@@ -63,15 +107,27 @@ class ComponentContext extends basecontex_1.BaseContext {
63
107
  return this.client.guilds.fetch(this.guildId, mode === 'rest');
64
108
  }
65
109
  }
110
+ /**
111
+ * Gets the ID of the guild of the interaction.
112
+ */
66
113
  get guildId() {
67
114
  return this.interaction.guildId;
68
115
  }
116
+ /**
117
+ * Gets the ID of the channel of the interaction.
118
+ */
69
119
  get channelId() {
70
120
  return this.interaction.channelId;
71
121
  }
122
+ /**
123
+ * Gets the author of the interaction.
124
+ */
72
125
  get author() {
73
126
  return this.interaction.user;
74
127
  }
128
+ /**
129
+ * Gets the member of the interaction.
130
+ */
75
131
  get member() {
76
132
  return this.interaction.member;
77
133
  }
@@ -10,6 +10,7 @@ import { UserSelectMenuComponent } from './UserSelectMenuComponent';
10
10
  export type MessageComponents = ButtonComponent | LinkButtonComponent | RoleSelectMenuComponent | UserSelectMenuComponent | StringSelectMenuComponent | ChannelSelectMenuComponent | MentionableSelectMenuComponent | TextInputComponent;
11
11
  export type ActionRowMessageComponents = Exclude<MessageComponents, TextInputComponent>;
12
12
  export * from './command';
13
+ export * from './componentcontext';
13
14
  /**
14
15
  * Return a new component instance based on the component type.
15
16
  *
@@ -24,6 +24,7 @@ const RoleSelectMenuComponent_1 = require("./RoleSelectMenuComponent");
24
24
  const StringSelectMenuComponent_1 = require("./StringSelectMenuComponent");
25
25
  const UserSelectMenuComponent_1 = require("./UserSelectMenuComponent");
26
26
  __exportStar(require("./command"), exports);
27
+ __exportStar(require("./componentcontext"), exports);
27
28
  /**
28
29
  * Return a new component instance based on the component type.
29
30
  *
@@ -26,7 +26,8 @@ class User extends DiscordBase_1.DiscordBase {
26
26
  }
27
27
  avatarURL(options) {
28
28
  if (!this.avatar) {
29
- return this.rest.cdn.defaultAvatar(Number(this.discriminator));
29
+ const avatarIndex = this.discriminator === '0' ? Number(BigInt(this.id) >> 22n) % 6 : Number.parseInt(this.discriminator) % 5;
30
+ return this.rest.cdn.defaultAvatar(avatarIndex);
30
31
  }
31
32
  return this.rest.cdn.avatar(this.id, this.avatar, options);
32
33
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "seyfert",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "The most advanced framework for discord bots",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",