mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
update forum channel type (#2423)
* update forum channel type * add forum stuff to editChannel * plugins/permissions: createChannel * Prefix ForumTag, DefaultReactionEmoji with Discord
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import { BotWithCache, ChannelTypes, PermissionStrings } from "../../deps.ts";
|
||||
import { requireBotGuildPermissions } from "../permissions.ts";
|
||||
|
||||
export default function createChannel(bot: BotWithCache) {
|
||||
const createChannelOld = bot.helpers.createChannel;
|
||||
|
||||
bot.helpers.createChannel = async function (guildId, options, reason) {
|
||||
const guild = bot.guilds.get(guildId);
|
||||
|
||||
if (guild) {
|
||||
if (options?.rateLimitPerUser && !(0 < options.rateLimitPerUser && options.rateLimitPerUser < 21600)) {
|
||||
throw new Error("Amount of seconds a user has to wait before sending another message must be between 0-21600");
|
||||
}
|
||||
|
||||
if (options?.name && !bot.utils.validateLength(options.name, { min: 1, max: 100 })) {
|
||||
throw new Error("The channel name must be between 1-100 characters.");
|
||||
}
|
||||
|
||||
const requiredPerms: PermissionStrings[] = [];
|
||||
|
||||
requiredPerms.push("MANAGE_CHANNELS");
|
||||
|
||||
if (options?.permissionOverwrites) requiredPerms.push("MANAGE_ROLES");
|
||||
|
||||
if (options?.type === ChannelTypes.GuildNews && !guild.toggles.has("news")) {
|
||||
throw new Error("The NEWS feature is missing in this guild to be able to modify the channel type.");
|
||||
}
|
||||
|
||||
if (
|
||||
options?.topic && !bot.utils.validateLength(options.topic, {
|
||||
min: 1,
|
||||
max: options.type === ChannelTypes.GuildForum ? 4096 : 1024,
|
||||
})
|
||||
) {
|
||||
throw new Error("The topic length must be between 1 and 1024 (4096 if forum)");
|
||||
}
|
||||
|
||||
if (options?.userLimit && options.userLimit > 99) {
|
||||
throw new Error("The user limit must be less than 99.");
|
||||
}
|
||||
|
||||
if (options?.parentId) {
|
||||
const category = bot.channels.get(options.parentId);
|
||||
if (category && category.type !== ChannelTypes.GuildCategory) {
|
||||
throw new Error("The parent id must be for a category channel type.");
|
||||
}
|
||||
}
|
||||
|
||||
requireBotGuildPermissions(bot, guild, requiredPerms);
|
||||
}
|
||||
|
||||
return await createChannelOld(guildId, options, reason);
|
||||
};
|
||||
}
|
||||
@@ -1,16 +1,18 @@
|
||||
import { BotWithCache } from "../../deps.ts";
|
||||
import setupThreadPermChecks from "./threads/mod.ts";
|
||||
import setupForumPermChecks from "./forums/mod.ts";
|
||||
import setupStagePermChecks from "./stage.ts";
|
||||
import createChannel from "./createChannel.ts";
|
||||
import deleteChannel from "./deleteChannel.ts";
|
||||
import deleteChannelOverwrite from "./deleteChannelOverwrite.ts";
|
||||
import editChannel from "./editChannel.ts";
|
||||
import editChannelOverwrite from "./editChannelOverwrite.ts";
|
||||
import followChannel from "./followChannel.ts";
|
||||
import setupForumPermChecks from "./forums/mod.ts";
|
||||
import getChannelWebhooks from "./getChannelWebhooks.ts";
|
||||
import setupStagePermChecks from "./stage.ts";
|
||||
import swapChannels from "./swapChannels.ts";
|
||||
import setupThreadPermChecks from "./threads/mod.ts";
|
||||
|
||||
export default function setupChannelPermChecks(bot: BotWithCache) {
|
||||
createChannel(bot);
|
||||
setupThreadPermChecks(bot);
|
||||
setupForumPermChecks(bot);
|
||||
setupStagePermChecks(bot);
|
||||
|
||||
Reference in New Issue
Block a user