Files
discordeno/plugins/permissions/src/guilds/events.ts
T
ITOHandTriForMine 7204665e77 fix(plugins): await old function return (#2065)
* 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>
2022-02-15 20:06:06 +00:00

142 lines
4.0 KiB
TypeScript

import { BotWithCache, ScheduledEventEntityType } from "../../deps.ts";
import { requireBotChannelPermissions, requireBotGuildPermissions } from "../permissions.ts";
export function createScheduledEvent(bot: BotWithCache) {
const createScheduledEventOld = bot.helpers.createScheduledEvent;
bot.helpers.createScheduledEvent = async function (guildId, options) {
if (options.entityType === ScheduledEventEntityType.StageInstance) {
if (!options.channelId) {
throw new Error(
"A channel id is required for creating a stage scheduled event.",
);
}
requireBotChannelPermissions(bot, options.channelId, [
"MANAGE_CHANNELS",
"MUTE_MEMBERS",
"MOVE_MEMBERS",
]);
// MANAGE_EVENTS at the guild level or at least MANAGE_EVENTS for the channel_id associated with the event
try {
requireBotGuildPermissions(bot, guildId, [
"MANAGE_EVENTS",
]);
} catch {
requireBotChannelPermissions(bot, options.channelId, [
"MANAGE_EVENTS",
]);
}
return createScheduledEventOld(guildId, options);
}
if (options.entityType === ScheduledEventEntityType.Voice) {
if (!options.channelId) {
throw new Error(
"A channel id is required for creating a voice scheduled event.",
);
}
requireBotChannelPermissions(bot, options.channelId, [
"VIEW_CHANNEL",
"CONNECT",
]);
// MANAGE_EVENTS at the guild level or at least MANAGE_EVENTS for the channel_id associated with the event
try {
requireBotGuildPermissions(bot, guildId, [
"MANAGE_EVENTS",
]);
} catch {
requireBotChannelPermissions(bot, options.channelId, [
"MANAGE_EVENTS",
]);
}
return createScheduledEventOld(guildId, options);
}
// EXTERNAL EVENTS
requireBotGuildPermissions(bot, guildId, [
"MANAGE_EVENTS",
]);
return await createScheduledEventOld(guildId, options);
};
}
export function editScheduledEvent(bot: BotWithCache) {
const editScheduledEventOld = bot.helpers.editScheduledEvent;
bot.helpers.editScheduledEvent = async function (guildId, eventId, options) {
if (options.entityType === ScheduledEventEntityType.StageInstance) {
if (!options.channelId) {
throw new Error(
"A channel id is required for creating a stage scheduled event.",
);
}
requireBotChannelPermissions(bot, options.channelId, [
"MANAGE_CHANNELS",
"MUTE_MEMBERS",
"MOVE_MEMBERS",
]);
// MANAGE_EVENTS at the guild level or at least MANAGE_EVENTS for the channel_id associated with the event
try {
requireBotGuildPermissions(bot, guildId, [
"MANAGE_EVENTS",
]);
} catch {
requireBotChannelPermissions(bot, options.channelId, [
"MANAGE_EVENTS",
]);
}
return editScheduledEventOld(guildId, eventId, options);
}
if (options.entityType === ScheduledEventEntityType.Voice) {
if (!options.channelId) {
throw new Error(
"A channel id is required for creating a voice scheduled event.",
);
}
requireBotChannelPermissions(bot, options.channelId, [
"VIEW_CHANNEL",
"CONNECT",
]);
// MANAGE_EVENTS at the guild level or at least MANAGE_EVENTS for the channel_id associated with the event
try {
requireBotGuildPermissions(bot, guildId, [
"MANAGE_EVENTS",
]);
} catch {
requireBotChannelPermissions(bot, options.channelId, [
"MANAGE_EVENTS",
]);
}
return editScheduledEventOld(guildId, eventId, options);
}
// EXTERNAL EVENTS
requireBotGuildPermissions(bot, guildId, [
"MANAGE_EVENTS",
]);
return await editScheduledEventOld(guildId, eventId, options);
};
}
export default function setupEventsPermChecks(bot: BotWithCache) {
createScheduledEvent(bot);
editScheduledEvent(bot);
}