structures made async to be overrideable

This commit is contained in:
Skillz
2020-09-17 17:49:18 -04:00
parent f1cf073d2c
commit f3a113a6e3
17 changed files with 70 additions and 65 deletions
+2 -2
View File
@@ -91,7 +91,7 @@ export async function getMessages(
endpoints.CHANNEL_MESSAGES(channelID),
options,
)) as MessageCreateOptions[];
return result.map((res) => structures.createMessage(res));
return Promise.all(result.map((res) => structures.createMessage(res)));
}
/** Get pinned messages in this channel. */
@@ -99,7 +99,7 @@ export async function getPins(channelID: string) {
const result = (await RequestManager.get(
endpoints.CHANNEL_PINS(channelID),
)) as MessageCreateOptions[];
return result.map((res) => structures.createMessage(res));
return Promise.all(result.map((res) => structures.createMessage(res)));
}
/** Send a message to the channel. Requires SEND_MESSAGES permission. */
+7 -7
View File
@@ -110,7 +110,7 @@ export async function createGuildChannel(
type: options?.type || ChannelTypes.GUILD_TEXT,
})) as ChannelCreatePayload;
const channel = structures.createChannel(result);
const channel = await structures.createChannel(result);
guild.channels.set(result.id, channel);
return channel;
}
@@ -136,13 +136,13 @@ export async function getChannels(guildID: string, addToCache = true) {
const result = await RequestManager.get(
endpoints.GUILD_CHANNELS(guildID),
) as ChannelCreatePayload[];
return result.map((res) => {
const channel = structures.createChannel(res, guildID);
return Promise.all(result.map(async (res) => {
const channel = await structures.createChannel(res, guildID);
if (addToCache) {
cacheHandlers.set("channels", channel.id, channel);
}
return channel;
});
}));
}
/** Fetches a single channel object from the api.
@@ -153,7 +153,7 @@ export async function getChannel(channelID: string, addToCache = true) {
const result = await RequestManager.get(
endpoints.GUILD_CHANNEL(channelID),
) as ChannelCreatePayload;
const channel = structures.createChannel(result, result.guild_id);
const channel = await structures.createChannel(result, result.guild_id);
if (addToCache) cacheHandlers.set("channels", channel.id, channel);
return channel;
}
@@ -184,7 +184,7 @@ export async function getMember(guildID: string, id: string) {
endpoints.GUILD_MEMBER(guildID, id),
) as MemberCreatePayload;
const member = structures.createMember(data, guild.id);
const member = await structures.createMember(data, guild.id);
guild.members.set(id, member);
return member;
}
@@ -290,7 +290,7 @@ export async function createGuildRole(
);
const roleData = result as RoleData;
const role = structures.createRole(roleData);
const role = await structures.createRole(roleData);
const guild = await cacheHandlers.get("guilds", guildID);
guild?.roles.set(role.id, role);
return role;
+1 -1
View File
@@ -108,7 +108,7 @@ export async function sendDirectMessage(
) as DMChannelCreatePayload;
// Channel create event will have added this channel to the cache
cacheHandlers.delete("channels", dmChannelData.id);
const channel = structures.createChannel(dmChannelData);
const channel = await structures.createChannel(dmChannelData);
// Recreate the channel and add it undert he users id
cacheHandlers.set("channels", memberID, channel);
dmChannel = channel;