mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 19:28:17 +00:00
fix: rest method uppercase
This commit is contained in:
@@ -22,8 +22,8 @@ For the purposes of this guide, I will be using the current
|
||||
## Preparations
|
||||
|
||||
- First, create a Discordeno Bot using the
|
||||
[Generator Template](https://github.com/discordeno/template) I will name
|
||||
it Zodiac.
|
||||
[Generator Template](https://github.com/discordeno/template) I will name it
|
||||
Zodiac.
|
||||
|
||||
- Then `git clone https://github.com/Skillz4Killz/Zodiac.git`
|
||||
|
||||
|
||||
@@ -10,9 +10,8 @@ you go through this guide it will make a lot more sense.
|
||||
> If you don't have these yet please prepare them first before going forward.
|
||||
|
||||
- First, create a Discordeno Bot using the
|
||||
[Generator Template](https://github.com/discordeno/template/generate).
|
||||
Give it any name you like. For the purpose of this guide we will call it,
|
||||
Stargate.
|
||||
[Generator Template](https://github.com/discordeno/template/generate). Give it
|
||||
any name you like. For the purpose of this guide we will call it, Stargate.
|
||||
|
||||
- Then `git clone https://github.com/Skillz4Killz/Stargate.git` Replace
|
||||
**Stargate** with the name you chose.
|
||||
|
||||
@@ -16,7 +16,7 @@ export function createRequestBody(queuedRequest: QueuedRequest) {
|
||||
// IF A REASON IS PROVIDED ENCODE IT IN HEADERS
|
||||
if (queuedRequest.payload.body?.reason) {
|
||||
headers["X-Audit-Log-Reason"] = encodeURIComponent(
|
||||
queuedRequest.payload.body.reason
|
||||
queuedRequest.payload.body.reason,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -26,11 +26,11 @@ export function createRequestBody(queuedRequest: QueuedRequest) {
|
||||
form.append(
|
||||
"file",
|
||||
queuedRequest.payload.body.file.blob,
|
||||
queuedRequest.payload.body.file.name
|
||||
queuedRequest.payload.body.file.name,
|
||||
);
|
||||
form.append(
|
||||
"payload_json",
|
||||
JSON.stringify({ ...queuedRequest.payload.body, file: undefined })
|
||||
JSON.stringify({ ...queuedRequest.payload.body, file: undefined }),
|
||||
);
|
||||
queuedRequest.payload.body.file = form;
|
||||
} else if (
|
||||
@@ -42,8 +42,7 @@ export function createRequestBody(queuedRequest: QueuedRequest) {
|
||||
|
||||
return {
|
||||
headers,
|
||||
body:
|
||||
queuedRequest.payload.body?.file ||
|
||||
body: queuedRequest.payload.body?.file ||
|
||||
JSON.stringify(queuedRequest.payload.body),
|
||||
method: queuedRequest.request.method.toUpperCase(),
|
||||
};
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -6,7 +6,7 @@ export function runMethod<T = any>(
|
||||
url: string,
|
||||
body?: unknown,
|
||||
retryCount = 0,
|
||||
bucketId?: string | null
|
||||
bucketId?: string | null,
|
||||
): Promise<T | undefined> {
|
||||
rest.eventHandlers.debug?.("requestCreate", {
|
||||
method,
|
||||
@@ -58,7 +58,7 @@ export function runMethod<T = any>(
|
||||
method,
|
||||
body,
|
||||
retryCount,
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -163,7 +163,9 @@ export async function createGuildStruct(
|
||||
),
|
||||
memberCount: createNewProp(memberCount),
|
||||
emojis: createNewProp(
|
||||
new Collection((emojis || []).map((emoji) => [emoji.id ?? emoji.name, emoji])),
|
||||
new Collection(
|
||||
(emojis || []).map((emoji) => [emoji.id ?? emoji.name, emoji]),
|
||||
),
|
||||
),
|
||||
voiceStates: createNewProp(
|
||||
new Collection(
|
||||
|
||||
+2
-3
@@ -72,10 +72,9 @@ type InnerCamelCaseStringArray<Parts extends any[], PreviousPart> =
|
||||
: "";
|
||||
|
||||
type CamelCaseStringArray<Parts extends string[]> = Parts extends
|
||||
[`${infer FirstPart}`, ...infer RemainingParts]
|
||||
? Uncapitalize<
|
||||
[`${infer FirstPart}`, ...infer RemainingParts] ? Uncapitalize<
|
||||
`${FirstPart}${InnerCamelCaseStringArray<RemainingParts, FirstPart>}`
|
||||
>
|
||||
>
|
||||
: never;
|
||||
|
||||
type StringPartToDelimiterCase<
|
||||
|
||||
@@ -4,7 +4,7 @@ import { ws } from "./ws.ts";
|
||||
/** Handler for processing all dispatch payloads that should be sent/forwarded to another server/vps/process. */
|
||||
export async function handleDiscordPayload(
|
||||
data: DiscordGatewayPayload,
|
||||
shardId: number
|
||||
shardId: number,
|
||||
) {
|
||||
await fetch(ws.url, {
|
||||
headers: {
|
||||
|
||||
+15
-5
@@ -2,22 +2,32 @@
|
||||
|
||||
Unit tests are MANDATORY!
|
||||
|
||||
Every time you create a new function in the library, you must also add a unit test for it. A PR should/will not be merged without a valid unit test for it. If you are unable to create a unit test, please leave a comment in your PR asking for help.
|
||||
Every time you create a new function in the library, you must also add a unit
|
||||
test for it. A PR should/will not be merged without a valid unit test for it. If
|
||||
you are unable to create a unit test, please leave a comment in your PR asking
|
||||
for help.
|
||||
|
||||
## Test Locally
|
||||
|
||||
You do not need to push to the github repo to have the CI do the tests for you. You can test them locally by doing the following:
|
||||
You do not need to push to the github repo to have the CI do the tests for you.
|
||||
You can test them locally by doing the following:
|
||||
|
||||
```shell
|
||||
DISCORD_TOKEN=YOUR_BOT_TOKEN_HERE deno test --no-check -A tests/mod.ts
|
||||
```
|
||||
|
||||
> Please note that the token you use should be for a trivial unused bot. Never use your main bot tokens for this.
|
||||
> Please note that the token you use should be for a trivial unused bot. Never
|
||||
> use your main bot tokens for this.
|
||||
|
||||
## Ordering
|
||||
|
||||
The order of unit tests is very important. Please do not move/change the order of the tests unless you know what you are doing. Certain tests depend on other previous tests. You may add a test but becareful where you add it.
|
||||
The order of unit tests is very important. Please do not move/change the order
|
||||
of the tests unless you know what you are doing. Certain tests depend on other
|
||||
previous tests. You may add a test but becareful where you add it.
|
||||
|
||||
## Naming
|
||||
|
||||
Each function should have it's own separate file for it's tests. The file should be organized under it's main category which will be the `[]` portion of the tests name. For example, `[guild] create a new guild` will be found in `tests/guilds/create_guild.ts`
|
||||
Each function should have it's own separate file for it's tests. The file should
|
||||
be organized under it's main category which will be the `[]` portion of the
|
||||
tests name. For example, `[guild] create a new guild` will be found in
|
||||
`tests/guilds/create_guild.ts`
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { cache, createGuild, delay } from "../../mod.ts";
|
||||
import { tempData, defaultTestOptions } from "../ws/start_bot.ts";
|
||||
import { assertExists, assertEquals } from "../deps.ts";
|
||||
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
|
||||
import { assertEquals, assertExists } from "../deps.ts";
|
||||
|
||||
Deno.test({
|
||||
name: "[guild] create a new guild",
|
||||
|
||||
@@ -1,19 +1,22 @@
|
||||
import { cache, deleteServer, delay } from "../../mod.ts";
|
||||
import { tempData, defaultTestOptions } from "../ws/start_bot.ts";
|
||||
import { cache, delay, deleteServer } from "../../mod.ts";
|
||||
import { defaultTestOptions, tempData } from "../ws/start_bot.ts";
|
||||
|
||||
Deno.test({
|
||||
name: "[guild] delete a guild",
|
||||
async fn() {
|
||||
if (!tempData.guildId)
|
||||
if (!tempData.guildId) {
|
||||
throw new Error("The guild id was not available to be deleted.");
|
||||
if (!cache.guilds.has(tempData.guildId))
|
||||
}
|
||||
if (!cache.guilds.has(tempData.guildId)) {
|
||||
throw new Error("The guild was not cached so impossible to delete.");
|
||||
}
|
||||
|
||||
await deleteServer(tempData.guildId);
|
||||
await delay(3000);
|
||||
|
||||
if (cache.guilds.has(tempData.guildId))
|
||||
if (cache.guilds.has(tempData.guildId)) {
|
||||
throw new Error("The guild was not able to be deleted.");
|
||||
}
|
||||
},
|
||||
...defaultTestOptions,
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { startBot, botId } from "../../src/bot.ts";
|
||||
import { botId, startBot } from "../../src/bot.ts";
|
||||
import { delay } from "../../src/util/utils.ts";
|
||||
import { ws } from "../../src/ws/ws.ts";
|
||||
import { assertExists } from "../deps.ts";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ws, delay } from "../../mod.ts";
|
||||
import { delay, ws } from "../../mod.ts";
|
||||
import { defaultTestOptions } from "./start_bot.ts";
|
||||
|
||||
// Exit the Deno process once all tests are done.
|
||||
|
||||
Reference in New Issue
Block a user