refactor: resolve async promises, fixed typos, and used inline variable for return (#299)

* Added await in async function, fixed typos and used inline variable for return

* Added await in async function, fixed typos and used inline variable for return

* Revert "Added await in async function, fixed typos and used inline variable for return"

This reverts commit f31caf5d

* Added await in async function, fixed typos and used inline variable for return

* Fixes format

* Fixes format 2

* Fixes format 4475757

* Fixes format 878757854786312378657865785785785785

* Change return to await

* Fixing more issues

* Fixing even more issues

* Fixing even more issues +

* Fixes format
This commit is contained in:
TriForMine
2020-12-30 09:31:11 +01:00
committed by GitHub
parent 6d7aa35d9c
commit 484f86638f
29 changed files with 126 additions and 141 deletions
+12 -22
View File
@@ -38,12 +38,7 @@ import { botHasPermission, calculateBits } from "../../util/permissions.ts";
import { formatImageURL, urlToBase64 } from "../../util/utils.ts";
import { requestAllMembers } from "../../ws/shard_manager.ts";
import { cacheHandlers } from "../controllers/cache.ts";
import {
Guild,
Member,
structures,
Template,
} from "../structures/structures.ts";
import { Guild, Member, structures, Template } from "../structures/mod.ts";
/** Create a new guild. Returns a guild object on success. Fires a Guild Create Gateway event. This endpoint can be used only by bots in less than 10 guilds. */
export async function createServer(options: CreateServerOptions) {
@@ -135,8 +130,7 @@ export async function createGuildChannel(
type: options?.type || ChannelTypes.GUILD_TEXT,
})) as ChannelCreatePayload;
const channel = await structures.createChannel(result);
return channel;
return await structures.createChannel(result);
}
/** Delete a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. */
@@ -167,7 +161,7 @@ export async function getChannels(guildID: string, addToCache = true) {
return Promise.all(result.map(async (res) => {
const channel = await structures.createChannel(res, guildID);
if (addToCache) {
cacheHandlers.set("channels", channel.id, channel);
await cacheHandlers.set("channels", channel.id, channel);
}
return channel;
}));
@@ -182,7 +176,7 @@ export async function getChannel(channelID: string, addToCache = true) {
endpoints.GUILD_CHANNEL(channelID),
) as ChannelCreatePayload;
const channel = await structures.createChannel(result, result.guild_id);
if (addToCache) cacheHandlers.set("channels", channel.id, channel);
if (addToCache) await cacheHandlers.set("channels", channel.id, channel);
return channel;
}
@@ -192,7 +186,7 @@ export function swapChannels(
channelPositions: PositionSwap[],
) {
if (channelPositions.length < 2) {
throw "You must provide atleast two channels to be swapped.";
throw "You must provide at least two channels to be swapped.";
}
return RequestManager.patch(
endpoints.GUILD_CHANNELS(guildID),
@@ -216,8 +210,7 @@ export async function getMember(
endpoints.GUILD_MEMBER(guildID, id),
) as MemberCreatePayload;
const member = await structures.createMember(data, guildID);
return member;
return await structures.createMember(data, guildID);
}
/** Returns guild member objects for the specified user by their nickname/username.
@@ -310,8 +303,6 @@ export async function createGuildRole(
throw new Error(Errors.MISSING_MANAGE_ROLES);
}
const bits = calculateBits(options.permissions || []);
const result = await RequestManager.post(
endpoints.GUILD_ROLES(guildID),
{
@@ -410,7 +401,7 @@ export async function pruneMembers(guildID: string, options: PruneOptions) {
throw new Error(Errors.MISSING_KICK_MEMBERS);
}
RequestManager.post(
return RequestManager.post(
endpoints.GUILD_PRUNE(guildID),
{ ...options, include_roles: options.roles.join(",") },
);
@@ -428,7 +419,7 @@ export function fetchMembers(guild: Guild, options?: FetchMembersOptions) {
// You can request 1 member without the intent
if (
(!options?.limit || options.limit > 1) &&
!(identifyPayload.intents & Intents.GUILD_MEMBERS)
!(identifyPayload.intents && Intents.GUILD_MEMBERS)
) {
throw new Error(Errors.MISSING_INTENT_GUILD_MEMBERS);
}
@@ -437,8 +428,8 @@ export function fetchMembers(guild: Guild, options?: FetchMembersOptions) {
options.limit = options.userIDs.length;
}
return new Promise((resolve) => {
requestAllMembers(guild, resolve, options);
return new Promise(async (resolve) => {
await requestAllMembers(guild, resolve, options);
}) as Promise<Collection<string, Member>>;
}
@@ -565,7 +556,7 @@ export async function getBan(guildID: string, memberID: string) {
throw new Error(Errors.MISSING_BAN_MEMBERS);
}
return RequestManager.get(
return await RequestManager.get(
endpoints.GUILD_BAN(guildID, memberID),
) as Promise<BannedUser>;
}
@@ -694,11 +685,10 @@ export async function createGuildFromTemplate(
data.icon = await urlToBase64(data.icon);
}
const guild = await RequestManager.post(
return await RequestManager.post(
endpoints.GUILD_TEMPLATE(templateCode),
data,
) as Promise<CreateGuildPayload>;
return guild;
}
/**