mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-19 04:38:17 +00:00
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:
@@ -22,7 +22,7 @@ import {
|
||||
calculateBits,
|
||||
} from "../../util/permissions.ts";
|
||||
import { cacheHandlers } from "../controllers/cache.ts";
|
||||
import { structures } from "../structures/structures.ts";
|
||||
import { structures } from "../structures/mod.ts";
|
||||
|
||||
/** Checks if a channel overwrite for a user id or a role id has permission in this channel */
|
||||
export function channelOverwriteHasPermission(
|
||||
@@ -38,8 +38,8 @@ export function channelOverwriteHasPermission(
|
||||
if (overwrite) {
|
||||
const allowBits = overwrite.allow;
|
||||
const denyBits = overwrite.deny;
|
||||
if (BigInt(denyBits) & BigInt(Permissions[perm])) return false;
|
||||
if (BigInt(allowBits) & BigInt(Permissions[perm])) return true;
|
||||
if (BigInt(denyBits) && BigInt(Permissions[perm])) return false;
|
||||
if (BigInt(allowBits) && BigInt(Permissions[perm])) return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
@@ -303,7 +303,9 @@ export async function getChannelWebhooks(channelID: string) {
|
||||
) {
|
||||
throw new Error(Errors.MISSING_MANAGE_WEBHOOKS);
|
||||
}
|
||||
return RequestManager.get(endpoints.CHANNEL_WEBHOOKS(channelID)) as Promise<
|
||||
return await RequestManager.get(
|
||||
endpoints.CHANNEL_WEBHOOKS(channelID),
|
||||
) as Promise<
|
||||
WebhookPayload[]
|
||||
>;
|
||||
}
|
||||
@@ -461,12 +463,7 @@ export async function isChannelSynced(channelID: string) {
|
||||
ow.id === overwrite.id
|
||||
);
|
||||
if (!permission) return false;
|
||||
if (
|
||||
overwrite.allow !== permission.allow || overwrite.deny !== permission.deny
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return !(overwrite.allow !== permission.allow ||
|
||||
overwrite.deny !== permission.deny);
|
||||
});
|
||||
}
|
||||
|
||||
+12
-22
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,7 +16,7 @@ import {
|
||||
} from "../../util/permissions.ts";
|
||||
import { formatImageURL, urlToBase64 } from "../../util/utils.ts";
|
||||
import { cacheHandlers } from "../controllers/cache.ts";
|
||||
import { Member, structures } from "../structures/structures.ts";
|
||||
import { Member, structures } from "../structures/mod.ts";
|
||||
import { sendMessage } from "./channel.ts";
|
||||
|
||||
/** The users custom avatar or the default avatar if you don't have a member object. */
|
||||
@@ -127,10 +127,10 @@ export async function sendDirectMessage(
|
||||
{ recipient_id: memberID },
|
||||
) as DMChannelCreatePayload;
|
||||
// Channel create event will have added this channel to the cache
|
||||
cacheHandlers.delete("channels", dmChannelData.id);
|
||||
await cacheHandlers.delete("channels", dmChannelData.id);
|
||||
const channel = await structures.createChannel(dmChannelData);
|
||||
// Recreate the channel and add it undert he users id
|
||||
cacheHandlers.set("channels", memberID, channel);
|
||||
await cacheHandlers.set("channels", memberID, channel);
|
||||
dmChannel = channel;
|
||||
}
|
||||
|
||||
@@ -240,9 +240,9 @@ export function moveMember(
|
||||
/** Modifies the bot's username or avatar.
|
||||
* NOTE: username: if changed may cause the bot's discriminator to be randomized.
|
||||
*/
|
||||
export async function editBotProfile(username?: string, avatarURL?: string) {
|
||||
export async function editBotProfile(username?: string, botAvatarURL?: string) {
|
||||
// Nothing was edited
|
||||
if (!username && !avatarURL) return;
|
||||
if (!username && !botAvatarURL) return;
|
||||
// Check username requirements if username was provided
|
||||
if (username) {
|
||||
if (username.length > 32) {
|
||||
@@ -259,8 +259,8 @@ export async function editBotProfile(username?: string, avatarURL?: string) {
|
||||
}
|
||||
}
|
||||
|
||||
const avatar = avatarURL ? await urlToBase64(avatarURL) : undefined;
|
||||
RequestManager.patch(
|
||||
const avatar = botAvatarURL ? await urlToBase64(botAvatarURL) : undefined;
|
||||
return RequestManager.patch(
|
||||
endpoints.USER_BOT,
|
||||
{
|
||||
username: username?.trim(),
|
||||
|
||||
@@ -10,7 +10,7 @@ import { endpoints } from "../../util/constants.ts";
|
||||
import { botHasChannelPermissions } from "../../util/permissions.ts";
|
||||
import { delay } from "../../util/utils.ts";
|
||||
import { cacheHandlers } from "../controllers/cache.ts";
|
||||
import { Message, structures } from "../structures/structures.ts";
|
||||
import { Message, structures } from "../structures/mod.ts";
|
||||
|
||||
/** Delete a message with the channel id and message id only. */
|
||||
export async function deleteMessageByID(
|
||||
@@ -68,7 +68,7 @@ export async function pin(channelID: string, messageID: string) {
|
||||
) {
|
||||
throw new Error(Errors.MISSING_MANAGE_MESSAGES);
|
||||
}
|
||||
RequestManager.put(endpoints.CHANNEL_MESSAGE(channelID, messageID));
|
||||
return RequestManager.put(endpoints.CHANNEL_MESSAGE(channelID, messageID));
|
||||
}
|
||||
|
||||
/** Unpin a message in a channel. Requires MANAGE_MESSAGES. */
|
||||
@@ -82,7 +82,7 @@ export async function unpin(channelID: string, messageID: string) {
|
||||
) {
|
||||
throw new Error(Errors.MISSING_MANAGE_MESSAGES);
|
||||
}
|
||||
RequestManager.delete(
|
||||
return RequestManager.delete(
|
||||
endpoints.CHANNEL_MESSAGE(channelID, messageID),
|
||||
);
|
||||
}
|
||||
@@ -134,8 +134,8 @@ export async function addReactions(
|
||||
ordered = false,
|
||||
) {
|
||||
if (!ordered) {
|
||||
reactions.forEach((reaction) =>
|
||||
addReaction(channelID, messageID, reaction)
|
||||
await Promise.all(
|
||||
reactions.map((reaction) => addReaction(channelID, messageID, reaction)),
|
||||
);
|
||||
} else {
|
||||
for (const reaction of reactions) {
|
||||
|
||||
@@ -17,7 +17,7 @@ import { cache } from "../../util/cache.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { botHasChannelPermissions } from "../../util/permissions.ts";
|
||||
import { urlToBase64 } from "../../util/utils.ts";
|
||||
import { structures } from "../structures/structures.ts";
|
||||
import { structures } from "../structures/mod.ts";
|
||||
|
||||
/** Create a new webhook. Requires the MANAGE_WEBHOOKS permission. Returns a webhook object on success. Webhook names follow our naming restrictions that can be found in our Usernames and Nicknames documentation, with the following additional stipulations:
|
||||
*
|
||||
@@ -46,7 +46,7 @@ export async function createWebhook(
|
||||
throw new Error(Errors.INVALID_WEBHOOK_NAME);
|
||||
}
|
||||
|
||||
return RequestManager.post(
|
||||
return await RequestManager.post(
|
||||
endpoints.CHANNEL_WEBHOOKS(channelID),
|
||||
{
|
||||
...options,
|
||||
|
||||
Reference in New Issue
Block a user