fix: add sendStartNotification to stages. Closes #2152

This commit is contained in:
Skillz4Killz
2022-03-31 14:01:25 +00:00
committed by GitHub
parent 23357c78a5
commit fd6b11a66b
2 changed files with 22 additions and 8 deletions
+11 -3
View File
@@ -2,16 +2,24 @@ import type { Bot } from "../../bot.ts";
import { DiscordStageInstance } from "../../types/discord.ts";
/** Creates a new Stage instance associated to a Stage channel. Requires the user to be a moderator of the Stage channel. */
export async function createStageInstance(bot: Bot, channelId: bigint, topic: string) {
export async function createStageInstance(bot: Bot, options: CreateStageInstance) {
const result = await bot.rest.runMethod<DiscordStageInstance>(
bot.rest,
"post",
bot.constants.endpoints.STAGE_INSTANCES(),
{
channel_id: channelId.toString(),
topic,
channel_id: options.channelId.toString(),
topic: options.topic,
send_start_notification: options.sendStartNotification,
},
);
return bot.transformers.stageInstance(bot, result);
}
export interface CreateStageInstance {
channelId: bigint;
topic: string;
/** Notify @everyone that the stage instance has started. Requires the MENTION_EVERYONE permission. */
sendStartNotification?: boolean;
}
+11 -5
View File
@@ -1,23 +1,29 @@
import { BotWithCache } from "../../deps.ts";
import { BotWithCache, PermissionStrings } from "../../deps.ts";
import { requireBotChannelPermissions } from "../permissions.ts";
export function createStageInstance(bot: BotWithCache) {
const createStageInstanceOld = bot.helpers.createStageInstance;
bot.helpers.createStageInstance = async function (channelId, topic) {
if (!bot.utils.validateLength(topic, { max: 120, min: 1 })) {
bot.helpers.createStageInstance = async function (options) {
if (!bot.utils.validateLength(options.topic, { max: 120, min: 1 })) {
throw new Error(
"The topic length for creating a stage instance must be between 1-120.",
);
}
requireBotChannelPermissions(bot, channelId, [
const perms = new Set<PermissionStrings>([
"MANAGE_CHANNELS",
"MUTE_MEMBERS",
"MOVE_MEMBERS",
]);
if (options.sendStartNotification) {
perms.add("MENTION_EVERYONE");
}
return await createStageInstanceOld(channelId, topic);
requireBotChannelPermissions(bot, options.channelId, [...perms.values()]);
return await createStageInstanceOld(options);
};
}