mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-01 08:20:08 +00:00
plugins: fix errors (#2446)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { BotWithCache } from "../cache/src/addCacheCollections.ts";
|
||||
import {
|
||||
ApplicationCommandOptionChoice,
|
||||
Bot,
|
||||
@@ -11,73 +12,44 @@ import {
|
||||
Message,
|
||||
} from "./deps.ts";
|
||||
import { cloneChannel } from "./src/channels.ts";
|
||||
import { sendAutocompleteChoices } from "./src/sendAutoCompleteChoices.ts";
|
||||
import { sendDirectMessage } from "./src/sendDirectMessage.ts";
|
||||
import { suppressEmbeds } from "./src/suppressEmbeds.ts";
|
||||
import { archiveThread, editThread, lockThread, ModifyThread, unarchiveThread, unlockThread } from "./src/threads.ts";
|
||||
import { disconnectMember } from "./src/disconnectMember.ts";
|
||||
import { fetchAndRetrieveMembers } from "./src/fetchAndRetrieveMembers.ts";
|
||||
import { getMembersPaginated } from "./src/getMembersPaginated.ts";
|
||||
import { moveMember } from "./src/moveMember.ts";
|
||||
import { fetchAndRetrieveMembers } from "./src/fetchAndRetrieveMembers.ts";
|
||||
import { BotWithCache } from "../cache/src/addCacheCollections.ts";
|
||||
import { sendTextMessage } from "./src/sendTextMessage.ts";
|
||||
import { sendAutocompleteChoices } from "./src/sendAutoCompleteChoices.ts";
|
||||
import { sendDirectMessage } from "./src/sendDirectMessage.ts";
|
||||
import { sendPrivateInteractionResponse } from "./src/sendPrivateInteractionResponse.ts";
|
||||
import { sendTextMessage } from "./src/sendTextMessage.ts";
|
||||
import { suppressEmbeds } from "./src/suppressEmbeds.ts";
|
||||
import { archiveThread, editThread, lockThread, ModifyThread, unarchiveThread, unlockThread } from "./src/threads.ts";
|
||||
|
||||
export type BotWithHelpersPlugin<B extends Bot = Bot> = Omit<B, "helpers"> & HelperFunctionsFromHelperPlugin;
|
||||
|
||||
export interface HelperFunctionsFromHelperPlugin {
|
||||
helpers: FinalHelpers & {
|
||||
fetchAndRetrieveMembers: (
|
||||
guildId: bigint,
|
||||
) => Promise<Collection<bigint, Member>>;
|
||||
sendDirectMessage: (
|
||||
userId: bigint,
|
||||
content: string | CreateMessage,
|
||||
) => Promise<Message>;
|
||||
sendTextMessage: (
|
||||
channelId: bigint,
|
||||
content: string | CreateMessage,
|
||||
) => Promise<Message>;
|
||||
fetchAndRetrieveMembers: (guildId: bigint) => Promise<Collection<bigint, Member>>;
|
||||
sendDirectMessage: (userId: bigint, content: string | CreateMessage) => Promise<Message>;
|
||||
sendTextMessage: (channelId: bigint, content: string | CreateMessage) => Promise<Message>;
|
||||
sendPrivateInteractionResponse: (
|
||||
id: bigint,
|
||||
token: string,
|
||||
options: InteractionResponse,
|
||||
) => Promise<Message | undefined>;
|
||||
suppressEmbeds: (
|
||||
channelId: bigint,
|
||||
messageId: bigint,
|
||||
) => Promise<Message>;
|
||||
) => Promise<void>;
|
||||
suppressEmbeds: (channelId: bigint, messageId: bigint) => Promise<Message>;
|
||||
archiveThread: (threadId: bigint) => Promise<Channel>;
|
||||
unarchiveThread: (threadId: bigint) => Promise<Channel>;
|
||||
lockThread: (threadId: bigint) => Promise<Channel>;
|
||||
unlockThread: (threadId: bigint) => Promise<Channel>;
|
||||
editThread: (
|
||||
threadId: bigint,
|
||||
options: ModifyThread,
|
||||
reason?: string,
|
||||
) => Promise<Channel>;
|
||||
cloneChannel: (
|
||||
channel: Channel,
|
||||
reason?: string,
|
||||
) => Promise<Channel>;
|
||||
editThread: (threadId: bigint, options: ModifyThread, reason?: string) => Promise<Channel>;
|
||||
cloneChannel: (channel: Channel, reason?: string) => Promise<Channel>;
|
||||
sendAutocompleteChoices: (
|
||||
interactionId: bigint,
|
||||
interactionToken: string,
|
||||
choices: ApplicationCommandOptionChoice[],
|
||||
) => Promise<void>;
|
||||
disconnectMember: (
|
||||
guildId: bigint,
|
||||
memberId: bigint,
|
||||
) => Promise<Member>;
|
||||
getMembersPaginated: (
|
||||
guildId: bigint,
|
||||
options: ListGuildMembers,
|
||||
) => Promise<Collection<bigint, Member>>;
|
||||
moveMember: (
|
||||
guildId: bigint,
|
||||
memberId: bigint,
|
||||
channelId: bigint,
|
||||
) => Promise<Member>;
|
||||
disconnectMember: (guildId: bigint, memberId: bigint) => Promise<Member>;
|
||||
getMembersPaginated: (guildId: bigint, options: ListGuildMembers) => Promise<Collection<bigint, Member>>;
|
||||
moveMember: (guildId: bigint, memberId: bigint, channelId: bigint) => Promise<Member>;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -85,32 +57,21 @@ export function enableHelpersPlugin<B extends Bot = Bot>(rawBot: B): BotWithHelp
|
||||
// FORCE OVERRIDE THE TYPE SO WE CAN SETUP FUNCTIONS
|
||||
const bot = rawBot as unknown as BotWithHelpersPlugin;
|
||||
|
||||
bot.helpers.fetchAndRetrieveMembers = (
|
||||
guildId: bigint,
|
||||
) => fetchAndRetrieveMembers(bot as unknown as BotWithCache, guildId);
|
||||
bot.helpers.sendDirectMessage = (
|
||||
userId: bigint,
|
||||
content: string | CreateMessage,
|
||||
) => sendDirectMessage(bot, userId, content);
|
||||
bot.helpers.sendTextMessage = (
|
||||
channelId: bigint,
|
||||
content: string | CreateMessage,
|
||||
) => sendTextMessage(bot, channelId, content);
|
||||
bot.helpers.sendPrivateInteractionResponse = (
|
||||
id: bigint,
|
||||
token: string,
|
||||
options: InteractionResponse,
|
||||
) => sendPrivateInteractionResponse(bot, id, token, options);
|
||||
bot.helpers.fetchAndRetrieveMembers = (guildId: bigint) =>
|
||||
fetchAndRetrieveMembers(bot as unknown as BotWithCache, guildId);
|
||||
bot.helpers.sendDirectMessage = (userId: bigint, content: string | CreateMessage) =>
|
||||
sendDirectMessage(bot, userId, content);
|
||||
bot.helpers.sendTextMessage = (channelId: bigint, content: string | CreateMessage) =>
|
||||
sendTextMessage(bot, channelId, content);
|
||||
bot.helpers.sendPrivateInteractionResponse = (id: bigint, token: string, options: InteractionResponse) =>
|
||||
sendPrivateInteractionResponse(bot, id, token, options);
|
||||
bot.helpers.suppressEmbeds = (channelId: bigint, messageId: bigint) => suppressEmbeds(bot, channelId, messageId);
|
||||
bot.helpers.archiveThread = (threadId: bigint) => archiveThread(bot, threadId);
|
||||
bot.helpers.unarchiveThread = (threadId: bigint) => unarchiveThread(bot, threadId);
|
||||
bot.helpers.lockThread = (threadId: bigint) => lockThread(bot, threadId);
|
||||
bot.helpers.unlockThread = (threadId: bigint) => unlockThread(bot, threadId);
|
||||
bot.helpers.editThread = (
|
||||
threadId: bigint,
|
||||
options: ModifyThread,
|
||||
reason?: string,
|
||||
) => editThread(bot, threadId, options, reason);
|
||||
bot.helpers.editThread = (threadId: bigint, options: ModifyThread, reason?: string) =>
|
||||
editThread(bot, threadId, options, reason);
|
||||
bot.helpers.cloneChannel = (channel: Channel, reason?: string) => cloneChannel(bot, channel, reason);
|
||||
bot.helpers.sendAutocompleteChoices = (
|
||||
interactionId: bigint,
|
||||
@@ -118,15 +79,10 @@ export function enableHelpersPlugin<B extends Bot = Bot>(rawBot: B): BotWithHelp
|
||||
choices: ApplicationCommandOptionChoice[],
|
||||
) => sendAutocompleteChoices(bot, interactionId, interactionToken, choices);
|
||||
bot.helpers.disconnectMember = (guildId: bigint, memberId: bigint) => disconnectMember(bot, guildId, memberId);
|
||||
bot.helpers.getMembersPaginated = (
|
||||
guildId: bigint,
|
||||
options: ListGuildMembers,
|
||||
) => getMembersPaginated(bot, guildId, options);
|
||||
bot.helpers.moveMember = (
|
||||
guildId: bigint,
|
||||
memberId: bigint,
|
||||
channelId: bigint,
|
||||
) => moveMember(bot, guildId, memberId, channelId);
|
||||
bot.helpers.getMembersPaginated = (guildId: bigint, options: ListGuildMembers) =>
|
||||
getMembersPaginated(bot, guildId, options);
|
||||
bot.helpers.moveMember = (guildId: bigint, memberId: bigint, channelId: bigint) =>
|
||||
moveMember(bot, guildId, memberId, channelId);
|
||||
|
||||
return bot as BotWithHelpersPlugin<B>;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,6 @@ export async function fetchAndRetrieveMembers(bot: BotWithCache, guildId: bigint
|
||||
throw new Error("The guild was not found in cache. Unable to fetch members for uncached guild.");
|
||||
}
|
||||
|
||||
await bot.helpers.fetchMembers(guildId, guild.shardId);
|
||||
await bot.helpers.fetchMembers(guildId, { limit: 0 });
|
||||
return bot.members.filter((member) => member.guildId === guildId);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import type { Bot, InteractionResponse, Message } from "../deps.ts";
|
||||
import type { Bot, InteractionResponse } from "../deps.ts";
|
||||
|
||||
/** sendInteractionResponse with ephemeral reply */
|
||||
export function sendPrivateInteractionResponse(
|
||||
/** sendInteractionResponse with ephemeral reply */
|
||||
export async function sendPrivateInteractionResponse(
|
||||
bot: Bot,
|
||||
id: bigint,
|
||||
token: string,
|
||||
options: InteractionResponse,
|
||||
): Promise<Message | undefined> {
|
||||
) {
|
||||
if (options.data && !options.data?.flags) options.data.flags = 64; // private: true
|
||||
return bot.helpers.sendInteractionResponse(id, token, options);
|
||||
return await bot.helpers.sendInteractionResponse(id, token, options);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ export default function createChannel(bot: BotWithCache) {
|
||||
|
||||
if (options?.permissionOverwrites) requiredPerms.push("MANAGE_ROLES");
|
||||
|
||||
if (options?.type === ChannelTypes.GuildNews && !guild.toggles.has("news")) {
|
||||
if (options?.type === ChannelTypes.GuildAnnouncement && !guild.toggles.has("news")) {
|
||||
throw new Error("The NEWS feature is missing in this guild to be able to modify the channel type.");
|
||||
}
|
||||
|
||||
|
||||
@@ -19,17 +19,10 @@ export default function deleteChannel(bot: BotWithCache) {
|
||||
throw new Error("UPDATES_CHANNEL_CANNOT_BE_DELETED");
|
||||
}
|
||||
|
||||
const isThread = [
|
||||
ChannelTypes.GuildNewsThread,
|
||||
ChannelTypes.GuildPublicThread,
|
||||
ChannelTypes.GuildPrivateThread,
|
||||
].includes(channel.type);
|
||||
const isThread = [ChannelTypes.AnnouncementThread, ChannelTypes.PublicThread, ChannelTypes.PrivateThread]
|
||||
.includes(channel.type);
|
||||
|
||||
requireBotGuildPermissions(
|
||||
bot,
|
||||
guild,
|
||||
isThread ? ["MANAGE_THREADS"] : ["MANAGE_CHANNELS"],
|
||||
);
|
||||
requireBotGuildPermissions(bot, guild, isThread ? ["MANAGE_THREADS"] : ["MANAGE_CHANNELS"]);
|
||||
}
|
||||
|
||||
return await deleteChannelOld(channelId, reason);
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
import { BotWithCache } from "../../deps.ts";
|
||||
import { requireBotChannelPermissions } from "../permissions.ts";
|
||||
|
||||
export default function deleteChannelOverwrite(bot: BotWithCache) {
|
||||
const deleteChannelOverwriteOld = bot.helpers.deleteChannelOverwrite;
|
||||
|
||||
bot.helpers.deleteChannelOverwrite = async function (channelId, overwriteId) {
|
||||
const channel = bot.channels.get(channelId);
|
||||
|
||||
if (channel?.guildId) {
|
||||
requireBotChannelPermissions(bot, channelId, ["MANAGE_ROLES"]);
|
||||
}
|
||||
|
||||
return await deleteChannelOverwriteOld(channelId, overwriteId);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { BotWithCache } from "../../deps.ts";
|
||||
import { requireBotChannelPermissions } from "../permissions.ts";
|
||||
|
||||
export default function deleteChannelPermissionOverride(bot: BotWithCache) {
|
||||
const deleteChannelPermissionOverrideOld = bot.helpers.deleteChannelPermissionOverride;
|
||||
|
||||
bot.helpers.deleteChannelPermissionOverride = async function (channelId, overwriteId) {
|
||||
const channel = bot.channels.get(channelId);
|
||||
|
||||
if (channel?.guildId) {
|
||||
requireBotChannelPermissions(bot, channelId, ["MANAGE_ROLES"]);
|
||||
}
|
||||
|
||||
return await deleteChannelPermissionOverrideOld(channelId, overwriteId);
|
||||
};
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
import { PermissionStrings } from "../../deps.ts";
|
||||
import { BotWithCache, ChannelTypes, GuildFeatures } from "../../deps.ts";
|
||||
import { BotWithCache, ChannelTypes, PermissionStrings } from "../../deps.ts";
|
||||
import { requireBotChannelPermissions } from "../permissions.ts";
|
||||
|
||||
export default function editChannel(bot: BotWithCache) {
|
||||
@@ -12,34 +11,22 @@ export default function editChannel(bot: BotWithCache) {
|
||||
const guild = bot.guilds.get(channel.guildId);
|
||||
|
||||
if (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",
|
||||
);
|
||||
throw new Error("Amount of seconds a user has to wait before sending another message must be between 0-21600");
|
||||
}
|
||||
|
||||
if (options.name) {
|
||||
if (!bot.utils.validateLength(options.name, { min: 1, max: 100 })) {
|
||||
throw new Error(
|
||||
"The channel name must be between 1-100 characters.",
|
||||
);
|
||||
throw new Error("The channel name must be between 1-100 characters.");
|
||||
}
|
||||
}
|
||||
|
||||
const isThread = [
|
||||
ChannelTypes.GuildNewsThread,
|
||||
ChannelTypes.GuildPublicThread,
|
||||
ChannelTypes.GuildPrivateThread,
|
||||
].includes(channel.type);
|
||||
const isThread = [ChannelTypes.AnnouncementThread, ChannelTypes.PublicThread, ChannelTypes.PrivateThread]
|
||||
.includes(channel.type);
|
||||
|
||||
const requiredPerms: PermissionStrings[] = [];
|
||||
if (isThread) {
|
||||
if (
|
||||
options.invitable !== undefined &&
|
||||
channel.type !== ChannelTypes.GuildPrivateThread
|
||||
) {
|
||||
throw new Error(
|
||||
"Invitable option is only allowed on private threads.",
|
||||
);
|
||||
if (options.invitable !== undefined && channel.type !== ChannelTypes.PrivateThread) {
|
||||
throw new Error("Invitable option is only allowed on private threads.");
|
||||
}
|
||||
|
||||
// UNARCHIVING AN UNLOCKED CHANNEL SIMPLY REQUIRES SEND
|
||||
@@ -60,18 +47,12 @@ export default function editChannel(bot: BotWithCache) {
|
||||
}
|
||||
|
||||
if (options.type) {
|
||||
if (
|
||||
[ChannelTypes.GuildNews, ChannelTypes.GuildText].includes(
|
||||
options.type,
|
||||
)
|
||||
) {
|
||||
if ([ChannelTypes.GuildAnnouncement, ChannelTypes.GuildText].includes(options.type)) {
|
||||
throw new Error("Only news and text types can be modified.");
|
||||
}
|
||||
|
||||
if (guild && !guild.toggles.has("news")) {
|
||||
throw new Error(
|
||||
"The NEWS feature is missing in this guild to be able to modify the channel type.",
|
||||
);
|
||||
throw new Error("The NEWS feature is missing in this guild to be able to modify the channel type.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,18 +69,12 @@ export default function editChannel(bot: BotWithCache) {
|
||||
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.",
|
||||
);
|
||||
throw new Error("The parent id must be for a category channel type.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
requireBotChannelPermissions(
|
||||
bot,
|
||||
channel,
|
||||
requiredPerms,
|
||||
);
|
||||
requireBotChannelPermissions(bot, channel, requiredPerms);
|
||||
}
|
||||
|
||||
return await editChannelOld(channelId, options, reason);
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
import { BotWithCache } from "../../deps.ts";
|
||||
import { requireBotChannelPermissions } from "../permissions.ts";
|
||||
|
||||
export default function editChannelOverwrite(bot: BotWithCache) {
|
||||
const editChannelOverwriteOld = bot.helpers.editChannelOverwrite;
|
||||
|
||||
bot.helpers.editChannelOverwrite = async function (channelId, overwrite) {
|
||||
const channel = bot.channels.get(channelId);
|
||||
if (channel?.guildId) {
|
||||
requireBotChannelPermissions(bot, channelId, ["MANAGE_ROLES"]);
|
||||
}
|
||||
|
||||
return await editChannelOverwriteOld(channelId, overwrite);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { BotWithCache } from "../../deps.ts";
|
||||
import { requireBotChannelPermissions } from "../permissions.ts";
|
||||
|
||||
export default function editChannelPermissionOverrides(bot: BotWithCache) {
|
||||
const editChannelPermissionOverridesOld = bot.helpers.editChannelPermissionOverrides;
|
||||
|
||||
bot.helpers.editChannelPermissionOverrides = async function (channelId, overwrite) {
|
||||
const channel = bot.channels.get(channelId);
|
||||
if (channel?.guildId) {
|
||||
requireBotChannelPermissions(bot, channelId, ["MANAGE_ROLES"]);
|
||||
}
|
||||
|
||||
return await editChannelPermissionOverridesOld(channelId, overwrite);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { BotWithCache } from "../../deps.ts";
|
||||
import { requireBotChannelPermissions } from "../permissions.ts";
|
||||
|
||||
export default function followAnnouncementChannel(bot: BotWithCache) {
|
||||
const followAnnouncementChannelOld = bot.helpers.followAnnouncementChannel;
|
||||
|
||||
bot.helpers.followAnnouncementChannel = async function (sourceChannelId, targetChannelId) {
|
||||
const channel = bot.channels.get(targetChannelId);
|
||||
if (channel?.guildId) {
|
||||
requireBotChannelPermissions(bot, channel, ["MANAGE_WEBHOOKS"]);
|
||||
}
|
||||
|
||||
return await followAnnouncementChannelOld(sourceChannelId, targetChannelId);
|
||||
};
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
import { BotWithCache } from "../../deps.ts";
|
||||
import { requireBotChannelPermissions } from "../permissions.ts";
|
||||
|
||||
export default function followChannel(bot: BotWithCache) {
|
||||
const followChannelOld = bot.helpers.followChannel;
|
||||
|
||||
bot.helpers.followChannel = async function (sourceChannelId, targetChannelId) {
|
||||
const channel = bot.channels.get(targetChannelId);
|
||||
if (channel?.guildId) {
|
||||
requireBotChannelPermissions(bot, channel, ["MANAGE_WEBHOOKS"]);
|
||||
}
|
||||
|
||||
return await followChannelOld(sourceChannelId, targetChannelId);
|
||||
};
|
||||
}
|
||||
@@ -1,16 +1,16 @@
|
||||
import { BotWithCache } from "../../../deps.ts";
|
||||
import { requireBotChannelPermissions } from "../../permissions.ts";
|
||||
|
||||
export default function createForumPosts(bot: BotWithCache) {
|
||||
const createForumPostsOld = bot.helpers.createForumPost;
|
||||
export default function createForumThread(bot: BotWithCache) {
|
||||
const createForumThreadOld = bot.helpers.createForumThread;
|
||||
|
||||
bot.helpers.createForumPost = async function (channelId, options) {
|
||||
bot.helpers.createForumThread = async function (channelId, options) {
|
||||
const channel = bot.channels.get(channelId);
|
||||
|
||||
if (channel) {
|
||||
requireBotChannelPermissions(bot, channel, ["SEND_MESSAGES"]);
|
||||
}
|
||||
|
||||
return await createForumPostsOld(channelId, options);
|
||||
return await createForumThreadOld(channelId, options);
|
||||
};
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { BotWithCache } from "../../../deps.ts";
|
||||
import createForumPost from "./createForumPost.ts";
|
||||
import createForumThread from "./createForumThread.ts";
|
||||
|
||||
export default function setupThreadPermChecks(bot: BotWithCache) {
|
||||
createForumPost(bot);
|
||||
createForumThread(bot);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { BotWithCache } from "../../deps.ts";
|
||||
import createChannel from "./createChannel.ts";
|
||||
import deleteChannel from "./deleteChannel.ts";
|
||||
import deleteChannelOverwrite from "./deleteChannelOverwrite.ts";
|
||||
import deleteChannelPermissionOverride from "./deleteChannelPermissionOverride.ts";
|
||||
import editChannel from "./editChannel.ts";
|
||||
import editChannelOverwrite from "./editChannelOverwrite.ts";
|
||||
import followChannel from "./followChannel.ts";
|
||||
import editChannelPermissionOverrides from "./editChannelPermissionOverrides.ts";
|
||||
import followAnnouncementChannel from "./followAnnouncementChannel.ts";
|
||||
import setupForumPermChecks from "./forums/mod.ts";
|
||||
import getChannelWebhooks from "./getChannelWebhooks.ts";
|
||||
import setupStagePermChecks from "./stage.ts";
|
||||
@@ -17,10 +17,10 @@ export default function setupChannelPermChecks(bot: BotWithCache) {
|
||||
setupForumPermChecks(bot);
|
||||
setupStagePermChecks(bot);
|
||||
deleteChannel(bot);
|
||||
deleteChannelOverwrite(bot);
|
||||
deleteChannelPermissionOverride(bot);
|
||||
editChannel(bot);
|
||||
editChannelOverwrite(bot);
|
||||
followChannel(bot);
|
||||
editChannelPermissionOverrides(bot);
|
||||
followAnnouncementChannel(bot);
|
||||
getChannelWebhooks(bot);
|
||||
swapChannels(bot);
|
||||
}
|
||||
|
||||
@@ -6,16 +6,10 @@ export function createStageInstance(bot: BotWithCache) {
|
||||
|
||||
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.",
|
||||
);
|
||||
throw new Error("The topic length for creating a stage instance must be between 1-120.");
|
||||
}
|
||||
|
||||
const perms = new Set<PermissionStrings>([
|
||||
"MANAGE_CHANNELS",
|
||||
"MUTE_MEMBERS",
|
||||
"MOVE_MEMBERS",
|
||||
]);
|
||||
const perms = new Set<PermissionStrings>(["MANAGE_CHANNELS", "MUTE_MEMBERS", "MOVE_MEMBERS"]);
|
||||
|
||||
if (options.sendStartNotification) {
|
||||
perms.add("MENTION_EVERYONE");
|
||||
@@ -31,32 +25,24 @@ export function deleteStageInstance(bot: BotWithCache) {
|
||||
const deleteStageInstanceOld = bot.helpers.deleteStageInstance;
|
||||
|
||||
bot.helpers.deleteStageInstance = async function (channelId) {
|
||||
requireBotChannelPermissions(bot, channelId, [
|
||||
"MANAGE_CHANNELS",
|
||||
"MUTE_MEMBERS",
|
||||
"MOVE_MEMBERS",
|
||||
]);
|
||||
requireBotChannelPermissions(bot, channelId, ["MANAGE_CHANNELS", "MUTE_MEMBERS", "MOVE_MEMBERS"]);
|
||||
|
||||
return await deleteStageInstanceOld(channelId);
|
||||
};
|
||||
}
|
||||
|
||||
export function updateStageInstance(bot: BotWithCache) {
|
||||
const updateStageInstanceOld = bot.helpers.updateStageInstance;
|
||||
export function editStageInstance(bot: BotWithCache) {
|
||||
const editStageInstanceOld = bot.helpers.editStageInstance;
|
||||
|
||||
bot.helpers.updateStageInstance = async function (channelId, data) {
|
||||
requireBotChannelPermissions(bot, channelId, [
|
||||
"MANAGE_CHANNELS",
|
||||
"MUTE_MEMBERS",
|
||||
"MOVE_MEMBERS",
|
||||
]);
|
||||
bot.helpers.editStageInstance = async function (channelId, data) {
|
||||
requireBotChannelPermissions(bot, channelId, ["MANAGE_CHANNELS", "MUTE_MEMBERS", "MOVE_MEMBERS"]);
|
||||
|
||||
return await updateStageInstanceOld(channelId, data);
|
||||
return await editStageInstanceOld(channelId, data);
|
||||
};
|
||||
}
|
||||
|
||||
export default function setupStagePermChecks(bot: BotWithCache) {
|
||||
createStageInstance(bot);
|
||||
deleteStageInstance(bot);
|
||||
updateStageInstance(bot);
|
||||
editStageInstance(bot);
|
||||
}
|
||||
|
||||
24
plugins/permissions/src/channels/threads/addThreadMember.ts
Normal file
24
plugins/permissions/src/channels/threads/addThreadMember.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { BotWithCache } from "../../../deps.ts";
|
||||
import { requireBotChannelPermissions } from "../../permissions.ts";
|
||||
|
||||
export default function addThreadMember(bot: BotWithCache) {
|
||||
const addThreadMemberOld = bot.helpers.addThreadMember;
|
||||
|
||||
bot.helpers.addThreadMember = async function (threadId, userId) {
|
||||
if (userId === bot.id) {
|
||||
throw new Error("To add the bot to a thread, you must use bot.helpers.joinThread()");
|
||||
}
|
||||
|
||||
const channel = bot.channels.get(threadId);
|
||||
|
||||
if (channel) {
|
||||
if (channel.archived) {
|
||||
throw new Error("Cannot add user to thread if thread is archived.");
|
||||
}
|
||||
|
||||
requireBotChannelPermissions(bot, channel, ["SEND_MESSAGES"]);
|
||||
}
|
||||
|
||||
return await addThreadMemberOld(threadId, userId);
|
||||
};
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
import { BotWithCache } from "../../../deps.ts";
|
||||
import { requireBotChannelPermissions } from "../../permissions.ts";
|
||||
|
||||
export default function addToThread(bot: BotWithCache) {
|
||||
const addToThreadOld = bot.helpers.addToThread;
|
||||
|
||||
bot.helpers.addToThread = async function (threadId, userId) {
|
||||
if (userId === bot.id) {
|
||||
throw new Error(
|
||||
"To add the bot to a thread, you must use bot.helpers.joinThread()",
|
||||
);
|
||||
}
|
||||
|
||||
const channel = bot.channels.get(threadId);
|
||||
|
||||
if (channel) {
|
||||
if (channel.archived) {
|
||||
throw new Error("Cannot add user to thread if thread is archived.");
|
||||
}
|
||||
|
||||
await requireBotChannelPermissions(bot, channel, ["SEND_MESSAGES"]);
|
||||
}
|
||||
|
||||
return await addToThreadOld(threadId, userId);
|
||||
};
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
import { BotWithCache } from "../../../deps.ts";
|
||||
import { requireBotChannelPermissions } from "../../permissions.ts";
|
||||
|
||||
export default function getArchivedThreads(bot: BotWithCache) {
|
||||
const getArchivedThreadsOld = bot.helpers.getArchivedThreads;
|
||||
|
||||
bot.helpers.getArchivedThreads = async function (channelId, options) {
|
||||
const channel = await bot.channels.get(channelId);
|
||||
|
||||
if (channel) {
|
||||
await requireBotChannelPermissions(
|
||||
bot,
|
||||
channel,
|
||||
options?.type === "private" ? ["READ_MESSAGE_HISTORY", "MANAGE_THREADS"] : ["READ_MESSAGE_HISTORY"],
|
||||
);
|
||||
}
|
||||
|
||||
return await getArchivedThreadsOld(channelId, options);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { BotWithCache } from "../../../deps.ts";
|
||||
import { requireBotChannelPermissions } from "../../permissions.ts";
|
||||
|
||||
export function getPrivateArchivedThreads(bot: BotWithCache) {
|
||||
const getPrivateArchivedThreadsOld = bot.helpers.getPrivateArchivedThreads;
|
||||
bot.helpers.getPublicArchivedThreads = async function (channelId, options) {
|
||||
const channel = bot.channels.get(channelId);
|
||||
if (channel) {
|
||||
requireBotChannelPermissions(bot, channel, ["READ_MESSAGE_HISTORY", "MANAGE_MESSAGES"]);
|
||||
}
|
||||
return await getPrivateArchivedThreadsOld(channelId, options);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { BotWithCache } from "../../../deps.ts";
|
||||
import { requireBotChannelPermissions } from "../../permissions.ts";
|
||||
|
||||
export function getPrivateJoinedArchivedThreads(bot: BotWithCache) {
|
||||
const getPrivateJoinedArchivedThreadsOld = bot.helpers.getPrivateJoinedArchivedThreads;
|
||||
bot.helpers.getPublicArchivedThreads = async function (channelId, options) {
|
||||
const channel = bot.channels.get(channelId);
|
||||
if (channel) {
|
||||
requireBotChannelPermissions(bot, channel, ["READ_MESSAGE_HISTORY"]);
|
||||
}
|
||||
return await getPrivateJoinedArchivedThreadsOld(channelId, options);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { BotWithCache } from "../../../deps.ts";
|
||||
import { requireBotChannelPermissions } from "../../permissions.ts";
|
||||
|
||||
export function getPublicArchivedThreads(bot: BotWithCache) {
|
||||
const getPublicArchivedThreadsOld = bot.helpers.getPublicArchivedThreads;
|
||||
bot.helpers.getPublicArchivedThreads = async function (channelId, options) {
|
||||
const channel = bot.channels.get(channelId);
|
||||
if (channel) {
|
||||
requireBotChannelPermissions(bot, channel, ["READ_MESSAGE_HISTORY"]);
|
||||
}
|
||||
return await getPublicArchivedThreadsOld(channelId, options);
|
||||
};
|
||||
}
|
||||
@@ -1,14 +1,18 @@
|
||||
import { BotWithCache } from "../../../deps.ts";
|
||||
import addToThread from "./addToThread.ts";
|
||||
import getArchivedThreads from "./getArchivedThreads.ts";
|
||||
import addThreadMember from "./addThreadMember.ts";
|
||||
import { getPrivateArchivedThreads } from "./getPrivateArchivedThreads.ts";
|
||||
import { getPrivateJoinedArchivedThreads } from "./getPrivateJoinedArchivedThreads.ts";
|
||||
import { getPublicArchivedThreads } from "./getPublicArchivedThreads.ts";
|
||||
import getThreadMembers from "./getThreadMembers.ts";
|
||||
import joinThread from "./joinThread.ts";
|
||||
import leaveThread from "./leaveThread.ts";
|
||||
import removeThreadMember from "./removeThreadMember.ts";
|
||||
|
||||
export default function setupThreadPermChecks(bot: BotWithCache) {
|
||||
addToThread(bot);
|
||||
getArchivedThreads(bot);
|
||||
addThreadMember(bot);
|
||||
getPublicArchivedThreads(bot);
|
||||
getPrivateArchivedThreads(bot);
|
||||
getPrivateJoinedArchivedThreads(bot);
|
||||
getThreadMembers(bot);
|
||||
joinThread(bot);
|
||||
leaveThread(bot);
|
||||
|
||||
@@ -6,25 +6,18 @@ export default function removeThreadMember(bot: BotWithCache) {
|
||||
|
||||
bot.helpers.removeThreadMember = async function (threadId, userId) {
|
||||
if (userId === bot.id) {
|
||||
throw new Error(
|
||||
"To remove the bot from a thread, you must use bot.helpers.leaveThread()",
|
||||
);
|
||||
throw new Error("To remove the bot from a thread, you must use bot.helpers.leaveThread()");
|
||||
}
|
||||
|
||||
const channel = bot.channels.get(threadId);
|
||||
|
||||
if (channel) {
|
||||
if (channel.archived) {
|
||||
throw new Error(
|
||||
"Cannot remove user from thread if thread is archived.",
|
||||
);
|
||||
throw new Error("Cannot remove user from thread if thread is archived.");
|
||||
}
|
||||
|
||||
if (
|
||||
!(bot.id === channel.ownerId &&
|
||||
channel.type === ChannelTypes.GuildPrivateThread)
|
||||
) {
|
||||
await requireBotChannelPermissions(bot, channel, ["MANAGE_MESSAGES"]);
|
||||
if (!(bot.id === channel.ownerId && channel.type === ChannelTypes.PrivateThread)) {
|
||||
requireBotChannelPermissions(bot, channel, ["MANAGE_MESSAGES"]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,13 +11,13 @@ export function addDiscoverySubcategory(bot: BotWithCache) {
|
||||
};
|
||||
}
|
||||
|
||||
export function removeDiscoverySubcategory(bot: BotWithCache) {
|
||||
const removeDiscoverySubcategoryOld = bot.helpers.removeDiscoverySubcategory;
|
||||
export function deleteDiscoverySubcategory(bot: BotWithCache) {
|
||||
const deleteDiscoverySubcategoryOld = bot.helpers.deleteDiscoverySubcategory;
|
||||
|
||||
bot.helpers.removeDiscoverySubcategory = async function (guildId, categoryId) {
|
||||
bot.helpers.deleteDiscoverySubcategory = async function (guildId, categoryId) {
|
||||
requireBotGuildPermissions(bot, guildId, ["MANAGE_GUILD"]);
|
||||
|
||||
return await removeDiscoverySubcategoryOld(guildId, categoryId);
|
||||
return await deleteDiscoverySubcategoryOld(guildId, categoryId);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -45,5 +45,5 @@ export default function setupDiscoveryPermChecks(bot: BotWithCache) {
|
||||
addDiscoverySubcategory(bot);
|
||||
editDiscovery(bot);
|
||||
getDiscovery(bot);
|
||||
removeDiscoverySubcategory(bot);
|
||||
deleteDiscoverySubcategory(bot);
|
||||
}
|
||||
|
||||
16
plugins/permissions/src/guilds/editWidgetSettings.ts
Normal file
16
plugins/permissions/src/guilds/editWidgetSettings.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { BotWithCache } from "../../deps.ts";
|
||||
import { requireBotGuildPermissions } from "../permissions.ts";
|
||||
|
||||
export function editWidgetSettings(bot: BotWithCache) {
|
||||
const editWidgetSettingsOld = bot.helpers.editWidgetSettings;
|
||||
|
||||
bot.helpers.editWidgetSettings = async function (guildId, enabled, channelId) {
|
||||
requireBotGuildPermissions(bot, guildId, ["MANAGE_GUILD"]);
|
||||
|
||||
return await editWidgetSettingsOld(guildId, enabled, channelId);
|
||||
};
|
||||
}
|
||||
|
||||
export default function (bot: BotWithCache) {
|
||||
editWidgetSettings(bot);
|
||||
}
|
||||
12
plugins/permissions/src/guilds/getAuditLog.ts
Normal file
12
plugins/permissions/src/guilds/getAuditLog.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { BotWithCache } from "../../deps.ts";
|
||||
import { requireBotGuildPermissions } from "../permissions.ts";
|
||||
|
||||
export default function getAuditLog(bot: BotWithCache) {
|
||||
const getAuditLogOld = bot.helpers.getAuditLog;
|
||||
|
||||
bot.helpers.getAuditLog = async function (guildId, options) {
|
||||
requireBotGuildPermissions(bot, guildId, ["VIEW_AUDIT_LOG"]);
|
||||
|
||||
return await getAuditLogOld(guildId, options);
|
||||
};
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
import { BotWithCache } from "../../deps.ts";
|
||||
import { requireBotGuildPermissions } from "../permissions.ts";
|
||||
|
||||
export default function getAuditLogs(bot: BotWithCache) {
|
||||
const getAuditLogsOld = bot.helpers.getAuditLogs;
|
||||
|
||||
bot.helpers.getAuditLogs = async function (guildId, options) {
|
||||
requireBotGuildPermissions(bot, guildId, ["VIEW_AUDIT_LOG"]);
|
||||
|
||||
return await getAuditLogsOld(guildId, options);
|
||||
};
|
||||
}
|
||||
@@ -1,26 +1,26 @@
|
||||
import { BotWithCache } from "../../deps.ts";
|
||||
import setupEventsPermChecks from "./events.ts";
|
||||
import setupWelcomeScreenPermChecks from "./welcomeScreen.ts";
|
||||
import setupWidgetPermChecks from "./widget.ts";
|
||||
import createGuild from "./createGuild.ts";
|
||||
import deleteGuild from "./deleteGuild.ts";
|
||||
import editGuild from "./editGuild.ts";
|
||||
import getAuditLogs from "./getAuditLogs.ts";
|
||||
import editWidgetSettings from "./editWidgetSettings.ts";
|
||||
import setupEventsPermChecks from "./events.ts";
|
||||
import getAuditLog from "./getAuditLog.ts";
|
||||
import getBan from "./getBan.ts";
|
||||
import getBans from "./getBans.ts";
|
||||
import getPruneCount from "./getPruneCount.ts";
|
||||
import getVanityUrl from "./getVanityUrl.ts";
|
||||
import setupWelcomeScreenPermChecks from "./welcomeScreen.ts";
|
||||
|
||||
export default function setupGuildPermChecks(bot: BotWithCache) {
|
||||
setupEventsPermChecks(bot);
|
||||
createGuild(bot);
|
||||
deleteGuild(bot);
|
||||
editGuild(bot);
|
||||
setupWelcomeScreenPermChecks(bot);
|
||||
setupWidgetPermChecks(bot);
|
||||
getAuditLogs(bot);
|
||||
editWidgetSettings(bot);
|
||||
setupEventsPermChecks(bot);
|
||||
getAuditLog(bot);
|
||||
getBan(bot);
|
||||
getBans(bot);
|
||||
getPruneCount(bot);
|
||||
getVanityUrl(bot);
|
||||
setupWelcomeScreenPermChecks(bot);
|
||||
}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
import { BotWithCache } from "../../deps.ts";
|
||||
import { requireBotGuildPermissions } from "../permissions.ts";
|
||||
|
||||
export function editWidget(bot: BotWithCache) {
|
||||
const editWidgetOld = bot.helpers.editWidget;
|
||||
|
||||
bot.helpers.editWidget = async function (guildId, enabled, channelId) {
|
||||
requireBotGuildPermissions(bot, guildId, ["MANAGE_GUILD"]);
|
||||
|
||||
return await editWidgetOld(guildId, enabled, channelId);
|
||||
};
|
||||
}
|
||||
|
||||
export default function setupWidgetPermChecks(bot: BotWithCache) {
|
||||
editWidget(bot);
|
||||
}
|
||||
@@ -7,12 +7,8 @@ import {
|
||||
CONTEXT_MENU_COMMANDS_NAME_REGEX,
|
||||
SLASH_COMMANDS_NAME_REGEX,
|
||||
} from "../../deps.ts";
|
||||
import { validateAttachments } from "../attachments.ts";
|
||||
|
||||
export function validateApplicationCommandOptions(
|
||||
bot: BotWithCache,
|
||||
options: ApplicationCommandOption[],
|
||||
) {
|
||||
export function validateApplicationCommandOptions(bot: BotWithCache, options: ApplicationCommandOption[]) {
|
||||
const requiredOptions: ApplicationCommandOption[] = [];
|
||||
const optionalOptions: ApplicationCommandOption[] = [];
|
||||
|
||||
@@ -25,8 +21,7 @@ export function validateApplicationCommandOptions(
|
||||
}
|
||||
|
||||
if (
|
||||
option.type !== ApplicationCommandOptionTypes.String &&
|
||||
option.type !== ApplicationCommandOptionTypes.Integer
|
||||
option.type !== ApplicationCommandOptionTypes.String && option.type !== ApplicationCommandOptionTypes.Integer
|
||||
) {
|
||||
throw new Error("Only string or integer options can have choices.");
|
||||
}
|
||||
@@ -42,23 +37,17 @@ export function validateApplicationCommandOptions(
|
||||
|
||||
option.choices?.every((choice) => {
|
||||
if (!bot.utils.validateLength(choice.name, { min: 1, max: 100 })) {
|
||||
throw new Error(
|
||||
"Invalid application command option choice name. Must be between 1-100 characters long.",
|
||||
);
|
||||
throw new Error("Invalid application command option choice name. Must be between 1-100 characters long.");
|
||||
}
|
||||
|
||||
if (
|
||||
option.type === ApplicationCommandOptionTypes.String &&
|
||||
(typeof choice.value !== "string" || choice.value.length < 1 ||
|
||||
choice.value.length > 100)
|
||||
(typeof choice.value !== "string" || choice.value.length < 1 || choice.value.length > 100)
|
||||
) {
|
||||
throw new Error("Invalid slash options choice value type.");
|
||||
}
|
||||
|
||||
if (
|
||||
option.type === ApplicationCommandOptionTypes.Integer &&
|
||||
typeof choice.value !== "number"
|
||||
) {
|
||||
if (option.type === ApplicationCommandOptionTypes.Integer && typeof choice.value !== "number") {
|
||||
throw new Error("A number must be set for Integer types.");
|
||||
}
|
||||
});
|
||||
@@ -74,12 +63,11 @@ export function validateApplicationCommandOptions(
|
||||
return [...requiredOptions, ...optionalOptions];
|
||||
}
|
||||
|
||||
export function createApplicationCommand(bot: BotWithCache) {
|
||||
const createApplicationCommandOld = bot.helpers.createApplicationCommand;
|
||||
export function createGuildApplicationCommand(bot: BotWithCache) {
|
||||
const createGuildApplicationCommandOld = bot.helpers.createGuildApplicationCommand;
|
||||
|
||||
bot.helpers.createApplicationCommand = async function (options, guildId) {
|
||||
const isChatInput = !options.type ||
|
||||
options.type === ApplicationCommandTypes.ChatInput;
|
||||
bot.helpers.createGuildApplicationCommand = async function (options, guildId) {
|
||||
const isChatInput = !options.type || options.type === ApplicationCommandTypes.ChatInput;
|
||||
|
||||
if (!options.name) {
|
||||
throw new Error("A name is required to create a options.");
|
||||
@@ -87,9 +75,7 @@ export function createApplicationCommand(bot: BotWithCache) {
|
||||
|
||||
if (isChatInput) {
|
||||
if (!SLASH_COMMANDS_NAME_REGEX.test(options.name)) {
|
||||
throw new Error(
|
||||
"The name of the slash command did not match the required regex.",
|
||||
);
|
||||
throw new Error("The name of the slash command did not match the required regex.");
|
||||
}
|
||||
|
||||
// Only slash need to be lowercase
|
||||
@@ -97,13 +83,9 @@ export function createApplicationCommand(bot: BotWithCache) {
|
||||
|
||||
// Slash commands require description
|
||||
if (!options.description) {
|
||||
throw new Error(
|
||||
"Slash commands require some form of a description be provided.",
|
||||
);
|
||||
throw new Error("Slash commands require some form of a description be provided.");
|
||||
} else if (!bot.utils.validateLength(options.description, { min: 1, max: 100 })) {
|
||||
throw new Error(
|
||||
"Application command descriptions must be between 1 and 100 characters.",
|
||||
);
|
||||
throw new Error("Application command descriptions must be between 1 and 100 characters.");
|
||||
}
|
||||
|
||||
if (options.options?.length) {
|
||||
@@ -115,20 +97,60 @@ export function createApplicationCommand(bot: BotWithCache) {
|
||||
}
|
||||
} else {
|
||||
if (!CONTEXT_MENU_COMMANDS_NAME_REGEX.test(options.name)) {
|
||||
throw new Error(
|
||||
"The name of the context menu did not match the required regex.",
|
||||
);
|
||||
throw new Error("The name of the context menu did not match the required regex.");
|
||||
}
|
||||
}
|
||||
|
||||
return await createApplicationCommandOld(options, guildId);
|
||||
return await createGuildApplicationCommandOld(options, guildId);
|
||||
};
|
||||
}
|
||||
|
||||
export function editInteractionResponse(bot: BotWithCache) {
|
||||
const editInteractionResponseOld = bot.helpers.editInteractionResponse;
|
||||
export function createGlobalApplicationCommand(bot: BotWithCache) {
|
||||
const createGlobalApplicationCommandOld = bot.helpers.createGlobalApplicationCommand;
|
||||
|
||||
bot.helpers.editInteractionResponse = async function (token, options) {
|
||||
bot.helpers.createGlobalApplicationCommand = async function (options) {
|
||||
const isChatInput = !options.type || options.type === ApplicationCommandTypes.ChatInput;
|
||||
|
||||
if (!options.name) {
|
||||
throw new Error("A name is required to create a options.");
|
||||
}
|
||||
|
||||
if (isChatInput) {
|
||||
if (!SLASH_COMMANDS_NAME_REGEX.test(options.name)) {
|
||||
throw new Error("The name of the slash command did not match the required regex.");
|
||||
}
|
||||
|
||||
// Only slash need to be lowercase
|
||||
options.name = options.name.toLowerCase();
|
||||
|
||||
// Slash commands require description
|
||||
if (!options.description) {
|
||||
throw new Error("Slash commands require some form of a description be provided.");
|
||||
} else if (!bot.utils.validateLength(options.description, { min: 1, max: 100 })) {
|
||||
throw new Error("Application command descriptions must be between 1 and 100 characters.");
|
||||
}
|
||||
|
||||
if (options.options?.length) {
|
||||
if (options.options.length > 25) {
|
||||
throw new Error("Only 25 options are allowed to be provided.");
|
||||
}
|
||||
|
||||
options.options = validateApplicationCommandOptions(bot, options.options);
|
||||
}
|
||||
} else {
|
||||
if (!CONTEXT_MENU_COMMANDS_NAME_REGEX.test(options.name)) {
|
||||
throw new Error("The name of the context menu did not match the required regex.");
|
||||
}
|
||||
}
|
||||
|
||||
return await createGlobalApplicationCommandOld(options);
|
||||
};
|
||||
}
|
||||
|
||||
export function editOriginalInteractionResponse(bot: BotWithCache) {
|
||||
const editOriginalInteractionResponseOld = bot.helpers.editOriginalInteractionResponse;
|
||||
|
||||
bot.helpers.editOriginalInteractionResponse = async function (token, options) {
|
||||
if (options.content && options.content.length > 2000) {
|
||||
throw Error(bot.constants.Errors.MESSAGE_MAX_LENGTH);
|
||||
}
|
||||
@@ -139,51 +161,32 @@ export function editInteractionResponse(bot: BotWithCache) {
|
||||
|
||||
if (options.allowedMentions) {
|
||||
if (options.allowedMentions.users?.length) {
|
||||
if (
|
||||
options.allowedMentions.parse?.includes(
|
||||
AllowedMentionsTypes.UserMentions,
|
||||
)
|
||||
) {
|
||||
options.allowedMentions.parse = options.allowedMentions.parse.filter((
|
||||
p,
|
||||
) => p !== "users");
|
||||
if (options.allowedMentions.parse?.includes(AllowedMentionsTypes.UserMentions)) {
|
||||
options.allowedMentions.parse = options.allowedMentions.parse.filter((p) => p !== "users");
|
||||
}
|
||||
|
||||
if (options.allowedMentions.users.length > 100) {
|
||||
options.allowedMentions.users = options.allowedMentions.users.slice(
|
||||
0,
|
||||
100,
|
||||
);
|
||||
options.allowedMentions.users = options.allowedMentions.users.slice(0, 100);
|
||||
}
|
||||
}
|
||||
|
||||
if (options.allowedMentions.roles?.length) {
|
||||
if (
|
||||
options.allowedMentions.parse?.includes(
|
||||
AllowedMentionsTypes.RoleMentions,
|
||||
)
|
||||
) {
|
||||
options.allowedMentions.parse = options.allowedMentions.parse.filter((
|
||||
p,
|
||||
) => p !== "roles");
|
||||
if (options.allowedMentions.parse?.includes(AllowedMentionsTypes.RoleMentions)) {
|
||||
options.allowedMentions.parse = options.allowedMentions.parse.filter((p) => p !== "roles");
|
||||
}
|
||||
|
||||
if (options.allowedMentions.roles.length > 100) {
|
||||
options.allowedMentions.roles = options.allowedMentions.roles.slice(
|
||||
0,
|
||||
100,
|
||||
);
|
||||
options.allowedMentions.roles = options.allowedMentions.roles.slice(0, 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (options.attachments) validateAttachments(bot, options.attachments);
|
||||
|
||||
return await editInteractionResponseOld(token, options);
|
||||
return await editOriginalInteractionResponseOld(token, options);
|
||||
};
|
||||
}
|
||||
|
||||
export default function setupInteractionCommandPermChecks(bot: BotWithCache) {
|
||||
createApplicationCommand(bot);
|
||||
editInteractionResponse(bot);
|
||||
createGlobalApplicationCommand(bot);
|
||||
createGuildApplicationCommand(bot);
|
||||
editOriginalInteractionResponse(bot);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
import { AllowedMentionsTypes, BotWithCache } from "../../deps.ts";
|
||||
import { validateAttachments } from "../attachments.ts";
|
||||
|
||||
export default function editFollowupMessage(bot: BotWithCache) {
|
||||
const editFollowupMessageOld = bot.helpers.editFollowupMessage;
|
||||
|
||||
bot.helpers.editFollowupMessage = async function (
|
||||
token,
|
||||
messageId,
|
||||
options,
|
||||
) {
|
||||
bot.helpers.editFollowupMessage = async function (token, messageId, options) {
|
||||
if (options.content && options.content.length > 2000) {
|
||||
throw Error("MESSAGE_MAX_LENGTH");
|
||||
}
|
||||
@@ -19,46 +14,26 @@ export default function editFollowupMessage(bot: BotWithCache) {
|
||||
|
||||
if (options.allowedMentions) {
|
||||
if (options.allowedMentions.users?.length) {
|
||||
if (
|
||||
options.allowedMentions.parse?.includes(
|
||||
AllowedMentionsTypes.UserMentions,
|
||||
)
|
||||
) {
|
||||
options.allowedMentions.parse = options.allowedMentions.parse.filter((
|
||||
p,
|
||||
) => p !== "users");
|
||||
if (options.allowedMentions.parse?.includes(AllowedMentionsTypes.UserMentions)) {
|
||||
options.allowedMentions.parse = options.allowedMentions.parse.filter((p) => p !== "users");
|
||||
}
|
||||
|
||||
if (options.allowedMentions.users.length > 100) {
|
||||
options.allowedMentions.users = options.allowedMentions.users.slice(
|
||||
0,
|
||||
100,
|
||||
);
|
||||
options.allowedMentions.users = options.allowedMentions.users.slice(0, 100);
|
||||
}
|
||||
}
|
||||
|
||||
if (options.allowedMentions.roles?.length) {
|
||||
if (
|
||||
options.allowedMentions.parse?.includes(
|
||||
AllowedMentionsTypes.RoleMentions,
|
||||
)
|
||||
) {
|
||||
options.allowedMentions.parse = options.allowedMentions.parse.filter((
|
||||
p,
|
||||
) => p !== "roles");
|
||||
if (options.allowedMentions.parse?.includes(AllowedMentionsTypes.RoleMentions)) {
|
||||
options.allowedMentions.parse = options.allowedMentions.parse.filter((p) => p !== "roles");
|
||||
}
|
||||
|
||||
if (options.allowedMentions.roles.length > 100) {
|
||||
options.allowedMentions.roles = options.allowedMentions.roles.slice(
|
||||
0,
|
||||
100,
|
||||
);
|
||||
options.allowedMentions.roles = options.allowedMentions.roles.slice(0, 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (options.attachments) validateAttachments(bot, options.attachments);
|
||||
|
||||
return await editFollowupMessageOld(token, messageId, options);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
import { BotWithCache } from "../../deps.ts";
|
||||
import { requireBotGuildPermissions } from "../permissions.ts";
|
||||
|
||||
export default function editBotNickname(bot: BotWithCache) {
|
||||
const editBotNicknameOld = bot.helpers.editBotNickname;
|
||||
|
||||
bot.helpers.editBotNickname = async function (guildId, options) {
|
||||
requireBotGuildPermissions(bot, guildId, ["CHANGE_NICKNAME"]);
|
||||
|
||||
return await editBotNicknameOld(guildId, options);
|
||||
};
|
||||
}
|
||||
12
plugins/permissions/src/members/editBotMember.ts
Normal file
12
plugins/permissions/src/members/editBotMember.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { BotWithCache } from "../../deps.ts";
|
||||
import { requireBotGuildPermissions } from "../permissions.ts";
|
||||
|
||||
export default function editBotMember(bot: BotWithCache) {
|
||||
const editBotMemberOld = bot.helpers.editBotMember;
|
||||
|
||||
bot.helpers.editBotMember = async function (guildId, options) {
|
||||
requireBotGuildPermissions(bot, guildId, ["CHANGE_NICKNAME"]);
|
||||
|
||||
return await editBotMemberOld(guildId, options);
|
||||
};
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
import { BotWithCache } from "../../deps.ts";
|
||||
import setupBanPermChecks from "./ban.ts";
|
||||
import editBotNickname from "./editBot.ts";
|
||||
import editBotMember from "./editBotMember.ts";
|
||||
import editMember from "./editMember.ts";
|
||||
import kickMember from "./kickMember.ts";
|
||||
import pruneMembers from "./pruneMembers.ts";
|
||||
|
||||
export default function setupMemberPermChecks(bot: BotWithCache) {
|
||||
setupBanPermChecks(bot);
|
||||
editBotNickname(bot);
|
||||
editBotMember(bot);
|
||||
editMember(bot);
|
||||
kickMember(bot);
|
||||
pruneMembers(bot);
|
||||
|
||||
@@ -5,10 +5,7 @@ export function addReaction(bot: BotWithCache) {
|
||||
const addReactionOld = bot.helpers.addReaction;
|
||||
|
||||
bot.helpers.addReaction = async function (channelId, messageId, reaction) {
|
||||
requireBotChannelPermissions(bot, channelId, [
|
||||
"READ_MESSAGE_HISTORY",
|
||||
"ADD_REACTIONS",
|
||||
]);
|
||||
requireBotChannelPermissions(bot, channelId, ["READ_MESSAGE_HISTORY", "ADD_REACTIONS"]);
|
||||
|
||||
return await addReactionOld(channelId, messageId, reaction);
|
||||
};
|
||||
@@ -17,76 +14,47 @@ export function addReaction(bot: BotWithCache) {
|
||||
export function addReactions(bot: BotWithCache) {
|
||||
const addReactionsOld = bot.helpers.addReactions;
|
||||
|
||||
bot.helpers.addReactions = async function (
|
||||
channelId,
|
||||
messageId,
|
||||
reactions,
|
||||
ordered,
|
||||
) {
|
||||
requireBotChannelPermissions(bot, channelId, [
|
||||
"READ_MESSAGE_HISTORY",
|
||||
"ADD_REACTIONS",
|
||||
]);
|
||||
bot.helpers.addReactions = async function (channelId, messageId, reactions, ordered) {
|
||||
requireBotChannelPermissions(bot, channelId, ["READ_MESSAGE_HISTORY", "ADD_REACTIONS"]);
|
||||
|
||||
return await addReactionsOld(channelId, messageId, reactions, ordered);
|
||||
};
|
||||
}
|
||||
|
||||
export function removeReaction(bot: BotWithCache) {
|
||||
const removeReactionOld = bot.helpers.removeReaction;
|
||||
export function deleteUserReaction(bot: BotWithCache) {
|
||||
const deleteUserReactionOld = bot.helpers.deleteUserReaction;
|
||||
|
||||
bot.helpers.removeReaction = async function (
|
||||
channelId,
|
||||
messageId,
|
||||
reactions,
|
||||
options,
|
||||
) {
|
||||
// IF REMOVING OTHER USER PERMS MANAGE MESSAGES IS REQUIRED
|
||||
if (options?.userId) {
|
||||
requireBotChannelPermissions(bot, channelId, [
|
||||
"MANAGE_MESSAGES",
|
||||
]);
|
||||
}
|
||||
bot.helpers.deleteUserReaction = async function (channelId, messageId, userId, reaction) {
|
||||
requireBotChannelPermissions(bot, channelId, ["MANAGE_MESSAGES"]);
|
||||
|
||||
return await removeReactionOld(channelId, messageId, reactions, options);
|
||||
return await deleteUserReactionOld(channelId, messageId, userId, reaction);
|
||||
};
|
||||
}
|
||||
|
||||
export function removeAllReactions(bot: BotWithCache) {
|
||||
const removeAllReactionsOld = bot.helpers.removeAllReactions;
|
||||
export function deleteReactionsAll(bot: BotWithCache) {
|
||||
const DeleteReactionsAllOld = bot.helpers.deleteReactionsAll;
|
||||
|
||||
bot.helpers.removeAllReactions = async function (
|
||||
channelId,
|
||||
messageId,
|
||||
) {
|
||||
requireBotChannelPermissions(bot, channelId, [
|
||||
"MANAGE_MESSAGES",
|
||||
]);
|
||||
bot.helpers.deleteReactionsAll = async function (channelId, messageId) {
|
||||
requireBotChannelPermissions(bot, channelId, ["MANAGE_MESSAGES"]);
|
||||
|
||||
return await removeAllReactionsOld(channelId, messageId);
|
||||
return await DeleteReactionsAllOld(channelId, messageId);
|
||||
};
|
||||
}
|
||||
|
||||
export function removeReactionEmoji(bot: BotWithCache) {
|
||||
const removeReactionEmojiOld = bot.helpers.removeReactionEmoji;
|
||||
export function deleteReactionsEmoji(bot: BotWithCache) {
|
||||
const deleteReactionsEmojiOld = bot.helpers.deleteReactionsEmoji;
|
||||
|
||||
bot.helpers.removeReactionEmoji = async function (
|
||||
channelId,
|
||||
messageId,
|
||||
reaction,
|
||||
) {
|
||||
requireBotChannelPermissions(bot, channelId, [
|
||||
"MANAGE_MESSAGES",
|
||||
]);
|
||||
bot.helpers.deleteReactionsEmoji = async function (channelId, messageId, reaction) {
|
||||
requireBotChannelPermissions(bot, channelId, ["MANAGE_MESSAGES"]);
|
||||
|
||||
return await removeReactionEmojiOld(channelId, messageId, reaction);
|
||||
return await deleteReactionsEmojiOld(channelId, messageId, reaction);
|
||||
};
|
||||
}
|
||||
|
||||
export default function setupReactionsPermChecks(bot: BotWithCache) {
|
||||
addReaction(bot);
|
||||
addReactions(bot);
|
||||
removeReaction(bot);
|
||||
removeAllReactions(bot);
|
||||
removeReactionEmoji(bot);
|
||||
deleteUserReaction(bot);
|
||||
deleteReactionsAll(bot);
|
||||
deleteReactionsEmoji(bot);
|
||||
}
|
||||
|
||||
@@ -1,19 +1,11 @@
|
||||
import { AllowedMentionsTypes, BotWithCache } from "../../deps.ts";
|
||||
import { validateAttachments } from "../attachments.ts";
|
||||
import { validateComponents } from "../components.ts";
|
||||
|
||||
export function editWebhookMessage(bot: BotWithCache) {
|
||||
const editWebhookMessageOld = bot.helpers.editWebhookMessage;
|
||||
|
||||
bot.helpers.editWebhookMessage = async function (
|
||||
webhookId,
|
||||
webhookToken,
|
||||
options,
|
||||
) {
|
||||
if (
|
||||
options.content &&
|
||||
!bot.utils.validateLength(options.content, { max: 2000 })
|
||||
) {
|
||||
bot.helpers.editWebhookMessage = async function (webhookId, webhookToken, messageId, options) {
|
||||
if (options.content && !bot.utils.validateLength(options.content, { max: 2000 })) {
|
||||
throw Error("The content can not exceed 2000 characters.");
|
||||
}
|
||||
|
||||
@@ -23,49 +15,29 @@ export function editWebhookMessage(bot: BotWithCache) {
|
||||
|
||||
if (options.allowedMentions) {
|
||||
if (options.allowedMentions.users?.length) {
|
||||
if (
|
||||
options.allowedMentions.parse?.includes(
|
||||
AllowedMentionsTypes.UserMentions,
|
||||
)
|
||||
) {
|
||||
options.allowedMentions.parse = options.allowedMentions.parse.filter((
|
||||
p,
|
||||
) => p !== "users");
|
||||
if (options.allowedMentions.parse?.includes(AllowedMentionsTypes.UserMentions)) {
|
||||
options.allowedMentions.parse = options.allowedMentions.parse.filter((p) => p !== "users");
|
||||
}
|
||||
|
||||
if (options.allowedMentions.users.length > 100) {
|
||||
options.allowedMentions.users = options.allowedMentions.users.slice(
|
||||
0,
|
||||
100,
|
||||
);
|
||||
options.allowedMentions.users = options.allowedMentions.users.slice(0, 100);
|
||||
}
|
||||
}
|
||||
|
||||
if (options.allowedMentions.roles?.length) {
|
||||
if (
|
||||
options.allowedMentions.parse?.includes(
|
||||
AllowedMentionsTypes.RoleMentions,
|
||||
)
|
||||
) {
|
||||
options.allowedMentions.parse = options.allowedMentions.parse.filter((
|
||||
p,
|
||||
) => p !== "roles");
|
||||
if (options.allowedMentions.parse?.includes(AllowedMentionsTypes.RoleMentions)) {
|
||||
options.allowedMentions.parse = options.allowedMentions.parse.filter((p) => p !== "roles");
|
||||
}
|
||||
|
||||
if (options.allowedMentions.roles.length > 100) {
|
||||
options.allowedMentions.roles = options.allowedMentions.roles.slice(
|
||||
0,
|
||||
100,
|
||||
);
|
||||
options.allowedMentions.roles = options.allowedMentions.roles.slice(0, 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (options.components) validateComponents(bot, options.components);
|
||||
|
||||
if (options.attachments) validateAttachments(bot, options.attachments);
|
||||
|
||||
return await editWebhookMessageOld(webhookId, webhookToken, options);
|
||||
return await editWebhookMessageOld(webhookId, webhookToken, messageId, options);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
export * from "./toggles/mod.ts";
|
||||
export * from "./reverse/mod.ts";
|
||||
|
||||
export * from "./activity.ts";
|
||||
export * from "./application.ts";
|
||||
export * from "./applicationCommand.ts";
|
||||
export * from "./applicationCommandOption.ts";
|
||||
export * from "./applicationCommandOptionChoice.ts";
|
||||
export * from "./applicationCommandPermission.ts";
|
||||
export * from "./attachment.ts";
|
||||
export * from "./auditLogEntry.ts";
|
||||
@@ -32,5 +34,3 @@ export * from "./webhook.ts";
|
||||
export * from "./welcomeScreen.ts";
|
||||
export * from "./widget.ts";
|
||||
export * from "./widgetSettings.ts";
|
||||
|
||||
export * from "./reverse/mod.ts";
|
||||
|
||||
Reference in New Issue
Block a user