3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-21 00:35:02 +00:00

perf: check user permissions before trying to parse the values

This commit is contained in:
Almeida 2021-05-05 19:36:09 +01:00
parent 58542e0169
commit de0b82cb5a

View file

@ -36,27 +36,32 @@ export const InfoCmd = utilityCmd({
});
// 1. Channel
if (userCfg.can_channelinfo) {
const channelId = getChannelId(value);
const channel = channelId && pluginData.guild.channels.get(channelId);
if (channel && userCfg.can_channelinfo) {
if (channel) {
const embed = await getChannelInfoEmbed(pluginData, channelId!, message.author.id);
if (embed) {
message.channel.createMessage({ embed });
return;
}
}
}
// 2. Server
if (userCfg.can_server) {
const guild = pluginData.client.guilds.get(value);
if (guild && userCfg.can_server) {
if (guild) {
const embed = await getServerInfoEmbed(pluginData, value, message.author.id);
if (embed) {
message.channel.createMessage({ embed });
return;
}
}
}
// 3. User
if (userCfg.can_userinfo) {
const user = await resolveUser(pluginData.client, value);
if (user && userCfg.can_userinfo) {
const embed = await getUserInfoEmbed(pluginData, user.id, Boolean(args.compact), message.author.id);
@ -65,10 +70,12 @@ export const InfoCmd = utilityCmd({
return;
}
}
}
// 4. Message
if (userCfg.can_messageinfo) {
const messageTarget = await resolveMessageTarget(pluginData, value);
if (messageTarget && userCfg.can_messageinfo) {
if (messageTarget) {
if (canReadChannel(messageTarget.channel, message.member)) {
const embed = await getMessageInfoEmbed(
pluginData,
@ -82,12 +89,14 @@ export const InfoCmd = utilityCmd({
}
}
}
}
// 5. Invite
if (userCfg.can_inviteinfo) {
const inviteCode = parseInviteCodeInput(value) ?? value;
if (inviteCode) {
const invite = await resolveInvite(pluginData.client, inviteCode, true);
if (invite && userCfg.can_inviteinfo) {
if (invite) {
const embed = await getInviteInfoEmbed(pluginData, inviteCode);
if (embed) {
message.channel.createMessage({ embed });
@ -95,35 +104,42 @@ export const InfoCmd = utilityCmd({
}
}
}
}
// 6. Server again (fallback for discovery servers)
if (userCfg.can_server) {
const serverPreview = getGuildPreview(pluginData.client, value).catch(() => null);
if (serverPreview && userCfg.can_server) {
if (serverPreview) {
const embed = await getServerInfoEmbed(pluginData, value, message.author.id);
if (embed) {
message.channel.createMessage({ embed });
return;
}
}
}
// 7. Role
if (userCfg.can_roleinfo) {
const roleId = getRoleId(value);
const role = roleId && pluginData.guild.roles.get(roleId);
if (role && userCfg.can_roleinfo) {
if (role) {
const embed = await getRoleInfoEmbed(pluginData, role, message.author.id);
message.channel.createMessage({ embed });
return;
}
}
// 8. Emoji
if (userCfg.can_emojiinfo) {
const emojiIdMatch = value.match(customEmojiRegex);
if (emojiIdMatch?.[2] && userCfg.can_emojiinfo) {
if (emojiIdMatch?.[2]) {
const embed = await getEmojiInfoEmbed(pluginData, emojiIdMatch[2]);
if (embed) {
message.channel.createMessage({ embed });
return;
}
}
}
// 9. Arbitrary ID
if (isValidSnowflake(value) && userCfg.can_snowflake) {