mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 11:28:15 +00:00
Add nicer Way to edit Channel Permission
This commit is contained in:
@@ -13,11 +13,13 @@ import {
|
|||||||
GetMessagesBefore,
|
GetMessagesBefore,
|
||||||
MessageContent,
|
MessageContent,
|
||||||
MessageCreateOptions,
|
MessageCreateOptions,
|
||||||
|
Overwrite,
|
||||||
Permission,
|
Permission,
|
||||||
Permissions,
|
Permissions,
|
||||||
RawOverwrite,
|
RawOverwrite,
|
||||||
WebhookPayload,
|
WebhookPayload,
|
||||||
} from "../types/types.ts";
|
} from "../types/types.ts";
|
||||||
|
import { cache } from "../utils/cache.ts";
|
||||||
import { endpoints } from "../utils/constants.ts";
|
import { endpoints } from "../utils/constants.ts";
|
||||||
import { botHasChannelPermissions } from "../utils/permissions.ts";
|
import { botHasChannelPermissions } from "../utils/permissions.ts";
|
||||||
|
|
||||||
@@ -422,6 +424,55 @@ export async function editChannel(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function editChannelOverwrite(
|
||||||
|
channelID: string,
|
||||||
|
overwrite: Overwrite,
|
||||||
|
reason?: string,
|
||||||
|
) {
|
||||||
|
const hasManageChannelPerm = await botHasChannelPermissions(
|
||||||
|
channelID,
|
||||||
|
["MANAGE_CHANNELS"],
|
||||||
|
);
|
||||||
|
if (!hasManageChannelPerm) {
|
||||||
|
throw new Error(Errors.MISSING_MANAGE_CHANNELS);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { allow, deny, ...info } = overwrite;
|
||||||
|
let channel = cache.channels.get(channelID);
|
||||||
|
|
||||||
|
if (!channel) return Errors.CHANNEL_NOT_FOUND;
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
permission_overwrites: [
|
||||||
|
...(channel?.permissionOverwrites || []).map((ro) => ({
|
||||||
|
id: ro.id,
|
||||||
|
type: ro.type,
|
||||||
|
allow: ro.allow,
|
||||||
|
deny: ro.deny,
|
||||||
|
})),
|
||||||
|
{
|
||||||
|
...info,
|
||||||
|
allow: allow.reduce(
|
||||||
|
(bits, perm) => bits |= BigInt(Permissions[perm]),
|
||||||
|
BigInt(0),
|
||||||
|
).toString(),
|
||||||
|
deny: deny.reduce(
|
||||||
|
(bits, perm) => bits |= BigInt(Permissions[perm]),
|
||||||
|
BigInt(0),
|
||||||
|
).toString(),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
return RequestManager.patch(
|
||||||
|
endpoints.GUILD_CHANNEL(channelID),
|
||||||
|
{
|
||||||
|
...payload,
|
||||||
|
reason,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/** Follow a News Channel to send messages to a target channel. Requires the `MANAGE_WEBHOOKS` permission in the target channel. Returns the webhook id. */
|
/** Follow a News Channel to send messages to a target channel. Requires the `MANAGE_WEBHOOKS` permission in the target channel. Returns the webhook id. */
|
||||||
export async function followChannel(
|
export async function followChannel(
|
||||||
sourceChannelID: string,
|
sourceChannelID: string,
|
||||||
|
|||||||
Reference in New Issue
Block a user