seyfert 1.2.2 → 1.3.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.
- package/LICENSE +190 -190
- package/README.md +46 -46
- package/lib/api/Router.d.ts +9 -0
- package/lib/api/Router.js +16 -8
- package/lib/api/Routes/cdn.d.ts +26 -15
- package/lib/api/Routes/channels.d.ts +15 -1
- package/lib/api/api.d.ts +2 -3
- package/lib/api/api.js +4 -9
- package/lib/api/index.d.ts +0 -1
- package/lib/api/index.js +0 -1
- package/lib/api/utils/utils.d.ts +1 -1
- package/lib/api/utils/utils.js +2 -2
- package/lib/builders/Modal.d.ts +4 -1
- package/lib/builders/Modal.js +4 -1
- package/lib/builders/Poll.d.ts +16 -0
- package/lib/builders/Poll.js +48 -0
- package/lib/builders/index.d.ts +1 -0
- package/lib/builders/index.js +1 -0
- package/lib/cache/adapters/default.d.ts +1 -0
- package/lib/cache/adapters/default.js +4 -0
- package/lib/cache/adapters/index.d.ts +1 -0
- package/lib/cache/adapters/index.js +1 -0
- package/lib/cache/adapters/limited.d.ts +50 -0
- package/lib/cache/adapters/limited.js +188 -0
- package/lib/cache/adapters/redis.d.ts +2 -0
- package/lib/cache/adapters/redis.js +17 -0
- package/lib/cache/adapters/types.d.ts +1 -0
- package/lib/cache/adapters/workeradapter.d.ts +1 -0
- package/lib/cache/adapters/workeradapter.js +6 -9
- package/lib/cache/index.d.ts +8 -3
- package/lib/cache/index.js +41 -7
- package/lib/cache/resources/channels.d.ts +2 -1
- package/lib/cache/resources/default/base.d.ts +3 -3
- package/lib/cache/resources/default/base.js +8 -3
- package/lib/cache/resources/default/guild-based.d.ts +2 -1
- package/lib/cache/resources/default/guild-based.js +7 -3
- package/lib/cache/resources/default/guild-related.d.ts +2 -1
- package/lib/cache/resources/default/guild-related.js +7 -3
- package/lib/cache/resources/emojis.d.ts +2 -0
- package/lib/cache/resources/emojis.js +4 -0
- package/lib/cache/resources/guilds.d.ts +2 -0
- package/lib/cache/resources/guilds.js +4 -0
- package/lib/cache/resources/members.d.ts +2 -0
- package/lib/cache/resources/members.js +5 -1
- package/lib/cache/resources/messages.d.ts +15 -0
- package/lib/cache/resources/messages.js +53 -0
- package/lib/cache/resources/overwrites.d.ts +4 -0
- package/lib/cache/resources/overwrites.js +4 -0
- package/lib/cache/resources/presence.d.ts +1 -0
- package/lib/cache/resources/presence.js +4 -0
- package/lib/cache/resources/roles.d.ts +2 -0
- package/lib/cache/resources/roles.js +4 -0
- package/lib/cache/resources/stage-instances.d.ts +1 -0
- package/lib/cache/resources/stage-instances.js +5 -1
- package/lib/cache/resources/stickers.d.ts +2 -0
- package/lib/cache/resources/stickers.js +4 -0
- package/lib/cache/resources/threads.d.ts +2 -0
- package/lib/cache/resources/threads.js +4 -0
- package/lib/cache/resources/users.d.ts +2 -0
- package/lib/cache/resources/users.js +4 -0
- package/lib/cache/resources/voice-states.d.ts +2 -1
- package/lib/cache/resources/voice-states.js +8 -4
- package/lib/client/base.d.ts +26 -14
- package/lib/client/base.js +41 -13
- package/lib/client/client.d.ts +6 -5
- package/lib/client/client.js +13 -1
- package/lib/client/oninteractioncreate.js +2 -2
- package/lib/client/onmessagecreate.js +17 -14
- package/lib/client/workerclient.d.ts +3 -3
- package/lib/client/workerclient.js +23 -14
- package/lib/collection.d.ts +8 -3
- package/lib/collection.js +22 -4
- package/lib/commands/applications/chat.d.ts +17 -20
- package/lib/commands/applications/chat.js +6 -21
- package/lib/commands/applications/chatcontext.d.ts +1 -1
- package/lib/commands/applications/menucontext.d.ts +1 -1
- package/lib/commands/applications/shared.d.ts +4 -0
- package/lib/commands/applications/shared.js +6 -0
- package/lib/commands/decorators.d.ts +11 -1
- package/lib/commands/decorators.js +24 -0
- package/lib/commands/handler.d.ts +11 -7
- package/lib/commands/handler.js +43 -14
- package/lib/common/index.d.ts +2 -0
- package/lib/common/index.js +2 -0
- package/lib/common/it/utils.d.ts +0 -1
- package/lib/common/it/utils.js +0 -1
- package/lib/common/shorters/channels.d.ts +8 -3
- package/lib/common/shorters/channels.js +27 -12
- package/lib/common/shorters/guilds.d.ts +6 -5
- package/lib/common/shorters/guilds.js +22 -4
- package/lib/common/shorters/interaction.d.ts +13 -0
- package/lib/common/shorters/interaction.js +61 -0
- package/lib/common/shorters/messages.d.ts +6 -3
- package/lib/common/shorters/messages.js +33 -15
- package/lib/common/shorters/roles.d.ts +3 -3
- package/lib/common/shorters/roles.js +12 -17
- package/lib/common/shorters/templates.d.ts +7 -6
- package/lib/common/shorters/templates.js +28 -6
- package/lib/common/shorters/threads.d.ts +39 -0
- package/lib/common/shorters/threads.js +76 -0
- package/lib/common/shorters/webhook.d.ts +1 -1
- package/lib/common/shorters/webhook.js +8 -2
- package/lib/common/types/options.d.ts +2 -2
- package/lib/common/types/write.d.ts +8 -5
- package/lib/components/ButtonComponent.js +1 -1
- package/lib/components/componentcontext.d.ts +1 -1
- package/lib/components/handler.d.ts +6 -17
- package/lib/components/handler.js +7 -2
- package/lib/events/handler.d.ts +8 -14
- package/lib/events/handler.js +9 -4
- package/lib/events/hooks/guild.d.ts +1 -1
- package/lib/events/hooks/guild.js +2 -2
- package/lib/events/hooks/message.d.ts +26 -8
- package/lib/events/hooks/message.js +18 -7
- package/lib/langs/handler.d.ts +4 -8
- package/lib/langs/handler.js +7 -2
- package/lib/structures/AutoModerationRule.d.ts +6 -6
- package/lib/structures/Guild.d.ts +15 -13
- package/lib/structures/GuildEmoji.d.ts +2 -2
- package/lib/structures/GuildEmoji.js +1 -1
- package/lib/structures/GuildMember.js +1 -1
- package/lib/structures/GuildRole.d.ts +5 -5
- package/lib/structures/GuildTemplate.d.ts +10 -10
- package/lib/structures/Interaction.d.ts +3 -3
- package/lib/structures/Interaction.js +27 -48
- package/lib/structures/Message.d.ts +5 -3
- package/lib/structures/Message.js +5 -0
- package/lib/structures/Poll.d.ts +15 -0
- package/lib/structures/Poll.js +26 -0
- package/lib/structures/User.d.ts +2 -3
- package/lib/structures/User.js +9 -4
- package/lib/structures/Webhook.d.ts +2 -2
- package/lib/structures/Webhook.js +1 -1
- package/lib/structures/channels.d.ts +11 -3
- package/lib/structures/channels.js +16 -8
- package/lib/structures/extra/BaseGuild.js +3 -3
- package/lib/structures/extra/Permissions.d.ts +1 -0
- package/lib/structures/index.d.ts +1 -0
- package/lib/structures/index.js +1 -0
- package/lib/websocket/SharedTypes.d.ts +7 -2
- package/lib/websocket/discord/worker.d.ts +1 -1
- package/lib/websocket/discord/workermanager.js +3 -9
- package/lib/websocket/structures/timeout.js +9 -12
- package/package.json +8 -8
- package/lib/api/CDN.d.ts +0 -212
- package/lib/api/CDN.js +0 -228
- package/lib/client/http/adapters/bun.d.ts +0 -14
- package/lib/client/http/adapters/bun.js +0 -117
- package/lib/client/http/adapters/index.d.ts +0 -15
- package/lib/client/http/adapters/index.js +0 -27
- package/lib/client/http/adapters/uws.d.ts +0 -17
- package/lib/client/http/adapters/uws.js +0 -142
- package/lib/client/http/httpclient.d.ts +0 -13
- package/lib/client/http/httpclient.js +0 -48
- package/lib/common/shorters/overwrites.d.ts +0 -29
- package/lib/common/shorters/overwrites.js +0 -63
- package/lib/components/listener.d.ts +0 -11
- package/lib/components/listener.js +0 -17
- package/lib/structures/extra/BaseComponent.d.ts +0 -9
- package/lib/structures/extra/BaseComponent.js +0 -12
- package/lib/structures/extra/BaseSelectMenuComponent.d.ts +0 -9
- package/lib/structures/extra/BaseSelectMenuComponent.js +0 -13
package/lib/api/CDN.js
DELETED
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CDN = void 0;
|
|
4
|
-
/* eslint-disable jsdoc/check-param-names */
|
|
5
|
-
const index_js_1 = require("../common/index.js");
|
|
6
|
-
const constants_js_1 = require("./utils/constants.js");
|
|
7
|
-
/**
|
|
8
|
-
* The CDN link builder
|
|
9
|
-
*/
|
|
10
|
-
class CDN {
|
|
11
|
-
base;
|
|
12
|
-
constructor(base = index_js_1.CDN_URL) {
|
|
13
|
-
this.base = base;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Generates an app asset URL for a client's asset.
|
|
17
|
-
*
|
|
18
|
-
* @param clientId - The client id that has the asset
|
|
19
|
-
* @param assetHash - The hash provided by Discord for this asset
|
|
20
|
-
* @param options - Optional options for the asset
|
|
21
|
-
*/
|
|
22
|
-
appAsset(clientId, assetHash, options) {
|
|
23
|
-
return this.makeURL(`/app-assets/${clientId}/${assetHash}`, options);
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Generates an app icon URL for a client's icon.
|
|
27
|
-
*
|
|
28
|
-
* @param clientId - The client id that has the icon
|
|
29
|
-
* @param iconHash - The hash provided by Discord for this icon
|
|
30
|
-
* @param options - Optional options for the icon
|
|
31
|
-
*/
|
|
32
|
-
appIcon(clientId, iconHash, options) {
|
|
33
|
-
return this.makeURL(`/app-icons/${clientId}/${iconHash}`, options);
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Generates an avatar URL, e.g. for a user or a webhook.
|
|
37
|
-
*
|
|
38
|
-
* @param id - The id that has the icon
|
|
39
|
-
* @param avatarHash - The hash provided by Discord for this avatar
|
|
40
|
-
* @param options - Optional options for the avatar
|
|
41
|
-
*/
|
|
42
|
-
avatar(id, avatarHash, options) {
|
|
43
|
-
return this.dynamicMakeURL(`/avatars/${id}/${avatarHash}`, avatarHash, options);
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Generates a user avatar decoration URL.
|
|
47
|
-
*
|
|
48
|
-
* @param userId - The id of the user
|
|
49
|
-
* @param userAvatarDecoration - The hash provided by Discord for this avatar decoration
|
|
50
|
-
* @param options - Optional options for the avatar decoration
|
|
51
|
-
*/
|
|
52
|
-
avatarDecoration(userId, userAvatarDecoration, options) {
|
|
53
|
-
return this.makeURL(`/avatar-decorations/${userId}/${userAvatarDecoration}`, options);
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Generates a banner URL, e.g. for a user or a guild.
|
|
57
|
-
*
|
|
58
|
-
* @param id - The id that has the banner splash
|
|
59
|
-
* @param bannerHash - The hash provided by Discord for this banner
|
|
60
|
-
* @param options - Optional options for the banner
|
|
61
|
-
*/
|
|
62
|
-
banner(id, bannerHash, options) {
|
|
63
|
-
return this.dynamicMakeURL(`/banners/${id}/${bannerHash}`, bannerHash, options);
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Generates an icon URL for a channel, e.g. a group DM.
|
|
67
|
-
*
|
|
68
|
-
* @param channelId - The channel id that has the icon
|
|
69
|
-
* @param iconHash - The hash provided by Discord for this channel
|
|
70
|
-
* @param options - Optional options for the icon
|
|
71
|
-
*/
|
|
72
|
-
channelIcon(channelId, iconHash, options) {
|
|
73
|
-
return this.makeURL(`/channel-icons/${channelId}/${iconHash}`, options);
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Generates a default avatar URL
|
|
77
|
-
*
|
|
78
|
-
* @param index - The default avatar index
|
|
79
|
-
* @remarks
|
|
80
|
-
* To calculate the index for a user do `(userId >> 22) % 6`,
|
|
81
|
-
* or `discriminator % 5` if they're using the legacy username system.
|
|
82
|
-
*/
|
|
83
|
-
defaultAvatar(index) {
|
|
84
|
-
return this.makeURL(`/embed/avatars/${index}`, { extension: 'png' });
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Generates a discovery splash URL for a guild's discovery splash.
|
|
88
|
-
*
|
|
89
|
-
* @param guildId - The guild id that has the discovery splash
|
|
90
|
-
* @param splashHash - The hash provided by Discord for this splash
|
|
91
|
-
* @param options - Optional options for the splash
|
|
92
|
-
*/
|
|
93
|
-
discoverySplash(guildId, splashHash, options) {
|
|
94
|
-
return this.makeURL(`/discovery-splashes/${guildId}/${splashHash}`, options);
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Generates an emoji's URL for an emoji.
|
|
98
|
-
*
|
|
99
|
-
* @param emojiId - The emoji id
|
|
100
|
-
* @param options - Optional options for the emoji
|
|
101
|
-
*/
|
|
102
|
-
emoji(emojiId, options) {
|
|
103
|
-
const resolvedOptions = options;
|
|
104
|
-
return this.makeURL(`/emojis/${emojiId}`, resolvedOptions);
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Generates a guild member avatar URL.
|
|
108
|
-
*
|
|
109
|
-
* @param guildId - The id of the guild
|
|
110
|
-
* @param userId - The id of the user
|
|
111
|
-
* @param avatarHash - The hash provided by Discord for this avatar
|
|
112
|
-
* @param options - Optional options for the avatar
|
|
113
|
-
*/
|
|
114
|
-
guildMemberAvatar(guildId, userId, avatarHash, options) {
|
|
115
|
-
return this.dynamicMakeURL(`/guilds/${guildId}/users/${userId}/avatars/${avatarHash}`, avatarHash, options);
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Generates a guild member banner URL.
|
|
119
|
-
*
|
|
120
|
-
* @param guildId - The id of the guild
|
|
121
|
-
* @param userId - The id of the user
|
|
122
|
-
* @param bannerHash - The hash provided by Discord for this banner
|
|
123
|
-
* @param options - Optional options for the banner
|
|
124
|
-
*/
|
|
125
|
-
guildMemberBanner(guildId, userId, bannerHash, options) {
|
|
126
|
-
return this.dynamicMakeURL(`/guilds/${guildId}/users/${userId}/banner`, bannerHash, options);
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Generates an icon URL, e.g. for a guild.
|
|
130
|
-
*
|
|
131
|
-
* @param id - The id that has the icon splash
|
|
132
|
-
* @param iconHash - The hash provided by Discord for this icon
|
|
133
|
-
* @param options - Optional options for the icon
|
|
134
|
-
*/
|
|
135
|
-
icon(id, iconHash, options) {
|
|
136
|
-
return this.dynamicMakeURL(`/icons/${id}/${iconHash}`, iconHash, options);
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Generates a URL for the icon of a role
|
|
140
|
-
*
|
|
141
|
-
* @param roleId - The id of the role that has the icon
|
|
142
|
-
* @param roleIconHash - The hash provided by Discord for this role icon
|
|
143
|
-
* @param options - Optional options for the role icon
|
|
144
|
-
*/
|
|
145
|
-
roleIcon(roleId, roleIconHash, options) {
|
|
146
|
-
return this.makeURL(`/role-icons/${roleId}/${roleIconHash}`, options);
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Generates a guild invite splash URL for a guild's invite splash.
|
|
150
|
-
*
|
|
151
|
-
* @param guildId - The guild id that has the invite splash
|
|
152
|
-
* @param splashHash - The hash provided by Discord for this splash
|
|
153
|
-
* @param options - Optional options for the splash
|
|
154
|
-
*/
|
|
155
|
-
splash(guildId, splashHash, options) {
|
|
156
|
-
return this.makeURL(`/splashes/${guildId}/${splashHash}`, options);
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Generates a sticker URL.
|
|
160
|
-
*
|
|
161
|
-
* @param stickerId - The sticker id
|
|
162
|
-
* @param extension - The extension of the sticker
|
|
163
|
-
* @privateRemarks
|
|
164
|
-
* Stickers cannot have a `.webp` extension, so we default to a `.png`
|
|
165
|
-
*/
|
|
166
|
-
sticker(stickerId, extension = 'png') {
|
|
167
|
-
return this.makeURL(`/stickers/${stickerId}`, { allowedExtensions: constants_js_1.ALLOWED_STICKER_EXTENSIONS, extension });
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Generates a sticker pack banner URL.
|
|
171
|
-
*
|
|
172
|
-
* @param bannerId - The banner id
|
|
173
|
-
* @param options - Optional options for the banner
|
|
174
|
-
*/
|
|
175
|
-
stickerPackBanner(bannerId, options) {
|
|
176
|
-
return this.makeURL(`/app-assets/710982414301790216/store/${bannerId}`, options);
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Generates a team icon URL for a team's icon.
|
|
180
|
-
*
|
|
181
|
-
* @param teamId - The team id that has the icon
|
|
182
|
-
* @param iconHash - The hash provided by Discord for this icon
|
|
183
|
-
* @param options - Optional options for the icon
|
|
184
|
-
*/
|
|
185
|
-
teamIcon(teamId, iconHash, options) {
|
|
186
|
-
return this.makeURL(`/team-icons/${teamId}/${iconHash}`, options);
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* Generates a cover image for a guild scheduled event.
|
|
190
|
-
*
|
|
191
|
-
* @param scheduledEventId - The scheduled event id
|
|
192
|
-
* @param coverHash - The hash provided by discord for this cover image
|
|
193
|
-
* @param options - Optional options for the cover image
|
|
194
|
-
*/
|
|
195
|
-
guildScheduledEventCover(scheduledEventId, coverHash, options) {
|
|
196
|
-
return this.makeURL(`/guild-events/${scheduledEventId}/${coverHash}`, options);
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Constructs the URL for the resource, checking whether or not `hash` starts with `a_` if `dynamic` is set to `true`.
|
|
200
|
-
*
|
|
201
|
-
* @param route - The base cdn route
|
|
202
|
-
* @param hash - The hash provided by Discord for this icon
|
|
203
|
-
* @param options - Optional options for the link
|
|
204
|
-
*/
|
|
205
|
-
dynamicMakeURL(route, hash, { forceStatic = false, ...options } = {}) {
|
|
206
|
-
return this.makeURL(route, !forceStatic && hash.startsWith('a_') ? { ...options, extension: 'gif' } : options);
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Constructs the URL for the resource
|
|
210
|
-
*
|
|
211
|
-
* @param route - The base cdn route
|
|
212
|
-
* @param options - The extension/size options for the link
|
|
213
|
-
*/
|
|
214
|
-
makeURL(route, { allowedExtensions = constants_js_1.ALLOWED_EXTENSIONS, extension = 'webp', size } = {}) {
|
|
215
|
-
if (!allowedExtensions.includes(extension)) {
|
|
216
|
-
throw new RangeError(`Invalid extension provided: ${extension}\nMust be one of: ${allowedExtensions.join(', ')}`);
|
|
217
|
-
}
|
|
218
|
-
if (size && !constants_js_1.ALLOWED_SIZES.includes(size)) {
|
|
219
|
-
throw new RangeError(`Invalid size provided: ${size}\nMust be one of: ${constants_js_1.ALLOWED_SIZES.join(', ')}`);
|
|
220
|
-
}
|
|
221
|
-
const url = new URL(`${this.base}${route}.${extension}`);
|
|
222
|
-
if (size) {
|
|
223
|
-
url.searchParams.set('size', String(size));
|
|
224
|
-
}
|
|
225
|
-
return url.toString();
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
exports.CDN = CDN;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { HttpAdapter } from ".";
|
|
2
|
-
import { Logger } from "../../../common";
|
|
3
|
-
import { HttpClient } from "../httpclient";
|
|
4
|
-
export declare class HttpBunAdapter extends HttpAdapter {
|
|
5
|
-
app: ReturnType<typeof Bun.serve>;
|
|
6
|
-
constructor(options: {
|
|
7
|
-
client: HttpClient;
|
|
8
|
-
debugger?: Logger;
|
|
9
|
-
logger: Logger;
|
|
10
|
-
});
|
|
11
|
-
listen(): void;
|
|
12
|
-
verifySignature(req: Request): Promise<any>;
|
|
13
|
-
onPacket(req: Request): Promise<Response>;
|
|
14
|
-
}
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.HttpBunAdapter = void 0;
|
|
7
|
-
const v10_1 = require("discord-api-types/v10");
|
|
8
|
-
const magic_bytes_js_1 = __importDefault(require("magic-bytes.js"));
|
|
9
|
-
const _1 = require(".");
|
|
10
|
-
const api_1 = require("../../../api");
|
|
11
|
-
const utils_1 = require("../../../api/utils/utils");
|
|
12
|
-
const oninteractioncreate_1 = require("../../oninteractioncreate");
|
|
13
|
-
let nacl;
|
|
14
|
-
try {
|
|
15
|
-
nacl = require('tweetnacl');
|
|
16
|
-
}
|
|
17
|
-
catch {
|
|
18
|
-
// I always cum
|
|
19
|
-
}
|
|
20
|
-
class HttpBunAdapter extends _1.HttpAdapter {
|
|
21
|
-
app;
|
|
22
|
-
constructor(options) {
|
|
23
|
-
super();
|
|
24
|
-
this.client = options.client;
|
|
25
|
-
this.debugger = options.debugger;
|
|
26
|
-
this.logger = options.logger;
|
|
27
|
-
if (typeof Bun === 'undefined') {
|
|
28
|
-
throw new Error('You are not using buntime.');
|
|
29
|
-
}
|
|
30
|
-
if (!nacl) {
|
|
31
|
-
throw new Error('No tweetnacl installed.');
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
listen() {
|
|
35
|
-
const self = this;
|
|
36
|
-
this.app = Bun.serve({
|
|
37
|
-
fetch(request) {
|
|
38
|
-
if (new URL(request.url).pathname === '/interactions') {
|
|
39
|
-
return self.onPacket(request);
|
|
40
|
-
}
|
|
41
|
-
return new Response('?');
|
|
42
|
-
},
|
|
43
|
-
port: 8080
|
|
44
|
-
});
|
|
45
|
-
this.logger.info(`Listening to port ${this.port}`);
|
|
46
|
-
}
|
|
47
|
-
async verifySignature(req) {
|
|
48
|
-
const timestamp = req.headers.get('x-signature-timestamp');
|
|
49
|
-
const ed25519 = req.headers.get('x-signature-ed25519');
|
|
50
|
-
const body = await req.json();
|
|
51
|
-
if (nacl.sign.detached.verify(Buffer.from(timestamp + JSON.stringify(body)), Buffer.from(ed25519, 'hex'), this.publicKeyHex)) {
|
|
52
|
-
return body;
|
|
53
|
-
}
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
async onPacket(req) {
|
|
57
|
-
const rawBody = await this.verifySignature(req);
|
|
58
|
-
if (!rawBody) {
|
|
59
|
-
this.debugger?.debug('Invalid request/No info, returning 418 status.');
|
|
60
|
-
// I'm a teapot
|
|
61
|
-
return new Response('', {
|
|
62
|
-
status: 418
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
switch (rawBody.type) {
|
|
67
|
-
case v10_1.InteractionType.Ping:
|
|
68
|
-
this.debugger?.debug('Ping interaction received, responding.');
|
|
69
|
-
return new Response(JSON.stringify({ type: v10_1.InteractionResponseType.Pong }), {
|
|
70
|
-
headers: {
|
|
71
|
-
'Content-Type': 'application/json'
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
default:
|
|
75
|
-
return new Promise(resolve => {
|
|
76
|
-
(0, oninteractioncreate_1.onInteractionCreate)(this.client, rawBody, -1, async ({ body, files }) => {
|
|
77
|
-
let response;
|
|
78
|
-
const headers = {};
|
|
79
|
-
if (files) {
|
|
80
|
-
response = new FormData();
|
|
81
|
-
for (const [index, file] of files.entries()) {
|
|
82
|
-
const fileKey = file.key ?? `files[${index}]`;
|
|
83
|
-
if ((0, utils_1.isBufferLike)(file.data)) {
|
|
84
|
-
let contentType = file.contentType;
|
|
85
|
-
if (!contentType) {
|
|
86
|
-
const [parsedType] = (0, magic_bytes_js_1.default)(file.data);
|
|
87
|
-
if (parsedType) {
|
|
88
|
-
contentType =
|
|
89
|
-
api_1.OverwrittenMimeTypes[parsedType.mime] ??
|
|
90
|
-
parsedType.mime ??
|
|
91
|
-
'application/octet-stream';
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
response.append(fileKey, new Blob([file.data], { type: contentType }), file.name);
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
response.append(fileKey, new Blob([`${file.data}`], { type: file.contentType }), file.name);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
if (body) {
|
|
101
|
-
response.append('payload_json', JSON.stringify(body));
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
response = body ?? {};
|
|
106
|
-
headers['Content-Type'] = 'application/json';
|
|
107
|
-
}
|
|
108
|
-
resolve(new Response(JSON.stringify(response), {
|
|
109
|
-
headers
|
|
110
|
-
}));
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
exports.HttpBunAdapter = HttpBunAdapter;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { Logger } from '../../../common';
|
|
3
|
-
import { HttpClient } from '../httpclient';
|
|
4
|
-
export * from './bun';
|
|
5
|
-
export * from './uws';
|
|
6
|
-
export declare abstract class HttpAdapter {
|
|
7
|
-
port: number;
|
|
8
|
-
client: HttpClient;
|
|
9
|
-
debugger?: Logger;
|
|
10
|
-
logger: Logger;
|
|
11
|
-
publicKeyHex: Buffer;
|
|
12
|
-
abstract onPacket(...args: any[]): any;
|
|
13
|
-
abstract listen(): any;
|
|
14
|
-
abstract verifySignature(...args: any[]): any;
|
|
15
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.HttpAdapter = void 0;
|
|
18
|
-
__exportStar(require("./bun"), exports);
|
|
19
|
-
__exportStar(require("./uws"), exports);
|
|
20
|
-
class HttpAdapter {
|
|
21
|
-
port;
|
|
22
|
-
client;
|
|
23
|
-
debugger;
|
|
24
|
-
logger;
|
|
25
|
-
publicKeyHex;
|
|
26
|
-
}
|
|
27
|
-
exports.HttpAdapter = HttpAdapter;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { APIInteraction } from "discord-api-types/v10";
|
|
2
|
-
import { HttpRequest, HttpResponse } from "uWebSockets.js";
|
|
3
|
-
import { HttpAdapter } from ".";
|
|
4
|
-
import { Logger } from "../../../common";
|
|
5
|
-
import { HttpClient } from "../httpclient";
|
|
6
|
-
export declare class HttpUWSAdapter extends HttpAdapter {
|
|
7
|
-
app: ReturnType<typeof import('uWebSockets.js').App>;
|
|
8
|
-
constructor(options: {
|
|
9
|
-
client: HttpClient;
|
|
10
|
-
debugger?: Logger;
|
|
11
|
-
logger: Logger;
|
|
12
|
-
});
|
|
13
|
-
listen(): void;
|
|
14
|
-
verifySignature(res: HttpResponse, req: HttpRequest): Promise<APIInteraction | undefined>;
|
|
15
|
-
onPacket(res: HttpResponse, req: HttpRequest): Promise<void>;
|
|
16
|
-
protected readJson<T extends Record<string, any>>(res: HttpResponse): Promise<T>;
|
|
17
|
-
}
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.HttpUWSAdapter = void 0;
|
|
7
|
-
const v10_1 = require("discord-api-types/v10");
|
|
8
|
-
const magic_bytes_js_1 = __importDefault(require("magic-bytes.js"));
|
|
9
|
-
const _1 = require(".");
|
|
10
|
-
const api_1 = require("../../../api");
|
|
11
|
-
const utils_1 = require("../../../api/utils/utils");
|
|
12
|
-
const oninteractioncreate_1 = require("../../oninteractioncreate");
|
|
13
|
-
let UWS;
|
|
14
|
-
let nacl;
|
|
15
|
-
try {
|
|
16
|
-
UWS = require('uWebSockets.js');
|
|
17
|
-
}
|
|
18
|
-
catch {
|
|
19
|
-
// easter egg #1
|
|
20
|
-
}
|
|
21
|
-
try {
|
|
22
|
-
nacl = require('tweetnacl');
|
|
23
|
-
}
|
|
24
|
-
catch {
|
|
25
|
-
// I always cum
|
|
26
|
-
}
|
|
27
|
-
class HttpUWSAdapter extends _1.HttpAdapter {
|
|
28
|
-
app;
|
|
29
|
-
constructor(options) {
|
|
30
|
-
super();
|
|
31
|
-
this.client = options.client;
|
|
32
|
-
this.debugger = options.debugger;
|
|
33
|
-
this.logger = options.logger;
|
|
34
|
-
if (!UWS) {
|
|
35
|
-
throw new Error('No uws installed.');
|
|
36
|
-
}
|
|
37
|
-
if (!nacl) {
|
|
38
|
-
throw new Error('No tweetnacl installed.');
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
listen() {
|
|
42
|
-
this.app = UWS.App();
|
|
43
|
-
this.app.post('/interactions', (res, req) => {
|
|
44
|
-
return this.onPacket(res, req);
|
|
45
|
-
});
|
|
46
|
-
this.app.listen(this.port, () => {
|
|
47
|
-
this.logger.info(`Listening to port ${this.port}`);
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
async verifySignature(res, req) {
|
|
51
|
-
const timestamp = req.getHeader('x-signature-timestamp');
|
|
52
|
-
const ed25519 = req.getHeader('x-signature-ed25519');
|
|
53
|
-
const body = await this.readJson(res);
|
|
54
|
-
if (nacl.sign.detached.verify(Buffer.from(timestamp + JSON.stringify(body)), Buffer.from(ed25519, 'hex'), this.publicKeyHex)) {
|
|
55
|
-
return body;
|
|
56
|
-
}
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
async onPacket(res, req) {
|
|
60
|
-
const rawBody = await this.verifySignature(res, req);
|
|
61
|
-
if (!rawBody) {
|
|
62
|
-
this.debugger?.debug('Invalid request/No info, returning 418 status.');
|
|
63
|
-
// I'm a teapot
|
|
64
|
-
res.writeStatus('418').end();
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
switch (rawBody.type) {
|
|
68
|
-
case v10_1.InteractionType.Ping:
|
|
69
|
-
this.debugger?.debug('Ping interaction received, responding.');
|
|
70
|
-
res
|
|
71
|
-
.writeHeader('Content-Type', 'application/json')
|
|
72
|
-
.end(JSON.stringify({ type: v10_1.InteractionResponseType.Pong }));
|
|
73
|
-
break;
|
|
74
|
-
default:
|
|
75
|
-
await (0, oninteractioncreate_1.onInteractionCreate)(this.client, rawBody, -1, async ({ body, files }) => {
|
|
76
|
-
res.cork(() => {
|
|
77
|
-
let response;
|
|
78
|
-
const headers = {};
|
|
79
|
-
if (files) {
|
|
80
|
-
response = new FormData();
|
|
81
|
-
for (const [index, file] of files.entries()) {
|
|
82
|
-
const fileKey = file.key ?? `files[${index}]`;
|
|
83
|
-
if ((0, utils_1.isBufferLike)(file.data)) {
|
|
84
|
-
let contentType = file.contentType;
|
|
85
|
-
if (!contentType) {
|
|
86
|
-
const [parsedType] = (0, magic_bytes_js_1.default)(file.data);
|
|
87
|
-
if (parsedType) {
|
|
88
|
-
contentType =
|
|
89
|
-
api_1.OverwrittenMimeTypes[parsedType.mime] ??
|
|
90
|
-
parsedType.mime ??
|
|
91
|
-
'application/octet-stream';
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
response.append(fileKey, new Blob([file.data], { type: contentType }), file.name);
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
response.append(fileKey, new Blob([`${file.data}`], { type: file.contentType }), file.name);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
if (body) {
|
|
101
|
-
response.append('payload_json', JSON.stringify(body));
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
response = body ?? {};
|
|
106
|
-
headers['Content-Type'] = 'application/json';
|
|
107
|
-
}
|
|
108
|
-
for (const i in headers) {
|
|
109
|
-
res.writeHeader(i, headers[i]);
|
|
110
|
-
}
|
|
111
|
-
return res.end(JSON.stringify(response));
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
break;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
readJson(res) {
|
|
119
|
-
return new Promise((cb, err) => {
|
|
120
|
-
let buffer;
|
|
121
|
-
res.onData((ab, isLast) => {
|
|
122
|
-
const chunk = Buffer.from(ab);
|
|
123
|
-
if (isLast) {
|
|
124
|
-
let json;
|
|
125
|
-
try {
|
|
126
|
-
json = JSON.parse(buffer ? Buffer.concat([buffer, chunk]).toString() : chunk.toString());
|
|
127
|
-
}
|
|
128
|
-
catch (e) {
|
|
129
|
-
res.close();
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
cb(json);
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
buffer = Buffer.concat(buffer ? [buffer, chunk] : [chunk]);
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
res.onAborted(err);
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
exports.HttpUWSAdapter = HttpUWSAdapter;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { DeepPartial } from '../../common';
|
|
2
|
-
import type { BaseClientOptions, StartOptions } from '../base';
|
|
3
|
-
import { BaseClient } from '../base';
|
|
4
|
-
import { HttpAdapter } from './adapters';
|
|
5
|
-
export declare class HttpClient extends BaseClient {
|
|
6
|
-
adapter: HttpAdapter;
|
|
7
|
-
constructor(options?: BaseClientOptions);
|
|
8
|
-
protected execute(options?: {
|
|
9
|
-
publicKey?: string;
|
|
10
|
-
port?: number;
|
|
11
|
-
}): Promise<any>;
|
|
12
|
-
start(options?: DeepPartial<Omit<StartOptions, 'connection'>>): Promise<any>;
|
|
13
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HttpClient = void 0;
|
|
4
|
-
const base_1 = require("../base");
|
|
5
|
-
const adapters_1 = require("./adapters");
|
|
6
|
-
class HttpClient extends base_1.BaseClient {
|
|
7
|
-
adapter;
|
|
8
|
-
constructor(options) {
|
|
9
|
-
super(options);
|
|
10
|
-
if (typeof Bun !== 'undefined') {
|
|
11
|
-
this.adapter = new adapters_1.HttpBunAdapter({
|
|
12
|
-
client: this,
|
|
13
|
-
logger: this.logger,
|
|
14
|
-
debugger: this.debugger
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
this.adapter = new adapters_1.HttpUWSAdapter({
|
|
19
|
-
client: this,
|
|
20
|
-
logger: this.logger,
|
|
21
|
-
debugger: this.debugger
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
async execute(options) {
|
|
26
|
-
await super.execute();
|
|
27
|
-
const { publicKey: publicKeyRC, port: portRC, applicationId: applicationIdRC, } = await this.getRC();
|
|
28
|
-
const publicKey = options?.publicKey ?? publicKeyRC;
|
|
29
|
-
const port = options?.port ?? portRC;
|
|
30
|
-
if (!publicKey) {
|
|
31
|
-
throw new Error('Expected a publicKey, check your config file');
|
|
32
|
-
}
|
|
33
|
-
if (!port) {
|
|
34
|
-
throw new Error('Expected a port, check your config file');
|
|
35
|
-
}
|
|
36
|
-
if (applicationIdRC) {
|
|
37
|
-
this.applicationId = applicationIdRC;
|
|
38
|
-
}
|
|
39
|
-
this.adapter.port = port;
|
|
40
|
-
this.adapter.publicKeyHex = Buffer.from(publicKey, 'hex');
|
|
41
|
-
return this.adapter.listen();
|
|
42
|
-
}
|
|
43
|
-
async start(options = {}) {
|
|
44
|
-
await super.start(options);
|
|
45
|
-
return this.execute(options.httpConnection);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
exports.HttpClient = HttpClient;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { GuildMember, GuildRole } from '../../structures';
|
|
2
|
-
import { PermissionsBitField } from '../../structures/extra/Permissions';
|
|
3
|
-
import { BaseShorter } from './base';
|
|
4
|
-
export declare class OverwritesShorter extends BaseShorter {
|
|
5
|
-
get overwrites(): {
|
|
6
|
-
memberPermissions: (channelId: string, member: GuildMember, checkAdmin?: boolean) => Promise<PermissionsBitField>;
|
|
7
|
-
overwritesFor: (channelId: string, member: GuildMember) => Promise<{
|
|
8
|
-
everyone: {
|
|
9
|
-
type: number;
|
|
10
|
-
id: string;
|
|
11
|
-
deny: PermissionsBitField;
|
|
12
|
-
allow: PermissionsBitField;
|
|
13
|
-
} | undefined;
|
|
14
|
-
roles: {
|
|
15
|
-
type: number;
|
|
16
|
-
id: string;
|
|
17
|
-
deny: PermissionsBitField;
|
|
18
|
-
allow: PermissionsBitField;
|
|
19
|
-
}[];
|
|
20
|
-
member: {
|
|
21
|
-
type: number;
|
|
22
|
-
id: string;
|
|
23
|
-
deny: PermissionsBitField;
|
|
24
|
-
allow: PermissionsBitField;
|
|
25
|
-
} | undefined;
|
|
26
|
-
}>;
|
|
27
|
-
rolePermissions: (channelId: string, role: GuildRole, checkAdmin?: boolean) => Promise<PermissionsBitField>;
|
|
28
|
-
};
|
|
29
|
-
}
|