mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 11:28:15 +00:00
deno fmt
This commit is contained in:
+14
-6
@@ -41,9 +41,13 @@ export async function startBot(config: BotConfig) {
|
||||
proxyWSURL = botGatewayData.url;
|
||||
identifyPayload.token = config.token;
|
||||
identifyPayload.intents = config.intents.reduce(
|
||||
(bits, next) =>
|
||||
(bits |= typeof next === "string" ? DiscordGatewayIntents[next] : next),
|
||||
0
|
||||
(
|
||||
bits,
|
||||
next,
|
||||
) => (bits |= typeof next === "string"
|
||||
? DiscordGatewayIntents[next]
|
||||
: next),
|
||||
0,
|
||||
);
|
||||
lastShardId = botGatewayData.shards;
|
||||
identifyPayload.shard = [0, lastShardId];
|
||||
@@ -90,9 +94,13 @@ export async function startBigBrainBot(data: BigBrainBotConfig) {
|
||||
}
|
||||
|
||||
identifyPayload.intents = data.intents.reduce(
|
||||
(bits, next) =>
|
||||
(bits |= typeof next === "string" ? DiscordGatewayIntents[next] : next),
|
||||
0
|
||||
(
|
||||
bits,
|
||||
next,
|
||||
) => (bits |= typeof next === "string"
|
||||
? DiscordGatewayIntents[next]
|
||||
: next),
|
||||
0,
|
||||
);
|
||||
|
||||
// PROXY DOESNT NEED US SPAWNING SHARDS
|
||||
|
||||
@@ -92,8 +92,7 @@ export async function sendMessage(
|
||||
}
|
||||
}
|
||||
|
||||
const result =
|
||||
(await rest.runMethod(
|
||||
const result = (await rest.runMethod(
|
||||
"post",
|
||||
endpoints.CHANNEL_MESSAGES(channelId),
|
||||
camelKeysToSnakeCase({
|
||||
@@ -102,8 +101,7 @@ export async function sendMessage(
|
||||
? {
|
||||
messageReference: {
|
||||
...content.messageReference,
|
||||
failIfNotExists:
|
||||
content.messageReference.failIfNotExists === true,
|
||||
failIfNotExists: content.messageReference.failIfNotExists === true,
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
|
||||
@@ -36,15 +36,16 @@ export async function processQueue(id: string) {
|
||||
// EXECUTE THE REQUEST
|
||||
|
||||
// IF THIS IS A GET REQUEST, CHANGE THE BODY TO QUERY PARAMETERS
|
||||
const query =
|
||||
queuedRequest.request.method.toUpperCase() === "GET" &&
|
||||
const query = queuedRequest.request.method.toUpperCase() === "GET" &&
|
||||
queuedRequest.payload.body
|
||||
? Object.entries(queuedRequest.payload.body)
|
||||
.map(
|
||||
([key, value]) =>
|
||||
`${encodeURIComponent(key)}=${encodeURIComponent(
|
||||
value as string
|
||||
)}`
|
||||
`${encodeURIComponent(key)}=${
|
||||
encodeURIComponent(
|
||||
value as string,
|
||||
)
|
||||
}`,
|
||||
)
|
||||
.join("&")
|
||||
: "";
|
||||
@@ -59,13 +60,13 @@ export async function processQueue(id: string) {
|
||||
try {
|
||||
const response = await fetch(
|
||||
urlToUse,
|
||||
rest.createRequestBody(queuedRequest)
|
||||
rest.createRequestBody(queuedRequest),
|
||||
);
|
||||
|
||||
rest.eventHandlers.fetched(queuedRequest.payload);
|
||||
const bucketIdFromHeaders = rest.processRequestHeaders(
|
||||
queuedRequest.request.url,
|
||||
response.headers
|
||||
response.headers,
|
||||
);
|
||||
|
||||
if (response.status < 200 || response.status >= 400) {
|
||||
|
||||
@@ -4,7 +4,7 @@ import { rest } from "./rest.ts";
|
||||
/** Processes a request and assigns it to a queue or creates a queue if none exists for it. */
|
||||
export function processRequest(
|
||||
request: ServerRequest,
|
||||
payload: RunMethodOptions
|
||||
payload: RunMethodOptions,
|
||||
) {
|
||||
const route = request.url.substring(request.url.indexOf("api/"));
|
||||
const parts = route.split("/");
|
||||
|
||||
@@ -140,7 +140,12 @@ export function runMethod<T = any>(
|
||||
}
|
||||
};
|
||||
|
||||
rest.processRequest({ url, method, respond: (data: { status: number, body?: string; }) => resolve(JSON.parse(data.body || "{}")) }, {
|
||||
rest.processRequest({
|
||||
url,
|
||||
method,
|
||||
respond: (data: { status: number; body?: string }) =>
|
||||
resolve(JSON.parse(data.body || "{}")),
|
||||
}, {
|
||||
callback,
|
||||
bucketId,
|
||||
url,
|
||||
|
||||
@@ -11,7 +11,8 @@ export async function createShard(shardId: number) {
|
||||
ws.log("ERROR", { shardId, error: errorEvent });
|
||||
};
|
||||
|
||||
socket.onmessage = ({ data: message }) => ws.handleOnMessage(message, shardId);
|
||||
socket.onmessage = ({ data: message }) =>
|
||||
ws.handleOnMessage(message, shardId);
|
||||
|
||||
socket.onclose = (event) => {
|
||||
ws.log("CLOSED", { shardId, payload: event });
|
||||
|
||||
@@ -15,8 +15,10 @@ export async function handleOnMessage(message: any, shardId: number) {
|
||||
}
|
||||
|
||||
if (message instanceof Uint8Array) {
|
||||
message = decompressWith(message, 0, (slice: Uint8Array) =>
|
||||
ws.utf8decoder.decode(slice)
|
||||
message = decompressWith(
|
||||
message,
|
||||
0,
|
||||
(slice: Uint8Array) => ws.utf8decoder.decode(slice),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -29,7 +31,7 @@ export async function handleOnMessage(message: any, shardId: number) {
|
||||
case DiscordGatewayOpcodes.Hello:
|
||||
ws.heartbeat(
|
||||
shardId,
|
||||
(messageData.d as DiscordHeartbeat).heartbeat_interval
|
||||
(messageData.d as DiscordHeartbeat).heartbeat_interval,
|
||||
);
|
||||
break;
|
||||
case DiscordGatewayOpcodes.HeartbeatACK:
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ export async function identify(shardId: number, maxShards: number) {
|
||||
JSON.stringify({
|
||||
op: DiscordGatewayOpcodes.Identify,
|
||||
d: { ...ws.identifyPayload, shard: [shardId, maxShards] },
|
||||
})
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user