mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-20 16:25:03 +00:00
perf: check user permissions before trying to parse the values
This commit is contained in:
parent
58542e0169
commit
de0b82cb5a
1 changed files with 72 additions and 56 deletions
|
@ -36,59 +36,81 @@ export const InfoCmd = utilityCmd({
|
|||
});
|
||||
|
||||
// 1. Channel
|
||||
const channelId = getChannelId(value);
|
||||
const channel = channelId && pluginData.guild.channels.get(channelId);
|
||||
if (channel && userCfg.can_channelinfo) {
|
||||
const embed = await getChannelInfoEmbed(pluginData, channelId!, message.author.id);
|
||||
if (embed) {
|
||||
message.channel.createMessage({ embed });
|
||||
return;
|
||||
if (userCfg.can_channelinfo) {
|
||||
const channelId = getChannelId(value);
|
||||
const channel = channelId && pluginData.guild.channels.get(channelId);
|
||||
if (channel) {
|
||||
const embed = await getChannelInfoEmbed(pluginData, channelId!, message.author.id);
|
||||
if (embed) {
|
||||
message.channel.createMessage({ embed });
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Server
|
||||
const guild = pluginData.client.guilds.get(value);
|
||||
if (guild && userCfg.can_server) {
|
||||
const embed = await getServerInfoEmbed(pluginData, value, message.author.id);
|
||||
if (embed) {
|
||||
message.channel.createMessage({ embed });
|
||||
return;
|
||||
if (userCfg.can_server) {
|
||||
const guild = pluginData.client.guilds.get(value);
|
||||
if (guild) {
|
||||
const embed = await getServerInfoEmbed(pluginData, value, message.author.id);
|
||||
if (embed) {
|
||||
message.channel.createMessage({ embed });
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3. User
|
||||
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);
|
||||
if (embed) {
|
||||
message.channel.createMessage({ embed });
|
||||
return;
|
||||
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);
|
||||
if (embed) {
|
||||
message.channel.createMessage({ embed });
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Message
|
||||
const messageTarget = await resolveMessageTarget(pluginData, value);
|
||||
if (messageTarget && userCfg.can_messageinfo) {
|
||||
if (canReadChannel(messageTarget.channel, message.member)) {
|
||||
const embed = await getMessageInfoEmbed(
|
||||
pluginData,
|
||||
messageTarget.channel.id,
|
||||
messageTarget.messageId,
|
||||
message.author.id,
|
||||
);
|
||||
if (embed) {
|
||||
message.channel.createMessage({ embed });
|
||||
return;
|
||||
if (userCfg.can_messageinfo) {
|
||||
const messageTarget = await resolveMessageTarget(pluginData, value);
|
||||
if (messageTarget) {
|
||||
if (canReadChannel(messageTarget.channel, message.member)) {
|
||||
const embed = await getMessageInfoEmbed(
|
||||
pluginData,
|
||||
messageTarget.channel.id,
|
||||
messageTarget.messageId,
|
||||
message.author.id,
|
||||
);
|
||||
if (embed) {
|
||||
message.channel.createMessage({ embed });
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 5. Invite
|
||||
const inviteCode = parseInviteCodeInput(value) ?? value;
|
||||
if (inviteCode) {
|
||||
const invite = await resolveInvite(pluginData.client, inviteCode, true);
|
||||
if (invite && userCfg.can_inviteinfo) {
|
||||
const embed = await getInviteInfoEmbed(pluginData, inviteCode);
|
||||
if (userCfg.can_inviteinfo) {
|
||||
const inviteCode = parseInviteCodeInput(value) ?? value;
|
||||
if (inviteCode) {
|
||||
const invite = await resolveInvite(pluginData.client, inviteCode, true);
|
||||
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) {
|
||||
message.channel.createMessage({ embed });
|
||||
return;
|
||||
|
@ -96,32 +118,26 @@ export const InfoCmd = utilityCmd({
|
|||
}
|
||||
}
|
||||
|
||||
// 6. Server again (fallback for discovery servers)
|
||||
const serverPreview = getGuildPreview(pluginData.client, value).catch(() => null);
|
||||
if (serverPreview && userCfg.can_server) {
|
||||
const embed = await getServerInfoEmbed(pluginData, value, message.author.id);
|
||||
if (embed) {
|
||||
// 7. Role
|
||||
if (userCfg.can_roleinfo) {
|
||||
const roleId = getRoleId(value);
|
||||
const role = roleId && pluginData.guild.roles.get(roleId);
|
||||
if (role) {
|
||||
const embed = await getRoleInfoEmbed(pluginData, role, message.author.id);
|
||||
message.channel.createMessage({ embed });
|
||||
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
|
||||
const emojiIdMatch = value.match(customEmojiRegex);
|
||||
if (emojiIdMatch?.[2] && userCfg.can_emojiinfo) {
|
||||
const embed = await getEmojiInfoEmbed(pluginData, emojiIdMatch[2]);
|
||||
if (embed) {
|
||||
message.channel.createMessage({ embed });
|
||||
return;
|
||||
if (userCfg.can_emojiinfo) {
|
||||
const emojiIdMatch = value.match(customEmojiRegex);
|
||||
if (emojiIdMatch?.[2]) {
|
||||
const embed = await getEmojiInfoEmbed(pluginData, emojiIdMatch[2]);
|
||||
if (embed) {
|
||||
message.channel.createMessage({ embed });
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue