mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 16:57:22 +00:00
Closes #1119 <Overwrite>.allow & deny optional
This commit is contained in:
@@ -29,8 +29,8 @@ export async function createChannel(bot: Bot, guildId: bigint, options?: CreateG
|
||||
permission_overwrites: options?.permissionOverwrites?.map((perm) => ({
|
||||
id: perm.id.toString(),
|
||||
type: perm.type,
|
||||
allow: bot.utils.calculateBits(perm.allow),
|
||||
deny: bot.utils.calculateBits(perm.deny),
|
||||
allow: perm.allow ? bot.utils.calculateBits(perm.allow) : "0",
|
||||
deny: perm.deny ? bot.utils.calculateBits(perm.deny) : "0",
|
||||
})),
|
||||
type: options?.type || DiscordChannelTypes.GuildText,
|
||||
reason,
|
||||
|
||||
@@ -53,8 +53,8 @@ export async function editChannel(bot: Bot, channelId: bigint, options: ModifyCh
|
||||
? options.permissionOverwrites?.map((overwrite) => {
|
||||
return {
|
||||
...overwrite,
|
||||
allow: bot.utils.calculateBits(overwrite.allow),
|
||||
deny: bot.utils.calculateBits(overwrite.deny),
|
||||
allow: overwrite.allow ? bot.utils.calculateBits(overwrite.allow) : "0",
|
||||
deny: overwrite.deny ? bot.utils.calculateBits(overwrite.deny) : "0",
|
||||
};
|
||||
})
|
||||
: undefined,
|
||||
|
||||
@@ -16,8 +16,8 @@ export async function editChannelOverwrite(
|
||||
"put",
|
||||
bot.constants.endpoints.CHANNEL_OVERWRITE(channelId, overwriteId),
|
||||
{
|
||||
allow: bot.utils.calculateBits(options.allow),
|
||||
deny: bot.utils.calculateBits(options.deny),
|
||||
allow: options.allow ? bot.utils.calculateBits(options.allow) : "0",
|
||||
deny: options.deny ? bot.utils.calculateBits(options.deny) : "0",
|
||||
type: options.type,
|
||||
}
|
||||
);
|
||||
|
||||
@@ -7,9 +7,9 @@ export interface Overwrite {
|
||||
/** Either 0 (role) or 1 (member) */
|
||||
type: DiscordOverwriteTypes;
|
||||
/** Permission bit set */
|
||||
allow: PermissionStrings[];
|
||||
allow?: PermissionStrings[];
|
||||
/** Permission bit set */
|
||||
deny: PermissionStrings[];
|
||||
deny?: PermissionStrings[];
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/resources/channel#overwrite-object */
|
||||
|
||||
+39
-9
@@ -159,7 +159,11 @@ export async function hasChannelPermissions(
|
||||
}
|
||||
|
||||
/** Checks if the bot has these permissions f0r the given channel */
|
||||
export function botHasChannelPermissions(bot: Bot, channel: bigint | DiscordenoChannel, permissions: PermissionStrings[]) {
|
||||
export function botHasChannelPermissions(
|
||||
bot: Bot,
|
||||
channel: bigint | DiscordenoChannel,
|
||||
permissions: PermissionStrings[]
|
||||
) {
|
||||
// Since Bot is a normal member we can use the hasRolePermissions() function
|
||||
return bot.utils.hasChannelPermissions(bot, channel, bot.id, permissions);
|
||||
}
|
||||
@@ -212,7 +216,11 @@ export async function requireGuildPermissions(
|
||||
}
|
||||
|
||||
/** Throws an error if the bot does not have all permissions */
|
||||
export function requireBotGuildPermissions(bot: Bot, guild: bigint | DiscordenoGuild, permissions: PermissionStrings[]) {
|
||||
export function requireBotGuildPermissions(
|
||||
bot: Bot,
|
||||
guild: bigint | DiscordenoGuild,
|
||||
permissions: PermissionStrings[]
|
||||
) {
|
||||
// Since Bot is a normal member we can use the throwOnMissingGuildPermission() function
|
||||
return bot.utils.requireGuildPermissions(bot, guild, bot.id, permissions);
|
||||
}
|
||||
@@ -232,7 +240,11 @@ export async function requireChannelPermissions(
|
||||
}
|
||||
|
||||
/** Throws an error if the bot has not all of the given channel permissions */
|
||||
export function requireBotChannelPermissions(bot: Bot, channel: bigint | DiscordenoChannel, permissions: PermissionStrings[]) {
|
||||
export function requireBotChannelPermissions(
|
||||
bot: Bot,
|
||||
channel: bigint | DiscordenoChannel,
|
||||
permissions: PermissionStrings[]
|
||||
) {
|
||||
// Since Bot is a normal member we can use the throwOnMissingChannelPermission() function
|
||||
return bot.utils.requireChannelPermissions(bot, channel, bot.id, permissions);
|
||||
}
|
||||
@@ -258,12 +270,16 @@ export function calculateBits(permissions: PermissionStrings[]) {
|
||||
}
|
||||
|
||||
/** Internal function to check if the bot has the permissions to set these overwrites */
|
||||
export async function requireOverwritePermissions(bot: Bot, guildOrId: bigint | DiscordenoGuild, overwrites: Overwrite[]) {
|
||||
export async function requireOverwritePermissions(
|
||||
bot: Bot,
|
||||
guildOrId: bigint | DiscordenoGuild,
|
||||
overwrites: Overwrite[]
|
||||
) {
|
||||
let requiredPerms: Set<PermissionStrings> = new Set(["MANAGE_CHANNELS"]);
|
||||
|
||||
overwrites?.forEach((overwrite) => {
|
||||
overwrite.allow.forEach(requiredPerms.add, requiredPerms);
|
||||
overwrite.deny.forEach(requiredPerms.add, requiredPerms);
|
||||
if (overwrite.allow) overwrite.allow.forEach(requiredPerms.add, requiredPerms);
|
||||
if (overwrite.deny) overwrite.deny.forEach(requiredPerms.add, requiredPerms);
|
||||
});
|
||||
|
||||
// MANAGE_ROLES permission can only be set by administrators
|
||||
@@ -275,7 +291,11 @@ export async function requireOverwritePermissions(bot: Bot, guildOrId: bigint |
|
||||
}
|
||||
|
||||
/** Gets the highest role from the member in this guild */
|
||||
export async function highestRole(bot: Bot, guildOrId: bigint | DiscordenoGuild, memberOrId: bigint | DiscordenoMember) {
|
||||
export async function highestRole(
|
||||
bot: Bot,
|
||||
guildOrId: bigint | DiscordenoGuild,
|
||||
memberOrId: bigint | DiscordenoMember
|
||||
) {
|
||||
const guild = await bot.utils.getCached(bot, "guilds", guildOrId);
|
||||
|
||||
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
|
||||
@@ -308,7 +328,12 @@ export async function highestRole(bot: Bot, guildOrId: bigint | DiscordenoGuild,
|
||||
}
|
||||
|
||||
/** Checks if the first role is higher than the second role */
|
||||
export async function higherRolePosition(bot: Bot, guildOrId: bigint | DiscordenoGuild, roleId: bigint, otherRoleId: bigint) {
|
||||
export async function higherRolePosition(
|
||||
bot: Bot,
|
||||
guildOrId: bigint | DiscordenoGuild,
|
||||
roleId: bigint,
|
||||
otherRoleId: bigint
|
||||
) {
|
||||
const guild = await bot.utils.getCached(bot, "guilds", guildOrId);
|
||||
|
||||
if (!guild) return true;
|
||||
@@ -326,7 +351,12 @@ export async function higherRolePosition(bot: Bot, guildOrId: bigint | Discorden
|
||||
}
|
||||
|
||||
/** Checks if the member has a higher position than the given role */
|
||||
export async function isHigherPosition(bot: Bot, guildOrId: bigint | DiscordenoGuild, memberId: bigint, compareRoleId: bigint) {
|
||||
export async function isHigherPosition(
|
||||
bot: Bot,
|
||||
guildOrId: bigint | DiscordenoGuild,
|
||||
memberId: bigint,
|
||||
compareRoleId: bigint
|
||||
) {
|
||||
const guild = await bot.utils.getCached(bot, "guilds", guildOrId);
|
||||
|
||||
if (!guild || guild.ownerId === memberId) return true;
|
||||
|
||||
Reference in New Issue
Block a user