chore: deno fmt

This commit is contained in:
Skillz4Killz
2021-04-04 00:34:40 +00:00
committed by GitHub
parent e7d9b58c81
commit b81bf8d484
24 changed files with 140 additions and 155 deletions
+4 -5
View File
@@ -9,11 +9,10 @@ import { endpoints } from "../../util/constants.ts";
* ⚠️ **If you need this, you are probably doing something wrong. This is not intended for use. Your channels will be cached in your guild.** * ⚠️ **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: string, addToCache = true) { export async function getChannel(channelId: string, addToCache = true) {
const result = const result = (await rest.runMethod(
(await rest.runMethod( "get",
"get", endpoints.CHANNEL_BASE(channelId),
endpoints.CHANNEL_BASE(channelId), )) as DiscordChannel;
)) as DiscordChannel;
const channelStruct = await structures.createChannelStruct( const channelStruct = await structures.createChannelStruct(
result, result,
+4 -5
View File
@@ -9,11 +9,10 @@ import { endpoints } from "../../util/constants.ts";
* ⚠️ **If you need this, you are probably doing something wrong. This is not intended for use. Your channels will be cached in your guild.** * ⚠️ **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 getChannels(guildId: string, addToCache = true) { export async function getChannels(guildId: string, addToCache = true) {
const result = const result = (await rest.runMethod(
(await rest.runMethod( "get",
"get", endpoints.GUILD_CHANNELS(guildId),
endpoints.GUILD_CHANNELS(guildId), ) as DiscordChannel[]);
) as DiscordChannel[]);
return Promise.all(result.map(async (res) => { return Promise.all(result.map(async (res) => {
const channelStruct = await structures.createChannelStruct(res, guildId); const channelStruct = await structures.createChannelStruct(res, guildId);
+4 -5
View File
@@ -5,11 +5,10 @@ import { endpoints } from "../../util/constants.ts";
/** Get pinned messages in this channel. */ /** Get pinned messages in this channel. */
export async function getPins(channelId: string) { export async function getPins(channelId: string) {
const result = const result = (await rest.runMethod(
(await rest.runMethod( "get",
"get", endpoints.CHANNEL_PINS(channelId),
endpoints.CHANNEL_PINS(channelId), )) as DiscordMessage[];
)) as DiscordMessage[];
return Promise.all( return Promise.all(
result.map((res) => structures.createMessageStruct(res)), result.map((res) => structures.createMessageStruct(res)),
+6 -7
View File
@@ -5,13 +5,12 @@ import { endpoints } from "../../util/constants.ts";
/** Fetch all of the global commands for your application. */ /** Fetch all of the global commands for your application. */
export async function getSlashCommands(guildId?: string) { export async function getSlashCommands(guildId?: string) {
const result = const result = (await rest.runMethod(
(await rest.runMethod( "get",
"get", guildId
guildId ? endpoints.COMMANDS_GUILD(applicationId, guildId)
? endpoints.COMMANDS_GUILD(applicationId, guildId) : endpoints.COMMANDS(applicationId),
: endpoints.COMMANDS(applicationId), )) as SlashCommand[];
)) as SlashCommand[];
return new Collection(result.map((command) => [command.name, command])); return new Collection(result.map((command) => [command.name, command]));
} }
+5 -6
View File
@@ -4,12 +4,11 @@ import { endpoints } from "../../util/constants.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. */ /** 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 createGuild(options: CreateServerOptions) { export async function createGuild(options: CreateServerOptions) {
const guild = const guild = (await rest.runMethod(
(await rest.runMethod( "post",
"post", endpoints.GUILDS,
endpoints.GUILDS, options,
options, )) as CreateGuildPayload;
)) as CreateGuildPayload;
return structures.createGuildStruct(guild, 0); return structures.createGuildStruct(guild, 0);
} }
+2 -1
View File
@@ -18,7 +18,8 @@ export async function getAuditLogs(
? AuditLogs[options.action_type] ? AuditLogs[options.action_type]
: undefined, : undefined,
limit: options.limit && options.limit >= 1 && options.limit <= 100 limit: options.limit && options.limit >= 1 && options.limit <= 100
? options.limit : 50, ? options.limit
: 50,
}, },
); );
+4 -5
View File
@@ -7,11 +7,10 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
export async function getBans(guildId: string) { export async function getBans(guildId: string) {
await requireBotGuildPermissions(guildId, ["BAN_MEMBERS"]); await requireBotGuildPermissions(guildId, ["BAN_MEMBERS"]);
const results = const results = (await rest.runMethod(
(await rest.runMethod( "get",
"get", endpoints.GUILD_BANS(guildId),
endpoints.GUILD_BANS(guildId), )) as BannedUser[];
)) as BannedUser[];
return new Collection<string, BannedUser>( return new Collection<string, BannedUser>(
results.map((res) => [res.user.id, res]), results.map((res) => [res.user.id, res]),
+5 -3
View File
@@ -15,9 +15,11 @@ export async function getMember(
const guild = await cacheHandlers.get("guilds", guildId); const guild = await cacheHandlers.get("guilds", guildId);
if (!guild && !options?.force) return; if (!guild && !options?.force) return;
const data = (await rest.runMethod("get", const data =
endpoints.GUILD_MEMBER(guildId, id), (await rest.runMethod(
)) as MemberCreatePayload; "get",
endpoints.GUILD_MEMBER(guildId, id),
)) as MemberCreatePayload;
const memberStruct = await structures.createMemberStruct(data, guildId); const memberStruct = await structures.createMemberStruct(data, guildId);
await cacheHandlers.set("members", memberStruct.id, memberStruct); await cacheHandlers.set("members", memberStruct.id, memberStruct);
+6 -13
View File
@@ -42,19 +42,12 @@ export async function getMembers(guildId: string, options?: GetMemberOptions) {
); );
} }
const result = const result = (await rest.runMethod(
(await rest.runMethod( "get",
"get", `${endpoints.GUILD_MEMBERS(guildId)}?limit=${
`${endpoints.GUILD_MEMBERS(guildId)}?limit=${ membersLeft > 1000 ? 1000 : membersLeft
membersLeft > 1000 }${options?.after ? `&after=${options.after}` : ""}`,
? 1000 )) as DiscordGuildMember[];
: membersLeft
}${
options?.after
? `&after=${options.after}`
: ""
}`,
)) as DiscordGuildMember[];
const memberStructures = await Promise.all( const memberStructures = await Promise.all(
result.map(async (member) => { result.map(async (member) => {
+4 -5
View File
@@ -10,11 +10,10 @@ export async function getMessage(channelId: string, id: string) {
"READ_MESSAGE_HISTORY", "READ_MESSAGE_HISTORY",
]); ]);
const result = const result = (await rest.runMethod(
(await rest.runMethod( "get",
"get", endpoints.CHANNEL_MESSAGE(channelId, id),
endpoints.CHANNEL_MESSAGE(channelId, id), )) as MessageCreateOptions;
)) as MessageCreateOptions;
return structures.createMessageStruct(result); return structures.createMessageStruct(result);
} }
+5 -6
View File
@@ -19,12 +19,11 @@ export async function getMessages(
if (options?.limit && options.limit > 100) return; if (options?.limit && options.limit > 100) return;
const result = const result = (await rest.runMethod(
(await rest.runMethod( "get",
"get", endpoints.CHANNEL_MESSAGES(channelId),
endpoints.CHANNEL_MESSAGES(channelId), options,
options, )) as MessageCreateOptions[];
)) as MessageCreateOptions[];
return Promise.all( return Promise.all(
result.map((res) => structures.createMessageStruct(res)), result.map((res) => structures.createMessageStruct(res)),
+5 -6
View File
@@ -9,12 +9,11 @@ export async function getReactions(
reaction: string, reaction: string,
options?: DiscordGetReactionsParams, options?: DiscordGetReactionsParams,
) { ) {
const users = const users = (await rest.runMethod(
(await rest.runMethod( "get",
"get", endpoints.CHANNEL_MESSAGE_REACTION(channelId, messageId, reaction),
endpoints.CHANNEL_MESSAGE_REACTION(channelId, messageId, reaction), options,
options, )) as UserPayload[];
)) as UserPayload[];
return new Collection(users.map((user) => [user.id, user])); return new Collection(users.map((user) => [user.id, user]));
} }
+4 -5
View File
@@ -4,11 +4,10 @@ import { endpoints } from "../../util/constants.ts";
/** Crosspost a message in a News Channel to following channels. */ /** Crosspost a message in a News Channel to following channels. */
export async function publishMessage(channelId: string, messageId: string) { export async function publishMessage(channelId: string, messageId: string) {
const data = const data = (await rest.runMethod(
(await rest.runMethod( "post",
"post", endpoints.CHANNEL_MESSAGE_CROSSPOST(channelId, messageId),
endpoints.CHANNEL_MESSAGE_CROSSPOST(channelId, messageId), )) as MessageCreateOptions;
)) as MessageCreateOptions;
return structures.createMessageStruct(data); return structures.createMessageStruct(data);
} }
@@ -23,12 +23,11 @@ export async function createGuildTemplate(
throw new Error("The description can only be in between 0-120 characters."); throw new Error("The description can only be in between 0-120 characters.");
} }
const template = const template = (await rest.runMethod(
(await rest.runMethod( "post",
"post", endpoints.GUILD_TEMPLATES(guildId),
endpoints.GUILD_TEMPLATES(guildId), data,
data, )) as GuildTemplate;
)) as GuildTemplate;
return structures.createTemplateStruct(template); return structures.createTemplateStruct(template);
} }
@@ -13,11 +13,10 @@ export async function deleteGuildTemplate(
) { ) {
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]); await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
const deletedTemplate = const deletedTemplate = (await rest.runMethod(
(await rest.runMethod( "delete",
"delete", `${endpoints.GUILD_TEMPLATES(guildId)}/${templateCode}`,
`${endpoints.GUILD_TEMPLATES(guildId)}/${templateCode}`, )) as GuildTemplate;
)) as GuildTemplate;
return structures.createTemplateStruct(deletedTemplate); return structures.createTemplateStruct(deletedTemplate);
} }
+5 -6
View File
@@ -22,12 +22,11 @@ export async function editGuildTemplate(
throw new Error("The description can only be in between 0-120 characters."); throw new Error("The description can only be in between 0-120 characters.");
} }
const template = const template = (await rest.runMethod(
(await rest.runMethod( "patch",
"patch", `${endpoints.GUILD_TEMPLATES(guildId)}/${templateCode}`,
`${endpoints.GUILD_TEMPLATES(guildId)}/${templateCode}`, data,
data, )) as GuildTemplate;
)) as GuildTemplate;
return structures.createTemplateStruct(template); return structures.createTemplateStruct(template);
} }
+4 -5
View File
@@ -10,11 +10,10 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
export async function getGuildTemplates(guildId: string) { export async function getGuildTemplates(guildId: string) {
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]); await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
const templates = const templates = (await rest.runMethod(
(await rest.runMethod( "get",
"get", endpoints.GUILD_TEMPLATES(guildId),
endpoints.GUILD_TEMPLATES(guildId), )) as GuildTemplate[];
)) as GuildTemplate[];
return templates.map((template) => structures.createTemplateStruct(template)); return templates.map((template) => structures.createTemplateStruct(template));
} }
+4 -5
View File
@@ -4,11 +4,10 @@ import { endpoints } from "../../util/constants.ts";
/** Returns the guild template if it exists */ /** Returns the guild template if it exists */
export async function getTemplate(templateCode: string) { export async function getTemplate(templateCode: string) {
const result = const result = (await rest.runMethod(
(await rest.runMethod( "get",
"get", endpoints.GUILD_TEMPLATE(templateCode),
endpoints.GUILD_TEMPLATE(templateCode), ) as GuildTemplate);
) as GuildTemplate);
const template = await structures.createTemplateStruct(result); const template = await structures.createTemplateStruct(result);
return template; return template;
+4 -5
View File
@@ -10,11 +10,10 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
export async function syncGuildTemplate(guildId: string, templateCode: string) { export async function syncGuildTemplate(guildId: string, templateCode: string) {
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]); await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
const template = const template = (await rest.runMethod(
(await rest.runMethod( "put",
"put", `${endpoints.GUILD_TEMPLATES(guildId)}/${templateCode}`,
`${endpoints.GUILD_TEMPLATES(guildId)}/${templateCode}`, )) as GuildTemplate;
)) as GuildTemplate;
return structures.createTemplateStruct(template); return structures.createTemplateStruct(template);
} }
+5 -1
View File
@@ -90,7 +90,11 @@ async function handleApplicationCommand(
} }
/** Internal function to verify security. Discord will send bad and good data and this function is important to verify it. If it is not verified properly, Discord will kill your bot. */ /** Internal function to verify security. Discord will send bad and good data and this function is important to verify it. If it is not verified properly, Discord will kill your bot. */
export function verifySecurity(buffer: Uint8Array, signature: string, time: string) { export function verifySecurity(
buffer: Uint8Array,
signature: string,
time: string,
) {
const sig = new Uint8Array(64); const sig = new Uint8Array(64);
const timestamp = new TextEncoder().encode(time); const timestamp = new TextEncoder().encode(time);
+1 -1
View File
@@ -22,7 +22,7 @@ export const rest = {
console.error(error); console.error(error);
}, },
// PLACEHOLDERS TO ALLOW USERS TO CUSTOMIZE // PLACEHOLDERS TO ALLOW USERS TO CUSTOMIZE
debug: function(_type, error) {}, debug: function (_type, error) {},
fetching() {}, fetching() {},
fetched() {}, fetched() {},
fetchSuccess() {}, fetchSuccess() {},
+16 -15
View File
@@ -9,7 +9,7 @@ export function runMethod(
url: string, url: string,
body?: unknown, body?: unknown,
retryCount = 0, retryCount = 0,
bucketId?: string | null bucketId?: string | null,
) { ) {
rest.eventHandlers.debug?.("requestCreate", { rest.eventHandlers.debug?.("requestCreate", {
method, method,
@@ -55,18 +55,19 @@ export function runMethod(
return { rateLimited: rateLimitResetIn, beforeFetch: true, bucketId }; return { rateLimited: rateLimitResetIn, beforeFetch: true, bucketId };
} }
const query = const query = method === "get" && body
method === "get" && body ? // deno-lint-ignore no-explicit-any
? // deno-lint-ignore no-explicit-any Object.entries(body as any)
Object.entries(body as any) .map(
.map( ([key, value]) =>
([key, value]) => `${encodeURIComponent(key)}=${
`${encodeURIComponent(key)}=${encodeURIComponent( encodeURIComponent(
value as string | number | boolean value as string | number | boolean,
)}` )
) }`,
.join("&") )
: ""; .join("&")
: "";
const urlToUse = method === "get" && query ? `${url}?${query}` : url; const urlToUse = method === "get" && query ? `${url}?${query}` : url;
rest.eventHandlers.debug?.("requestFetch", { rest.eventHandlers.debug?.("requestFetch", {
@@ -78,7 +79,7 @@ export function runMethod(
}); });
const response = await fetch( const response = await fetch(
urlToUse, urlToUse,
rest.createRequestBody(body, method) rest.createRequestBody(body, method),
); );
rest.eventHandlers.debug?.("requestFetched", { rest.eventHandlers.debug?.("requestFetched", {
method, method,
@@ -90,7 +91,7 @@ export function runMethod(
}); });
const bucketIdFromHeaders = rest.processRequestHeaders( const bucketIdFromHeaders = rest.processRequestHeaders(
url, url,
response.headers response.headers,
); );
await rest.handleStatusCode(response, errorStack); await rest.handleStatusCode(response, errorStack);
-1
View File
@@ -1,4 +1,3 @@
export interface ListGuildMembers { export interface ListGuildMembers {
/** Max number of members to return (1-1000). Default: 1 */ /** Max number of members to return (1-1000). Default: 1 */
limit?: number; limit?: number;
+34 -33
View File
@@ -8,24 +8,23 @@ import { PermissionStrings } from "../types/permissions/permission_strings.ts";
async function getCached(table: "guilds", key: string | Guild): Promise<Guild>; async function getCached(table: "guilds", key: string | Guild): Promise<Guild>;
async function getCached( async function getCached(
table: "channels", table: "channels",
key: string | Channel key: string | Channel,
): Promise<Channel>; ): Promise<Channel>;
async function getCached( async function getCached(
table: "members", table: "members",
key: string | Member key: string | Member,
): Promise<Member>; ): Promise<Member>;
async function getCached( async function getCached(
table: "guilds" | "channels" | "members", table: "guilds" | "channels" | "members",
key: string | Guild | Channel | Member key: string | Guild | Channel | Member,
) { ) {
const cached = const cached = typeof key === "string"
typeof key === "string" ? // @ts-ignore TS is wrong here
? // @ts-ignore TS is wrong here await cacheHandlers.get(table, key)
await cacheHandlers.get(table, key) : key;
: key;
if (!cached || typeof cached === "string") { if (!cached || typeof cached === "string") {
throw new Error( throw new Error(
Errors[`${table.slice(0, -1).toUpperCase()}_NOT_FOUND` as Errors] Errors[`${table.slice(0, -1).toUpperCase()}_NOT_FOUND` as Errors],
); );
} }
@@ -35,7 +34,7 @@ async function getCached(
/** Calculates the permissions this member has in the given guild */ /** Calculates the permissions this member has in the given guild */
export async function calculateBasePermissions( export async function calculateBasePermissions(
guild: string | Guild, guild: string | Guild,
member: string | Member member: string | Member,
) { ) {
guild = await getCached("guilds", guild); guild = await getCached("guilds", guild);
member = await getCached("members", member); member = await getCached("members", member);
@@ -60,7 +59,7 @@ export async function calculateBasePermissions(
/** Calculates the permissions this member has for the given Channel */ /** Calculates the permissions this member has for the given Channel */
export async function calculateChannelOverwrites( export async function calculateChannelOverwrites(
channel: string | Channel, channel: string | Channel,
member: string | Member member: string | Member,
) { ) {
channel = await getCached("channels", channel); channel = await getCached("channels", channel);
@@ -71,12 +70,12 @@ export async function calculateChannelOverwrites(
// Get all the role permissions this member already has // Get all the role permissions this member already has
let permissions = BigInt( let permissions = BigInt(
await calculateBasePermissions(channel.guildId, member) await calculateBasePermissions(channel.guildId, member),
); );
// First calculate @everyone overwrites since these have the lowest priority // First calculate @everyone overwrites since these have the lowest priority
const overwriteEveryone = channel?.permissionOverwrites.find( const overwriteEveryone = channel?.permissionOverwrites.find(
(overwrite) => overwrite.id === (channel as Channel).guildId (overwrite) => overwrite.id === (channel as Channel).guildId,
); );
if (overwriteEveryone) { if (overwriteEveryone) {
// First remove denied permissions since denied < allowed // First remove denied permissions since denied < allowed
@@ -103,7 +102,7 @@ export async function calculateChannelOverwrites(
// Third calculate member specific overwrites since these have the highest priority // Third calculate member specific overwrites since these have the highest priority
const overwriteMember = overwrites.find( const overwriteMember = overwrites.find(
(overwrite) => overwrite.id === (member as Member).id (overwrite) => overwrite.id === (member as Member).id,
); );
if (overwriteMember) { if (overwriteMember) {
permissions &= ~BigInt(overwriteMember.deny); permissions &= ~BigInt(overwriteMember.deny);
@@ -116,14 +115,15 @@ export async function calculateChannelOverwrites(
/** Checks if the given permission bits are matching the given permissions. `ADMINISTRATOR` always returns `true` */ /** Checks if the given permission bits are matching the given permissions. `ADMINISTRATOR` always returns `true` */
export function validatePermissions( export function validatePermissions(
permissionBits: string, permissionBits: string,
permissions: PermissionStrings[] permissions: PermissionStrings[],
) { ) {
if (BigInt(permissionBits) & 8n) return true; if (BigInt(permissionBits) & 8n) return true;
return permissions.every( return permissions.every(
(permission) => (permission) =>
// Check if permission is in permissionBits // Check if permission is in permissionBits
BigInt(permissionBits) & BigInt(DiscordBitwisePermissionFlags[permission]) BigInt(permissionBits) &
BigInt(DiscordBitwisePermissionFlags[permission]),
); );
} }
@@ -131,7 +131,7 @@ export function validatePermissions(
export async function hasGuildPermissions( export async function hasGuildPermissions(
guild: string | Guild, guild: string | Guild,
member: string | Member, member: string | Member,
permissions: PermissionStrings[] permissions: PermissionStrings[],
) { ) {
// First we need the role permission bits this member has // First we need the role permission bits this member has
const basePermissions = await calculateBasePermissions(guild, member); const basePermissions = await calculateBasePermissions(guild, member);
@@ -142,7 +142,7 @@ export async function hasGuildPermissions(
/** Checks if the bot has these permissions in the given guild */ /** Checks if the bot has these permissions in the given guild */
export function botHasGuildPermissions( export function botHasGuildPermissions(
guild: string | Guild, guild: string | Guild,
permissions: PermissionStrings[] permissions: PermissionStrings[],
) { ) {
// Since Bot is a normal member we can use the hasRolePermissions() function // Since Bot is a normal member we can use the hasRolePermissions() function
return hasGuildPermissions(guild, botId, permissions); return hasGuildPermissions(guild, botId, permissions);
@@ -152,7 +152,7 @@ export function botHasGuildPermissions(
export async function hasChannelPermissions( export async function hasChannelPermissions(
channel: string | Channel, channel: string | Channel,
member: string | Member, member: string | Member,
permissions: PermissionStrings[] permissions: PermissionStrings[],
) { ) {
// First we need the overwrite bits this member has // First we need the overwrite bits this member has
const channelOverwrites = await calculateChannelOverwrites(channel, member); const channelOverwrites = await calculateChannelOverwrites(channel, member);
@@ -163,7 +163,7 @@ export async function hasChannelPermissions(
/** Checks if the bot has these permissions f0r the given channel */ /** Checks if the bot has these permissions f0r the given channel */
export function botHasChannelPermissions( export function botHasChannelPermissions(
channel: string | Channel, channel: string | Channel,
permissions: PermissionStrings[] permissions: PermissionStrings[],
) { ) {
// Since Bot is a normal member we can use the hasRolePermissions() function // Since Bot is a normal member we can use the hasRolePermissions() function
return hasChannelPermissions(channel, botId, permissions); return hasChannelPermissions(channel, botId, permissions);
@@ -172,7 +172,7 @@ export function botHasChannelPermissions(
/** Returns the permissions that are not in the given permissionBits */ /** Returns the permissions that are not in the given permissionBits */
export function missingPermissions( export function missingPermissions(
permissionBits: string, permissionBits: string,
permissions: PermissionStrings[] permissions: PermissionStrings[],
) { ) {
if (BigInt(permissionBits) & 8n) return []; if (BigInt(permissionBits) & 8n) return [];
@@ -181,7 +181,7 @@ export function missingPermissions(
!( !(
BigInt(permissionBits) & BigInt(permissionBits) &
BigInt(DiscordBitwisePermissionFlags[permission]) BigInt(DiscordBitwisePermissionFlags[permission])
) ),
); );
} }
@@ -189,7 +189,7 @@ export function missingPermissions(
export async function getMissingGuildPermissions( export async function getMissingGuildPermissions(
guild: string | Guild, guild: string | Guild,
member: string | Member, member: string | Member,
permissions: PermissionStrings[] permissions: PermissionStrings[],
) { ) {
// First we need the role permissino bits this member has // First we need the role permissino bits this member has
const permissionBits = await calculateBasePermissions(guild, member); const permissionBits = await calculateBasePermissions(guild, member);
@@ -201,7 +201,7 @@ export async function getMissingGuildPermissions(
export async function getMissingChannelPermissions( export async function getMissingChannelPermissions(
channel: string | Channel, channel: string | Channel,
member: string | Member, member: string | Member,
permissions: PermissionStrings[] permissions: PermissionStrings[],
) { ) {
// First we need the role permissino bits this member has // First we need the role permissino bits this member has
const permissionBits = await calculateChannelOverwrites(channel, member); const permissionBits = await calculateChannelOverwrites(channel, member);
@@ -213,7 +213,7 @@ export async function getMissingChannelPermissions(
export async function requireGuildPermissions( export async function requireGuildPermissions(
guild: string | Guild, guild: string | Guild,
member: string | Member, member: string | Member,
permissions: PermissionStrings[] permissions: PermissionStrings[],
) { ) {
const missing = await getMissingGuildPermissions(guild, member, permissions); const missing = await getMissingGuildPermissions(guild, member, permissions);
if (missing.length) { if (missing.length) {
@@ -225,7 +225,7 @@ export async function requireGuildPermissions(
/** Throws an error if the bot does not have all permissions */ /** Throws an error if the bot does not have all permissions */
export function requireBotGuildPermissions( export function requireBotGuildPermissions(
guild: string | Guild, guild: string | Guild,
permissions: PermissionStrings[] permissions: PermissionStrings[],
) { ) {
// Since Bot is a normal member we can use the throwOnMissingGuildPermission() function // Since Bot is a normal member we can use the throwOnMissingGuildPermission() function
return requireGuildPermissions(guild, botId, permissions); return requireGuildPermissions(guild, botId, permissions);
@@ -235,12 +235,12 @@ export function requireBotGuildPermissions(
export async function requireChannelPermissions( export async function requireChannelPermissions(
channel: string | Channel, channel: string | Channel,
member: string | Member, member: string | Member,
permissions: PermissionStrings[] permissions: PermissionStrings[],
) { ) {
const missing = await getMissingChannelPermissions( const missing = await getMissingChannelPermissions(
channel, channel,
member, member,
permissions permissions,
); );
if (missing.length) { if (missing.length) {
// If the member is missing a permission throw an Error // If the member is missing a permission throw an Error
@@ -251,7 +251,7 @@ export async function requireChannelPermissions(
/** Throws an error if the bot has not all of the given channel permissions */ /** Throws an error if the bot has not all of the given channel permissions */
export function requireBotChannelPermissions( export function requireBotChannelPermissions(
channel: string | Channel, channel: string | Channel,
permissions: PermissionStrings[] permissions: PermissionStrings[],
) { ) {
// Since Bot is a normal member we can use the throwOnMissingChannelPermission() function // Since Bot is a normal member we can use the throwOnMissingChannelPermission() function
return requireChannelPermissions(channel, botId, permissions); return requireChannelPermissions(channel, botId, permissions);
@@ -263,7 +263,8 @@ export function calculatePermissions(permissionBits: bigint) {
// Since Object.keys() not only returns the permission names but also the bit values we need to return false if it is a Number // Since Object.keys() not only returns the permission names but also the bit values we need to return false if it is a Number
if (Number(permission)) return false; if (Number(permission)) return false;
// Check if permissionBits has this permission // Check if permissionBits has this permission
return permissionBits & BigInt(DiscordBitwisePermissionFlags[permission as PermissionStrings]); return permissionBits &
BigInt(DiscordBitwisePermissionFlags[permission as PermissionStrings]);
}) as PermissionStrings[]; }) as PermissionStrings[];
} }
@@ -280,7 +281,7 @@ export function calculateBits(permissions: PermissionStrings[]) {
/** Gets the highest role from the member in this guild */ /** Gets the highest role from the member in this guild */
export async function highestRole( export async function highestRole(
guild: string | Guild, guild: string | Guild,
member: string | Member member: string | Member,
) { ) {
guild = await getCached("guilds", guild); guild = await getCached("guilds", guild);
@@ -316,7 +317,7 @@ export async function highestRole(
export async function higherRolePosition( export async function higherRolePosition(
guild: string | Guild, guild: string | Guild,
roleId: string, roleId: string,
otherRoleId: string otherRoleId: string,
) { ) {
guild = await getCached("guilds", guild); guild = await getCached("guilds", guild);
@@ -336,7 +337,7 @@ export async function higherRolePosition(
export async function isHigherPosition( export async function isHigherPosition(
guild: string | Guild, guild: string | Guild,
memberId: string, memberId: string,
compareRoleId: string compareRoleId: string,
) { ) {
guild = await getCached("guilds", guild); guild = await getCached("guilds", guild);