fix: bunch of imports that were missing

This commit is contained in:
Skillz4Killz
2021-04-03 23:30:48 +00:00
committed by GitHub
parent cc46698245
commit 408120c508
24 changed files with 81 additions and 59 deletions
+2 -1
View File
@@ -1,6 +1,7 @@
import { cacheHandlers } from "../../cache.ts"; import { cacheHandlers } from "../../cache.ts";
import { rest } from "../../rest/rest.ts"; import { rest } from "../../rest/rest.ts";
import { DiscordChannelTypes, Errors } from "../../types/mod.ts"; import { DiscordChannelTypes } from "../../types/channels/channel_types.ts";
import { Errors } from "../../types/misc/errors.ts";
import { endpoints } from "../../util/constants.ts"; import { endpoints } from "../../util/constants.ts";
import { botHasChannelPermissions } from "../../util/permissions.ts"; import { botHasChannelPermissions } from "../../util/permissions.ts";
@@ -1,6 +1,7 @@
import { applicationId } from "../../bot.ts"; import { applicationId } from "../../bot.ts";
import { rest } from "../../rest/rest.ts"; import { rest } from "../../rest/rest.ts";
import { structures } from "../../structures/mod.ts"; import { structures } from "../../structures/mod.ts";
import { Errors } from "../../types/misc/errors.ts";
import { endpoints } from "../../util/constants.ts"; import { endpoints } from "../../util/constants.ts";
/** To edit your response to a slash command. If a messageId is not provided it will default to editing the original response. */ /** To edit your response to a slash command. If a messageId is not provided it will default to editing the original response. */
+1
View File
@@ -1,4 +1,5 @@
import { rest } from "../../rest/rest.ts"; import { rest } from "../../rest/rest.ts";
import { Errors } from "../../types/misc/errors.ts";
import { endpoints } from "../../util/constants.ts"; import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts";
import { camelKeysToSnakeCase } from "../../util/utils.ts"; import { camelKeysToSnakeCase } from "../../util/utils.ts";
+1
View File
@@ -1,5 +1,6 @@
import { cacheHandlers } from "../../cache.ts"; import { cacheHandlers } from "../../cache.ts";
import { rest } from "../../rest/rest.ts"; import { rest } from "../../rest/rest.ts";
import { Errors } from "../../types/misc/errors.ts";
import { endpoints } from "../../util/constants.ts"; import { endpoints } from "../../util/constants.ts";
/** Returns the widget for the guild. */ /** Returns the widget for the guild. */
@@ -1,4 +1,5 @@
import { cacheHandlers } from "../../cache.ts"; import { cacheHandlers } from "../../cache.ts";
import { Errors } from "../../types/misc/errors.ts";
import { endpoints } from "../../util/constants.ts"; import { endpoints } from "../../util/constants.ts";
/** Returns the widget image URL for the guild. */ /** Returns the widget image URL for the guild. */
+1
View File
@@ -1,5 +1,6 @@
import { cacheHandlers } from "../../cache.ts"; import { cacheHandlers } from "../../cache.ts";
import { rest } from "../../rest/rest.ts"; import { rest } from "../../rest/rest.ts";
import { Errors } from "../../types/misc/errors.ts";
import { endpoints } from "../../util/constants.ts"; import { endpoints } from "../../util/constants.ts";
import { import {
botHasChannelPermissions, botHasChannelPermissions,
+1
View File
@@ -1,4 +1,5 @@
import { rest } from "../../rest/rest.ts"; import { rest } from "../../rest/rest.ts";
import { Errors } from "../../types/misc/errors.ts";
import { endpoints } from "../../util/constants.ts"; import { endpoints } from "../../util/constants.ts";
import { urlToBase64 } from "../../util/utils.ts"; import { urlToBase64 } from "../../util/utils.ts";
+1
View File
@@ -1,6 +1,7 @@
import { cacheHandlers } from "../../cache.ts"; import { cacheHandlers } from "../../cache.ts";
import { rest } from "../../rest/rest.ts"; import { rest } from "../../rest/rest.ts";
import { structures } from "../../structures/mod.ts"; import { structures } from "../../structures/mod.ts";
import { Errors } from "../../types/misc/errors.ts";
import { endpoints } from "../../util/constants.ts"; import { endpoints } from "../../util/constants.ts";
import { import {
requireBotChannelPermissions, requireBotChannelPermissions,
+3 -1
View File
@@ -1,5 +1,7 @@
import { identifyPayload } from "../../bot.ts"; import { identifyPayload } from "../../bot.ts";
import { Member } from "../../structures/mod.ts"; import { Member } from "../../structures/mod.ts";
import { DiscordGatewayIntents } from "../../types/gateway/gateway_intents.ts";
import { Errors } from "../../types/misc/errors.ts";
import { Collection } from "../../util/collection.ts"; import { Collection } from "../../util/collection.ts";
import { requestAllMembers } from "../../ws/shard_manager.ts"; import { requestAllMembers } from "../../ws/shard_manager.ts";
@@ -19,7 +21,7 @@ export function fetchMembers(
// You can request 1 member without the intent // You can request 1 member without the intent
if ( if (
(!options?.limit || options.limit > 1) && (!options?.limit || options.limit > 1) &&
!(identifyPayload.intents && Intents.GUILD_MEMBERS) !(identifyPayload.intents && DiscordGatewayIntents.GUILD_MEMBERS)
) { ) {
throw new Error(Errors.MISSING_INTENT_GUILD_MEMBERS); throw new Error(Errors.MISSING_INTENT_GUILD_MEMBERS);
} }
-1
View File
@@ -1,5 +1,4 @@
import { cacheHandlers } from "../../cache.ts"; import { cacheHandlers } from "../../cache.ts";
import { RequestManager } from "../../rest/request_manager.ts";
import { rest } from "../../rest/rest.ts"; import { rest } from "../../rest/rest.ts";
import { structures } from "../../structures/mod.ts"; import { structures } from "../../structures/mod.ts";
import { endpoints } from "../../util/constants.ts"; import { endpoints } from "../../util/constants.ts";
+5 -2
View File
@@ -2,6 +2,9 @@ import { identifyPayload } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts"; import { cacheHandlers } from "../../cache.ts";
import { rest } from "../../rest/rest.ts"; import { rest } from "../../rest/rest.ts";
import { Member, structures } from "../../structures/mod.ts"; import { Member, structures } from "../../structures/mod.ts";
import { DiscordGatewayIntents } from "../../types/gateway/gateway_intents.ts";
import { DiscordGuildMember } from "../../types/guilds/guild_member.ts";
import { Errors } from "../../types/misc/errors.ts";
import { Collection } from "../../util/collection.ts"; import { Collection } from "../../util/collection.ts";
import { endpoints } from "../../util/constants.ts"; import { endpoints } from "../../util/constants.ts";
@@ -14,7 +17,7 @@ import { endpoints } from "../../util/constants.ts";
* GW(fetchMembers): 120/m(PER shard) rate limit. Meaning if you have 8 shards your limit is 960/m. * GW(fetchMembers): 120/m(PER shard) rate limit. Meaning if you have 8 shards your limit is 960/m.
*/ */
export async function getMembers(guildId: string, options?: GetMemberOptions) { export async function getMembers(guildId: string, options?: GetMemberOptions) {
if (!(identifyPayload.intents && Intents.GUILD_MEMBERS)) { if (!(identifyPayload.intents && DiscordGatewayIntents.GUILD_MEMBERS)) {
throw new Error(Errors.MISSING_INTENT_GUILD_MEMBERS); throw new Error(Errors.MISSING_INTENT_GUILD_MEMBERS);
} }
@@ -51,7 +54,7 @@ export async function getMembers(guildId: string, options?: GetMemberOptions) {
? `&after=${options.after}` ? `&after=${options.after}`
: "" : ""
}`, }`,
)) as MemberCreatePayload[]; )) as DiscordGuildMember[];
const memberStructures = await Promise.all( const memberStructures = await Promise.all(
result.map(async (member) => { result.map(async (member) => {
+1
View File
@@ -1,5 +1,6 @@
import { botId } from "../../bot.ts"; import { botId } from "../../bot.ts";
import { rest } from "../../rest/rest.ts"; import { rest } from "../../rest/rest.ts";
import { Errors } from "../../types/misc/errors.ts";
import { endpoints } from "../../util/constants.ts"; import { endpoints } from "../../util/constants.ts";
import { import {
highestRole, highestRole,
+1
View File
@@ -1,4 +1,5 @@
import { rest } from "../../rest/rest.ts"; import { rest } from "../../rest/rest.ts";
import { Errors } from "../../types/misc/errors.ts";
import { endpoints } from "../../util/constants.ts"; import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts";
import { camelKeysToSnakeCase } from "../../util/utils.ts"; import { camelKeysToSnakeCase } from "../../util/utils.ts";
+1
View File
@@ -1,4 +1,5 @@
import { rest } from "../../rest/rest.ts"; import { rest } from "../../rest/rest.ts";
import { Errors } from "../../types/misc/errors.ts";
import { endpoints } from "../../util/constants.ts"; import { endpoints } from "../../util/constants.ts";
import { requireBotChannelPermissions } from "../../util/permissions.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts";
+1
View File
@@ -1,6 +1,7 @@
import { botId } from "../../bot.ts"; import { botId } from "../../bot.ts";
import { rest } from "../../rest/rest.ts"; import { rest } from "../../rest/rest.ts";
import { Message, structures } from "../../structures/mod.ts"; import { Message, structures } from "../../structures/mod.ts";
import { Errors } from "../../types/misc/errors.ts";
import { endpoints } from "../../util/constants.ts"; import { endpoints } from "../../util/constants.ts";
import { requireBotChannelPermissions } from "../../util/permissions.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts";
+2 -1
View File
@@ -2,7 +2,8 @@ import { cacheHandlers } from "../../cache.ts";
import { rest } from "../../rest/rest.ts"; import { rest } from "../../rest/rest.ts";
import { structures } from "../../structures/mod.ts"; import { structures } from "../../structures/mod.ts";
import { DiscordChannelTypes } from "../../types/channels/channel_types.ts"; import { DiscordChannelTypes } from "../../types/channels/channel_types.ts";
import { PermissionStrings } from "../../types/mod.ts"; import { Errors } from "../../types/misc/errors.ts";
import { PermissionStrings } from "../../types/permissions/permission_strings.ts";
import { endpoints } from "../../util/constants.ts"; import { endpoints } from "../../util/constants.ts";
import { requireBotChannelPermissions } from "../../util/permissions.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts";
+1
View File
@@ -1,5 +1,6 @@
import { botId } from "../../bot.ts"; import { botId } from "../../bot.ts";
import { rest } from "../../rest/rest.ts"; import { rest } from "../../rest/rest.ts";
import { Errors } from "../../types/misc/errors.ts";
import { endpoints } from "../../util/constants.ts"; import { endpoints } from "../../util/constants.ts";
import { import {
isHigherPosition, isHigherPosition,
+1
View File
@@ -1,5 +1,6 @@
import { botId } from "../../bot.ts"; import { botId } from "../../bot.ts";
import { rest } from "../../rest/rest.ts"; import { rest } from "../../rest/rest.ts";
import { Errors } from "../../types/misc/errors.ts";
import { endpoints } from "../../util/constants.ts"; import { endpoints } from "../../util/constants.ts";
import { import {
isHigherPosition, isHigherPosition,
+1
View File
@@ -1,4 +1,5 @@
import { rest } from "../../rest/rest.ts"; import { rest } from "../../rest/rest.ts";
import { Errors } from "../../types/misc/errors.ts";
import { endpoints } from "../../util/constants.ts"; import { endpoints } from "../../util/constants.ts";
import { requireBotChannelPermissions } from "../../util/permissions.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts";
import { urlToBase64 } from "../../util/utils.ts"; import { urlToBase64 } from "../../util/utils.ts";
@@ -1,5 +1,6 @@
import { rest } from "../../rest/rest.ts"; import { rest } from "../../rest/rest.ts";
import { structures } from "../../structures/mod.ts"; import { structures } from "../../structures/mod.ts";
import { Errors } from "../../types/misc/errors.ts";
import { endpoints } from "../../util/constants.ts"; import { endpoints } from "../../util/constants.ts";
export async function editWebhookMessage( export async function editWebhookMessage(
+1
View File
@@ -1,5 +1,6 @@
import { rest } from "../../rest/rest.ts"; import { rest } from "../../rest/rest.ts";
import { structures } from "../../structures/mod.ts"; import { structures } from "../../structures/mod.ts";
import { Errors } from "../../types/misc/errors.ts";
import { endpoints } from "../../util/constants.ts"; import { endpoints } from "../../util/constants.ts";
/** Execute a webhook with webhook Id and webhook token */ /** Execute a webhook with webhook Id and webhook token */
+4
View File
@@ -1,3 +1,7 @@
import { Errors } from "../types/misc/errors.ts";
import { IMAGE_BASE_URL } from "../util/constants.ts";
import { API_VERSION } from "../util/constants.ts";
import { BASE_URL } from "../util/constants.ts";
import { rest } from "./rest.ts"; import { rest } from "./rest.ts";
export function runMethod( export function runMethod(
+47 -52
View File
@@ -1,34 +1,31 @@
import { botId } from "../bot.ts"; import { botId } from "../bot.ts";
import { cacheHandlers } from "../cache.ts"; import { cacheHandlers } from "../cache.ts";
import { Channel, Guild, Member, Role } from "../structures/mod.ts"; import { Channel, Guild, Member, Role } from "../structures/mod.ts";
import { import { Errors } from "../types/misc/errors.ts";
DiscordBitwisePermissionFlags, import { DiscordBitwisePermissionFlags } from "../types/permissions/bitwise_permission_flags.ts";
PermissionStrings, import { PermissionStrings } from "../types/permissions/permission_strings.ts";
} from "../types/mod.ts";
async function getCached( async function getCached(table: "guilds", key: string | Guild): Promise<Guild>;
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 = typeof key === "string" const cached =
? // @ts-ignore TS is wrong here typeof key === "string"
(await cacheHandlers.get(table, key)) ? // @ts-ignore TS is wrong here
: key; await cacheHandlers.get(table, 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]
); );
} }
@@ -38,7 +35,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);
@@ -63,7 +60,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);
@@ -74,12 +71,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
@@ -106,7 +103,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);
@@ -119,14 +116,14 @@ 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: Permission[], 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(Permissions[permission]), BigInt(permissionBits) & BigInt(DiscordBitwisePermissionFlags[permission])
); );
} }
@@ -134,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: Permission[], 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);
@@ -145,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: Permission[], 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);
@@ -155,13 +152,10 @@ export function botHasGuildPermissions(
export async function hasChannelPermissions( export async function hasChannelPermissions(
channel: string | Channel, channel: string | Channel,
member: string | Member, member: string | Member,
permissions: Permission[], permissions: PermissionStrings[]
) { ) {
// First we need the overwrite bits this member has // First we need the overwrite bits this member has
const channelOverwrites = await calculateChannelOverwrites( const channelOverwrites = await calculateChannelOverwrites(channel, member);
channel,
member,
);
// Second use the validatePermissions function to check if the member has every permission // Second use the validatePermissions function to check if the member has every permission
return validatePermissions(channelOverwrites, permissions); return validatePermissions(channelOverwrites, permissions);
} }
@@ -169,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: Permission[], 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);
@@ -178,14 +172,16 @@ 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 [];
return permissions.filter( return permissions.filter(
(permission) => (permission) =>
!(BigInt(permissionBits) & !(
BigInt(DiscordBitwisePermissionFlags[permission])), BigInt(permissionBits) &
BigInt(DiscordBitwisePermissionFlags[permission])
)
); );
} }
@@ -193,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: Permission[], 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);
@@ -205,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: Permission[], 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);
@@ -217,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: Permission[], permissions: PermissionStrings[]
) { ) {
const missing = await getMissingGuildPermissions(guild, member, permissions); const missing = await getMissingGuildPermissions(guild, member, permissions);
if (missing.length) { if (missing.length) {
@@ -229,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: Permission[], 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);
@@ -239,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: Permission[], 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
@@ -255,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: Permission[], 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,19 +259,19 @@ export function requireBotChannelPermissions(
/** This function converts a bitwise string to permission strings */ /** This function converts a bitwise string to permission strings */
export function calculatePermissions(permissionBits: bigint) { export function calculatePermissions(permissionBits: bigint) {
return Object.keys(Permissions).filter((permission) => { return Object.keys(DiscordBitwisePermissionFlags).filter((permission) => {
// 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(Permissions[permission as Permission]); return permissionBits & BigInt(DiscordBitwisePermissionFlags[permission as PermissionStrings]);
}) as Permission[]; }) as PermissionStrings[];
} }
/** This function converts an array of permissions into the bitwise string. */ /** This function converts an array of permissions into the bitwise string. */
export function calculateBits(permissions: Permission[]) { export function calculateBits(permissions: PermissionStrings[]) {
return permissions return permissions
.reduce((bits, perm) => { .reduce((bits, perm) => {
bits |= BigInt(Permissions[perm]); bits |= BigInt(DiscordBitwisePermissionFlags[perm]);
return bits; return bits;
}, 0n) }, 0n)
.toString(); .toString();
@@ -284,14 +280,13 @@ export function calculateBits(permissions: Permission[]) {
/** 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);
// Get the roles from the member // Get the roles from the member
const memberRoles = ( const memberRoles = (await getCached("members", member)).guilds.get(guild.id)
await getCached("members", member) ?.roles;
).guilds.get(guild.id)?.roles;
// This member has no roles so the highest one is the @everyone role // This member has no roles so the highest one is the @everyone role
if (!memberRoles) return guild.roles.get(guild.id) as Role; if (!memberRoles) return guild.roles.get(guild.id) as Role;
@@ -321,7 +316,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);
@@ -341,7 +336,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);
+2 -1
View File
@@ -1,5 +1,6 @@
import { encode } from "../../deps.ts"; import { encode } from "../../deps.ts";
import { DiscordGatewayOpcodes } from "../types/mod.ts"; import { DiscordGatewayOpcodes } from "../types/codes/gateway_opcodes.ts";
import { Errors } from "../types/misc/errors.ts";
import { basicShards, sendWS } from "../ws/shard.ts"; import { basicShards, sendWS } from "../ws/shard.ts";
import { SLASH_COMMANDS_NAME_REGEX } from "./constants.ts"; import { SLASH_COMMANDS_NAME_REGEX } from "./constants.ts";