mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 12:25:02 +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
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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue