From e8b8c11bf00df9d251ba540b6e394284fd22e6c9 Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Sat, 24 Jun 2023 10:41:02 +0000 Subject: [PATCH] feat: new username support --- backend/src/data/GuildArchives.ts | 5 +++-- .../matchMultipleTextTypesOnMessage.ts | 4 ++-- .../commands/ArchiveChannelCmd.ts | 9 +++++---- .../Utility/functions/getUserInfoEmbed.ts | 17 ++++++++++------- backend/src/utils.ts | 7 +++++++ 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/backend/src/data/GuildArchives.ts b/backend/src/data/GuildArchives.ts index bc1df143..2ee9116b 100644 --- a/backend/src/data/GuildArchives.ts +++ b/backend/src/data/GuildArchives.ts @@ -3,7 +3,7 @@ import moment from "moment-timezone"; import { isDefaultSticker } from "src/utils/isDefaultSticker"; import { Repository, getRepository } from "typeorm"; import { TemplateSafeValueContainer, renderTemplate } from "../templateFormatter"; -import { trimLines } from "../utils"; +import { renderUsername, trimLines } from "../utils"; import { decrypt, encrypt } from "../utils/crypt"; import { channelToTemplateSafeChannel, guildToTemplateSafeGuild } from "../utils/templateSafeObjects"; import { BaseGuildRepository } from "./BaseGuildRepository"; @@ -16,7 +16,7 @@ const MESSAGE_ARCHIVE_HEADER_FORMAT = trimLines(` Server: {guild.name} ({guild.id}) `); const MESSAGE_ARCHIVE_MESSAGE_FORMAT = - "[#{channel.name}] [{user.id}] [{timestamp}] {user.username}#{user.discriminator}: {content}{attachments}{stickers}"; + "[#{channel.name}] [{user.id}] [{timestamp}] {username}: {content}{attachments}{stickers}"; export class GuildArchives extends BaseGuildRepository { protected archives: Repository; @@ -97,6 +97,7 @@ export class GuildArchives extends BaseGuildRepository { }), user: partialUser, channel: channel ? channelToTemplateSafeChannel(channel) : null, + username: renderUsername(msg.data.author.username, msg.data.author.discriminator), }), ); diff --git a/backend/src/plugins/Automod/functions/matchMultipleTextTypesOnMessage.ts b/backend/src/plugins/Automod/functions/matchMultipleTextTypesOnMessage.ts index 29d07cd9..9e51c490 100644 --- a/backend/src/plugins/Automod/functions/matchMultipleTextTypesOnMessage.ts +++ b/backend/src/plugins/Automod/functions/matchMultipleTextTypesOnMessage.ts @@ -1,7 +1,7 @@ import { ActivityType, Embed } from "discord.js"; import { GuildPluginData } from "knub"; import { SavedMessage } from "../../../data/entities/SavedMessage"; -import { resolveMember } from "../../../utils"; +import { renderUsername, resolveMember } from "../../../utils"; import { DeepMutable } from "../../../utils/typeUtils.js"; import { AutomodPluginType } from "../types"; @@ -46,7 +46,7 @@ export async function* matchMultipleTextTypesOnMessage( } if (trigger.match_usernames) { - yield ["username", `${msg.data.author.username}#${msg.data.author.discriminator}`]; + yield ["username", renderUsername(msg.data.author.username, msg.data.author.discriminator)]; } if (trigger.match_nicknames && member.nickname) { diff --git a/backend/src/plugins/ChannelArchiver/commands/ArchiveChannelCmd.ts b/backend/src/plugins/ChannelArchiver/commands/ArchiveChannelCmd.ts index 1ed47f9b..13a72a87 100644 --- a/backend/src/plugins/ChannelArchiver/commands/ArchiveChannelCmd.ts +++ b/backend/src/plugins/ChannelArchiver/commands/ArchiveChannelCmd.ts @@ -2,7 +2,7 @@ import { Snowflake } from "discord.js"; import moment from "moment-timezone"; import { commandTypeHelpers as ct } from "../../../commandTypes"; import { isOwner, sendErrorMessage } from "../../../pluginUtils"; -import { SECONDS, confirm, noop } from "../../../utils"; +import { SECONDS, confirm, noop, renderUsername } from "../../../utils"; import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin"; import { rehostAttachment } from "../rehostAttachment"; import { channelArchiverCmd } from "../types"; @@ -68,9 +68,10 @@ export const ArchiveChannelCmd = channelArchiverCmd({ for (const message of messages.values()) { const ts = moment.utc(message.createdTimestamp).format("YYYY-MM-DD HH:mm:ss"); - let content = `[${ts}] [${message.author.id}] [${message.author.username}#${message.author.discriminator}]: ${ - message.content || "" - }`; + let content = `[${ts}] [${message.author.id}] [${renderUsername( + message.author.username, + message.author.discriminator, + )}]: ${message.content || ""}`; if (message.attachments.size) { if (args["attachment-channel"]) { diff --git a/backend/src/plugins/Utility/functions/getUserInfoEmbed.ts b/backend/src/plugins/Utility/functions/getUserInfoEmbed.ts index 4b9e2724..c6778a1d 100644 --- a/backend/src/plugins/Utility/functions/getUserInfoEmbed.ts +++ b/backend/src/plugins/Utility/functions/getUserInfoEmbed.ts @@ -7,6 +7,7 @@ import { EmbedWith, messageLink, preEmbedPadding, + renderUsername, resolveMember, resolveUser, sorter, @@ -43,7 +44,7 @@ export async function getUserInfoEmbed( const timeAndDate = pluginData.getPlugin(TimeAndDatePlugin); embed.author = { - name: `${user.bot ? "Bot" : "User"}: ${user.tag}`, + name: `${user.bot ? "Bot" : "User"}: ${renderUsername(user.username, user.discriminator)}`, }; const avatarURL = user.displayAvatarURL(); @@ -89,14 +90,16 @@ export async function getUserInfoEmbed( return embed; } + const userInfoLines = [`ID: \`${user.id}\``, `Username: **${user.username}**`]; + if (user.discriminator !== "0") { + userInfoLines.push(`Discriminator: **${user.discriminator}**`); + } + userInfoLines.push(`Created: **${accountAge} ago** (\`${prettyCreatedAt}\`)`); + userInfoLines.push(`Mention: <@!${user.id}>`); + embed.fields.push({ name: preEmbedPadding + `${user.bot ? "Bot" : "User"} information`, - value: trimLines(` - Name: **${user.tag}** - ID: \`${user.id}\` - Created: **${accountAge} ago** (\`${prettyCreatedAt}\`) - Mention: <@!${user.id}> - `), + value: userInfoLines.join("\n"), }); if (member) { diff --git a/backend/src/utils.ts b/backend/src/utils.ts index 831a8a11..e24a7318 100644 --- a/backend/src/utils.ts +++ b/backend/src/utils.ts @@ -1602,3 +1602,10 @@ export function isTruthy(value: T): value is Exclude