mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 03:18:17 +00:00
guilds
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import { Guild } from "../../types/guilds/guild.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||
import { ws } from "../../ws/ws.ts";
|
||||
|
||||
/**
|
||||
* ⚠️ **If you need this, you are probably doing something wrong. Always use cache.guilds.get()
|
||||
@@ -10,10 +12,29 @@ import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||
* This function fetches a guild's data. This is not the same data as a GUILD_CREATE.
|
||||
* So it does not cache the guild, you must do it manually.
|
||||
* */
|
||||
export async function getGuild(guildId: string, counts = true) {
|
||||
const result = await rest.runMethod("get", endpoints.GUILDS_BASE(guildId), {
|
||||
with_counts: counts,
|
||||
});
|
||||
export async function getGuild(
|
||||
guildId: string,
|
||||
options: { counts?: boolean; addToCache?: boolean } = {
|
||||
counts: true,
|
||||
addToCache: true,
|
||||
},
|
||||
) {
|
||||
const result = await rest.runMethod<Guild>(
|
||||
"get",
|
||||
endpoints.GUILDS_BASE(guildId),
|
||||
{
|
||||
with_counts: options.counts,
|
||||
},
|
||||
);
|
||||
|
||||
return snakeKeysToCamelCase<Guild>(result);
|
||||
const structure = await structures.createDiscordenoGuild(
|
||||
result,
|
||||
(BigInt(guildId) >> 22n) % BigInt(ws.botGatewayData.shards),
|
||||
);
|
||||
|
||||
if (options.addToCache) {
|
||||
await cacheHandlers.set("guilds", guildId, structure);
|
||||
}
|
||||
|
||||
return structure;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user