feat: use native timestamps more
This commit is contained in:
parent
0e70412bc4
commit
ecaa16bf7c
10 changed files with 22 additions and 160 deletions
|
@ -11,7 +11,7 @@
|
||||||
"MEMBER_UNBAN": "{timestamp} 🔓 User (`{userId}`) was unbanned by {userMention(mod)}",
|
"MEMBER_UNBAN": "{timestamp} 🔓 User (`{userId}`) was unbanned by {userMention(mod)}",
|
||||||
"MEMBER_FORCEBAN": "{timestamp} 🔨 User (`{userId}`) was forcebanned by {userMention(mod)}",
|
"MEMBER_FORCEBAN": "{timestamp} 🔨 User (`{userId}`) was forcebanned by {userMention(mod)}",
|
||||||
"MEMBER_SOFTBAN": "{timestamp} 🔨 {userMention(member)} was softbanned by {userMention(mod)}",
|
"MEMBER_SOFTBAN": "{timestamp} 🔨 {userMention(member)} was softbanned by {userMention(mod)}",
|
||||||
"MEMBER_JOIN": "{timestamp} 📥 {new} {userMention(member)} joined (created {account_age} ago)",
|
"MEMBER_JOIN": "{timestamp} 📥 {new} {userMention(member)} joined (created <t:{account_age_ts}:R>)",
|
||||||
"MEMBER_LEAVE": "{timestamp} 📤 {userMention(member)} left the server",
|
"MEMBER_LEAVE": "{timestamp} 📤 {userMention(member)} left the server",
|
||||||
"MEMBER_ROLE_ADD": "{timestamp} 🔑 {userMention(mod)} added roles for {userMention(member)}: **{roles}**",
|
"MEMBER_ROLE_ADD": "{timestamp} 🔑 {userMention(mod)} added roles for {userMention(member)}: **{roles}**",
|
||||||
"MEMBER_ROLE_REMOVE": "{timestamp} 🔑 {userMention(mod)} removed roles from {userMention(member)}: **{roles}**",
|
"MEMBER_ROLE_REMOVE": "{timestamp} 🔑 {userMention(mod)} removed roles from {userMention(member)}: **{roles}**",
|
||||||
|
|
|
@ -26,6 +26,7 @@ export function logMemberJoin(pluginData: GuildPluginData<LogsPluginType>, data:
|
||||||
member: memberToTemplateSafeMember(data.member),
|
member: memberToTemplateSafeMember(data.member),
|
||||||
new: data.member.user.createdTimestamp >= newThreshold ? " :new:" : "",
|
new: data.member.user.createdTimestamp >= newThreshold ? " :new:" : "",
|
||||||
account_age: accountAge,
|
account_age: accountAge,
|
||||||
|
account_age_ts: Math.round(data.member.user.createdTimestamp / 1000).toString(),
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
userId: data.member.id,
|
userId: data.member.id,
|
||||||
|
|
|
@ -150,6 +150,7 @@ export const LogTypeData = z.object({
|
||||||
member: z.instanceof(TemplateSafeMember),
|
member: z.instanceof(TemplateSafeMember),
|
||||||
new: z.string(),
|
new: z.string(),
|
||||||
account_age: z.string(),
|
account_age: z.string(),
|
||||||
|
account_age_ts: z.string(),
|
||||||
}),
|
}),
|
||||||
|
|
||||||
[LogType.MEMBER_LEAVE]: z.object({
|
[LogType.MEMBER_LEAVE]: z.object({
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
import { APIEmbed, ChannelType, Snowflake, StageChannel, VoiceChannel } from "discord.js";
|
import { APIEmbed, ChannelType, Snowflake, StageChannel, VoiceChannel } from "discord.js";
|
||||||
import humanizeDuration from "humanize-duration";
|
import humanizeDuration from "humanize-duration";
|
||||||
import { GuildPluginData } from "knub";
|
import { GuildPluginData } from "knub";
|
||||||
import moment from "moment-timezone";
|
|
||||||
import { EmbedWith, MINUTES, formatNumber, preEmbedPadding, trimLines, verboseUserMention } from "../../../utils";
|
import { EmbedWith, MINUTES, formatNumber, preEmbedPadding, trimLines, verboseUserMention } from "../../../utils";
|
||||||
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
|
|
||||||
import { UtilityPluginType } from "../types";
|
import { UtilityPluginType } from "../types";
|
||||||
|
|
||||||
const TEXT_CHANNEL_ICON =
|
const TEXT_CHANNEL_ICON =
|
||||||
|
@ -74,17 +72,6 @@ export async function getChannelInfoEmbed(
|
||||||
channelName = channel.name;
|
channelName = channel.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
const createdAt = moment.utc(channel.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 channelAge = humanizeDuration(Date.now() - channel.createdTimestamp!, {
|
|
||||||
largest: 2,
|
|
||||||
round: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
const showMention = channel.type !== ChannelType.GuildCategory;
|
const showMention = channel.type !== ChannelType.GuildCategory;
|
||||||
|
|
||||||
embed.fields.push({
|
embed.fields.push({
|
||||||
|
@ -92,7 +79,7 @@ export async function getChannelInfoEmbed(
|
||||||
value: trimLines(`
|
value: trimLines(`
|
||||||
Name: **${channelName}**
|
Name: **${channelName}**
|
||||||
ID: \`${channel.id}\`
|
ID: \`${channel.id}\`
|
||||||
Created: **${channelAge} ago** (\`${prettyCreatedAt}\`)
|
Created: **<t:${Math.round(channel.createdTimestamp! / 1000)}:R>**
|
||||||
Type: **${channelType}**
|
Type: **${channelType}**
|
||||||
${showMention ? `Mention: <#${channel.id}>` : ""}
|
${showMention ? `Mention: <#${channel.id}>` : ""}
|
||||||
`),
|
`),
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import { APIEmbed, ChannelType } from "discord.js";
|
import { APIEmbed, ChannelType } from "discord.js";
|
||||||
import humanizeDuration from "humanize-duration";
|
|
||||||
import { GuildPluginData } from "knub";
|
import { GuildPluginData } from "knub";
|
||||||
import {
|
import {
|
||||||
EmbedWith,
|
EmbedWith,
|
||||||
|
@ -44,10 +43,6 @@ export async function getInviteInfoEmbed(
|
||||||
}
|
}
|
||||||
|
|
||||||
const serverCreatedAtTimestamp = snowflakeToTimestamp(invite.guild.id);
|
const serverCreatedAtTimestamp = snowflakeToTimestamp(invite.guild.id);
|
||||||
const serverAge = humanizeDuration(Date.now() - serverCreatedAtTimestamp, {
|
|
||||||
largest: 2,
|
|
||||||
round: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
const memberCount = inviteHasCounts(invite) ? invite.memberCount : 0;
|
const memberCount = inviteHasCounts(invite) ? invite.memberCount : 0;
|
||||||
|
|
||||||
|
@ -58,7 +53,7 @@ export async function getInviteInfoEmbed(
|
||||||
value: trimLines(`
|
value: trimLines(`
|
||||||
Name: **${invite.guild.name}**
|
Name: **${invite.guild.name}**
|
||||||
ID: \`${invite.guild.id}\`
|
ID: \`${invite.guild.id}\`
|
||||||
Created: **${serverAge} ago**
|
Created: **<t:${Math.round(serverCreatedAtTimestamp / 1000)}:R>**
|
||||||
Members: **${formatNumber(memberCount)}** (${formatNumber(presenceCount)} online)
|
Members: **${formatNumber(memberCount)}** (${formatNumber(presenceCount)} online)
|
||||||
`),
|
`),
|
||||||
inline: true,
|
inline: true,
|
||||||
|
@ -68,15 +63,11 @@ export async function getInviteInfoEmbed(
|
||||||
invite.channel.type === ChannelType.GuildVoice ? `🔉 ${invite.channel.name}` : `#${invite.channel.name}`;
|
invite.channel.type === ChannelType.GuildVoice ? `🔉 ${invite.channel.name}` : `#${invite.channel.name}`;
|
||||||
|
|
||||||
const channelCreatedAtTimestamp = snowflakeToTimestamp(invite.channel.id);
|
const channelCreatedAtTimestamp = snowflakeToTimestamp(invite.channel.id);
|
||||||
const channelAge = humanizeDuration(Date.now() - channelCreatedAtTimestamp, {
|
|
||||||
largest: 2,
|
|
||||||
round: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
let channelInfo = trimLines(`
|
let channelInfo = trimLines(`
|
||||||
Name: **${channelName}**
|
Name: **${channelName}**
|
||||||
ID: \`${invite.channel.id}\`
|
ID: \`${invite.channel.id}\`
|
||||||
Created: **${channelAge} ago**
|
Created: **<t:${Math.round(channelCreatedAtTimestamp / 1000)}:R>**
|
||||||
`);
|
`);
|
||||||
|
|
||||||
if (invite.channel.type !== ChannelType.GuildVoice) {
|
if (invite.channel.type !== ChannelType.GuildVoice) {
|
||||||
|
@ -120,17 +111,13 @@ export async function getInviteInfoEmbed(
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
const channelCreatedAtTimestamp = snowflakeToTimestamp(invite.channel!.id);
|
const channelCreatedAtTimestamp = snowflakeToTimestamp(invite.channel!.id);
|
||||||
const channelAge = humanizeDuration(Date.now() - channelCreatedAtTimestamp, {
|
|
||||||
largest: 2,
|
|
||||||
round: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
embed.fields.push({
|
embed.fields.push({
|
||||||
name: preEmbedPadding + "Group DM information",
|
name: preEmbedPadding + "Group DM information",
|
||||||
value: trimLines(`
|
value: trimLines(`
|
||||||
Name: ${invite.channel!.name ? `**${invite.channel!.name}**` : `_Unknown_`}
|
Name: ${invite.channel!.name ? `**${invite.channel!.name}**` : `_Unknown_`}
|
||||||
ID: \`${invite.channel!.id}\`
|
ID: \`${invite.channel!.id}\`
|
||||||
Created: **${channelAge} ago**
|
Created: **<t:${Math.round(channelCreatedAtTimestamp / 1000)}:R>**
|
||||||
Members: **${formatNumber((invite as any).memberCount)}**
|
Members: **${formatNumber((invite as any).memberCount)}**
|
||||||
`),
|
`),
|
||||||
inline: true,
|
inline: true,
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
import { APIEmbed, MessageType, Snowflake, TextChannel } from "discord.js";
|
import { APIEmbed, MessageType, Snowflake, TextChannel } from "discord.js";
|
||||||
import humanizeDuration from "humanize-duration";
|
|
||||||
import { GuildPluginData, getDefaultMessageCommandPrefix } from "knub";
|
import { GuildPluginData, getDefaultMessageCommandPrefix } from "knub";
|
||||||
import moment from "moment-timezone";
|
|
||||||
import {
|
import {
|
||||||
EmbedWith,
|
EmbedWith,
|
||||||
chunkMessageLines,
|
chunkMessageLines,
|
||||||
|
@ -39,28 +37,6 @@ export async function getMessageInfoEmbed(
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const createdAt = moment.utc(message.createdAt, "x");
|
|
||||||
const tzCreatedAt = requestMemberId
|
|
||||||
? await timeAndDate.inMemberTz(requestMemberId, createdAt)
|
|
||||||
: timeAndDate.inGuildTz(createdAt);
|
|
||||||
const prettyCreatedAt = tzCreatedAt.format(timeAndDate.getDateFormat("pretty_datetime"));
|
|
||||||
const messageAge = humanizeDuration(Date.now() - message.createdTimestamp, {
|
|
||||||
largest: 2,
|
|
||||||
round: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
const editedAt = message.editedTimestamp ? moment.utc(message.editedTimestamp!, "x") : undefined;
|
|
||||||
const tzEditedAt = requestMemberId
|
|
||||||
? await timeAndDate.inMemberTz(requestMemberId, editedAt)
|
|
||||||
: timeAndDate.inGuildTz(editedAt);
|
|
||||||
const prettyEditedAt = tzEditedAt.format(timeAndDate.getDateFormat("pretty_datetime"));
|
|
||||||
const editAge =
|
|
||||||
message.editedTimestamp &&
|
|
||||||
humanizeDuration(Date.now() - message.editedTimestamp, {
|
|
||||||
largest: 2,
|
|
||||||
round: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
const type =
|
const type =
|
||||||
{
|
{
|
||||||
[MessageType.Default]: "Regular message",
|
[MessageType.Default]: "Regular message",
|
||||||
|
@ -82,45 +58,23 @@ export async function getMessageInfoEmbed(
|
||||||
ID: \`${message.id}\`
|
ID: \`${message.id}\`
|
||||||
Channel: <#${message.channel.id}>
|
Channel: <#${message.channel.id}>
|
||||||
Channel ID: \`${message.channel.id}\`
|
Channel ID: \`${message.channel.id}\`
|
||||||
Created: **${messageAge} ago** (\`${prettyCreatedAt}\`)
|
Created: **<t:${Math.round(message.createdTimestamp / 1000)}:R>**
|
||||||
${editedAt ? `Edited at: **${editAge} ago** (\`${prettyEditedAt}\`)` : ""}
|
${message.editedTimestamp ? `Edited at: **<t:${Math.round(message.editedTimestamp / 1000)}:R>**` : ""}
|
||||||
Type: **${type}**
|
Type: **${type}**
|
||||||
Link: [**Go to message ➔**](${messageLink(pluginData.guild.id, message.channel.id, message.id)})
|
Link: [**Go to message ➔**](${messageLink(pluginData.guild.id, message.channel.id, message.id)})
|
||||||
`),
|
`),
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
const authorCreatedAt = moment.utc(message.author.createdAt, "x");
|
const authorJoinedAtTS = message.member?.joinedTimestamp;
|
||||||
const tzAuthorCreatedAt = requestMemberId
|
|
||||||
? await timeAndDate.inMemberTz(requestMemberId, authorCreatedAt)
|
|
||||||
: timeAndDate.inGuildTz(authorCreatedAt);
|
|
||||||
const prettyAuthorCreatedAt = tzAuthorCreatedAt.format(timeAndDate.getDateFormat("pretty_datetime"));
|
|
||||||
const authorAccountAge = humanizeDuration(Date.now() - message.author.createdTimestamp, {
|
|
||||||
largest: 2,
|
|
||||||
round: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
const authorJoinedAt = message.member && moment.utc(message.member.joinedTimestamp!, "x");
|
|
||||||
const tzAuthorJoinedAt = authorJoinedAt
|
|
||||||
? requestMemberId
|
|
||||||
? await timeAndDate.inMemberTz(requestMemberId, authorJoinedAt)
|
|
||||||
: timeAndDate.inGuildTz(authorJoinedAt)
|
|
||||||
: null;
|
|
||||||
const prettyAuthorJoinedAt = tzAuthorJoinedAt?.format(timeAndDate.getDateFormat("pretty_datetime"));
|
|
||||||
const authorServerAge =
|
|
||||||
message.member &&
|
|
||||||
humanizeDuration(Date.now() - message.member.joinedTimestamp!, {
|
|
||||||
largest: 2,
|
|
||||||
round: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
embed.fields.push({
|
embed.fields.push({
|
||||||
name: preEmbedPadding + "Author information",
|
name: preEmbedPadding + "Author information",
|
||||||
value: trimLines(`
|
value: trimLines(`
|
||||||
Name: **${renderUsername(message.author.username, message.author.discriminator)}**
|
Name: **${renderUsername(message.author.username, message.author.discriminator)}**
|
||||||
ID: \`${message.author.id}\`
|
ID: \`${message.author.id}\`
|
||||||
Created: **${authorAccountAge} ago** (\`${prettyAuthorCreatedAt}\`)
|
Created: **<t:${Math.round(message.author.createdTimestamp / 1000)}:R>**
|
||||||
${authorJoinedAt ? `Joined: **${authorServerAge} ago** (\`${prettyAuthorJoinedAt}\`)` : ""}
|
${authorJoinedAtTS ? `Joined: **<t:${Math.round(authorJoinedAtTS / 1000)}:R>**` : ""}
|
||||||
Mention: <@!${message.author.id}>
|
Mention: <@!${message.author.id}>
|
||||||
`),
|
`),
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
import { APIEmbed, PermissionFlagsBits, Role } from "discord.js";
|
import { APIEmbed, PermissionFlagsBits, Role } from "discord.js";
|
||||||
import humanizeDuration from "humanize-duration";
|
|
||||||
import { GuildPluginData } from "knub";
|
import { GuildPluginData } from "knub";
|
||||||
import moment from "moment-timezone";
|
|
||||||
import { EmbedWith, preEmbedPadding, trimLines } from "../../../utils";
|
import { EmbedWith, preEmbedPadding, trimLines } from "../../../utils";
|
||||||
import { PERMISSION_NAMES } from "../../../utils/permissionNames.js";
|
import { PERMISSION_NAMES } from "../../../utils/permissionNames.js";
|
||||||
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
|
|
||||||
import { UtilityPluginType } from "../types";
|
import { UtilityPluginType } from "../types";
|
||||||
|
|
||||||
const MENTION_ICON = "https://cdn.discordapp.com/attachments/705009450855039042/839284872152481792/mention.png";
|
const MENTION_ICON = "https://cdn.discordapp.com/attachments/705009450855039042/839284872152481792/mention.png";
|
||||||
|
@ -23,17 +20,6 @@ export async function getRoleInfoEmbed(
|
||||||
color: role.color,
|
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.createdTimestamp, {
|
|
||||||
largest: 2,
|
|
||||||
round: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
const rolePerms = role.permissions.has(PermissionFlagsBits.Administrator)
|
const rolePerms = role.permissions.has(PermissionFlagsBits.Administrator)
|
||||||
? [PERMISSION_NAMES.Administrator]
|
? [PERMISSION_NAMES.Administrator]
|
||||||
: role.permissions.toArray().map((p) => PERMISSION_NAMES[p]);
|
: role.permissions.toArray().map((p) => PERMISSION_NAMES[p]);
|
||||||
|
@ -46,7 +32,7 @@ export async function getRoleInfoEmbed(
|
||||||
value: trimLines(`
|
value: trimLines(`
|
||||||
Name: **${role.name}**
|
Name: **${role.name}**
|
||||||
ID: \`${role.id}\`
|
ID: \`${role.id}\`
|
||||||
Created: **${roleAge} ago** (\`${prettyCreatedAt}\`)
|
Created: **<t:${Math.round(role.createdTimestamp / 1000)}:R>**
|
||||||
Position: **${role.position} / ${totalGuildRoles}**
|
Position: **${role.position} / ${totalGuildRoles}**
|
||||||
Color: **#${role.color.toString(16).toUpperCase().padStart(6, "0")}**
|
Color: **#${role.color.toString(16).toUpperCase().padStart(6, "0")}**
|
||||||
Mentionable: **${role.mentionable ? "Yes" : "No"}**
|
Mentionable: **${role.mentionable ? "Yes" : "No"}**
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
import { APIEmbed, ChannelType, GuildPremiumTier, Snowflake } from "discord.js";
|
import { APIEmbed, ChannelType, GuildPremiumTier, Snowflake } from "discord.js";
|
||||||
import humanizeDuration from "humanize-duration";
|
|
||||||
import { GuildPluginData } from "knub";
|
import { GuildPluginData } from "knub";
|
||||||
import moment from "moment-timezone";
|
|
||||||
import {
|
import {
|
||||||
EmbedWith,
|
EmbedWith,
|
||||||
MINUTES,
|
MINUTES,
|
||||||
|
@ -15,7 +13,6 @@ import {
|
||||||
trimLines,
|
trimLines,
|
||||||
} from "../../../utils";
|
} from "../../../utils";
|
||||||
import { idToTimestamp } from "../../../utils/idToTimestamp";
|
import { idToTimestamp } from "../../../utils/idToTimestamp";
|
||||||
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
|
|
||||||
import { UtilityPluginType } from "../types";
|
import { UtilityPluginType } from "../types";
|
||||||
import { getGuildPreview } from "./getGuildPreview";
|
import { getGuildPreview } from "./getGuildPreview";
|
||||||
|
|
||||||
|
@ -51,19 +48,10 @@ export async function getServerInfoEmbed(
|
||||||
};
|
};
|
||||||
|
|
||||||
// BASIC INFORMATION
|
// BASIC INFORMATION
|
||||||
const timeAndDate = pluginData.getPlugin(TimeAndDatePlugin);
|
const createdAtTs = Number(idToTimestamp((guildPreview || restGuild)!.id)!);
|
||||||
const createdAt = moment.utc(idToTimestamp((guildPreview || restGuild)!.id)!, "x");
|
|
||||||
const tzCreatedAt = requestMemberId
|
|
||||||
? await timeAndDate.inMemberTz(requestMemberId, createdAt)
|
|
||||||
: timeAndDate.inGuildTz(createdAt);
|
|
||||||
const prettyCreatedAt = tzCreatedAt.format(timeAndDate.getDateFormat("pretty_datetime"));
|
|
||||||
const serverAge = humanizeDuration(moment.utc().valueOf() - createdAt.valueOf(), {
|
|
||||||
largest: 2,
|
|
||||||
round: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
const basicInformation: string[] = [];
|
const basicInformation: string[] = [];
|
||||||
basicInformation.push(`Created: **${serverAge} ago** (\`${prettyCreatedAt}\`)`);
|
basicInformation.push(`Created: **<t:${Math.round(createdAtTs / 1000)}:R>**`);
|
||||||
|
|
||||||
if (thisServer) {
|
if (thisServer) {
|
||||||
const owner = await resolveUser(pluginData.client, thisServer.ownerId);
|
const owner = await resolveUser(pluginData.client, thisServer.ownerId);
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
import { APIEmbed } from "discord.js";
|
import { APIEmbed } from "discord.js";
|
||||||
import humanizeDuration from "humanize-duration";
|
|
||||||
import { GuildPluginData } from "knub";
|
import { GuildPluginData } from "knub";
|
||||||
import moment from "moment-timezone";
|
|
||||||
import { EmbedWith, preEmbedPadding } from "../../../utils";
|
import { EmbedWith, preEmbedPadding } from "../../../utils";
|
||||||
import { snowflakeToTimestamp } from "../../../utils/snowflakeToTimestamp";
|
import { snowflakeToTimestamp } from "../../../utils/snowflakeToTimestamp";
|
||||||
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
|
|
||||||
import { UtilityPluginType } from "../types";
|
import { UtilityPluginType } from "../types";
|
||||||
|
|
||||||
const SNOWFLAKE_ICON = "https://cdn.discordapp.com/attachments/740650744830623756/742020790471491668/snowflake.png";
|
const SNOWFLAKE_ICON = "https://cdn.discordapp.com/attachments/740650744830623756/742020790471491668/snowflake.png";
|
||||||
|
@ -28,21 +25,11 @@ export async function getSnowflakeInfoEmbed(
|
||||||
"This is a valid [snowflake ID](https://discord.com/developers/docs/reference#snowflakes), but I don't know what it's for.";
|
"This is a valid [snowflake ID](https://discord.com/developers/docs/reference#snowflakes), but I don't know what it's for.";
|
||||||
}
|
}
|
||||||
|
|
||||||
const timeAndDate = pluginData.getPlugin(TimeAndDatePlugin);
|
|
||||||
const createdAtMS = snowflakeToTimestamp(snowflake);
|
const createdAtMS = snowflakeToTimestamp(snowflake);
|
||||||
const createdAt = moment.utc(createdAtMS, "x");
|
|
||||||
const tzCreatedAt = requestMemberId
|
|
||||||
? await timeAndDate.inMemberTz(requestMemberId, createdAt)
|
|
||||||
: timeAndDate.inGuildTz(createdAt);
|
|
||||||
const prettyCreatedAt = tzCreatedAt.format(timeAndDate.getDateFormat("pretty_datetime"));
|
|
||||||
const snowflakeAge = humanizeDuration(Date.now() - createdAtMS, {
|
|
||||||
largest: 2,
|
|
||||||
round: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
embed.fields.push({
|
embed.fields.push({
|
||||||
name: preEmbedPadding + "Basic information",
|
name: preEmbedPadding + "Basic information",
|
||||||
value: `Created: **${snowflakeAge} ago** (\`${prettyCreatedAt}\`)`,
|
value: `Created: **<t:${Math.round(createdAtMS / 1000)}:R>**`,
|
||||||
});
|
});
|
||||||
|
|
||||||
return embed;
|
return embed;
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
import { APIEmbed } from "discord.js";
|
import { APIEmbed } from "discord.js";
|
||||||
import humanizeDuration from "humanize-duration";
|
|
||||||
import { GuildPluginData } from "knub";
|
import { GuildPluginData } from "knub";
|
||||||
import moment from "moment-timezone";
|
|
||||||
import { CaseTypes } from "../../../data/CaseTypes";
|
import { CaseTypes } from "../../../data/CaseTypes";
|
||||||
import {
|
import {
|
||||||
EmbedWith,
|
EmbedWith,
|
||||||
|
@ -50,36 +48,18 @@ export async function getUserInfoEmbed(
|
||||||
const avatarURL = user.displayAvatarURL();
|
const avatarURL = user.displayAvatarURL();
|
||||||
embed.author.icon_url = avatarURL;
|
embed.author.icon_url = avatarURL;
|
||||||
|
|
||||||
const createdAt = moment.utc(user.createdAt, "x");
|
|
||||||
const tzCreatedAt = requestMemberId
|
|
||||||
? await timeAndDate.inMemberTz(requestMemberId, createdAt)
|
|
||||||
: timeAndDate.inGuildTz(createdAt);
|
|
||||||
const prettyCreatedAt = tzCreatedAt.format(timeAndDate.getDateFormat("pretty_datetime"));
|
|
||||||
const accountAge = humanizeDuration(moment.utc().valueOf() - user.createdTimestamp, {
|
|
||||||
largest: 2,
|
|
||||||
round: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (compact) {
|
if (compact) {
|
||||||
embed.fields.push({
|
embed.fields.push({
|
||||||
name: preEmbedPadding + `${user.bot ? "Bot" : "User"} information`,
|
name: preEmbedPadding + `${user.bot ? "Bot" : "User"} information`,
|
||||||
value: trimLines(`
|
value: trimLines(`
|
||||||
Profile: <@!${user.id}>
|
Profile: <@!${user.id}>
|
||||||
Created: **${accountAge} ago** (\`${prettyCreatedAt}\`)
|
Created: **<t:${Math.round(user.createdTimestamp / 1000)}:R>**
|
||||||
`),
|
`),
|
||||||
});
|
});
|
||||||
if (member) {
|
if (member) {
|
||||||
const joinedAt = moment.utc(member.joinedTimestamp!, "x");
|
embed.fields[0].value += `\n${user.bot ? "Added" : "Joined"}: **<t:${Math.round(
|
||||||
const tzJoinedAt = requestMemberId
|
member.joinedTimestamp! / 1000,
|
||||||
? await timeAndDate.inMemberTz(requestMemberId, joinedAt)
|
)}:R>**`;
|
||||||
: timeAndDate.inGuildTz(joinedAt);
|
|
||||||
const prettyJoinedAt = tzJoinedAt.format(timeAndDate.getDateFormat("pretty_datetime"));
|
|
||||||
const joinAge = humanizeDuration(moment.utc().valueOf() - member.joinedTimestamp!, {
|
|
||||||
largest: 2,
|
|
||||||
round: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
embed.fields[0].value += `\n${user.bot ? "Added" : "Joined"}: **${joinAge} ago** (\`${prettyJoinedAt}\`)`;
|
|
||||||
} else {
|
} else {
|
||||||
embed.fields.push({
|
embed.fields.push({
|
||||||
name: preEmbedPadding + "!! NOTE !!",
|
name: preEmbedPadding + "!! NOTE !!",
|
||||||
|
@ -94,7 +74,7 @@ export async function getUserInfoEmbed(
|
||||||
if (user.discriminator !== "0") {
|
if (user.discriminator !== "0") {
|
||||||
userInfoLines.push(`Discriminator: **${user.discriminator}**`);
|
userInfoLines.push(`Discriminator: **${user.discriminator}**`);
|
||||||
}
|
}
|
||||||
userInfoLines.push(`Created: **${accountAge} ago** (\`${prettyCreatedAt}\`)`);
|
userInfoLines.push(`Created: **<t:${Math.round(user.createdTimestamp / 1000)}:R>**`);
|
||||||
userInfoLines.push(`Mention: <@!${user.id}>`);
|
userInfoLines.push(`Mention: <@!${user.id}>`);
|
||||||
|
|
||||||
embed.fields.push({
|
embed.fields.push({
|
||||||
|
@ -103,22 +83,13 @@ export async function getUserInfoEmbed(
|
||||||
});
|
});
|
||||||
|
|
||||||
if (member) {
|
if (member) {
|
||||||
const joinedAt = moment.utc(member.joinedTimestamp!, "x");
|
|
||||||
const tzJoinedAt = requestMemberId
|
|
||||||
? await timeAndDate.inMemberTz(requestMemberId, joinedAt)
|
|
||||||
: timeAndDate.inGuildTz(joinedAt);
|
|
||||||
const prettyJoinedAt = tzJoinedAt.format(timeAndDate.getDateFormat("pretty_datetime"));
|
|
||||||
const joinAge = humanizeDuration(moment.utc().valueOf() - member.joinedTimestamp!, {
|
|
||||||
largest: 2,
|
|
||||||
round: true,
|
|
||||||
});
|
|
||||||
const roles = Array.from(member.roles.cache.values()).filter((r) => r.id !== pluginData.guild.id);
|
const roles = Array.from(member.roles.cache.values()).filter((r) => r.id !== pluginData.guild.id);
|
||||||
roles.sort(sorter("position", "DESC"));
|
roles.sort(sorter("position", "DESC"));
|
||||||
|
|
||||||
embed.fields.push({
|
embed.fields.push({
|
||||||
name: preEmbedPadding + "Member information",
|
name: preEmbedPadding + "Member information",
|
||||||
value: trimLines(`
|
value: trimLines(`
|
||||||
${user.bot ? "Added" : "Joined"}: **${joinAge} ago** (\`${prettyJoinedAt}\`)
|
${user.bot ? "Added" : "Joined"}: **<t:${Math.round(member.joinedTimestamp! / 1000)}:R>**
|
||||||
${roles.length > 0 ? "Roles: " + trimRoles(roles.map((r) => `<@&${r.id}>`)) : ""}
|
${roles.length > 0 ? "Roles: " + trimRoles(roles.map((r) => `<@&${r.id}>`)) : ""}
|
||||||
`),
|
`),
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue