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 { 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 { botHasChannelPermissions } from "../../util/permissions.ts";
@@ -1,6 +1,7 @@
import { applicationId } from "../../bot.ts";
import { rest } from "../../rest/rest.ts";
import { structures } from "../../structures/mod.ts";
import { Errors } from "../../types/misc/errors.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. */
+1
View File
@@ -1,4 +1,5 @@
import { rest } from "../../rest/rest.ts";
import { Errors } from "../../types/misc/errors.ts";
import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts";
import { camelKeysToSnakeCase } from "../../util/utils.ts";
+1
View File
@@ -1,5 +1,6 @@
import { cacheHandlers } from "../../cache.ts";
import { rest } from "../../rest/rest.ts";
import { Errors } from "../../types/misc/errors.ts";
import { endpoints } from "../../util/constants.ts";
/** Returns the widget for the guild. */
@@ -1,4 +1,5 @@
import { cacheHandlers } from "../../cache.ts";
import { Errors } from "../../types/misc/errors.ts";
import { endpoints } from "../../util/constants.ts";
/** Returns the widget image URL for the guild. */
+1
View File
@@ -1,5 +1,6 @@
import { cacheHandlers } from "../../cache.ts";
import { rest } from "../../rest/rest.ts";
import { Errors } from "../../types/misc/errors.ts";
import { endpoints } from "../../util/constants.ts";
import {
botHasChannelPermissions,
+1
View File
@@ -1,4 +1,5 @@
import { rest } from "../../rest/rest.ts";
import { Errors } from "../../types/misc/errors.ts";
import { endpoints } from "../../util/constants.ts";
import { urlToBase64 } from "../../util/utils.ts";
+1
View File
@@ -1,6 +1,7 @@
import { cacheHandlers } from "../../cache.ts";
import { rest } from "../../rest/rest.ts";
import { structures } from "../../structures/mod.ts";
import { Errors } from "../../types/misc/errors.ts";
import { endpoints } from "../../util/constants.ts";
import {
requireBotChannelPermissions,
+3 -1
View File
@@ -1,5 +1,7 @@
import { identifyPayload } from "../../bot.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 { requestAllMembers } from "../../ws/shard_manager.ts";
@@ -19,7 +21,7 @@ export function fetchMembers(
// You can request 1 member without the intent
if (
(!options?.limit || options.limit > 1) &&
!(identifyPayload.intents && Intents.GUILD_MEMBERS)
!(identifyPayload.intents && DiscordGatewayIntents.GUILD_MEMBERS)
) {
throw new Error(Errors.MISSING_INTENT_GUILD_MEMBERS);
}
-1
View File
@@ -1,5 +1,4 @@
import { cacheHandlers } from "../../cache.ts";
import { RequestManager } from "../../rest/request_manager.ts";
import { rest } from "../../rest/rest.ts";
import { structures } from "../../structures/mod.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 { rest } from "../../rest/rest.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 { 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.
*/
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);
}
@@ -51,7 +54,7 @@ export async function getMembers(guildId: string, options?: GetMemberOptions) {
? `&after=${options.after}`
: ""
}`,
)) as MemberCreatePayload[];
)) as DiscordGuildMember[];
const memberStructures = await Promise.all(
result.map(async (member) => {
+1
View File
@@ -1,5 +1,6 @@
import { botId } from "../../bot.ts";
import { rest } from "../../rest/rest.ts";
import { Errors } from "../../types/misc/errors.ts";
import { endpoints } from "../../util/constants.ts";
import {
highestRole,
+1
View File
@@ -1,4 +1,5 @@
import { rest } from "../../rest/rest.ts";
import { Errors } from "../../types/misc/errors.ts";
import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts";
import { camelKeysToSnakeCase } from "../../util/utils.ts";
+1
View File
@@ -1,4 +1,5 @@
import { rest } from "../../rest/rest.ts";
import { Errors } from "../../types/misc/errors.ts";
import { endpoints } from "../../util/constants.ts";
import { requireBotChannelPermissions } from "../../util/permissions.ts";
+1
View File
@@ -1,6 +1,7 @@
import { botId } from "../../bot.ts";
import { rest } from "../../rest/rest.ts";
import { Message, structures } from "../../structures/mod.ts";
import { Errors } from "../../types/misc/errors.ts";
import { endpoints } from "../../util/constants.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 { structures } from "../../structures/mod.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 { requireBotChannelPermissions } from "../../util/permissions.ts";
+1
View File
@@ -1,5 +1,6 @@
import { botId } from "../../bot.ts";
import { rest } from "../../rest/rest.ts";
import { Errors } from "../../types/misc/errors.ts";
import { endpoints } from "../../util/constants.ts";
import {
isHigherPosition,
+1
View File
@@ -1,5 +1,6 @@
import { botId } from "../../bot.ts";
import { rest } from "../../rest/rest.ts";
import { Errors } from "../../types/misc/errors.ts";
import { endpoints } from "../../util/constants.ts";
import {
isHigherPosition,
+1
View File
@@ -1,4 +1,5 @@
import { rest } from "../../rest/rest.ts";
import { Errors } from "../../types/misc/errors.ts";
import { endpoints } from "../../util/constants.ts";
import { requireBotChannelPermissions } from "../../util/permissions.ts";
import { urlToBase64 } from "../../util/utils.ts";
@@ -1,5 +1,6 @@
import { rest } from "../../rest/rest.ts";
import { structures } from "../../structures/mod.ts";
import { Errors } from "../../types/misc/errors.ts";
import { endpoints } from "../../util/constants.ts";
export async function editWebhookMessage(
+1
View File
@@ -1,5 +1,6 @@
import { rest } from "../../rest/rest.ts";
import { structures } from "../../structures/mod.ts";
import { Errors } from "../../types/misc/errors.ts";
import { endpoints } from "../../util/constants.ts";
/** 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";
export function runMethod(
+47 -52
View File
@@ -1,34 +1,31 @@
import { botId } from "../bot.ts";
import { cacheHandlers } from "../cache.ts";
import { Channel, Guild, Member, Role } from "../structures/mod.ts";
import {
DiscordBitwisePermissionFlags,
PermissionStrings,
} from "../types/mod.ts";
import { Errors } from "../types/misc/errors.ts";
import { DiscordBitwisePermissionFlags } from "../types/permissions/bitwise_permission_flags.ts";
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(
table: "channels",
key: string | Channel,
key: string | Channel
): Promise<Channel>;
async function getCached(
table: "members",
key: string | Member,
key: string | Member
): Promise<Member>;
async function getCached(
table: "guilds" | "channels" | "members",
key: string | Guild | Channel | Member,
key: string | Guild | Channel | Member
) {
const cached = typeof key === "string"
? // @ts-ignore TS is wrong here
(await cacheHandlers.get(table, key))
: key;
const cached =
typeof key === "string"
? // @ts-ignore TS is wrong here
await cacheHandlers.get(table, key)
: key;
if (!cached || typeof cached === "string") {
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 */
export async function calculateBasePermissions(
guild: string | Guild,
member: string | Member,
member: string | Member
) {
guild = await getCached("guilds", guild);
member = await getCached("members", member);
@@ -63,7 +60,7 @@ export async function calculateBasePermissions(
/** Calculates the permissions this member has for the given Channel */
export async function calculateChannelOverwrites(
channel: string | Channel,
member: string | Member,
member: string | Member
) {
channel = await getCached("channels", channel);
@@ -74,12 +71,12 @@ export async function calculateChannelOverwrites(
// Get all the role permissions this member already has
let permissions = BigInt(
await calculateBasePermissions(channel.guildId, member),
await calculateBasePermissions(channel.guildId, member)
);
// First calculate @everyone overwrites since these have the lowest priority
const overwriteEveryone = channel?.permissionOverwrites.find(
(overwrite) => overwrite.id === (channel as Channel).guildId,
(overwrite) => overwrite.id === (channel as Channel).guildId
);
if (overwriteEveryone) {
// 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
const overwriteMember = overwrites.find(
(overwrite) => overwrite.id === (member as Member).id,
(overwrite) => overwrite.id === (member as Member).id
);
if (overwriteMember) {
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` */
export function validatePermissions(
permissionBits: string,
permissions: Permission[],
permissions: PermissionStrings[]
) {
if (BigInt(permissionBits) & 8n) return true;
return permissions.every(
(permission) =>
// 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(
guild: string | Guild,
member: string | Member,
permissions: Permission[],
permissions: PermissionStrings[]
) {
// First we need the role permission bits this member has
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 */
export function botHasGuildPermissions(
guild: string | Guild,
permissions: Permission[],
permissions: PermissionStrings[]
) {
// Since Bot is a normal member we can use the hasRolePermissions() function
return hasGuildPermissions(guild, botId, permissions);
@@ -155,13 +152,10 @@ export function botHasGuildPermissions(
export async function hasChannelPermissions(
channel: string | Channel,
member: string | Member,
permissions: Permission[],
permissions: PermissionStrings[]
) {
// First we need the overwrite bits this member has
const channelOverwrites = await calculateChannelOverwrites(
channel,
member,
);
const channelOverwrites = await calculateChannelOverwrites(channel, member);
// Second use the validatePermissions function to check if the member has every permission
return validatePermissions(channelOverwrites, permissions);
}
@@ -169,7 +163,7 @@ export async function hasChannelPermissions(
/** Checks if the bot has these permissions f0r the given channel */
export function botHasChannelPermissions(
channel: string | Channel,
permissions: Permission[],
permissions: PermissionStrings[]
) {
// Since Bot is a normal member we can use the hasRolePermissions() function
return hasChannelPermissions(channel, botId, permissions);
@@ -178,14 +172,16 @@ export function botHasChannelPermissions(
/** Returns the permissions that are not in the given permissionBits */
export function missingPermissions(
permissionBits: string,
permissions: PermissionStrings[],
permissions: PermissionStrings[]
) {
if (BigInt(permissionBits) & 8n) return [];
return permissions.filter(
(permission) =>
!(BigInt(permissionBits) &
BigInt(DiscordBitwisePermissionFlags[permission])),
!(
BigInt(permissionBits) &
BigInt(DiscordBitwisePermissionFlags[permission])
)
);
}
@@ -193,7 +189,7 @@ export function missingPermissions(
export async function getMissingGuildPermissions(
guild: string | Guild,
member: string | Member,
permissions: Permission[],
permissions: PermissionStrings[]
) {
// First we need the role permissino bits this member has
const permissionBits = await calculateBasePermissions(guild, member);
@@ -205,7 +201,7 @@ export async function getMissingGuildPermissions(
export async function getMissingChannelPermissions(
channel: string | Channel,
member: string | Member,
permissions: Permission[],
permissions: PermissionStrings[]
) {
// First we need the role permissino bits this member has
const permissionBits = await calculateChannelOverwrites(channel, member);
@@ -217,7 +213,7 @@ export async function getMissingChannelPermissions(
export async function requireGuildPermissions(
guild: string | Guild,
member: string | Member,
permissions: Permission[],
permissions: PermissionStrings[]
) {
const missing = await getMissingGuildPermissions(guild, member, permissions);
if (missing.length) {
@@ -229,7 +225,7 @@ export async function requireGuildPermissions(
/** Throws an error if the bot does not have all permissions */
export function requireBotGuildPermissions(
guild: string | Guild,
permissions: Permission[],
permissions: PermissionStrings[]
) {
// Since Bot is a normal member we can use the throwOnMissingGuildPermission() function
return requireGuildPermissions(guild, botId, permissions);
@@ -239,12 +235,12 @@ export function requireBotGuildPermissions(
export async function requireChannelPermissions(
channel: string | Channel,
member: string | Member,
permissions: Permission[],
permissions: PermissionStrings[]
) {
const missing = await getMissingChannelPermissions(
channel,
member,
permissions,
permissions
);
if (missing.length) {
// 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 */
export function requireBotChannelPermissions(
channel: string | Channel,
permissions: Permission[],
permissions: PermissionStrings[]
) {
// Since Bot is a normal member we can use the throwOnMissingChannelPermission() function
return requireChannelPermissions(channel, botId, permissions);
@@ -263,19 +259,19 @@ export function requireBotChannelPermissions(
/** This function converts a bitwise string to permission strings */
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
if (Number(permission)) return false;
// Check if permissionBits has this permission
return permissionBits & BigInt(Permissions[permission as Permission]);
}) as Permission[];
return permissionBits & BigInt(DiscordBitwisePermissionFlags[permission as PermissionStrings]);
}) as PermissionStrings[];
}
/** This function converts an array of permissions into the bitwise string. */
export function calculateBits(permissions: Permission[]) {
export function calculateBits(permissions: PermissionStrings[]) {
return permissions
.reduce((bits, perm) => {
bits |= BigInt(Permissions[perm]);
bits |= BigInt(DiscordBitwisePermissionFlags[perm]);
return bits;
}, 0n)
.toString();
@@ -284,14 +280,13 @@ export function calculateBits(permissions: Permission[]) {
/** Gets the highest role from the member in this guild */
export async function highestRole(
guild: string | Guild,
member: string | Member,
member: string | Member
) {
guild = await getCached("guilds", guild);
// Get the roles from the member
const memberRoles = (
await getCached("members", member)
).guilds.get(guild.id)?.roles;
const memberRoles = (await getCached("members", member)).guilds.get(guild.id)
?.roles;
// This member has no roles so the highest one is the @everyone role
if (!memberRoles) return guild.roles.get(guild.id) as Role;
@@ -321,7 +316,7 @@ export async function highestRole(
export async function higherRolePosition(
guild: string | Guild,
roleId: string,
otherRoleId: string,
otherRoleId: string
) {
guild = await getCached("guilds", guild);
@@ -341,7 +336,7 @@ export async function higherRolePosition(
export async function isHigherPosition(
guild: string | Guild,
memberId: string,
compareRoleId: string,
compareRoleId: string
) {
guild = await getCached("guilds", guild);
+2 -1
View File
@@ -1,5 +1,6 @@
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 { SLASH_COMMANDS_NAME_REGEX } from "./constants.ts";