fix(plugins): errors caused by bigstring support (#2486)

This commit is contained in:
LTS20050703
2022-09-22 11:40:41 -04:00
committed by GitHub
parent 17132aaf61
commit bf70526029
71 changed files with 122 additions and 112 deletions
+2 -1
View File
@@ -1,4 +1,5 @@
import {
BigString,
Bot,
Channel,
Collection,
@@ -17,7 +18,7 @@ export type BotWithCache<B extends Bot = Bot> = Omit<B, "helpers"> & CacheProps
export type BotHelpersWithCache<T> = Omit<T, "editWebhook"> & {
/** The added channelId argument at the end is used to validate permission checks */
editWebhook: (webhookId: bigint, options: ModifyWebhook, fromChannelId?: bigint) => Promise<Webhook>;
editWebhook: (webhookId: BigString, options: ModifyWebhook, fromChannelId?: bigint) => Promise<Webhook>;
};
export interface CacheProps {
@@ -5,7 +5,7 @@ export function createChannel(bot: BotWithCache) {
const createChannel = bot.helpers.createChannel;
bot.helpers.createChannel = async function (guildId, options) {
const guild = bot.guilds.get(guildId);
const guild = bot.guilds.get(bot.transformers.snowflake(guildId));
if (guild) {
if (options?.rateLimitPerUser && !(0 < options.rateLimitPerUser && options.rateLimitPerUser < 21600)) {
@@ -38,7 +38,7 @@ export function createChannel(bot: BotWithCache) {
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);
const category = bot.channels.get(bot.transformers.snowflake(options.parentId));
if (category && category.type !== ChannelTypes.GuildCategory) {
throw new Error("The parent id must be for a category channel type.");
}
@@ -5,7 +5,7 @@ export function deleteChannel(bot: BotWithCache) {
const deleteChannel = bot.helpers.deleteChannel;
bot.helpers.deleteChannel = async function (channelId, reason) {
const channel = bot.channels.get(channelId);
const channel = bot.channels.get(bot.transformers.snowflake(channelId));
if (channel?.guildId) {
const guild = bot.guilds.get(channel.guildId);
@@ -25,7 +25,7 @@ export function deleteChannel(bot: BotWithCache) {
if (isVoice) perms.push("CONNECT");
requireBotChannelPermissions(bot, channelId, perms);
requireBotChannelPermissions(bot, bot.transformers.snowflake(channelId), perms);
}
return await deleteChannel(channelId, reason);
@@ -5,7 +5,7 @@ export function deleteChannelPermissionOverride(bot: BotWithCache) {
const deleteChannelPermissionOverride = bot.helpers.deleteChannelPermissionOverride;
bot.helpers.deleteChannelPermissionOverride = async function (channelId, overwriteId) {
const channel = bot.channels.get(channelId);
const channel = bot.channels.get(bot.transformers.snowflake(channelId));
if (channel?.guildId) {
const perms: PermissionStrings[] = ["VIEW_CHANNEL", "MANAGE_ROLES"];
@@ -13,7 +13,7 @@ export function deleteChannelPermissionOverride(bot: BotWithCache) {
if (isVoice) perms.push("CONNECT");
requireBotChannelPermissions(bot, channelId, perms);
requireBotChannelPermissions(bot, bot.transformers.snowflake(channelId), perms);
}
return await deleteChannelPermissionOverride(channelId, overwriteId);
@@ -5,7 +5,7 @@ export function editChannel(bot: BotWithCache) {
const editChannel = bot.helpers.editChannel;
bot.helpers.editChannel = async function (channelId, options) {
const channel = bot.channels.get(channelId);
const channel = bot.channels.get(bot.transformers.snowflake(channelId));
if (channel?.guildId) {
const guild = bot.guilds.get(channel.guildId);
@@ -64,7 +64,7 @@ export function editChannel(bot: BotWithCache) {
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);
const category = bot.channels.get(bot.transformers.snowflake(options.parentId));
if (category && category.type !== ChannelTypes.GuildCategory) {
throw new Error("The parent id must be for a category channel type.");
}
@@ -5,14 +5,14 @@ export function editChannelPermissionOverrides(bot: BotWithCache) {
const editChannelPermissionOverrides = bot.helpers.editChannelPermissionOverrides;
bot.helpers.editChannelPermissionOverrides = async function (channelId, overwrite) {
const channel = bot.channels.get(channelId);
const channel = bot.channels.get(bot.transformers.snowflake(channelId));
if (channel?.guildId) {
const perms: PermissionStrings[] = ["VIEW_CHANNEL", "MANAGE_ROLES"];
const isVoice = [ChannelTypes.GuildVoice, ChannelTypes.GuildStageVoice].includes(channel.type);
if (isVoice) perms.push("CONNECT");
requireBotChannelPermissions(bot, channelId, perms);
requireBotChannelPermissions(bot, bot.transformers.snowflake(channelId), perms);
}
return await editChannelPermissionOverrides(channelId, overwrite);
@@ -5,19 +5,19 @@ export function followAnnouncementChannel(bot: BotWithCache) {
const followAnnouncementChannel = bot.helpers.followAnnouncementChannel;
bot.helpers.followAnnouncementChannel = async function (sourceChannelId, targetChannelId) {
const sourceChannel = bot.channels.get(sourceChannelId);
const sourceChannel = bot.channels.get(bot.transformers.snowflake(sourceChannelId));
if (sourceChannel && sourceChannel.type !== ChannelTypes.GuildAnnouncement) {
throw new Error("Source channel must be an announcement channel");
}
const targetChannel = bot.channels.get(targetChannelId);
const targetChannel = bot.channels.get(bot.transformers.snowflake(targetChannelId));
if (targetChannel) {
const isWebhookParent = [ChannelTypes.GuildAnnouncement, ChannelTypes.GuildText].includes(targetChannel.type);
if (!isWebhookParent) {
throw new Error("Target channel must be a text channel or an announcement channel");
}
}
requireBotChannelPermissions(bot, sourceChannelId, ["VIEW_CHANNEL"]);
requireBotChannelPermissions(bot, targetChannelId, ["VIEW_CHANNEL", "MANAGE_WEBHOOKS"]);
requireBotChannelPermissions(bot, bot.transformers.snowflake(sourceChannelId), ["VIEW_CHANNEL"]);
requireBotChannelPermissions(bot, bot.transformers.snowflake(targetChannelId), ["VIEW_CHANNEL", "MANAGE_WEBHOOKS"]);
return await followAnnouncementChannel(sourceChannelId, targetChannelId);
};
}
@@ -5,12 +5,12 @@ export function createForumThread(bot: BotWithCache) {
const createForumThread = bot.helpers.createForumThread;
bot.helpers.createForumThread = async function (channelId, options) {
const channel = bot.channels.get(channelId);
const channel = bot.channels.get(bot.transformers.snowflake(channelId));
if (channel && channel.type !== ChannelTypes.GuildForum) {
throw new Error("Channel must be a forum channel");
}
requireBotChannelPermissions(bot, channelId, ["VIEW_CHANNEL", "SEND_MESSAGES"]);
requireBotChannelPermissions(bot, bot.transformers.snowflake(channelId), ["VIEW_CHANNEL", "SEND_MESSAGES"]);
return await createForumThread(channelId, options);
};
@@ -5,13 +5,13 @@ export function getChannelWebhooks(bot: BotWithCache) {
const getChannelWebhooks = bot.helpers.getChannelWebhooks;
bot.helpers.getChannelWebhooks = async function (channelId) {
const channel = bot.channels.get(channelId);
const channel = bot.channels.get(bot.transformers.snowflake(channelId));
if (channel) {
const isWebhookParent = [ChannelTypes.GuildAnnouncement, ChannelTypes.GuildText].includes(channel.type);
if (!isWebhookParent) {
throw new Error("Target channel must be a text channel or an announcement channel");
}
requireBotChannelPermissions(bot, channelId, ["VIEW_CHANNEL", "MANAGE_WEBHOOKS"]);
requireBotChannelPermissions(bot, bot.transformers.snowflake(channelId), ["VIEW_CHANNEL", "MANAGE_WEBHOOKS"]);
}
return await getChannelWebhooks(channelId);
@@ -5,14 +5,14 @@ export function createStageInstance(bot: BotWithCache) {
const createStageInstance = bot.helpers.createStageInstance;
bot.helpers.createStageInstance = async function (options) {
const channel = bot.channels.get(options.channelId);
const channel = bot.channels.get(bot.transformers.snowflake(options.channelId));
if (channel && channel.type !== ChannelTypes.GuildStageVoice) {
throw new Error("Channel must be a stage voice channel");
}
const perms: PermissionStrings[] = ["VIEW_CHANNEL", "CONNECT", "MANAGE_CHANNELS", "MUTE_MEMBERS", "MOVE_MEMBERS"];
if (options.sendStartNotification) perms.push("MENTION_EVERYONE");
requireBotChannelPermissions(bot, options.channelId, perms);
requireBotChannelPermissions(bot, bot.transformers.snowflake(options.channelId), perms);
return await createStageInstance(options);
};
@@ -5,11 +5,11 @@ export function deleteStageInstance(bot: BotWithCache) {
const deleteStageInstance = bot.helpers.deleteStageInstance;
bot.helpers.deleteStageInstance = async function (channelId) {
const channel = bot.channels.get(channelId);
const channel = bot.channels.get(bot.transformers.snowflake(channelId));
if (channel && channel.type !== ChannelTypes.GuildStageVoice) {
throw new Error("Channel must be a stage voice channel");
}
requireBotChannelPermissions(bot, channelId, [
requireBotChannelPermissions(bot, bot.transformers.snowflake(channelId), [
"VIEW_CHANNEL",
"CONNECT",
"MANAGE_CHANNELS",
@@ -5,12 +5,12 @@ export function editStageInstance(bot: BotWithCache) {
const editStageInstance = bot.helpers.editStageInstance;
bot.helpers.editStageInstance = async function (channelId, data) {
const channel = bot.channels.get(channelId);
const channel = bot.channels.get(bot.transformers.snowflake(channelId));
if (channel && channel.type !== ChannelTypes.GuildStageVoice) {
throw new Error("Channel must be a stage voice channel");
}
requireBotChannelPermissions(bot, channelId, [
requireBotChannelPermissions(bot, bot.transformers.snowflake(channelId), [
"VIEW_CHANNEL",
"CONNECT",
"MANAGE_CHANNELS",
@@ -5,7 +5,7 @@ export function addThreadMember(bot: BotWithCache) {
const addThreadMember = bot.helpers.addThreadMember;
bot.helpers.addThreadMember = async function (threadId, userId) {
const channel = bot.channels.get(threadId);
const channel = bot.channels.get(bot.transformers.snowflake(threadId));
if (channel) {
const isThread = ![ChannelTypes.PublicThread, ChannelTypes.PrivateThread, ChannelTypes.AnnouncementThread]
@@ -4,7 +4,7 @@ import { requireBotChannelPermissions } from "../../permissions.ts";
export function getPrivateArchivedThreads(bot: BotWithCache) {
const getPrivateArchivedThreads = bot.helpers.getPrivateArchivedThreads;
bot.helpers.getPrivateArchivedThreads = async function (channelId, options) {
const channel = bot.channels.get(channelId);
const channel = bot.channels.get(bot.transformers.snowflake(channelId));
if (channel) {
const isThreadParent = [ChannelTypes.GuildText, ChannelTypes.GuildAnnouncement, ChannelTypes.GuildForum]
@@ -14,7 +14,11 @@ export function getPrivateArchivedThreads(bot: BotWithCache) {
}
}
requireBotChannelPermissions(bot, channelId, ["VIEW_CHANNEL", "READ_MESSAGE_HISTORY", "MANAGE_MESSAGES"]);
requireBotChannelPermissions(bot, bot.transformers.snowflake(channelId), [
"VIEW_CHANNEL",
"READ_MESSAGE_HISTORY",
"MANAGE_MESSAGES",
]);
return await getPrivateArchivedThreads(channelId, options);
};
@@ -4,7 +4,7 @@ import { requireBotChannelPermissions } from "../../permissions.ts";
export function getPrivateJoinedArchivedThreads(bot: BotWithCache) {
const getPrivateJoinedArchivedThreads = bot.helpers.getPrivateJoinedArchivedThreads;
bot.helpers.getPrivateJoinedArchivedThreads = async function (channelId, options) {
const channel = bot.channels.get(channelId);
const channel = bot.channels.get(bot.transformers.snowflake(channelId));
if (channel) {
const isThreadParent = [ChannelTypes.GuildText, ChannelTypes.GuildAnnouncement, ChannelTypes.GuildForum]
@@ -13,7 +13,7 @@ export function getPrivateJoinedArchivedThreads(bot: BotWithCache) {
throw new Error("Channel must be a text channel, a forum channel, or an announcement channel");
}
}
requireBotChannelPermissions(bot, channelId, ["VIEW_CHANNEL", "READ_MESSAGE_HISTORY"]);
requireBotChannelPermissions(bot, bot.transformers.snowflake(channelId), ["VIEW_CHANNEL", "READ_MESSAGE_HISTORY"]);
return await getPrivateJoinedArchivedThreads(channelId, options);
};
@@ -4,7 +4,7 @@ import { requireBotChannelPermissions } from "../../permissions.ts";
export function getPublicArchivedThreads(bot: BotWithCache) {
const getPublicArchivedThreads = bot.helpers.getPublicArchivedThreads;
bot.helpers.getPublicArchivedThreads = async function (channelId, options) {
const channel = bot.channels.get(channelId);
const channel = bot.channels.get(bot.transformers.snowflake(channelId));
if (channel) {
const isThreadParent = [ChannelTypes.GuildText, ChannelTypes.GuildAnnouncement, ChannelTypes.GuildForum]
@@ -13,7 +13,7 @@ export function getPublicArchivedThreads(bot: BotWithCache) {
throw new Error("Channel must be a text channel, a forum channel, or an announcement channel");
}
}
requireBotChannelPermissions(bot, channelId, ["VIEW_CHANNEL", "READ_MESSAGE_HISTORY"]);
requireBotChannelPermissions(bot, bot.transformers.snowflake(channelId), ["VIEW_CHANNEL", "READ_MESSAGE_HISTORY"]);
return await getPublicArchivedThreads(channelId, options);
};
@@ -5,7 +5,7 @@ export function joinThread(bot: BotWithCache) {
const joinThread = bot.helpers.joinThread;
bot.helpers.joinThread = async function (threadId) {
const channel = bot.channels.get(threadId);
const channel = bot.channels.get(bot.transformers.snowflake(threadId));
if (channel) {
const isThread = ![ChannelTypes.PublicThread, ChannelTypes.PrivateThread, ChannelTypes.AnnouncementThread]
@@ -15,7 +15,7 @@ export function joinThread(bot: BotWithCache) {
if (channel.archived) throw new Error("You can not join an archived channel.");
}
requireBotChannelPermissions(bot, threadId, ["VIEW_CHANNEL"]);
requireBotChannelPermissions(bot, bot.transformers.snowflake(threadId), ["VIEW_CHANNEL"]);
return await joinThread(threadId);
};
@@ -5,7 +5,7 @@ export function leaveThread(bot: BotWithCache) {
const leaveThread = bot.helpers.leaveThread;
bot.helpers.leaveThread = async function (threadId) {
const channel = bot.channels.get(threadId);
const channel = bot.channels.get(bot.transformers.snowflake(threadId));
if (channel) {
const isThread = ![ChannelTypes.PublicThread, ChannelTypes.PrivateThread, ChannelTypes.AnnouncementThread]
@@ -15,7 +15,7 @@ export function leaveThread(bot: BotWithCache) {
if (channel.archived) throw new Error("You can not leave an archived channel.");
}
requireBotChannelPermissions(bot, threadId, ["VIEW_CHANNEL"]);
requireBotChannelPermissions(bot, bot.transformers.snowflake(threadId), ["VIEW_CHANNEL"]);
return await leaveThread(threadId);
};
@@ -5,7 +5,7 @@ export function removeThreadMember(bot: BotWithCache) {
const removeThreadMember = bot.helpers.removeThreadMember;
bot.helpers.removeThreadMember = async function (threadId, userId) {
const channel = bot.channels.get(threadId);
const channel = bot.channels.get(bot.transformers.snowflake(threadId));
if (channel) {
const isThread = ![ChannelTypes.PublicThread, ChannelTypes.PrivateThread, ChannelTypes.AnnouncementThread]
@@ -5,7 +5,7 @@ export function createEmoji(bot: BotWithCache) {
const createEmoji = bot.helpers.createEmoji;
bot.helpers.createEmoji = async function (guildId, id) {
requireBotGuildPermissions(bot, guildId, ["MANAGE_EMOJIS_AND_STICKERS"]);
requireBotGuildPermissions(bot, bot.transformers.snowflake(guildId), ["MANAGE_EMOJIS_AND_STICKERS"]);
return await createEmoji(guildId, id);
};
@@ -5,7 +5,7 @@ export function deleteEmoji(bot: BotWithCache) {
const deleteEmoji = bot.helpers.deleteEmoji;
bot.helpers.deleteEmoji = async function (guildId, id) {
requireBotGuildPermissions(bot, guildId, ["MANAGE_EMOJIS_AND_STICKERS"]);
requireBotGuildPermissions(bot, bot.transformers.snowflake(guildId), ["MANAGE_EMOJIS_AND_STICKERS"]);
return await deleteEmoji(guildId, id);
};
+1 -1
View File
@@ -5,7 +5,7 @@ export function editEmoji(bot: BotWithCache) {
const editEmoji = bot.helpers.editEmoji;
bot.helpers.editEmoji = async function (guildId, id, options) {
requireBotGuildPermissions(bot, guildId, ["MANAGE_EMOJIS_AND_STICKERS"]);
requireBotGuildPermissions(bot, bot.transformers.snowflake(guildId), ["MANAGE_EMOJIS_AND_STICKERS"]);
return await editEmoji(guildId, id, options);
};
@@ -5,7 +5,7 @@ export function createAutomodRule(bot: BotWithCache) {
const createAutomodRule = bot.helpers.createAutomodRule;
bot.helpers.createAutomodRule = async function (guildId, options) {
requireBotGuildPermissions(bot, guildId, ["MANAGE_GUILD"]);
requireBotGuildPermissions(bot, bot.transformers.snowflake(guildId), ["MANAGE_GUILD"]);
for (const action of options.actions) {
// Check for maximum duration seconds
@@ -19,7 +19,7 @@ export function createAutomodRule(bot: BotWithCache) {
// Timeout actions require perm check
if (action.type === AutoModerationActionType.Timeout) {
requireBotGuildPermissions(bot, guildId, ["MODERATE_MEMBERS"]);
requireBotGuildPermissions(bot, bot.transformers.snowflake(guildId), ["MODERATE_MEMBERS"]);
}
}
@@ -5,7 +5,7 @@ export function deleteAutomodRule(bot: BotWithCache) {
const deleteAutomodRule = bot.helpers.deleteAutomodRule;
bot.helpers.deleteAutomodRule = async function (guildId, options) {
requireBotGuildPermissions(bot, guildId, ["MANAGE_GUILD"]);
requireBotGuildPermissions(bot, bot.transformers.snowflake(guildId), ["MANAGE_GUILD"]);
return await deleteAutomodRule(guildId, options);
};
@@ -5,7 +5,7 @@ export function editAutomodRule(bot: BotWithCache) {
const editAutomodRule = bot.helpers.editAutomodRule;
bot.helpers.editAutomodRule = async function (guildId, ruleId, options) {
requireBotGuildPermissions(bot, guildId, ["MANAGE_GUILD"]);
requireBotGuildPermissions(bot, bot.transformers.snowflake(guildId), ["MANAGE_GUILD"]);
for (const action of options.actions ?? []) {
// Check for maximum duration seconds
@@ -19,7 +19,7 @@ export function editAutomodRule(bot: BotWithCache) {
// Timeout actions require perm check
if (action.type === AutoModerationActionType.Timeout) {
requireBotGuildPermissions(bot, guildId, ["MODERATE_MEMBERS"]);
requireBotGuildPermissions(bot, bot.transformers.snowflake(guildId), ["MODERATE_MEMBERS"]);
}
}
@@ -5,7 +5,7 @@ export function getAutomodRule(bot: BotWithCache) {
const getAutomodRule = bot.helpers.getAutomodRule;
bot.helpers.getAutomodRule = async function (guildId, ruleId) {
requireBotGuildPermissions(bot, guildId, ["MANAGE_GUILD"]);
requireBotGuildPermissions(bot, bot.transformers.snowflake(guildId), ["MANAGE_GUILD"]);
return await getAutomodRule(guildId, ruleId);
};
@@ -5,7 +5,7 @@ export function getAutomodRules(bot: BotWithCache) {
const getAutomodRules = bot.helpers.getAutomodRules;
bot.helpers.getAutomodRules = async function (guildId) {
requireBotGuildPermissions(bot, guildId, ["MANAGE_GUILD"]);
requireBotGuildPermissions(bot, bot.transformers.snowflake(guildId), ["MANAGE_GUILD"]);
return await getAutomodRules(guildId);
};
@@ -4,7 +4,7 @@ export function deleteGuild(bot: BotWithCache) {
const deleteGuild = bot.helpers.deleteGuild;
bot.helpers.deleteGuild = async function (guildId) {
const guild = bot.guilds.get(guildId);
const guild = bot.guilds.get(bot.transformers.snowflake(guildId));
if (guild && guild.ownerId !== bot.id) throw new Error("A bot can only delete a guild it owns.");
return await deleteGuild(guildId);
+2 -2
View File
@@ -6,8 +6,8 @@ export function editGuild(bot: BotWithCache) {
bot.helpers.editGuild = async function (guildId, options, shardId) {
if (options.features?.includes(GuildFeatures.Community)) {
requireBotGuildPermissions(bot, guildId, ["ADMINISTRATOR"]);
} else requireBotGuildPermissions(bot, guildId, ["MANAGE_GUILD"]);
requireBotGuildPermissions(bot, bot.transformers.snowflake(guildId), ["ADMINISTRATOR"]);
} else requireBotGuildPermissions(bot, bot.transformers.snowflake(guildId), ["MANAGE_GUILD"]);
return await editGuild(guildId, options, shardId);
};
@@ -4,7 +4,7 @@ export function editGuildMfaLevel(bot: BotWithCache) {
const editGuildMfaLevel = bot.helpers.editGuildMfaLevel;
bot.helpers.editGuildMfaLevel = async function (guildId, mfaLevel, reason) {
const guild = bot.guilds.get(guildId);
const guild = bot.guilds.get(bot.transformers.snowflake(guildId));
if (guild?.ownerId !== bot.id) throw new Error("The bot is not the owner of the guild");
return await editGuildMfaLevel(guildId, mfaLevel, reason);
};
@@ -5,7 +5,7 @@ export function editWelcomeScreen(bot: BotWithCache) {
const editWelcomeScreen = bot.helpers.editWelcomeScreen;
bot.helpers.editWelcomeScreen = async function (guildId, options) {
requireBotGuildPermissions(bot, guildId, ["MANAGE_GUILD"]);
requireBotGuildPermissions(bot, bot.transformers.snowflake(guildId), ["MANAGE_GUILD"]);
return await editWelcomeScreen(guildId, options);
};
@@ -12,7 +12,7 @@ export function createScheduledEvent(bot: BotWithCache) {
);
}
requireBotChannelPermissions(bot, options.channelId, [
requireBotChannelPermissions(bot, bot.transformers.snowflake(options.channelId), [
"MANAGE_CHANNELS",
"MUTE_MEMBERS",
"MOVE_MEMBERS",
@@ -20,11 +20,11 @@ export function createScheduledEvent(bot: BotWithCache) {
// MANAGE_EVENTS at the guild level or at least MANAGE_EVENTS for the channel_id associated with the event
try {
requireBotGuildPermissions(bot, guildId, [
requireBotGuildPermissions(bot, bot.transformers.snowflake(guildId), [
"MANAGE_EVENTS",
]);
} catch {
requireBotChannelPermissions(bot, options.channelId, [
requireBotChannelPermissions(bot, bot.transformers.snowflake(options.channelId), [
"MANAGE_EVENTS",
]);
}
@@ -39,18 +39,18 @@ export function createScheduledEvent(bot: BotWithCache) {
);
}
requireBotChannelPermissions(bot, options.channelId, [
requireBotChannelPermissions(bot, bot.transformers.snowflake(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, [
requireBotGuildPermissions(bot, bot.transformers.snowflake(guildId), [
"MANAGE_EVENTS",
]);
} catch {
requireBotChannelPermissions(bot, options.channelId, [
requireBotChannelPermissions(bot, bot.transformers.snowflake(options.channelId), [
"MANAGE_EVENTS",
]);
}
@@ -60,7 +60,7 @@ export function createScheduledEvent(bot: BotWithCache) {
// EXTERNAL EVENTS
requireBotGuildPermissions(bot, guildId, [
requireBotGuildPermissions(bot, bot.transformers.snowflake(guildId), [
"MANAGE_EVENTS",
]);
@@ -12,7 +12,7 @@ export function editScheduledEvent(bot: BotWithCache) {
);
}
requireBotChannelPermissions(bot, options.channelId, [
requireBotChannelPermissions(bot, bot.transformers.snowflake(options.channelId), [
"MANAGE_CHANNELS",
"MUTE_MEMBERS",
"MOVE_MEMBERS",
@@ -20,11 +20,11 @@ export function editScheduledEvent(bot: BotWithCache) {
// MANAGE_EVENTS at the guild level or at least MANAGE_EVENTS for the channel_id associated with the event
try {
requireBotGuildPermissions(bot, guildId, [
requireBotGuildPermissions(bot, bot.transformers.snowflake(guildId), [
"MANAGE_EVENTS",
]);
} catch {
requireBotChannelPermissions(bot, options.channelId, [
requireBotChannelPermissions(bot, bot.transformers.snowflake(options.channelId), [
"MANAGE_EVENTS",
]);
}
@@ -39,18 +39,18 @@ export function editScheduledEvent(bot: BotWithCache) {
);
}
requireBotChannelPermissions(bot, options.channelId, [
requireBotChannelPermissions(bot, bot.transformers.snowflake(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, [
requireBotGuildPermissions(bot, bot.transformers.snowflake(guildId), [
"MANAGE_EVENTS",
]);
} catch {
requireBotChannelPermissions(bot, options.channelId, [
requireBotChannelPermissions(bot, bot.transformers.snowflake(options.channelId), [
"MANAGE_EVENTS",
]);
}
@@ -60,7 +60,7 @@ export function editScheduledEvent(bot: BotWithCache) {
// EXTERNAL EVENTS
requireBotGuildPermissions(bot, guildId, [
requireBotGuildPermissions(bot, bot.transformers.snowflake(guildId), [
"MANAGE_EVENTS",
]);
@@ -5,7 +5,7 @@ export function getAuditLog(bot: BotWithCache) {
const getAuditLog = bot.helpers.getAuditLog;
bot.helpers.getAuditLog = async function (guildId, options) {
requireBotGuildPermissions(bot, guildId, ["VIEW_AUDIT_LOG"]);
requireBotGuildPermissions(bot, bot.transformers.snowflake(guildId), ["VIEW_AUDIT_LOG"]);
return await getAuditLog(guildId, options);
};
+1 -1
View File
@@ -5,7 +5,7 @@ export function getBan(bot: BotWithCache) {
const getBan = bot.helpers.getBan;
bot.helpers.getBan = async function (guildId, memberId) {
requireBotGuildPermissions(bot, guildId, ["BAN_MEMBERS"]);
requireBotGuildPermissions(bot, bot.transformers.snowflake(guildId), ["BAN_MEMBERS"]);
return await getBan(guildId, memberId);
};
+1 -1
View File
@@ -5,7 +5,7 @@ export function getBans(bot: BotWithCache) {
const getBans = bot.helpers.getBans;
bot.helpers.getBans = async function (guildId) {
requireBotGuildPermissions(bot, guildId, ["BAN_MEMBERS"]);
requireBotGuildPermissions(bot, bot.transformers.snowflake(guildId), ["BAN_MEMBERS"]);
return await getBans(guildId);
};
@@ -5,7 +5,7 @@ export function getPruneCount(bot: BotWithCache) {
const getPruneCount = bot.helpers.getPruneCount;
bot.helpers.getPruneCount = async function (guildId, options) {
requireBotGuildPermissions(bot, guildId, ["KICK_MEMBERS"]);
requireBotGuildPermissions(bot, bot.transformers.snowflake(guildId), ["KICK_MEMBERS"]);
return await getPruneCount(guildId, options);
};
@@ -5,7 +5,7 @@ export function getVanityUrl(bot: BotWithCache) {
const getVanityUrl = bot.helpers.getVanityUrl;
bot.helpers.getVanityUrl = async function (guildId) {
requireBotGuildPermissions(bot, guildId, ["MANAGE_GUILD"]);
requireBotGuildPermissions(bot, bot.transformers.snowflake(guildId), ["MANAGE_GUILD"]);
return await getVanityUrl(guildId);
};
@@ -5,8 +5,8 @@ export function getWelcomeScreen(bot: BotWithCache) {
const getWelcomeScreen = bot.helpers.getWelcomeScreen;
bot.helpers.getWelcomeScreen = async function (guildId) {
const guild = bot.guilds.get(guildId);
if (!guild?.welcomeScreen) requireBotGuildPermissions(bot, guildId, ["MANAGE_GUILD"]);
const guild = bot.guilds.get(bot.transformers.snowflake(guildId));
if (!guild?.welcomeScreen) requireBotGuildPermissions(bot, bot.transformers.snowflake(guildId), ["MANAGE_GUILD"]);
return await getWelcomeScreen(guildId);
};
@@ -5,7 +5,7 @@ export function connectToVoiceChannel(bot: BotWithCache) {
const connectToVoiceChannel = bot.helpers.connectToVoiceChannel;
bot.helpers.connectToVoiceChannel = async function (guildId, channelId, options) {
const channel = bot.channels.get(channelId);
const channel = bot.channels.get(bot.transformers.snowflake(channelId));
if (!channel) throw new Error("CHANNEL_NOT_FOUND");
if (
@@ -5,7 +5,7 @@ export function editWidgetSettings(bot: BotWithCache) {
const editWidgetSettings = bot.helpers.editWidgetSettings;
bot.helpers.editWidgetSettings = async function (guildId, enabled, channelId) {
requireBotGuildPermissions(bot, guildId, ["MANAGE_GUILD"]);
requireBotGuildPermissions(bot, bot.transformers.snowflake(guildId), ["MANAGE_GUILD"]);
return await editWidgetSettings(guildId, enabled, channelId);
};
@@ -5,7 +5,7 @@ export function deleteIntegration(bot: BotWithCache) {
const deleteIntegration = bot.helpers.deleteIntegration;
bot.helpers.deleteIntegration = async function (guildId, id) {
requireBotGuildPermissions(bot, guildId, ["MANAGE_GUILD"]);
requireBotGuildPermissions(bot, bot.transformers.snowflake(guildId), ["MANAGE_GUILD"]);
return await deleteIntegration(guildId, id);
};
@@ -5,7 +5,7 @@ export function getIntegrations(bot: BotWithCache) {
const getIntegrations = bot.helpers.getIntegrations;
bot.helpers.getIntegrations = async function (guildId) {
requireBotGuildPermissions(bot, guildId, ["MANAGE_GUILD"]);
requireBotGuildPermissions(bot, bot.transformers.snowflake(guildId), ["MANAGE_GUILD"]);
return await getIntegrations(guildId);
};
+1 -1
View File
@@ -5,7 +5,7 @@ export function banMember(bot: BotWithCache) {
const banMember = bot.helpers.banMember;
bot.helpers.banMember = async function (guildId, id, options) {
requireBotGuildPermissions(bot, guildId, ["BAN_MEMBERS"]);
requireBotGuildPermissions(bot, bot.transformers.snowflake(guildId), ["BAN_MEMBERS"]);
return await banMember(guildId, id, options);
};
@@ -5,7 +5,7 @@ export function editBotMember(bot: BotWithCache) {
const editBotMember = bot.helpers.editBotMember;
bot.helpers.editBotMember = async function (guildId, options) {
requireBotGuildPermissions(bot, guildId, ["CHANGE_NICKNAME"]);
requireBotGuildPermissions(bot, bot.transformers.snowflake(guildId), ["CHANGE_NICKNAME"]);
return await editBotMember(guildId, options);
};
@@ -15,8 +15,8 @@ export function editMember(bot: BotWithCache) {
options.mute !== undefined || options.deaf !== undefined ||
options.channelId !== undefined
) {
const memberVoiceState = (bot.guilds.get(guildId))
?.voiceStates.get(memberId);
const memberVoiceState = (bot.guilds.get(bot.transformers.snowflake(guildId)))
?.voiceStates.get(bot.transformers.snowflake(memberId));
if (!memberVoiceState?.channelId) throw new Error("MEMBER_NOT_IN_VOICE_CHANNEL");
@@ -27,11 +27,11 @@ export function editMember(bot: BotWithCache) {
if (options.channelId) {
const requiredVoicePerms: PermissionStrings[] = ["CONNECT", "MOVE_MEMBERS"];
if (memberVoiceState) requireBotChannelPermissions(bot, memberVoiceState?.channelId, requiredVoicePerms);
requireBotChannelPermissions(bot, options.channelId, requiredVoicePerms);
requireBotChannelPermissions(bot, bot.transformers.snowflake(options.channelId), requiredVoicePerms);
}
}
requireBotGuildPermissions(bot, guildId, requiredPerms);
requireBotGuildPermissions(bot, bot.transformers.snowflake(guildId), requiredPerms);
return await editMember(guildId, memberId, options);
};
@@ -5,7 +5,7 @@ export function kickMember(bot: BotWithCache) {
const kickMember = bot.helpers.kickMember;
bot.helpers.kickMember = async function (guildId, memberId, reason) {
requireBotGuildPermissions(bot, guildId, ["KICK_MEMBERS"]);
requireBotGuildPermissions(bot, bot.transformers.snowflake(guildId), ["KICK_MEMBERS"]);
return await kickMember(guildId, memberId, reason);
};
@@ -5,7 +5,7 @@ export function pruneMembers(bot: BotWithCache) {
const pruneMembers = bot.helpers.pruneMembers;
bot.helpers.pruneMembers = async function (guildId, options) {
requireBotGuildPermissions(bot, guildId, ["KICK_MEMBERS"]);
requireBotGuildPermissions(bot, bot.transformers.snowflake(guildId), ["KICK_MEMBERS"]);
return await pruneMembers(guildId, options);
};
@@ -5,7 +5,7 @@ export function unbanMember(bot: BotWithCache) {
const unbanMember = bot.helpers.unbanMember;
bot.helpers.unbanMember = async function (guildId, id) {
requireBotGuildPermissions(bot, guildId, ["BAN_MEMBERS"]);
requireBotGuildPermissions(bot, bot.transformers.snowflake(guildId), ["BAN_MEMBERS"]);
return await unbanMember(guildId, id);
};
@@ -5,11 +5,11 @@ export function deleteMessage(bot: BotWithCache) {
const deleteMessage = bot.helpers.deleteMessage;
bot.helpers.deleteMessage = async function (channelId, messageId, reason, milliseconds) {
const message = bot.messages.get(messageId);
const message = bot.messages.get(bot.transformers.snowflake(messageId));
// DELETING SELF MESSAGES IS ALWAYS ALLOWED
if (message?.authorId === bot.id) return deleteMessage(channelId, messageId, reason, milliseconds);
const channel = bot.channels.get(channelId);
const channel = bot.channels.get(bot.transformers.snowflake(channelId));
if (channel?.guildId) {
requireBotChannelPermissions(bot, channel, [
"MANAGE_MESSAGES",
@@ -5,7 +5,7 @@ export function deleteMessages(bot: BotWithCache) {
const deleteMessages = bot.helpers.deleteMessages;
bot.helpers.deleteMessages = async function (channelId, ids, reason) {
const channel = bot.channels.get(channelId);
const channel = bot.channels.get(bot.transformers.snowflake(channelId));
if (!channel?.guildId) {
throw new Error(
`Bulk deleting messages is only allowed in channels which has a guild id. Channel ID: ${channelId} IDS: ${
@@ -5,7 +5,7 @@ export function getMessage(bot: BotWithCache) {
const getMessage = bot.helpers.getMessage;
bot.helpers.getMessage = async function (channelId, messageId) {
const channel = bot.channels.get(channelId);
const channel = bot.channels.get(bot.transformers.snowflake(channelId));
if (channel?.guildId) requireBotChannelPermissions(bot, channel, ["READ_MESSAGE_HISTORY"]);
return await getMessage(channelId, messageId);
@@ -5,7 +5,7 @@ export function getMessages(bot: BotWithCache) {
const getMessages = bot.helpers.getMessages;
bot.helpers.getMessages = async function (channelId, options) {
const channel = bot.channels.get(channelId);
const channel = bot.channels.get(bot.transformers.snowflake(channelId));
if (channel?.guildId) {
requireBotChannelPermissions(bot, channel, [
"READ_MESSAGE_HISTORY",
@@ -8,7 +8,7 @@ export function pinMessage(bot: BotWithCache) {
channelId,
messageId,
) {
requireBotChannelPermissions(bot, channelId, [
requireBotChannelPermissions(bot, bot.transformers.snowflake(channelId), [
"MANAGE_MESSAGES",
]);
@@ -5,7 +5,7 @@ export function addReaction(bot: BotWithCache) {
const addReaction = bot.helpers.addReaction;
bot.helpers.addReaction = async function (channelId, messageId, reaction) {
requireBotChannelPermissions(bot, channelId, ["READ_MESSAGE_HISTORY", "ADD_REACTIONS"]);
requireBotChannelPermissions(bot, bot.transformers.snowflake(channelId), ["READ_MESSAGE_HISTORY", "ADD_REACTIONS"]);
return await addReaction(channelId, messageId, reaction);
};
@@ -5,7 +5,7 @@ export function addReactions(bot: BotWithCache) {
const addReactions = bot.helpers.addReactions;
bot.helpers.addReactions = async function (channelId, messageId, reactions, ordered) {
requireBotChannelPermissions(bot, channelId, ["READ_MESSAGE_HISTORY", "ADD_REACTIONS"]);
requireBotChannelPermissions(bot, bot.transformers.snowflake(channelId), ["READ_MESSAGE_HISTORY", "ADD_REACTIONS"]);
return await addReactions(channelId, messageId, reactions, ordered);
};
@@ -5,7 +5,7 @@ export function deleteReactionsAll(bot: BotWithCache) {
const deleteReactionsAll = bot.helpers.deleteReactionsAll;
bot.helpers.deleteReactionsAll = async function (channelId, messageId) {
requireBotChannelPermissions(bot, channelId, ["MANAGE_MESSAGES"]);
requireBotChannelPermissions(bot, bot.transformers.snowflake(channelId), ["MANAGE_MESSAGES"]);
return await deleteReactionsAll(channelId, messageId);
};
@@ -5,7 +5,7 @@ export function deleteReactionsEmoji(bot: BotWithCache) {
const deleteReactionsEmoji = bot.helpers.deleteReactionsEmoji;
bot.helpers.deleteReactionsEmoji = async function (channelId, messageId, reaction) {
requireBotChannelPermissions(bot, channelId, ["MANAGE_MESSAGES"]);
requireBotChannelPermissions(bot, bot.transformers.snowflake(channelId), ["MANAGE_MESSAGES"]);
return await deleteReactionsEmoji(channelId, messageId, reaction);
};
@@ -5,7 +5,7 @@ export function deleteUserReaction(bot: BotWithCache) {
const deleteUserReaction = bot.helpers.deleteUserReaction;
bot.helpers.deleteUserReaction = async function (channelId, messageId, userId, reaction) {
requireBotChannelPermissions(bot, channelId, ["MANAGE_MESSAGES"]);
requireBotChannelPermissions(bot, bot.transformers.snowflake(channelId), ["MANAGE_MESSAGES"]);
return await deleteUserReaction(channelId, messageId, userId, reaction);
};
@@ -5,7 +5,7 @@ export function sendMessage(bot: BotWithCache) {
const sendMessage = bot.helpers.sendMessage;
bot.helpers.sendMessage = async function (channelId, content) {
const channel = bot.channels.get(channelId);
const channel = bot.channels.get(bot.transformers.snowflake(channelId));
if (
channel &&
[ChannelTypes.GuildCategory, ChannelTypes.GuildStageVoice, ChannelTypes.GuildForum].includes(channel.type)
@@ -5,7 +5,7 @@ export function unpinMessage(bot: BotWithCache) {
const unpinMessage = bot.helpers.unpinMessage;
bot.helpers.unpinMessage = async function (channelId, messageId) {
requireBotChannelPermissions(bot, channelId, ["MANAGE_MESSAGES"]);
requireBotChannelPermissions(bot, bot.transformers.snowflake(channelId), ["MANAGE_MESSAGES"]);
return await unpinMessage(channelId, messageId);
};
+2 -2
View File
@@ -5,9 +5,9 @@ export function addRole(bot: BotWithCache) {
const addRole = bot.helpers.addRole;
bot.helpers.addRole = async function (guildId, memberId, roleId, reason) {
const guild = bot.guilds.get(guildId);
const guild = bot.guilds.get(bot.transformers.snowflake(guildId));
if (guild) {
const role = guild.roles.get(roleId);
const role = guild.roles.get(bot.transformers.snowflake(roleId));
if (role) {
const botRole = highestRole(bot, guild, bot.id);
+1 -1
View File
@@ -5,7 +5,7 @@ export function createRole(bot: BotWithCache) {
const createRole = bot.helpers.createRole;
bot.helpers.createRole = async function (guildId, options, reason) {
requireBotGuildPermissions(bot, guildId, ["MANAGE_ROLES"]);
requireBotGuildPermissions(bot, bot.transformers.snowflake(guildId), ["MANAGE_ROLES"]);
return await createRole(guildId, options, reason);
};
+1 -1
View File
@@ -5,7 +5,7 @@ export function deleteRole(bot: BotWithCache) {
const deleteRole = bot.helpers.deleteRole;
bot.helpers.deleteRole = async function (guildId, id) {
requireBotGuildPermissions(bot, guildId, ["MANAGE_ROLES"]);
requireBotGuildPermissions(bot, bot.transformers.snowflake(guildId), ["MANAGE_ROLES"]);
return await deleteRole(guildId, id);
};
+2 -2
View File
@@ -10,9 +10,9 @@ export function editRole(bot: BotWithCache) {
id,
options,
) {
const guild = bot.guilds.get(guildId);
const guild = bot.guilds.get(bot.transformers.snowflake(guildId));
if (guild) {
const role = guild.roles.get(id);
const role = guild.roles.get(bot.transformers.snowflake(id));
if (role) {
const botRole = highestRole(bot, guild, bot.id);
@@ -5,7 +5,7 @@ export function modifyRolePositions(bot: BotWithCache) {
const modifyRolePositions = bot.helpers.modifyRolePositions;
bot.helpers.modifyRolePositions = async function (guildId, categoryId) {
requireBotGuildPermissions(bot, guildId, ["MANAGE_ROLES"]);
requireBotGuildPermissions(bot, bot.transformers.snowflake(guildId), ["MANAGE_ROLES"]);
return await modifyRolePositions(guildId, categoryId);
};
+2 -2
View File
@@ -10,9 +10,9 @@ export function removeRole(bot: BotWithCache) {
roleId,
reason,
) {
const guild = bot.guilds.get(guildId);
const guild = bot.guilds.get(bot.transformers.snowflake(guildId));
if (guild) {
const role = guild.roles.get(roleId);
const role = guild.roles.get(bot.transformers.snowflake(roleId));
if (role) {
const botRole = highestRole(bot, guild, bot.id);
@@ -5,7 +5,7 @@ export function createWebhook(bot: BotWithCache) {
const createWebhook = bot.helpers.createWebhook;
bot.helpers.createWebhook = async function (channelId, options) {
requireBotChannelPermissions(bot, channelId, ["MANAGE_WEBHOOKS", "VIEW_CHANNEL"]);
requireBotChannelPermissions(bot, bot.transformers.snowflake(channelId), ["MANAGE_WEBHOOKS", "VIEW_CHANNEL"]);
return await createWebhook(channelId, options);
};
@@ -5,7 +5,7 @@ export function deleteWebhook(bot: BotWithCache) {
const deleteWebhook = bot.helpers.deleteWebhook;
bot.helpers.deleteWebhook = async function (channelId, options) {
requireBotChannelPermissions(bot, channelId, ["MANAGE_WEBHOOKS", "VIEW_CHANNEL"]);
requireBotChannelPermissions(bot, bot.transformers.snowflake(channelId), ["MANAGE_WEBHOOKS", "VIEW_CHANNEL"]);
return await deleteWebhook(channelId, options);
};
@@ -5,7 +5,12 @@ export function editWebhook(bot: BotWithCache) {
const editWebhook = bot.helpers.editWebhook;
bot.helpers.editWebhook = async function (webhookId, options, fromChannelId) {
if (options.channelId) requireBotChannelPermissions(bot, options.channelId, ["MANAGE_WEBHOOKS", "VIEW_CHANNEL"]);
if (options.channelId) {
requireBotChannelPermissions(bot, bot.transformers.snowflake(options.channelId), [
"MANAGE_WEBHOOKS",
"VIEW_CHANNEL",
]);
}
if (fromChannelId) requireBotChannelPermissions(bot, fromChannelId, ["MANAGE_WEBHOOKS", "VIEW_CHANNEL"]);
return await editWebhook(webhookId, options);
@@ -12,7 +12,7 @@ export function deleteMessages(bot: Bot) {
const oldestAllowed = Date.now() - 1209600000;
ids = ids.filter((id) => {
const createdAt = Number(id / 4194304n + 1420070400000n);
const createdAt = Number(bot.transformers.snowflake(id) / 4194304n + 1420070400000n);
// IF MESSAGE IS OLDER THAN 2 WEEKS
if (createdAt > oldestAllowed) return true;