mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-15 05:41:51 +00:00
Add !roleinfo and !emojiinfo (#198)
This commit is contained in:
parent
fb4f70a29c
commit
519cb4ece2
7 changed files with 247 additions and 46 deletions
|
@ -26,7 +26,6 @@ import { ReloadGuildCmd } from "./commands/ReloadGuildCmd";
|
||||||
import { JumboCmd } from "./commands/JumboCmd";
|
import { JumboCmd } from "./commands/JumboCmd";
|
||||||
import { AvatarCmd } from "./commands/AvatarCmd";
|
import { AvatarCmd } from "./commands/AvatarCmd";
|
||||||
import { CleanCmd } from "./commands/CleanCmd";
|
import { CleanCmd } from "./commands/CleanCmd";
|
||||||
import { Message } from "eris";
|
|
||||||
import { InviteInfoCmd } from "./commands/InviteInfoCmd";
|
import { InviteInfoCmd } from "./commands/InviteInfoCmd";
|
||||||
import { ChannelInfoCmd } from "./commands/ChannelInfoCmd";
|
import { ChannelInfoCmd } from "./commands/ChannelInfoCmd";
|
||||||
import { MessageInfoCmd } from "./commands/MessageInfoCmd";
|
import { MessageInfoCmd } from "./commands/MessageInfoCmd";
|
||||||
|
@ -37,6 +36,8 @@ import { TimeAndDatePlugin } from "../TimeAndDate/TimeAndDatePlugin";
|
||||||
import { VcdisconnectCmd } from "./commands/VcdisconnectCmd";
|
import { VcdisconnectCmd } from "./commands/VcdisconnectCmd";
|
||||||
import { ModActionsPlugin } from "../ModActions/ModActionsPlugin";
|
import { ModActionsPlugin } from "../ModActions/ModActionsPlugin";
|
||||||
import { refreshMembersIfNeeded } from "./refreshMembers";
|
import { refreshMembersIfNeeded } from "./refreshMembers";
|
||||||
|
import { RoleInfoCmd } from "./commands/RoleInfoCmd";
|
||||||
|
import { EmojiInfoCmd } from "./commands/EmojiInfoCmd";
|
||||||
|
|
||||||
const defaultOptions: PluginOptions<UtilityPluginType> = {
|
const defaultOptions: PluginOptions<UtilityPluginType> = {
|
||||||
config: {
|
config: {
|
||||||
|
@ -50,6 +51,8 @@ const defaultOptions: PluginOptions<UtilityPluginType> = {
|
||||||
can_channelinfo: false,
|
can_channelinfo: false,
|
||||||
can_messageinfo: false,
|
can_messageinfo: false,
|
||||||
can_userinfo: false,
|
can_userinfo: false,
|
||||||
|
can_roleinfo: false,
|
||||||
|
can_emojiinfo: false,
|
||||||
can_snowflake: false,
|
can_snowflake: false,
|
||||||
can_reload_guild: false,
|
can_reload_guild: false,
|
||||||
can_nickname: false,
|
can_nickname: false,
|
||||||
|
@ -79,6 +82,8 @@ const defaultOptions: PluginOptions<UtilityPluginType> = {
|
||||||
can_channelinfo: true,
|
can_channelinfo: true,
|
||||||
can_messageinfo: true,
|
can_messageinfo: true,
|
||||||
can_userinfo: true,
|
can_userinfo: true,
|
||||||
|
can_roleinfo: true,
|
||||||
|
can_emojiinfo: true,
|
||||||
can_snowflake: true,
|
can_snowflake: true,
|
||||||
can_nickname: true,
|
can_nickname: true,
|
||||||
can_vcmove: true,
|
can_vcmove: true,
|
||||||
|
@ -138,6 +143,8 @@ export const UtilityPlugin = zeppelinGuildPlugin<UtilityPluginType>()("utility",
|
||||||
MessageInfoCmd,
|
MessageInfoCmd,
|
||||||
InfoCmd,
|
InfoCmd,
|
||||||
SnowflakeInfoCmd,
|
SnowflakeInfoCmd,
|
||||||
|
RoleInfoCmd,
|
||||||
|
EmojiInfoCmd,
|
||||||
],
|
],
|
||||||
|
|
||||||
onLoad(pluginData) {
|
onLoad(pluginData) {
|
||||||
|
|
32
backend/src/plugins/Utility/commands/EmojiInfoCmd.ts
Normal file
32
backend/src/plugins/Utility/commands/EmojiInfoCmd.ts
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
import { utilityCmd } from "../types";
|
||||||
|
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||||
|
import { sendErrorMessage } from "../../../pluginUtils";
|
||||||
|
import { customEmojiRegex } from "../../../utils";
|
||||||
|
import { getEmojiInfoEmbed } from "../functions/getEmojiInfoEmbed";
|
||||||
|
|
||||||
|
export const EmojiInfoCmd = utilityCmd({
|
||||||
|
trigger: ["emoji", "emojiinfo"],
|
||||||
|
description: "Show information about an emoji",
|
||||||
|
usage: "!emoji 106391128718245888",
|
||||||
|
permission: "can_emojiinfo",
|
||||||
|
|
||||||
|
signature: {
|
||||||
|
emoji: ct.string({ required: false }),
|
||||||
|
},
|
||||||
|
|
||||||
|
async run({ message, args, pluginData }) {
|
||||||
|
const emojiIdMatch = args.emoji.match(customEmojiRegex);
|
||||||
|
if (!emojiIdMatch?.[2]) {
|
||||||
|
sendErrorMessage(pluginData, message.channel, "Emoji not found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const embed = await getEmojiInfoEmbed(pluginData, emojiIdMatch[2]);
|
||||||
|
if (!embed) {
|
||||||
|
sendErrorMessage(pluginData, message.channel, "Emoji not found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
message.channel.createMessage({ embed });
|
||||||
|
},
|
||||||
|
});
|
|
@ -2,16 +2,18 @@ import { utilityCmd } from "../types";
|
||||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||||
import { sendErrorMessage } from "../../../pluginUtils";
|
import { sendErrorMessage } from "../../../pluginUtils";
|
||||||
import { getInviteInfoEmbed } from "../functions/getInviteInfoEmbed";
|
import { getInviteInfoEmbed } from "../functions/getInviteInfoEmbed";
|
||||||
import { isValidSnowflake, parseInviteCodeInput, resolveInvite, resolveUser } from "../../../utils";
|
import { customEmojiRegex, isValidSnowflake, parseInviteCodeInput, resolveInvite, resolveUser } from "../../../utils";
|
||||||
import { getUserInfoEmbed } from "../functions/getUserInfoEmbed";
|
import { getUserInfoEmbed } from "../functions/getUserInfoEmbed";
|
||||||
import { resolveMessageTarget } from "../../../utils/resolveMessageTarget";
|
import { resolveMessageTarget } from "../../../utils/resolveMessageTarget";
|
||||||
import { canReadChannel } from "../../../utils/canReadChannel";
|
import { canReadChannel } from "../../../utils/canReadChannel";
|
||||||
import { getMessageInfoEmbed } from "../functions/getMessageInfoEmbed";
|
import { getMessageInfoEmbed } from "../functions/getMessageInfoEmbed";
|
||||||
import { getChannelInfoEmbed } from "../functions/getChannelInfoEmbed";
|
import { getChannelInfoEmbed } from "../functions/getChannelInfoEmbed";
|
||||||
import { getServerInfoEmbed } from "../functions/getServerInfoEmbed";
|
import { getServerInfoEmbed } from "../functions/getServerInfoEmbed";
|
||||||
import { getChannelId } from "knub/dist/utils";
|
import { getChannelId, getRoleId } from "knub/dist/utils";
|
||||||
import { getGuildPreview } from "../functions/getGuildPreview";
|
import { getGuildPreview } from "../functions/getGuildPreview";
|
||||||
import { getSnowflakeInfoEmbed } from "../functions/getSnowflakeInfoEmbed";
|
import { getSnowflakeInfoEmbed } from "../functions/getSnowflakeInfoEmbed";
|
||||||
|
import { getRoleInfoEmbed } from "../functions/getRoleInfoEmbed";
|
||||||
|
import { getEmojiInfoEmbed } from "../functions/getEmojiInfoEmbed";
|
||||||
|
|
||||||
export const InfoCmd = utilityCmd({
|
export const InfoCmd = utilityCmd({
|
||||||
trigger: "info",
|
trigger: "info",
|
||||||
|
@ -34,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;
|
||||||
|
@ -94,24 +118,37 @@ 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. Arbitrary ID
|
// 8. Emoji
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 9. Arbitrary ID
|
||||||
if (isValidSnowflake(value) && userCfg.can_snowflake) {
|
if (isValidSnowflake(value) && userCfg.can_snowflake) {
|
||||||
const embed = await getSnowflakeInfoEmbed(pluginData, value, true, message.author.id);
|
const embed = await getSnowflakeInfoEmbed(pluginData, value, true, message.author.id);
|
||||||
message.channel.createMessage({ embed });
|
message.channel.createMessage({ embed });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7. No can do
|
// 10. No can do
|
||||||
sendErrorMessage(
|
sendErrorMessage(
|
||||||
pluginData,
|
pluginData,
|
||||||
message.channel,
|
message.channel,
|
||||||
|
|
20
backend/src/plugins/Utility/commands/RoleInfoCmd.ts
Normal file
20
backend/src/plugins/Utility/commands/RoleInfoCmd.ts
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
import { utilityCmd } from "../types";
|
||||||
|
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||||
|
import { sendErrorMessage } from "../../../pluginUtils";
|
||||||
|
import { getRoleInfoEmbed } from "../functions/getRoleInfoEmbed";
|
||||||
|
|
||||||
|
export const RoleInfoCmd = utilityCmd({
|
||||||
|
trigger: ["role", "roleinfo"],
|
||||||
|
description: "Show information about a role",
|
||||||
|
usage: "!role 106391128718245888",
|
||||||
|
permission: "can_roleinfo",
|
||||||
|
|
||||||
|
signature: {
|
||||||
|
role: ct.role({ required: true }),
|
||||||
|
},
|
||||||
|
|
||||||
|
async run({ message, args, pluginData }) {
|
||||||
|
const embed = await getRoleInfoEmbed(pluginData, args.role, message.author.id);
|
||||||
|
message.channel.createMessage({ embed });
|
||||||
|
},
|
||||||
|
});
|
34
backend/src/plugins/Utility/functions/getEmojiInfoEmbed.ts
Normal file
34
backend/src/plugins/Utility/functions/getEmojiInfoEmbed.ts
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
import { EmbedOptions } from "eris";
|
||||||
|
import { GuildPluginData } from "knub";
|
||||||
|
import { UtilityPluginType } from "../types";
|
||||||
|
import { trimLines, preEmbedPadding, EmbedWith } from "../../../utils";
|
||||||
|
|
||||||
|
export async function getEmojiInfoEmbed(
|
||||||
|
pluginData: GuildPluginData<UtilityPluginType>,
|
||||||
|
emojiId: string,
|
||||||
|
): Promise<EmbedOptions | null> {
|
||||||
|
const emoji = pluginData.guild.emojis.find(e => e.id === emojiId);
|
||||||
|
if (!emoji) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const embed: EmbedWith<"fields"> = {
|
||||||
|
fields: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
embed.author = {
|
||||||
|
name: `Emoji: ${emoji.name}`,
|
||||||
|
icon_url: `https://cdn.discordapp.com/emojis/${emoji.id}.${emoji.animated ? "gif" : "png"}?v=1`,
|
||||||
|
};
|
||||||
|
|
||||||
|
embed.fields.push({
|
||||||
|
name: preEmbedPadding + "Emoji information",
|
||||||
|
value: trimLines(`
|
||||||
|
Name: **${emoji.name}**
|
||||||
|
ID: \`${emoji.id}\`
|
||||||
|
Animated: **${emoji.animated ? "Yes" : "No"}**
|
||||||
|
`),
|
||||||
|
});
|
||||||
|
|
||||||
|
return embed;
|
||||||
|
}
|
69
backend/src/plugins/Utility/functions/getRoleInfoEmbed.ts
Normal file
69
backend/src/plugins/Utility/functions/getRoleInfoEmbed.ts
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
import { EmbedOptions, Role } from "eris";
|
||||||
|
import { GuildPluginData } from "knub";
|
||||||
|
import { UtilityPluginType } from "../types";
|
||||||
|
import { trimLines, preEmbedPadding, EmbedWith } from "../../../utils";
|
||||||
|
import moment from "moment-timezone";
|
||||||
|
import humanizeDuration from "humanize-duration";
|
||||||
|
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
|
||||||
|
|
||||||
|
const MENTION_ICON = "https://cdn.discordapp.com/attachments/705009450855039042/839284872152481792/mention.png";
|
||||||
|
|
||||||
|
export async function getRoleInfoEmbed(
|
||||||
|
pluginData: GuildPluginData<UtilityPluginType>,
|
||||||
|
role: Role,
|
||||||
|
requestMemberId?: string,
|
||||||
|
): Promise<EmbedOptions> {
|
||||||
|
const embed: EmbedWith<"fields"> = {
|
||||||
|
fields: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
embed.author = {
|
||||||
|
name: `Role: ${role.name}`,
|
||||||
|
icon_url: MENTION_ICON,
|
||||||
|
};
|
||||||
|
|
||||||
|
embed.color = role.color;
|
||||||
|
|
||||||
|
const createdAt = moment.utc(role.createdAt, "x");
|
||||||
|
const timeAndDate = pluginData.getPlugin(TimeAndDatePlugin);
|
||||||
|
const tzCreatedAt = requestMemberId
|
||||||
|
? await timeAndDate.inMemberTz(requestMemberId, createdAt)
|
||||||
|
: timeAndDate.inGuildTz(createdAt);
|
||||||
|
const prettyCreatedAt = tzCreatedAt.format(timeAndDate.getDateFormat("pretty_datetime"));
|
||||||
|
const roleAge = humanizeDuration(Date.now() - role.createdAt, {
|
||||||
|
largest: 2,
|
||||||
|
round: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const rolePerms = Object.keys(role.permissions.json).map(p =>
|
||||||
|
p
|
||||||
|
// Voice channel related permission names start with 'voice'
|
||||||
|
.replace(/^voice/i, "")
|
||||||
|
.replace(/([a-z])([A-Z])/g, "$1 $2")
|
||||||
|
.toLowerCase()
|
||||||
|
.replace(/(^\w{1})|(\s{1}\w{1})/g, l => l.toUpperCase()),
|
||||||
|
);
|
||||||
|
|
||||||
|
// -1 because of the @everyone role
|
||||||
|
const totalGuildRoles = pluginData.guild.roles.size - 1;
|
||||||
|
|
||||||
|
embed.fields.push({
|
||||||
|
name: preEmbedPadding + "Role information",
|
||||||
|
value: trimLines(`
|
||||||
|
Name: **${role.name}**
|
||||||
|
ID: \`${role.id}\`
|
||||||
|
Created: **${roleAge} ago** (\`${prettyCreatedAt}\`)
|
||||||
|
Position: **${role.position} / ${totalGuildRoles}**
|
||||||
|
Color: **#${role.color
|
||||||
|
.toString(16)
|
||||||
|
.toUpperCase()
|
||||||
|
.padStart(6, "0")}**
|
||||||
|
Mentionable: **${role.mentionable ? "Yes" : "No"}**
|
||||||
|
Hoisted: **${role.hoist ? "Yes" : "No"}**
|
||||||
|
Permissions: \`${rolePerms.length ? rolePerms.join(", ") : "None"}\`
|
||||||
|
Mention: <@&${role.id}> (\`<@&${role.id}>\`)
|
||||||
|
`),
|
||||||
|
});
|
||||||
|
|
||||||
|
return embed;
|
||||||
|
}
|
|
@ -18,6 +18,8 @@ export const ConfigSchema = t.type({
|
||||||
can_channelinfo: t.boolean,
|
can_channelinfo: t.boolean,
|
||||||
can_messageinfo: t.boolean,
|
can_messageinfo: t.boolean,
|
||||||
can_userinfo: t.boolean,
|
can_userinfo: t.boolean,
|
||||||
|
can_roleinfo: t.boolean,
|
||||||
|
can_emojiinfo: t.boolean,
|
||||||
can_snowflake: t.boolean,
|
can_snowflake: t.boolean,
|
||||||
can_reload_guild: t.boolean,
|
can_reload_guild: t.boolean,
|
||||||
can_nickname: t.boolean,
|
can_nickname: t.boolean,
|
||||||
|
|
Loading…
Add table
Reference in a new issue