diff --git a/backend/src/data/DefaultLogMessages.json b/backend/src/data/DefaultLogMessages.json index e6ad770b..53534132 100644 --- a/backend/src/data/DefaultLogMessages.json +++ b/backend/src/data/DefaultLogMessages.json @@ -11,7 +11,7 @@ "MEMBER_UNBAN": "{timestamp} 🔓 User (`{userId}`) was unbanned by {userMention(mod)}", "MEMBER_FORCEBAN": "{timestamp} 🔨 User (`{userId}`) was forcebanned 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 )", "MEMBER_LEAVE": "{timestamp} 📤 {userMention(member)} left the server", "MEMBER_ROLE_ADD": "{timestamp} 🔑 {userMention(mod)} added roles for {userMention(member)}: **{roles}**", "MEMBER_ROLE_REMOVE": "{timestamp} 🔑 {userMention(mod)} removed roles from {userMention(member)}: **{roles}**", diff --git a/backend/src/plugins/Logs/logFunctions/logMemberJoin.ts b/backend/src/plugins/Logs/logFunctions/logMemberJoin.ts index f1368209..81771fbd 100644 --- a/backend/src/plugins/Logs/logFunctions/logMemberJoin.ts +++ b/backend/src/plugins/Logs/logFunctions/logMemberJoin.ts @@ -26,6 +26,7 @@ export function logMemberJoin(pluginData: GuildPluginData, data: member: memberToTemplateSafeMember(data.member), new: data.member.user.createdTimestamp >= newThreshold ? " :new:" : "", account_age: accountAge, + account_age_ts: Math.round(data.member.user.createdTimestamp / 1000).toString(), }), { userId: data.member.id, diff --git a/backend/src/plugins/Logs/types.ts b/backend/src/plugins/Logs/types.ts index 714d1de5..62008aab 100644 --- a/backend/src/plugins/Logs/types.ts +++ b/backend/src/plugins/Logs/types.ts @@ -150,6 +150,7 @@ export const LogTypeData = z.object({ member: z.instanceof(TemplateSafeMember), new: z.string(), account_age: z.string(), + account_age_ts: z.string(), }), [LogType.MEMBER_LEAVE]: z.object({ diff --git a/backend/src/plugins/Utility/functions/getChannelInfoEmbed.ts b/backend/src/plugins/Utility/functions/getChannelInfoEmbed.ts index a1955ca2..ee006f5f 100644 --- a/backend/src/plugins/Utility/functions/getChannelInfoEmbed.ts +++ b/backend/src/plugins/Utility/functions/getChannelInfoEmbed.ts @@ -1,9 +1,7 @@ import { APIEmbed, ChannelType, Snowflake, StageChannel, VoiceChannel } from "discord.js"; import humanizeDuration from "humanize-duration"; import { GuildPluginData } from "knub"; -import moment from "moment-timezone"; import { EmbedWith, MINUTES, formatNumber, preEmbedPadding, trimLines, verboseUserMention } from "../../../utils"; -import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin"; import { UtilityPluginType } from "../types"; const TEXT_CHANNEL_ICON = @@ -74,17 +72,6 @@ export async function getChannelInfoEmbed( 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; embed.fields.push({ @@ -92,7 +79,7 @@ export async function getChannelInfoEmbed( value: trimLines(` Name: **${channelName}** ID: \`${channel.id}\` - Created: **${channelAge} ago** (\`${prettyCreatedAt}\`) + Created: **** Type: **${channelType}** ${showMention ? `Mention: <#${channel.id}>` : ""} `), diff --git a/backend/src/plugins/Utility/functions/getInviteInfoEmbed.ts b/backend/src/plugins/Utility/functions/getInviteInfoEmbed.ts index f7e7e293..12c97a8a 100644 --- a/backend/src/plugins/Utility/functions/getInviteInfoEmbed.ts +++ b/backend/src/plugins/Utility/functions/getInviteInfoEmbed.ts @@ -1,5 +1,4 @@ import { APIEmbed, ChannelType } from "discord.js"; -import humanizeDuration from "humanize-duration"; import { GuildPluginData } from "knub"; import { EmbedWith, @@ -44,10 +43,6 @@ export async function getInviteInfoEmbed( } const serverCreatedAtTimestamp = snowflakeToTimestamp(invite.guild.id); - const serverAge = humanizeDuration(Date.now() - serverCreatedAtTimestamp, { - largest: 2, - round: true, - }); const memberCount = inviteHasCounts(invite) ? invite.memberCount : 0; @@ -58,7 +53,7 @@ export async function getInviteInfoEmbed( value: trimLines(` Name: **${invite.guild.name}** ID: \`${invite.guild.id}\` - Created: **${serverAge} ago** + Created: **** Members: **${formatNumber(memberCount)}** (${formatNumber(presenceCount)} online) `), inline: true, @@ -68,15 +63,11 @@ export async function getInviteInfoEmbed( invite.channel.type === ChannelType.GuildVoice ? `🔉 ${invite.channel.name}` : `#${invite.channel.name}`; const channelCreatedAtTimestamp = snowflakeToTimestamp(invite.channel.id); - const channelAge = humanizeDuration(Date.now() - channelCreatedAtTimestamp, { - largest: 2, - round: true, - }); let channelInfo = trimLines(` Name: **${channelName}** ID: \`${invite.channel.id}\` - Created: **${channelAge} ago** + Created: **** `); if (invite.channel.type !== ChannelType.GuildVoice) { @@ -120,17 +111,13 @@ export async function getInviteInfoEmbed( }*/ const channelCreatedAtTimestamp = snowflakeToTimestamp(invite.channel!.id); - const channelAge = humanizeDuration(Date.now() - channelCreatedAtTimestamp, { - largest: 2, - round: true, - }); embed.fields.push({ name: preEmbedPadding + "Group DM information", value: trimLines(` Name: ${invite.channel!.name ? `**${invite.channel!.name}**` : `_Unknown_`} ID: \`${invite.channel!.id}\` - Created: **${channelAge} ago** + Created: **** Members: **${formatNumber((invite as any).memberCount)}** `), inline: true, diff --git a/backend/src/plugins/Utility/functions/getMessageInfoEmbed.ts b/backend/src/plugins/Utility/functions/getMessageInfoEmbed.ts index aed3ac10..1568a3e3 100644 --- a/backend/src/plugins/Utility/functions/getMessageInfoEmbed.ts +++ b/backend/src/plugins/Utility/functions/getMessageInfoEmbed.ts @@ -1,7 +1,5 @@ import { APIEmbed, MessageType, Snowflake, TextChannel } from "discord.js"; -import humanizeDuration from "humanize-duration"; import { GuildPluginData, getDefaultMessageCommandPrefix } from "knub"; -import moment from "moment-timezone"; import { EmbedWith, 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 = { [MessageType.Default]: "Regular message", @@ -82,45 +58,23 @@ export async function getMessageInfoEmbed( ID: \`${message.id}\` Channel: <#${message.channel.id}> Channel ID: \`${message.channel.id}\` - Created: **${messageAge} ago** (\`${prettyCreatedAt}\`) - ${editedAt ? `Edited at: **${editAge} ago** (\`${prettyEditedAt}\`)` : ""} + Created: **** + ${message.editedTimestamp ? `Edited at: ****` : ""} Type: **${type}** Link: [**Go to message ➔**](${messageLink(pluginData.guild.id, message.channel.id, message.id)}) `), ), }); - const authorCreatedAt = moment.utc(message.author.createdAt, "x"); - 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, - }); + const authorJoinedAtTS = message.member?.joinedTimestamp; embed.fields.push({ name: preEmbedPadding + "Author information", value: trimLines(` Name: **${renderUsername(message.author.username, message.author.discriminator)}** ID: \`${message.author.id}\` - Created: **${authorAccountAge} ago** (\`${prettyAuthorCreatedAt}\`) - ${authorJoinedAt ? `Joined: **${authorServerAge} ago** (\`${prettyAuthorJoinedAt}\`)` : ""} + Created: **** + ${authorJoinedAtTS ? `Joined: ****` : ""} Mention: <@!${message.author.id}> `), }); diff --git a/backend/src/plugins/Utility/functions/getRoleInfoEmbed.ts b/backend/src/plugins/Utility/functions/getRoleInfoEmbed.ts index 5acd8c72..fa3188ec 100644 --- a/backend/src/plugins/Utility/functions/getRoleInfoEmbed.ts +++ b/backend/src/plugins/Utility/functions/getRoleInfoEmbed.ts @@ -1,10 +1,7 @@ import { APIEmbed, PermissionFlagsBits, Role } from "discord.js"; -import humanizeDuration from "humanize-duration"; import { GuildPluginData } from "knub"; -import moment from "moment-timezone"; import { EmbedWith, preEmbedPadding, trimLines } from "../../../utils"; import { PERMISSION_NAMES } from "../../../utils/permissionNames.js"; -import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin"; import { UtilityPluginType } from "../types"; const MENTION_ICON = "https://cdn.discordapp.com/attachments/705009450855039042/839284872152481792/mention.png"; @@ -23,17 +20,6 @@ export async function getRoleInfoEmbed( 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) ? [PERMISSION_NAMES.Administrator] : role.permissions.toArray().map((p) => PERMISSION_NAMES[p]); @@ -46,7 +32,7 @@ export async function getRoleInfoEmbed( value: trimLines(` Name: **${role.name}** ID: \`${role.id}\` - Created: **${roleAge} ago** (\`${prettyCreatedAt}\`) + Created: **** Position: **${role.position} / ${totalGuildRoles}** Color: **#${role.color.toString(16).toUpperCase().padStart(6, "0")}** Mentionable: **${role.mentionable ? "Yes" : "No"}** diff --git a/backend/src/plugins/Utility/functions/getServerInfoEmbed.ts b/backend/src/plugins/Utility/functions/getServerInfoEmbed.ts index 1d3b736f..c8cf4ccd 100644 --- a/backend/src/plugins/Utility/functions/getServerInfoEmbed.ts +++ b/backend/src/plugins/Utility/functions/getServerInfoEmbed.ts @@ -1,7 +1,5 @@ import { APIEmbed, ChannelType, GuildPremiumTier, Snowflake } from "discord.js"; -import humanizeDuration from "humanize-duration"; import { GuildPluginData } from "knub"; -import moment from "moment-timezone"; import { EmbedWith, MINUTES, @@ -15,7 +13,6 @@ import { trimLines, } from "../../../utils"; import { idToTimestamp } from "../../../utils/idToTimestamp"; -import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin"; import { UtilityPluginType } from "../types"; import { getGuildPreview } from "./getGuildPreview"; @@ -51,19 +48,10 @@ export async function getServerInfoEmbed( }; // BASIC INFORMATION - const timeAndDate = pluginData.getPlugin(TimeAndDatePlugin); - 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 createdAtTs = Number(idToTimestamp((guildPreview || restGuild)!.id)!); const basicInformation: string[] = []; - basicInformation.push(`Created: **${serverAge} ago** (\`${prettyCreatedAt}\`)`); + basicInformation.push(`Created: ****`); if (thisServer) { const owner = await resolveUser(pluginData.client, thisServer.ownerId); diff --git a/backend/src/plugins/Utility/functions/getSnowflakeInfoEmbed.ts b/backend/src/plugins/Utility/functions/getSnowflakeInfoEmbed.ts index 901df722..ef676fd1 100644 --- a/backend/src/plugins/Utility/functions/getSnowflakeInfoEmbed.ts +++ b/backend/src/plugins/Utility/functions/getSnowflakeInfoEmbed.ts @@ -1,10 +1,7 @@ import { APIEmbed } from "discord.js"; -import humanizeDuration from "humanize-duration"; import { GuildPluginData } from "knub"; -import moment from "moment-timezone"; import { EmbedWith, preEmbedPadding } from "../../../utils"; import { snowflakeToTimestamp } from "../../../utils/snowflakeToTimestamp"; -import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin"; import { UtilityPluginType } from "../types"; 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."; } - const timeAndDate = pluginData.getPlugin(TimeAndDatePlugin); 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({ name: preEmbedPadding + "Basic information", - value: `Created: **${snowflakeAge} ago** (\`${prettyCreatedAt}\`)`, + value: `Created: ****`, }); return embed; diff --git a/backend/src/plugins/Utility/functions/getUserInfoEmbed.ts b/backend/src/plugins/Utility/functions/getUserInfoEmbed.ts index c6778a1d..3d720721 100644 --- a/backend/src/plugins/Utility/functions/getUserInfoEmbed.ts +++ b/backend/src/plugins/Utility/functions/getUserInfoEmbed.ts @@ -1,7 +1,5 @@ import { APIEmbed } from "discord.js"; -import humanizeDuration from "humanize-duration"; import { GuildPluginData } from "knub"; -import moment from "moment-timezone"; import { CaseTypes } from "../../../data/CaseTypes"; import { EmbedWith, @@ -50,36 +48,18 @@ export async function getUserInfoEmbed( const avatarURL = user.displayAvatarURL(); 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) { embed.fields.push({ name: preEmbedPadding + `${user.bot ? "Bot" : "User"} information`, value: trimLines(` Profile: <@!${user.id}> - Created: **${accountAge} ago** (\`${prettyCreatedAt}\`) + Created: **** `), }); 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, - }); - - embed.fields[0].value += `\n${user.bot ? "Added" : "Joined"}: **${joinAge} ago** (\`${prettyJoinedAt}\`)`; + embed.fields[0].value += `\n${user.bot ? "Added" : "Joined"}: ****`; } else { embed.fields.push({ name: preEmbedPadding + "!! NOTE !!", @@ -94,7 +74,7 @@ export async function getUserInfoEmbed( if (user.discriminator !== "0") { userInfoLines.push(`Discriminator: **${user.discriminator}**`); } - userInfoLines.push(`Created: **${accountAge} ago** (\`${prettyCreatedAt}\`)`); + userInfoLines.push(`Created: ****`); userInfoLines.push(`Mention: <@!${user.id}>`); embed.fields.push({ @@ -103,22 +83,13 @@ export async function getUserInfoEmbed( }); 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); roles.sort(sorter("position", "DESC")); embed.fields.push({ name: preEmbedPadding + "Member information", value: trimLines(` - ${user.bot ? "Added" : "Joined"}: **${joinAge} ago** (\`${prettyJoinedAt}\`) + ${user.bot ? "Added" : "Joined"}: **** ${roles.length > 0 ? "Roles: " + trimRoles(roles.map((r) => `<@&${r.id}>`)) : ""} `), });