
* update pkgs Signed-off-by: GitHub <noreply@github.com> * new knub typings Signed-off-by: GitHub <noreply@github.com> * more pkg updates Signed-off-by: GitHub <noreply@github.com> * more fixes Signed-off-by: GitHub <noreply@github.com> * channel typings Signed-off-by: GitHub <noreply@github.com> * more message utils typings fixes Signed-off-by: GitHub <noreply@github.com> * migrate permissions Signed-off-by: GitHub <noreply@github.com> * fix: InternalPoster webhookables Signed-off-by: GitHub <noreply@github.com> * djs typings: Attachment & Util Signed-off-by: GitHub <noreply@github.com> * more typings Signed-off-by: GitHub <noreply@github.com> * fix: rename permissionNames Signed-off-by: GitHub <noreply@github.com> * more fixes Signed-off-by: GitHub <noreply@github.com> * half the number of errors * knub commands => messageCommands Signed-off-by: GitHub <noreply@github.com> * configPreprocessor => configParser Signed-off-by: GitHub <noreply@github.com> * fix channel.messages Signed-off-by: GitHub <noreply@github.com> * revert automod any typing Signed-off-by: GitHub <noreply@github.com> * more configParser typings Signed-off-by: GitHub <noreply@github.com> * revert Signed-off-by: GitHub <noreply@github.com> * remove knub type params Signed-off-by: GitHub <noreply@github.com> * fix more MessageEmbed / MessageOptions Signed-off-by: GitHub <noreply@github.com> * dumb commit for @almeidx to see why this is stupid Signed-off-by: GitHub <noreply@github.com> * temp disable custom_events Signed-off-by: GitHub <noreply@github.com> * more minor typings fixes - 23 err left Signed-off-by: GitHub <noreply@github.com> * update djs dep * +debug build method (revert this) Signed-off-by: GitHub <noreply@github.com> * Revert "+debug build method (revert this)" This reverts commit a80af1e729b742d1aad1097df538d224fbd32ce7. * Redo +debug build (Revert this) Signed-off-by: GitHub <noreply@github.com> * uniform before/after Load shorthands Signed-off-by: GitHub <noreply@github.com> * remove unused imports & add prettier plugin Signed-off-by: GitHub <noreply@github.com> * env fixes for web platform hosting Signed-off-by: GitHub <noreply@github.com> * feat: knub v32-next; related fixes * fix: allow legacy keys in change_perms action * fix: request Message Content intent * fix: use Knub's config validation logic in API * fix(dashboard): fix error when there are no message and/or slash commands in a plugin * fix(automod): start_thread action thread options * fix(CustomEvents): message command types * chore: remove unneeded type annotation * feat: add forum channel icon; use thread icon for news threads * chore: make tslint happy * chore: fix formatting --------- Signed-off-by: GitHub <noreply@github.com> Co-authored-by: almeidx <almeidx@pm.me> Co-authored-by: Dragory <2606411+Dragory@users.noreply.github.com>
160 lines
5.3 KiB
TypeScript
160 lines
5.3 KiB
TypeScript
import { Snowflake } from "discord.js";
|
|
import { getChannelId, getRoleId } from "knub/helpers";
|
|
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
|
import { sendErrorMessage } from "../../../pluginUtils";
|
|
import { isValidSnowflake, noop, parseInviteCodeInput, resolveInvite, resolveUser } from "../../../utils";
|
|
import { canReadChannel } from "../../../utils/canReadChannel";
|
|
import { resolveMessageTarget } from "../../../utils/resolveMessageTarget";
|
|
import { getChannelInfoEmbed } from "../functions/getChannelInfoEmbed";
|
|
import { getCustomEmojiId } from "../functions/getCustomEmojiId";
|
|
import { getEmojiInfoEmbed } from "../functions/getEmojiInfoEmbed";
|
|
import { getGuildPreview } from "../functions/getGuildPreview";
|
|
import { getInviteInfoEmbed } from "../functions/getInviteInfoEmbed";
|
|
import { getMessageInfoEmbed } from "../functions/getMessageInfoEmbed";
|
|
import { getRoleInfoEmbed } from "../functions/getRoleInfoEmbed";
|
|
import { getServerInfoEmbed } from "../functions/getServerInfoEmbed";
|
|
import { getSnowflakeInfoEmbed } from "../functions/getSnowflakeInfoEmbed";
|
|
import { getUserInfoEmbed } from "../functions/getUserInfoEmbed";
|
|
import { utilityCmd } from "../types";
|
|
|
|
export const InfoCmd = utilityCmd({
|
|
trigger: "info",
|
|
description: "Show information about the specified thing",
|
|
usage: "!info",
|
|
permission: "can_info",
|
|
|
|
signature: {
|
|
value: ct.string({ required: false }),
|
|
|
|
compact: ct.switchOption({ def: false, shortcut: "c" }),
|
|
},
|
|
|
|
async run({ message, args, pluginData }) {
|
|
const value = args.value || message.author.id;
|
|
const userCfg = await pluginData.config.getMatchingConfig({
|
|
member: message.member,
|
|
channelId: message.channel.id,
|
|
message,
|
|
});
|
|
|
|
// 1. Channel
|
|
if (userCfg.can_channelinfo) {
|
|
const channelId = getChannelId(value);
|
|
const channel = channelId && pluginData.guild.channels.cache.get(channelId as Snowflake);
|
|
if (channel) {
|
|
const embed = await getChannelInfoEmbed(pluginData, channelId!, message.author.id);
|
|
if (embed) {
|
|
message.channel.send({ embeds: [embed] });
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
// 2. Server
|
|
if (userCfg.can_server) {
|
|
const guild = await pluginData.client.guilds.fetch(value as Snowflake).catch(noop);
|
|
if (guild) {
|
|
const embed = await getServerInfoEmbed(pluginData, value, message.author.id);
|
|
if (embed) {
|
|
message.channel.send({ embeds: [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);
|
|
if (embed) {
|
|
message.channel.send({ embeds: [embed] });
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
// 4. Message
|
|
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.send({ embeds: [embed] });
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// 5. Invite
|
|
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.send({ embeds: [embed] });
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// 6. Server again (fallback for discovery servers)
|
|
if (userCfg.can_server) {
|
|
const serverPreview = await getGuildPreview(pluginData.client, value).catch(() => null);
|
|
if (serverPreview) {
|
|
const embed = await getServerInfoEmbed(pluginData, value, message.author.id);
|
|
if (embed) {
|
|
message.channel.send({ embeds: [embed] });
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
// 7. Role
|
|
if (userCfg.can_roleinfo) {
|
|
const roleId = getRoleId(value);
|
|
const role = roleId && pluginData.guild.roles.cache.get(roleId as Snowflake);
|
|
if (role) {
|
|
const embed = await getRoleInfoEmbed(pluginData, role, message.author.id);
|
|
message.channel.send({ embeds: [embed] });
|
|
return;
|
|
}
|
|
}
|
|
|
|
// 8. Emoji
|
|
if (userCfg.can_emojiinfo) {
|
|
const emojiId = getCustomEmojiId(value);
|
|
if (emojiId) {
|
|
const embed = await getEmojiInfoEmbed(pluginData, emojiId);
|
|
if (embed) {
|
|
message.channel.send({ embeds: [embed] });
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
// 9. Arbitrary ID
|
|
if (isValidSnowflake(value) && userCfg.can_snowflake) {
|
|
const embed = await getSnowflakeInfoEmbed(pluginData, value, true, message.author.id);
|
|
message.channel.send({ embeds: [embed] });
|
|
return;
|
|
}
|
|
|
|
// 10. No can do
|
|
sendErrorMessage(
|
|
pluginData,
|
|
message.channel,
|
|
"Could not find anything with that value or you are lacking permission for the snowflake type",
|
|
);
|
|
},
|
|
});
|