mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 11:28:15 +00:00
chore: deno fmt
This commit is contained in:
@@ -9,8 +9,7 @@ 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;
|
||||||
|
|||||||
@@ -9,8 +9,7 @@ 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[]);
|
||||||
|
|||||||
@@ -5,8 +5,7 @@ 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[];
|
||||||
|
|||||||
@@ -5,8 +5,7 @@ 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)
|
||||||
|
|||||||
@@ -4,8 +4,7 @@ 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,
|
||||||
|
|||||||
@@ -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,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -7,8 +7,7 @@ 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[];
|
||||||
|
|||||||
@@ -15,7 +15,9 @@ 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 =
|
||||||
|
(await rest.runMethod(
|
||||||
|
"get",
|
||||||
endpoints.GUILD_MEMBER(guildId, id),
|
endpoints.GUILD_MEMBER(guildId, id),
|
||||||
)) as MemberCreatePayload;
|
)) as MemberCreatePayload;
|
||||||
|
|
||||||
|
|||||||
@@ -42,18 +42,11 @@ 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
|
membersLeft > 1000 ? 1000 : membersLeft
|
||||||
? 1000
|
}${options?.after ? `&after=${options.after}` : ""}`,
|
||||||
: membersLeft
|
|
||||||
}${
|
|
||||||
options?.after
|
|
||||||
? `&after=${options.after}`
|
|
||||||
: ""
|
|
||||||
}`,
|
|
||||||
)) as DiscordGuildMember[];
|
)) as DiscordGuildMember[];
|
||||||
|
|
||||||
const memberStructures = await Promise.all(
|
const memberStructures = await Promise.all(
|
||||||
|
|||||||
@@ -10,8 +10,7 @@ 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;
|
||||||
|
|||||||
@@ -19,8 +19,7 @@ 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,
|
||||||
|
|||||||
@@ -9,8 +9,7 @@ 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,
|
||||||
|
|||||||
@@ -4,8 +4,7 @@ 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;
|
||||||
|
|||||||
@@ -23,8 +23,7 @@ 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,
|
||||||
|
|||||||
@@ -13,8 +13,7 @@ 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;
|
||||||
|
|||||||
@@ -22,8 +22,7 @@ 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,
|
||||||
|
|||||||
@@ -10,8 +10,7 @@ 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[];
|
||||||
|
|||||||
@@ -4,8 +4,7 @@ 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);
|
||||||
|
|||||||
@@ -10,8 +10,7 @@ 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;
|
||||||
|
|||||||
@@ -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
@@ -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() {},
|
||||||
|
|||||||
@@ -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,15 +55,16 @@ 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(
|
`${encodeURIComponent(key)}=${
|
||||||
value as string | number | boolean
|
encodeURIComponent(
|
||||||
)}`
|
value as string | number | boolean,
|
||||||
|
)
|
||||||
|
}`,
|
||||||
)
|
)
|
||||||
.join("&")
|
.join("&")
|
||||||
: "";
|
: "";
|
||||||
@@ -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,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;
|
||||||
|
|||||||
+31
-30
@@ -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);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user