fix(helpers/guilds): createGuild not caching the guild (#814)

This commit is contained in:
Skillz4Killz
2021-04-11 05:27:57 -04:00
committed by GitHub
parent b80f3149eb
commit 5d20c1c638
3 changed files with 18 additions and 8 deletions
+12 -3
View File
@@ -1,16 +1,25 @@
import { botId } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts";
import { rest } from "../../rest/rest.ts"; import { rest } from "../../rest/rest.ts";
import { structures } from "../../structures/mod.ts"; import { structures } from "../../structures/mod.ts";
import { CreateGuild } from "../../types/guilds/create_guild.ts"; import { CreateGuild } from "../../types/guilds/create_guild.ts";
import { DiscordGuild } from "../../types/guilds/guild.ts"; import { DiscordGuild } from "../../types/guilds/guild.ts";
import { endpoints } from "../../util/constants.ts"; import { endpoints } from "../../util/constants.ts";
import { getMember } from "../members/get_member.ts";
/** Create a new guild. Returns a guild object on success. Fires a Guild Create Gateway event. This endpoint can be used only by bots in less than 10 guilds. */ /** Create a new guild. Returns a guild object on success. Fires a Guild Create Gateway event. This endpoint can be used only by bots in less than 10 guilds. */
export async function createGuild(options: CreateGuild) { export async function createGuild(options: CreateGuild) {
const guild = (await rest.runMethod( const result = (await rest.runMethod(
"post", "post",
endpoints.GUILDS, endpoints.GUILDS,
options, options
)) as DiscordGuild; )) as DiscordGuild;
return structures.createDiscordenoGuild(guild, 0); const guild = await structures.createDiscordenoGuild(result, 0);
// MANUALLY CACHE THE GUILD
await cacheHandlers.set("guilds", guild.id, guild);
// MANUALLY CACHE THE BOT
await getMember(guild.id, botId)
return guild;
} }
+2 -1
View File
@@ -13,6 +13,7 @@ Deno.test({
// Assertions // Assertions
assertExists(guild); assertExists(guild);
assertExists(guild.id);
tempData.guildId = guild.id; tempData.guildId = guild.id;
@@ -20,7 +21,7 @@ Deno.test({
delayUntil(10000, () => cache.guilds.has(guild.id)); delayUntil(10000, () => cache.guilds.has(guild.id));
if (!cache.guilds.has(guild.id)) { if (!cache.guilds.has(guild.id)) {
throw new Error("The guild seemed to be created but it was not cached."); throw new Error(`The guild seemed to be created but it was not cached. ${JSON.stringify(guild)}`);
} }
}, },
...defaultTestOptions, ...defaultTestOptions,
+4 -4
View File
@@ -33,7 +33,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw", custom = false) {
name: "blamewolf", name: "blamewolf",
image: "https://cdn.discordapp.com/emojis/814955268123000832.png", image: "https://cdn.discordapp.com/emojis/814955268123000832.png",
roles: [], roles: [],
}, }
) )
).id ).id
}>`; }>`;
@@ -47,7 +47,7 @@ async function ifItFailsBlameWolf(type: "getter" | "raw", custom = false) {
delayUntil( delayUntil(
10000, 10000,
() => cache.messages.get(message.id)?.reactions?.length > 0, () => (cache.messages.get(message.id)?.reactions?.length || 0) > 0
); );
assertEquals( assertEquals(
@@ -55,9 +55,9 @@ async function ifItFailsBlameWolf(type: "getter" | "raw", custom = false) {
.get(message.id) .get(message.id)
?.reactions?.filter( ?.reactions?.filter(
(reaction: DiscordReaction) => (reaction: DiscordReaction) =>
reaction.emoji?.name === (custom ? "blamewolf" : "❤"), reaction.emoji?.name === (custom ? "blamewolf" : "❤")
).length, ).length,
1, 1
); );
} }