Channel helpers

This commit is contained in:
TriForMine
2021-10-21 22:10:26 +02:00
parent 4a12b7714b
commit 96b5782bad
20 changed files with 183 additions and 204 deletions
+9 -11
View File
@@ -1,23 +1,21 @@
import { cacheHandlers } from "../../cache.ts";
import { rest } from "../../rest/rest.ts";
import { structures } from "../../structures/mod.ts";
import type { Bot } from "../../bot.ts";
import type { Channel } from "../../types/channels/channel.ts";
import { snowflakeToBigint } from "../../util/bigint.ts";
import { endpoints } from "../../util/constants.ts";
/** Fetches a single channel object from the api.
*
* ⚠️ **If you need this, you are probably doing something wrong. This is not intended for use. Your channels will be cached in your guild.**
*/
export async function getChannel(channelId: bigint, addToCache = true) {
const result = await rest.runMethod<Channel>("get", endpoints.CHANNEL_BASE(channelId));
export async function getChannel(bot: Bot, channelId: bigint, addToCache = true) {
const result = await bot.rest.runMethod<Channel>(bot.rest,"get", bot.constants.endpoints.CHANNEL_BASE(channelId));
const discordenoChannel = await structures.createDiscordenoChannel(
result,
result.guildId ? snowflakeToBigint(result.guildId) : undefined
const discordenoChannel = bot.transformers.channel(
{
channel: result,
guildId: result.guildId ? bot.transformers.snowflake(result.guildId) : undefined
}
);
if (addToCache) {
await cacheHandlers.set("channels", discordenoChannel.id, discordenoChannel);
await bot.cache.channels.set(discordenoChannel.id, discordenoChannel);
}
return discordenoChannel;