fix: return types [] => Collection

This commit is contained in:
Skillz4Killz
2021-04-13 17:53:49 +00:00
committed by GitHub
parent f8d6a74948
commit c2f2afb211
8 changed files with 91 additions and 34 deletions
+23 -16
View File
@@ -2,6 +2,7 @@ import { cacheHandlers } from "../../cache.ts";
import { rest } from "../../rest/rest.ts";
import { structures } from "../../structures/mod.ts";
import { DiscordChannel } from "../../types/channels/channel.ts";
import { Collection } from "../../util/collection.ts";
import { endpoints } from "../../util/constants.ts";
/** Returns a list of guild channel objects.
@@ -11,22 +12,28 @@ import { endpoints } from "../../util/constants.ts";
export async function getChannels(guildId: string, addToCache = true) {
const result = (await rest.runMethod(
"get",
endpoints.GUILD_CHANNELS(guildId),
) as DiscordChannel[]);
endpoints.GUILD_CHANNELS(guildId)
)) as DiscordChannel[];
return Promise.all(result.map(async (res) => {
const discordenoChannel = await structures.createDiscordenoChannel(
res,
guildId,
);
if (addToCache) {
await cacheHandlers.set(
"channels",
discordenoChannel.id,
discordenoChannel,
);
}
return new Collection(
(
await Promise.all(
result.map(async (res) => {
const discordenoChannel = await structures.createDiscordenoChannel(
res,
guildId
);
if (addToCache) {
await cacheHandlers.set(
"channels",
discordenoChannel.id,
discordenoChannel
);
}
return discordenoChannel;
}));
return discordenoChannel;
})
)
).map((c) => [c.id, c])
);
}