Guilds helpers

This commit is contained in:
TriForMine
2021-10-21 19:38:09 +02:00
parent baf8583976
commit 20616e8a36
29 changed files with 156 additions and 167 deletions
+15 -15
View File
@@ -1,9 +1,5 @@
import { cacheHandlers } from "../../cache.ts";
import { rest } from "../../rest/rest.ts";
import { structures } from "../../structures/mod.ts";
import type { Guild } from "../../types/guilds/guild.ts";
import { endpoints } from "../../util/constants.ts";
import { ws } from "../../ws/ws.ts";
import type { Bot } from "../../bot.ts";
/**
* ⚠️ **If you need this, you are probably doing something wrong. Always use cache.guilds.get()
@@ -13,23 +9,27 @@ import { ws } from "../../ws/ws.ts";
* So it does not cache the guild, you must do it manually.
* */
export async function getGuild(
guildId: bigint,
options: { counts?: boolean; addToCache?: boolean } = {
counts: true,
addToCache: true,
}
bot: Bot,
guildId: bigint,
options: { counts?: boolean; addToCache?: boolean } = {
counts: true,
addToCache: true,
}
) {
const result = await rest.runMethod<Guild>("get", endpoints.GUILDS_BASE(guildId), {
const result = await bot.rest.runMethod<Guild>(bot.rest,"get", bot.constants.endpoints.GUILDS_BASE(guildId), {
with_counts: options.counts,
});
const guild = await structures.createDiscordenoGuild(
result,
Number((BigInt(guildId) >> 22n) % BigInt(ws.botGatewayData.shards))
const guild = await bot.transformers.guild(
bot,
{
guild: result,
shardId: Number((BigInt(guildId) >> 22n) % BigInt(ws.botGatewayData.shards))
}
);
if (options.addToCache) {
await cacheHandlers.set("guilds", guild.id, guild);
await bot.cache.guilds.set(guild.id, guild);
}
return guild;