seyfert 1.2.1 → 1.2.2
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/lib/cache/index.d.ts +1 -5
- package/lib/cache/resources/voice-states.d.ts +7 -2
- package/lib/cache/resources/voice-states.js +11 -0
- package/lib/client/http/adapters/bun.d.ts +14 -0
- package/lib/client/http/adapters/bun.js +117 -0
- package/lib/client/http/adapters/index.d.ts +15 -0
- package/lib/client/http/adapters/index.js +27 -0
- package/lib/client/http/adapters/uws.d.ts +17 -0
- package/lib/client/http/adapters/uws.js +142 -0
- package/lib/client/http/httpclient.d.ts +13 -0
- package/lib/client/http/httpclient.js +48 -0
- package/lib/client/oninteractioncreate.js +7 -7
- package/lib/client/onmessagecreate.js +12 -3
- package/lib/client/workerclient.js +1 -1
- package/lib/commands/applications/chat.d.ts +11 -9
- package/lib/commands/applications/chat.js +9 -6
- package/lib/commands/applications/chatcontext.d.ts +2 -1
- package/lib/commands/applications/chatcontext.js +3 -0
- package/lib/commands/applications/menu.d.ts +4 -3
- package/lib/commands/applications/menu.js +9 -6
- package/lib/commands/applications/menucontext.d.ts +4 -1
- package/lib/commands/applications/menucontext.js +9 -0
- package/lib/commands/basecontex.d.ts +1 -1
- package/lib/commands/basecontex.js +5 -11
- package/lib/commands/decorators.d.ts +3 -3
- package/lib/commands/decorators.js +5 -5
- package/lib/commands/handler.js +2 -0
- package/lib/common/shorters/channels.d.ts +9 -2
- package/lib/common/shorters/channels.js +13 -0
- package/lib/common/shorters/members.d.ts +6 -0
- package/lib/common/shorters/members.js +6 -0
- package/lib/common/shorters/messages.d.ts +2 -2
- package/lib/common/shorters/messages.js +7 -3
- package/lib/components/componentcontext.d.ts +1 -0
- package/lib/components/componentcontext.js +3 -0
- package/lib/structures/GuildMember.d.ts +1 -5
- package/lib/structures/GuildMember.js +2 -2
- package/lib/structures/Message.d.ts +1 -1
- package/lib/structures/User.js +1 -1
- package/lib/structures/VoiceState.d.ts +18 -0
- package/lib/structures/VoiceState.js +48 -0
- package/lib/structures/channels.d.ts +6 -3
- package/lib/structures/channels.js +14 -1
- package/lib/structures/extra/Permissions.d.ts +1 -1
- package/lib/structures/index.d.ts +1 -0
- package/lib/structures/index.js +1 -0
- package/lib/websocket/discord/shard.d.ts +4 -4
- package/lib/websocket/discord/shard.js +12 -17
- package/lib/websocket/discord/sharder.d.ts +1 -1
- package/lib/websocket/discord/sharder.js +2 -2
- package/lib/websocket/discord/workermanager.js +1 -1
- package/lib/websocket/structures/index.d.ts +6 -99
- package/lib/websocket/structures/index.js +29 -211
- package/lib/websocket/structures/timeout.d.ts +2 -2
- package/lib/websocket/structures/timeout.js +4 -4
- package/package.json +2 -2
package/lib/cache/index.d.ts
CHANGED
|
@@ -70,11 +70,7 @@ export declare class Cache {
|
|
|
70
70
|
} & {
|
|
71
71
|
guild_id: string;
|
|
72
72
|
})[];
|
|
73
|
-
voiceStates:
|
|
74
|
-
guild_id: string;
|
|
75
|
-
} & {
|
|
76
|
-
guild_id: string;
|
|
77
|
-
})[];
|
|
73
|
+
voiceStates: import("..").VoiceState[];
|
|
78
74
|
stageInstances: (import("discord-api-types/v10").APIStageInstance & {
|
|
79
75
|
guild_id: string;
|
|
80
76
|
})[];
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import type { GatewayVoiceState } from 'discord-api-types/v10';
|
|
2
|
+
import type { ReturnCache } from '../..';
|
|
3
|
+
import { VoiceState } from '../../structures';
|
|
2
4
|
import { GuildBasedResource } from './default/guild-based';
|
|
3
|
-
export declare class VoiceStates extends GuildBasedResource
|
|
5
|
+
export declare class VoiceStates extends GuildBasedResource {
|
|
4
6
|
namespace: string;
|
|
5
|
-
|
|
7
|
+
get(memberId: string, guildId: string): ReturnCache<VoiceState | undefined>;
|
|
8
|
+
bulk(ids: string[], guild: string): ReturnCache<VoiceState[]>;
|
|
9
|
+
values(guildId: string): ReturnCache<VoiceState[]>;
|
|
10
|
+
parse(data: any, id: string, guild_id: string): any;
|
|
6
11
|
}
|
|
7
12
|
export type VoiceStateResource = Omit<GatewayVoiceState, 'member'> & {
|
|
8
13
|
guild_id: string;
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.VoiceStates = void 0;
|
|
4
|
+
const common_1 = require("../../common");
|
|
5
|
+
const structures_1 = require("../../structures");
|
|
4
6
|
const guild_based_1 = require("./default/guild-based");
|
|
5
7
|
class VoiceStates extends guild_based_1.GuildBasedResource {
|
|
6
8
|
namespace = 'voice_state';
|
|
9
|
+
get(memberId, guildId) {
|
|
10
|
+
return (0, common_1.fakePromise)(super.get(memberId, guildId)).then(state => state ? new structures_1.VoiceState(this.client, state) : undefined);
|
|
11
|
+
}
|
|
12
|
+
bulk(ids, guild) {
|
|
13
|
+
return (0, common_1.fakePromise)(super.bulk(ids, guild)).then(states => states.map(state => (state ? new structures_1.VoiceState(this.client, state) : undefined)).filter(y => !!y));
|
|
14
|
+
}
|
|
15
|
+
values(guildId) {
|
|
16
|
+
return (0, common_1.fakePromise)(super.values(guildId)).then(states => states.map(state => new structures_1.VoiceState(this.client, state)));
|
|
17
|
+
}
|
|
7
18
|
parse(data, id, guild_id) {
|
|
8
19
|
const { member, ...rest } = super.parse(data, id, guild_id);
|
|
9
20
|
return rest;
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
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;
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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;
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
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;
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
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;
|
|
@@ -11,7 +11,7 @@ async function onInteractionCreate(self, body, shardId, __reply) {
|
|
|
11
11
|
{
|
|
12
12
|
const parentCommand = self.commands?.values.find(x => {
|
|
13
13
|
if (body.data.guild_id) {
|
|
14
|
-
return x.
|
|
14
|
+
return x.guildId?.includes(body.data.guild_id) && x.name === body.data.name;
|
|
15
15
|
}
|
|
16
16
|
return x.name === body.data.name;
|
|
17
17
|
});
|
|
@@ -49,7 +49,7 @@ async function onInteractionCreate(self, body, shardId, __reply) {
|
|
|
49
49
|
{
|
|
50
50
|
const command = self.commands?.values.find(x => {
|
|
51
51
|
if (body.data.guild_id) {
|
|
52
|
-
return x.
|
|
52
|
+
return x.guildId?.includes(body.data.guild_id) && x.name === body.data.name;
|
|
53
53
|
}
|
|
54
54
|
return x.name === body.data.name;
|
|
55
55
|
});
|
|
@@ -63,8 +63,8 @@ async function onInteractionCreate(self, body, shardId, __reply) {
|
|
|
63
63
|
try {
|
|
64
64
|
if (command.botPermissions && interaction.appPermissions) {
|
|
65
65
|
const permissions = interaction.appPermissions.missings(...interaction.appPermissions.values([command.botPermissions]));
|
|
66
|
-
if (permissions.length) {
|
|
67
|
-
return command.
|
|
66
|
+
if (!interaction.appPermissions.has('Administrator') && permissions.length) {
|
|
67
|
+
return command.onBotPermissionsFail?.(context, interaction.appPermissions.keys(permissions));
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
const resultRunGlobalMiddlewares = await command.__runGlobalMiddlewares(context);
|
|
@@ -104,7 +104,7 @@ async function onInteractionCreate(self, body, shardId, __reply) {
|
|
|
104
104
|
{
|
|
105
105
|
const parentCommand = self.commands?.values.find(x => {
|
|
106
106
|
if (body.data.guild_id) {
|
|
107
|
-
return x.
|
|
107
|
+
return x.guildId?.includes(body.data.guild_id) && x.name === body.data.name;
|
|
108
108
|
}
|
|
109
109
|
return x.name === body.data.name;
|
|
110
110
|
});
|
|
@@ -119,8 +119,8 @@ async function onInteractionCreate(self, body, shardId, __reply) {
|
|
|
119
119
|
try {
|
|
120
120
|
if (command.botPermissions && interaction.appPermissions) {
|
|
121
121
|
const permissions = interaction.appPermissions.missings(...interaction.appPermissions.values([command.botPermissions]));
|
|
122
|
-
if (permissions.length) {
|
|
123
|
-
return command.
|
|
122
|
+
if (!interaction.appPermissions.has('Administrator') && permissions.length) {
|
|
123
|
+
return command.onBotPermissionsFail?.(context, interaction.appPermissions.keys(permissions));
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
const [erroredOptions, result] = await command.__runOptions(context, optionsResolver);
|
|
@@ -55,7 +55,7 @@ async function onMessageCreate(self, rawMessage, shardId) {
|
|
|
55
55
|
return self.logger.warn(`${fullCommandName} command does not have 'run' callback`);
|
|
56
56
|
if (!command.contexts?.includes(__1.InteractionContextTypes.BOT_DM) && !message.guildId)
|
|
57
57
|
return;
|
|
58
|
-
if (command.
|
|
58
|
+
if (command.guildId && !command.guildId?.includes(message.guildId))
|
|
59
59
|
return;
|
|
60
60
|
const resolved = {
|
|
61
61
|
channels: {},
|
|
@@ -72,14 +72,23 @@ async function onMessageCreate(self, rawMessage, shardId) {
|
|
|
72
72
|
const extendContext = self.options?.context?.(message) ?? {};
|
|
73
73
|
Object.assign(context, extendContext);
|
|
74
74
|
try {
|
|
75
|
+
if (command.defaultMemberPermissions && message.guildId) {
|
|
76
|
+
const memberPermissions = await self.members.permissions(message.guildId, message.author.id);
|
|
77
|
+
const permissions = memberPermissions.missings(...memberPermissions.values([command.defaultMemberPermissions]));
|
|
78
|
+
if (!memberPermissions.has('Administrator') &&
|
|
79
|
+
permissions.length &&
|
|
80
|
+
(await message.guild()).ownerId !== message.author.id) {
|
|
81
|
+
return command.onPermissionsFail?.(context, memberPermissions.keys(permissions));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
75
84
|
if (command.botPermissions && message.guildId) {
|
|
76
85
|
const meMember = await self.cache.members?.get(self.botId, message.guildId);
|
|
77
86
|
if (!meMember)
|
|
78
87
|
return; //enable member cache and "Guilds" intent, lol
|
|
79
88
|
const appPermissions = await meMember.fetchPermissions();
|
|
80
89
|
const permissions = appPermissions.missings(...appPermissions.values([command.botPermissions]));
|
|
81
|
-
if (permissions.length) {
|
|
82
|
-
return command.
|
|
90
|
+
if (!appPermissions.has('Administrator') && permissions.length) {
|
|
91
|
+
return command.onBotPermissionsFail?.(context, appPermissions.keys(permissions));
|
|
83
92
|
}
|
|
84
93
|
}
|
|
85
94
|
if (errors.length) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type APIApplicationCommandBasicOption, type APIApplicationCommandOption,
|
|
1
|
+
import { ApplicationCommandOptionType, ApplicationCommandType, type APIApplicationCommandBasicOption, type APIApplicationCommandOption, type LocaleString } from 'discord-api-types/v10';
|
|
2
2
|
import type { PermissionStrings, SeyfertNumberOption, SeyfertStringOption } from '../..';
|
|
3
3
|
import type { Attachment } from '../../builders';
|
|
4
4
|
import { type FlatObjectKeys } from '../../common';
|
|
@@ -77,13 +77,13 @@ declare class BaseCommand {
|
|
|
77
77
|
description: string | undefined;
|
|
78
78
|
defaultDescription: string;
|
|
79
79
|
}>;
|
|
80
|
-
|
|
80
|
+
guildId?: string[];
|
|
81
81
|
name: string;
|
|
82
82
|
type: number;
|
|
83
83
|
nsfw?: boolean;
|
|
84
84
|
description: string;
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
defaultMemberPermissions?: bigint;
|
|
86
|
+
integrationTypes?: IntegrationTypes[];
|
|
87
87
|
contexts?: InteractionContextTypes[];
|
|
88
88
|
botPermissions?: bigint;
|
|
89
89
|
name_localizations?: Partial<Record<LocaleString, string>>;
|
|
@@ -96,10 +96,10 @@ declare class BaseCommand {
|
|
|
96
96
|
description: BaseCommand['description'];
|
|
97
97
|
name_localizations: BaseCommand['name_localizations'];
|
|
98
98
|
description_localizations: BaseCommand['description_localizations'];
|
|
99
|
-
guild_id: BaseCommand['
|
|
100
|
-
default_member_permissions:
|
|
99
|
+
guild_id: BaseCommand['guildId'];
|
|
100
|
+
default_member_permissions: string;
|
|
101
101
|
contexts: BaseCommand['contexts'];
|
|
102
|
-
integration_types: BaseCommand['
|
|
102
|
+
integration_types: BaseCommand['integrationTypes'];
|
|
103
103
|
};
|
|
104
104
|
reload(): Promise<void>;
|
|
105
105
|
run?(context: CommandContext<any>): any;
|
|
@@ -107,6 +107,7 @@ declare class BaseCommand {
|
|
|
107
107
|
onRunError?(context: CommandContext<any>, error: unknown): any;
|
|
108
108
|
onOptionsError?(context: CommandContext<{}, never>, metadata: OnOptionsReturnObject): any;
|
|
109
109
|
onMiddlewaresError?(context: CommandContext<{}, never>, error: string): any;
|
|
110
|
+
onBotPermissionsFail?(context: CommandContext<{}, never>, permissions: PermissionStrings): any;
|
|
110
111
|
onPermissionsFail?(context: CommandContext<{}, never>, permissions: PermissionStrings): any;
|
|
111
112
|
onInternalError?(client: UsingClient, error?: unknown): any;
|
|
112
113
|
}
|
|
@@ -122,13 +123,14 @@ export declare class Command extends BaseCommand {
|
|
|
122
123
|
name_localizations: Partial<Record<"id" | "en-US" | "en-GB" | "bg" | "zh-CN" | "zh-TW" | "hr" | "cs" | "da" | "nl" | "fi" | "fr" | "de" | "el" | "hi" | "hu" | "it" | "ja" | "ko" | "lt" | "no" | "pl" | "pt-BR" | "ro" | "ru" | "es-ES" | "es-419" | "sv-SE" | "th" | "tr" | "uk" | "vi", string>> | undefined;
|
|
123
124
|
description_localizations: Partial<Record<"id" | "en-US" | "en-GB" | "bg" | "zh-CN" | "zh-TW" | "hr" | "cs" | "da" | "nl" | "fi" | "fr" | "de" | "el" | "hi" | "hu" | "it" | "ja" | "ko" | "lt" | "no" | "pl" | "pt-BR" | "ro" | "ru" | "es-ES" | "es-419" | "sv-SE" | "th" | "tr" | "uk" | "vi", string>> | undefined;
|
|
124
125
|
guild_id: string[] | undefined;
|
|
125
|
-
default_member_permissions: string
|
|
126
|
+
default_member_permissions: string;
|
|
126
127
|
contexts: InteractionContextTypes[] | undefined;
|
|
127
128
|
integration_types: IntegrationTypes[] | undefined;
|
|
128
129
|
};
|
|
129
130
|
onRunError(context: CommandContext<any>, error: unknown): any;
|
|
130
131
|
onOptionsError(context: CommandContext<{}, never>, metadata: OnOptionsReturnObject): any;
|
|
131
132
|
onMiddlewaresError(context: CommandContext<{}, never>, error: string): any;
|
|
133
|
+
onBotPermissionsFail(context: CommandContext<{}, never>, permissions: PermissionStrings): any;
|
|
132
134
|
onPermissionsFail(context: CommandContext<{}, never>, permissions: PermissionStrings): any;
|
|
133
135
|
onInternalError(client: UsingClient, error?: unknown): any;
|
|
134
136
|
}
|
|
@@ -145,7 +147,7 @@ export declare abstract class SubCommand extends BaseCommand {
|
|
|
145
147
|
name_localizations: Partial<Record<"id" | "en-US" | "en-GB" | "bg" | "zh-CN" | "zh-TW" | "hr" | "cs" | "da" | "nl" | "fi" | "fr" | "de" | "el" | "hi" | "hu" | "it" | "ja" | "ko" | "lt" | "no" | "pl" | "pt-BR" | "ro" | "ru" | "es-ES" | "es-419" | "sv-SE" | "th" | "tr" | "uk" | "vi", string>> | undefined;
|
|
146
148
|
description_localizations: Partial<Record<"id" | "en-US" | "en-GB" | "bg" | "zh-CN" | "zh-TW" | "hr" | "cs" | "da" | "nl" | "fi" | "fr" | "de" | "el" | "hi" | "hu" | "it" | "ja" | "ko" | "lt" | "no" | "pl" | "pt-BR" | "ro" | "ru" | "es-ES" | "es-419" | "sv-SE" | "th" | "tr" | "uk" | "vi", string>> | undefined;
|
|
147
149
|
guild_id: string[] | undefined;
|
|
148
|
-
default_member_permissions: string
|
|
150
|
+
default_member_permissions: string;
|
|
149
151
|
contexts: InteractionContextTypes[] | undefined;
|
|
150
152
|
integration_types: IntegrationTypes[] | undefined;
|
|
151
153
|
};
|
|
@@ -9,13 +9,13 @@ class BaseCommand {
|
|
|
9
9
|
__t;
|
|
10
10
|
__autoload;
|
|
11
11
|
__tGroups;
|
|
12
|
-
|
|
12
|
+
guildId;
|
|
13
13
|
name;
|
|
14
14
|
type; // ApplicationCommandType.ChatInput | ApplicationCommandOptionType.Subcommand
|
|
15
15
|
nsfw;
|
|
16
16
|
description;
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
defaultMemberPermissions;
|
|
18
|
+
integrationTypes;
|
|
19
19
|
contexts;
|
|
20
20
|
botPermissions;
|
|
21
21
|
name_localizations;
|
|
@@ -118,10 +118,10 @@ class BaseCommand {
|
|
|
118
118
|
description: this.description,
|
|
119
119
|
name_localizations: this.name_localizations,
|
|
120
120
|
description_localizations: this.description_localizations,
|
|
121
|
-
guild_id: this.
|
|
122
|
-
default_member_permissions: this.
|
|
121
|
+
guild_id: this.guildId,
|
|
122
|
+
default_member_permissions: this.defaultMemberPermissions ? this.defaultMemberPermissions.toString() : undefined,
|
|
123
123
|
contexts: this.contexts,
|
|
124
|
-
integration_types: this.
|
|
124
|
+
integration_types: this.integrationTypes,
|
|
125
125
|
};
|
|
126
126
|
return data;
|
|
127
127
|
}
|
|
@@ -177,6 +177,9 @@ class Command extends BaseCommand {
|
|
|
177
177
|
onMiddlewaresError(context, error) {
|
|
178
178
|
context.client.logger.fatal(`${this.name}.<onMiddlewaresError>`, context.author.id, error);
|
|
179
179
|
}
|
|
180
|
+
onBotPermissionsFail(context, permissions) {
|
|
181
|
+
context.client.logger.fatal(`${this.name}.<onBotPermissionsFail>`, context.author.id, permissions);
|
|
182
|
+
}
|
|
180
183
|
onPermissionsFail(context, permissions) {
|
|
181
184
|
context.client.logger.fatal(`${this.name}.<onPermissionsFail>`, context.author.id, permissions);
|
|
182
185
|
}
|