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,59 +36,81 @@ export const InfoCmd = utilityCmd({
}); });
// 1. Channel // 1. Channel
const channelId = getChannelId(value); if (userCfg.can_channelinfo) {
const channel = channelId && pluginData.guild.channels.get(channelId); const channelId = getChannelId(value);
if (channel && userCfg.can_channelinfo) { const channel = channelId && pluginData.guild.channels.get(channelId);
const embed = await getChannelInfoEmbed(pluginData, channelId!, message.author.id); if (channel) {
if (embed) { const embed = await getChannelInfoEmbed(pluginData, channelId!, message.author.id);
message.channel.createMessage({ embed }); if (embed) {
return; message.channel.createMessage({ embed });
return;
}
} }
} }
// 2. Server // 2. Server
const guild = pluginData.client.guilds.get(value); if (userCfg.can_server) {
if (guild && userCfg.can_server) { const guild = pluginData.client.guilds.get(value);
const embed = await getServerInfoEmbed(pluginData, value, message.author.id); if (guild) {
if (embed) { const embed = await getServerInfoEmbed(pluginData, value, message.author.id);
message.channel.createMessage({ embed }); if (embed) {
return; message.channel.createMessage({ embed });
return;
}
} }
} }
// 3. User // 3. User
const user = await resolveUser(pluginData.client, value); if (userCfg.can_userinfo) {
if (user && userCfg.can_userinfo) { const user = await resolveUser(pluginData.client, value);
const embed = await getUserInfoEmbed(pluginData, user.id, Boolean(args.compact), message.author.id); if (user && userCfg.can_userinfo) {
if (embed) { const embed = await getUserInfoEmbed(pluginData, user.id, Boolean(args.compact), message.author.id);
message.channel.createMessage({ embed }); if (embed) {
return; message.channel.createMessage({ embed });
return;
}
} }
} }
// 4. Message // 4. Message
const messageTarget = await resolveMessageTarget(pluginData, value); if (userCfg.can_messageinfo) {
if (messageTarget && userCfg.can_messageinfo) { const messageTarget = await resolveMessageTarget(pluginData, value);
if (canReadChannel(messageTarget.channel, message.member)) { if (messageTarget) {
const embed = await getMessageInfoEmbed( if (canReadChannel(messageTarget.channel, message.member)) {
pluginData, const embed = await getMessageInfoEmbed(
messageTarget.channel.id, pluginData,
messageTarget.messageId, messageTarget.channel.id,
message.author.id, messageTarget.messageId,
); message.author.id,
if (embed) { );
message.channel.createMessage({ embed }); if (embed) {
return; message.channel.createMessage({ embed });
return;
}
} }
} }
} }
// 5. Invite // 5. Invite
const inviteCode = parseInviteCodeInput(value) ?? value; if (userCfg.can_inviteinfo) {
if (inviteCode) { const inviteCode = parseInviteCodeInput(value) ?? value;
const invite = await resolveInvite(pluginData.client, inviteCode, true); if (inviteCode) {
if (invite && userCfg.can_inviteinfo) { const invite = await resolveInvite(pluginData.client, inviteCode, true);
const embed = await getInviteInfoEmbed(pluginData, inviteCode); if (invite) {
const embed = await getInviteInfoEmbed(pluginData, inviteCode);
if (embed) {
message.channel.createMessage({ embed });
return;
}
}
}
}
// 6. Server again (fallback for discovery servers)
if (userCfg.can_server) {
const serverPreview = getGuildPreview(pluginData.client, value).catch(() => null);
if (serverPreview) {
const embed = await getServerInfoEmbed(pluginData, value, message.author.id);
if (embed) { if (embed) {
message.channel.createMessage({ embed }); message.channel.createMessage({ embed });
return; return;
@ -96,32 +118,26 @@ export const InfoCmd = utilityCmd({
} }
} }
// 6. Server again (fallback for discovery servers) // 7. Role
const serverPreview = getGuildPreview(pluginData.client, value).catch(() => null); if (userCfg.can_roleinfo) {
if (serverPreview && userCfg.can_server) { const roleId = getRoleId(value);
const embed = await getServerInfoEmbed(pluginData, value, message.author.id); const role = roleId && pluginData.guild.roles.get(roleId);
if (embed) { if (role) {
const embed = await getRoleInfoEmbed(pluginData, role, message.author.id);
message.channel.createMessage({ embed }); message.channel.createMessage({ embed });
return; return;
} }
} }
// 7. Role
const roleId = getRoleId(value);
const role = roleId && pluginData.guild.roles.get(roleId);
if (role && userCfg.can_roleinfo) {
const embed = await getRoleInfoEmbed(pluginData, role, message.author.id);
message.channel.createMessage({ embed });
return;
}
// 8. Emoji // 8. Emoji
const emojiIdMatch = value.match(customEmojiRegex); if (userCfg.can_emojiinfo) {
if (emojiIdMatch?.[2] && userCfg.can_emojiinfo) { const emojiIdMatch = value.match(customEmojiRegex);
const embed = await getEmojiInfoEmbed(pluginData, emojiIdMatch[2]); if (emojiIdMatch?.[2]) {
if (embed) { const embed = await getEmojiInfoEmbed(pluginData, emojiIdMatch[2]);
message.channel.createMessage({ embed }); if (embed) {
return; message.channel.createMessage({ embed });
return;
}
} }
} }