mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-02 00:40:07 +00:00
* fix(plugins): await old function return * Update plugins/permissions/src/channels/stage.ts lol Co-authored-by: TriForMine <quentin.nicolini@hotmail.fr> Co-authored-by: TriForMine <quentin.nicolini@hotmail.fr>
65 lines
1.8 KiB
TypeScript
65 lines
1.8 KiB
TypeScript
import { BotWithCache, PermissionStrings } from "../deps.ts";
|
|
import { requireBotChannelPermissions, requireBotGuildPermissions } from "./permissions.ts";
|
|
|
|
export default function editMember(bot: BotWithCache) {
|
|
const editMemberOld = bot.helpers.editMember;
|
|
|
|
bot.helpers.editMember = async function (guildId, memberId, options) {
|
|
const requiredPerms: Set<PermissionStrings> = new Set();
|
|
|
|
if (options.nick) {
|
|
if (options.nick.length > 32) {
|
|
throw new Error("NICKNAMES_MAX_LENGTH");
|
|
}
|
|
requiredPerms.add("MANAGE_NICKNAMES");
|
|
}
|
|
|
|
if (options.roles) requiredPerms.add("MANAGE_ROLES");
|
|
|
|
if (
|
|
options.mute !== undefined || options.deaf !== undefined ||
|
|
options.channelId !== undefined
|
|
) {
|
|
const memberVoiceState = (await bot.guilds.get(guildId))
|
|
?.voiceStates.get(memberId);
|
|
|
|
if (!memberVoiceState?.channelId) {
|
|
throw new Error("MEMBER_NOT_IN_VOICE_CHANNEL");
|
|
}
|
|
|
|
if (options.mute !== undefined) {
|
|
requiredPerms.add("MUTE_MEMBERS");
|
|
}
|
|
|
|
if (options.deaf !== undefined) {
|
|
requiredPerms.add("DEAFEN_MEMBERS");
|
|
}
|
|
|
|
if (options.channelId) {
|
|
const requiredVoicePerms: Set<PermissionStrings> = new Set([
|
|
"CONNECT",
|
|
"MOVE_MEMBERS",
|
|
]);
|
|
if (memberVoiceState) {
|
|
await requireBotChannelPermissions(
|
|
bot,
|
|
memberVoiceState?.channelId,
|
|
[
|
|
...requiredVoicePerms,
|
|
],
|
|
);
|
|
}
|
|
await requireBotChannelPermissions(bot, options.channelId, [
|
|
...requiredVoicePerms,
|
|
]);
|
|
}
|
|
}
|
|
|
|
await requireBotGuildPermissions(bot, guildId, [
|
|
...requiredPerms,
|
|
]);
|
|
|
|
return await editMemberOld(guildId, memberId, options);
|
|
};
|
|
}
|