mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-20 00:05:04 +00:00
Implement in progress roleId Info command
This commit is contained in:
parent
5d579446c5
commit
8ff2b6614c
2 changed files with 75 additions and 2 deletions
|
@ -9,9 +9,11 @@ import { canReadChannel } from "../../../utils/canReadChannel";
|
|||
import { getMessageInfoEmbed } from "../functions/getMessageInfoEmbed";
|
||||
import { getChannelInfoEmbed } from "../functions/getChannelInfoEmbed";
|
||||
import { getServerInfoEmbed } from "../functions/getServerInfoEmbed";
|
||||
import { getRoleInfoEmbed } from "../functions/getRoleInfoEmbed";
|
||||
import { getChannelId } from "knub/dist/utils";
|
||||
import { getGuildPreview } from "../functions/getGuildPreview";
|
||||
import { getSnowflakeInfoEmbed } from "../functions/getSnowflakeInfoEmbed";
|
||||
import { getRoleId } from "knub/dist/utils";
|
||||
|
||||
export const InfoCmd = utilityCmd({
|
||||
trigger: "info",
|
||||
|
@ -99,14 +101,27 @@ export const InfoCmd = utilityCmd({
|
|||
}
|
||||
}
|
||||
|
||||
// 7. Arbitrary ID
|
||||
// 7. Role ID
|
||||
const roleId = getRoleId(value);
|
||||
const role = roleId && pluginData.guild.roles.get(roleId);
|
||||
if (role) {
|
||||
const embed = await getRoleInfoEmbed(pluginData, roleId, message.author.id);
|
||||
if (embed) {
|
||||
message.channel.createMessage({ embed });
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO 8. Emoji ID
|
||||
|
||||
// 9. Arbitrary ID
|
||||
if (isValidSnowflake(value)) {
|
||||
const embed = await getSnowflakeInfoEmbed(pluginData, value, true, message.author.id);
|
||||
message.channel.createMessage({ embed });
|
||||
return;
|
||||
}
|
||||
|
||||
// 7. No can do
|
||||
// 10. No can do
|
||||
sendErrorMessage(pluginData, message.channel, "Could not find anything with that value");
|
||||
},
|
||||
});
|
||||
|
|
58
backend/src/plugins/Utility/functions/getRoleInfoEmbed.ts
Normal file
58
backend/src/plugins/Utility/functions/getRoleInfoEmbed.ts
Normal file
|
@ -0,0 +1,58 @@
|
|||
import { PluginData } from "knub";
|
||||
import { UtilityPluginType } from "../types";
|
||||
import { Constants, EmbedOptions } from "eris";
|
||||
import moment from "moment-timezone";
|
||||
import humanizeDuration from "humanize-duration";
|
||||
import { formatNumber, preEmbedPadding, trimLines } from "../../../utils";
|
||||
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
|
||||
|
||||
export async function getRoleInfoEmbed(
|
||||
pluginData: PluginData<UtilityPluginType>,
|
||||
roleId: string,
|
||||
requestMemberId?: string,
|
||||
): Promise<EmbedOptions | null> {
|
||||
const role = pluginData.guild.roles.get(roleId);
|
||||
if (!role) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const embed: EmbedOptions = {
|
||||
fields: []
|
||||
}
|
||||
|
||||
// TODO Perhaps use a '@' as icon?
|
||||
// embed.author = {
|
||||
// name: role.name,
|
||||
// icon_url: icon,
|
||||
// };
|
||||
|
||||
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
|
||||
});
|
||||
|
||||
embed.fields.push({
|
||||
name: preEmbedPadding + "Role information",
|
||||
value: trimLines(`
|
||||
Name: **${role.name}**
|
||||
ID: \`${role.id}\`
|
||||
Created: **${roleAge} ago** (\`${prettyCreatedAt}\`)
|
||||
Position: ${role.position}
|
||||
Color: #${role.color.toString(16).toUpperCase()}
|
||||
Mentionable: ${role.mentionable}
|
||||
Hoisted: ${role.hoist}
|
||||
Managed: ${role.managed}
|
||||
Permissions: TODO
|
||||
Members: TODO
|
||||
Mention: <@&${role.id}>
|
||||
`),
|
||||
});
|
||||
|
||||
return embed;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue