diff --git a/backend/src/plugins/Automod/functions/matchMultipleTextTypesOnMessage.ts b/backend/src/plugins/Automod/functions/matchMultipleTextTypesOnMessage.ts index f0eee5ec..a82c526e 100644 --- a/backend/src/plugins/Automod/functions/matchMultipleTextTypesOnMessage.ts +++ b/backend/src/plugins/Automod/functions/matchMultipleTextTypesOnMessage.ts @@ -42,7 +42,7 @@ export async function* matchMultipleTextTypesOnMessage( } if (trigger.match_visible_names) { - yield ["visiblename", member.nickname || member.user.globalName || msg.data.author.username]; + yield ["visiblename", member.displayName || msg.data.author.username]; } if (trigger.match_usernames) { diff --git a/backend/src/plugins/Automod/triggers/roleAdded.ts b/backend/src/plugins/Automod/triggers/roleAdded.ts index 754be1b3..5d18de99 100644 --- a/backend/src/plugins/Automod/triggers/roleAdded.ts +++ b/backend/src/plugins/Automod/triggers/roleAdded.ts @@ -38,7 +38,7 @@ export const RoleAddedTrigger = automodTrigger()({ const role = pluginData.guild.roles.cache.get(matchResult.extra.matchedRoleId as Snowflake); const roleName = role?.name || "Unknown"; const member = contexts[0].member!; - const memberName = `**${renderUsername(member.user)}** (\`${member.id}\`)`; + const memberName = `**${renderUsername(member)}** (\`${member.id}\`)`; return `Role ${roleName} (\`${matchResult.extra.matchedRoleId}\`) was added to ${memberName}`; }, }); diff --git a/backend/src/plugins/Automod/triggers/roleRemoved.ts b/backend/src/plugins/Automod/triggers/roleRemoved.ts index fc5d5ae3..9452bdda 100644 --- a/backend/src/plugins/Automod/triggers/roleRemoved.ts +++ b/backend/src/plugins/Automod/triggers/roleRemoved.ts @@ -38,7 +38,7 @@ export const RoleRemovedTrigger = automodTrigger()({ const role = pluginData.guild.roles.cache.get(matchResult.extra.matchedRoleId as Snowflake); const roleName = role?.name || "Unknown"; const member = contexts[0].member!; - const memberName = `**${renderUsername(member.user)}** (\`${member.id}\`)`; + const memberName = `**${renderUsername(member)}** (\`${member.id}\`)`; return `Role ${roleName} (\`${matchResult.extra.matchedRoleId}\`) was removed from ${memberName}`; }, }); diff --git a/backend/src/plugins/BotControl/commands/ServersCmd.ts b/backend/src/plugins/BotControl/commands/ServersCmd.ts index 3658a36c..5b2cf9c7 100644 --- a/backend/src/plugins/BotControl/commands/ServersCmd.ts +++ b/backend/src/plugins/BotControl/commands/ServersCmd.ts @@ -48,10 +48,9 @@ export const ServersCmd = botControlCmd({ const lines = filteredGuilds.map((g) => { const paddedId = g.id.padEnd(longestId, " "); const owner = getUser(pluginData.client, g.ownerId); - return `\`${paddedId}\` **${g.name}** (${g.memberCount} members) (owner **${renderUsername( - owner.username, - owner.discriminator, - )}** \`${owner.id}\`)`; + return `\`${paddedId}\` **${g.name}** (${g.memberCount} members) (owner **${renderUsername(owner)}** \`${ + owner.id + }\`)`; }); createChunkedMessage(msg.channel, lines.join("\n")); } else { diff --git a/backend/src/plugins/Cases/functions/createCase.ts b/backend/src/plugins/Cases/functions/createCase.ts index 70717f51..c68b899f 100644 --- a/backend/src/plugins/Cases/functions/createCase.ts +++ b/backend/src/plugins/Cases/functions/createCase.ts @@ -8,16 +8,16 @@ import { postCaseToCaseLogChannel } from "./postToCaseLogChannel"; export async function createCase(pluginData: GuildPluginData, args: CaseArgs) { const user = await resolveUser(pluginData.client, args.userId); - const userName = renderUsername(user.username, user.discriminator); + const name = renderUsername(user); const mod = await resolveUser(pluginData.client, args.modId); - const modName = renderUsername(mod.username, mod.discriminator); + const modName = renderUsername(mod); let ppName: string | null = null; let ppId: Snowflake | null = null; if (args.ppId) { const pp = await resolveUser(pluginData.client, args.ppId); - ppName = renderUsername(pp.username, pp.discriminator); + ppName = renderUsername(pp); ppId = pp.id; } @@ -32,7 +32,7 @@ export async function createCase(pluginData: GuildPluginData, a const createdCase = await pluginData.state.cases.create({ type: args.type, user_id: user.id, - user_name: userName, + user_name: name, mod_id: mod.id, mod_name: modName, audit_log_id: args.auditLogId, diff --git a/backend/src/plugins/ModActions/commands/CasesModCmd.ts b/backend/src/plugins/ModActions/commands/CasesModCmd.ts index a911091d..12b6c05c 100644 --- a/backend/src/plugins/ModActions/commands/CasesModCmd.ts +++ b/backend/src/plugins/ModActions/commands/CasesModCmd.ts @@ -1,7 +1,7 @@ -import { APIEmbed, GuildMember, User } from "discord.js"; +import { APIEmbed } from "discord.js"; import { commandTypeHelpers as ct } from "../../../commandTypes"; import { sendErrorMessage } from "../../../pluginUtils"; -import { emptyEmbedValue, renderUsername, resolveMember, resolveUser, trimLines } from "../../../utils"; +import { UnknownUser, emptyEmbedValue, renderUsername, resolveMember, resolveUser, trimLines } from "../../../utils"; import { asyncMap } from "../../../utils/async"; import { createPaginatedMessage } from "../../../utils/createPaginatedMessage"; import { getChunkedEmbedFields } from "../../../utils/getChunkedEmbedFields"; @@ -31,7 +31,7 @@ export const CasesModCmd = modActionsCmd({ const mod = (await resolveMember(pluginData.client, pluginData.guild, modId)) || (await resolveUser(pluginData.client, modId)); - const modName = mod instanceof User ? renderUsername(mod) : modId; + const modName = mod instanceof UnknownUser ? modId : renderUsername(mod); const casesPlugin = pluginData.getPlugin(CasesPlugin); const totalCases = await casesPlugin.getTotalCasesByMod(modId); @@ -59,7 +59,7 @@ export const CasesModCmd = modActionsCmd({ const embed = { author: { name: title, - icon_url: mod instanceof User || mod instanceof GuildMember ? mod.displayAvatarURL() : undefined, + icon_url: mod instanceof UnknownUser ? undefined : mod.displayAvatarURL(), }, fields: [ ...getChunkedEmbedFields(emptyEmbedValue, lines.join("\n")), diff --git a/backend/src/plugins/ModActions/commands/CasesUserCmd.ts b/backend/src/plugins/ModActions/commands/CasesUserCmd.ts index 05ab65eb..7b3714b6 100644 --- a/backend/src/plugins/ModActions/commands/CasesUserCmd.ts +++ b/backend/src/plugins/ModActions/commands/CasesUserCmd.ts @@ -46,7 +46,7 @@ export const CasesUserCmd = modActionsCmd({ const user = (await resolveMember(pluginData.client, pluginData.guild, args.user)) || (await resolveUser(pluginData.client, args.user)); - if (!user.id || user instanceof UnknownUser) { + if (user instanceof UnknownUser) { sendErrorMessage(pluginData, msg.channel, `User not found`); return; } diff --git a/backend/src/plugins/ModActions/commands/WarnCmd.ts b/backend/src/plugins/ModActions/commands/WarnCmd.ts index f917c55e..218eeaf3 100644 --- a/backend/src/plugins/ModActions/commands/WarnCmd.ts +++ b/backend/src/plugins/ModActions/commands/WarnCmd.ts @@ -106,7 +106,7 @@ export const WarnCmd = modActionsCmd({ sendSuccessMessage( pluginData, msg.channel, - `Warned **${renderUsername(memberToWarn.user)}** (Case #${warnResult.case.case_number})${messageResultText}`, + `Warned **${renderUsername(memberToWarn)}** (Case #${warnResult.case.case_number})${messageResultText}`, ); }, }); diff --git a/backend/src/plugins/ModActions/events/PostAlertOnMemberJoinEvt.ts b/backend/src/plugins/ModActions/events/PostAlertOnMemberJoinEvt.ts index 7874c241..82e39547 100644 --- a/backend/src/plugins/ModActions/events/PostAlertOnMemberJoinEvt.ts +++ b/backend/src/plugins/ModActions/events/PostAlertOnMemberJoinEvt.ts @@ -46,9 +46,7 @@ export const PostAlertOnMemberJoinEvt = modActionsEvt({ } await alertChannel.send( - `<@!${member.id}> (${renderUsername(member.user)} \`${member.id}\`) joined with ${ - actions.length - } prior record(s)`, + `<@!${member.id}> (${renderUsername(member)} \`${member.id}\`) joined with ${actions.length} prior record(s)`, ); } }, diff --git a/backend/src/plugins/ModActions/functions/actualKickMemberCmd.ts b/backend/src/plugins/ModActions/functions/actualKickMemberCmd.ts index fac3f906..a755ee08 100644 --- a/backend/src/plugins/ModActions/functions/actualKickMemberCmd.ts +++ b/backend/src/plugins/ModActions/functions/actualKickMemberCmd.ts @@ -103,7 +103,7 @@ export async function actualKickMemberCmd( } // Confirm the action to the moderator - let response = `Kicked **${renderUsername(memberToKick.user)}** (Case #${kickResult.case.case_number})`; + let response = `Kicked **${renderUsername(memberToKick)}** (Case #${kickResult.case.case_number})`; if (kickResult.notifyResult.text) response += ` (${kickResult.notifyResult.text})`; sendSuccessMessage(pluginData, msg.channel, response); diff --git a/backend/src/plugins/Mutes/commands/MutesCmd.ts b/backend/src/plugins/Mutes/commands/MutesCmd.ts index 22cd74c5..5000218c 100644 --- a/backend/src/plugins/Mutes/commands/MutesCmd.ts +++ b/backend/src/plugins/Mutes/commands/MutesCmd.ts @@ -74,7 +74,7 @@ export const MutesCmd = mutesCmd({ totalMutes = manuallyMutedMembers.length; lines = manuallyMutedMembers.map((member) => { - return `<@!${member.id}> (**${renderUsername(member.user)}**, \`${member.id}\`) 🔧 Manual mute`; + return `<@!${member.id}> (**${renderUsername(member)}**, \`${member.id}\`) 🔧 Manual mute`; }); } else { // Show filtered active mutes (but not manual mutes) diff --git a/backend/src/plugins/Starboard/util/createStarboardEmbedFromMessage.ts b/backend/src/plugins/Starboard/util/createStarboardEmbedFromMessage.ts index 5126f20f..93ba4dfd 100644 --- a/backend/src/plugins/Starboard/util/createStarboardEmbedFromMessage.ts +++ b/backend/src/plugins/Starboard/util/createStarboardEmbedFromMessage.ts @@ -28,7 +28,7 @@ export function createStarboardEmbedFromMessage( embed.color = color; } - embed.author.icon_url = (msg.member || msg.author).displayAvatarURL(); + embed.author.icon_url = (msg.member ?? msg.author).displayAvatarURL(); // The second condition here checks for messages with only an image link that is then embedded. // The message content in that case is hidden by the Discord client, so we hide it here too. diff --git a/backend/src/plugins/Utility/commands/AvatarCmd.ts b/backend/src/plugins/Utility/commands/AvatarCmd.ts index b1215df6..e4ba07d5 100644 --- a/backend/src/plugins/Utility/commands/AvatarCmd.ts +++ b/backend/src/plugins/Utility/commands/AvatarCmd.ts @@ -14,7 +14,7 @@ export const AvatarCmd = utilityCmd({ }, async run({ message: msg, args, pluginData }) { - const user = args.user || msg.member || msg.author; + const user = args.user ?? msg.member ?? msg.author; if (!(user instanceof UnknownUser)) { const embed: APIEmbed = { image: { diff --git a/backend/src/plugins/Utility/commands/LevelCmd.ts b/backend/src/plugins/Utility/commands/LevelCmd.ts index df4d9325..5830f66a 100644 --- a/backend/src/plugins/Utility/commands/LevelCmd.ts +++ b/backend/src/plugins/Utility/commands/LevelCmd.ts @@ -18,6 +18,6 @@ export const LevelCmd = utilityCmd({ run({ message, args, pluginData }) { const member = args.member || message.member; const level = getMemberLevel(pluginData, member); - message.channel.send(`The permission level of ${renderUsername(member.user)} is **${level}**`); + message.channel.send(`The permission level of ${renderUsername(member)} is **${level}**`); }, }); diff --git a/backend/src/plugins/Utility/commands/VcdisconnectCmd.ts b/backend/src/plugins/Utility/commands/VcdisconnectCmd.ts index 240c763f..b6863599 100644 --- a/backend/src/plugins/Utility/commands/VcdisconnectCmd.ts +++ b/backend/src/plugins/Utility/commands/VcdisconnectCmd.ts @@ -43,7 +43,7 @@ export const VcdisconnectCmd = utilityCmd({ sendSuccessMessage( pluginData, msg.channel, - `**${renderUsername(args.member.user)}** disconnected from **${channel.name}**`, + `**${renderUsername(args.member)}** disconnected from **${channel.name}**`, ); }, }); diff --git a/backend/src/plugins/Utility/commands/VcmoveCmd.ts b/backend/src/plugins/Utility/commands/VcmoveCmd.ts index 6ffe8588..259c60b5 100644 --- a/backend/src/plugins/Utility/commands/VcmoveCmd.ts +++ b/backend/src/plugins/Utility/commands/VcmoveCmd.ts @@ -80,7 +80,7 @@ export const VcmoveCmd = utilityCmd({ newChannel: channel, }); - sendSuccessMessage(pluginData, msg.channel, `**${renderUsername(args.member.user)}** moved to **${channel.name}**`); + sendSuccessMessage(pluginData, msg.channel, `**${renderUsername(args.member)}** moved to **${channel.name}**`); }, }); @@ -153,7 +153,7 @@ export const VcmoveAllCmd = utilityCmd({ sendErrorMessage( pluginData, msg.channel, - `Failed to move ${renderUsername(currMember.user)} (${currMember.id}): You cannot act on this member`, + `Failed to move ${renderUsername(currMember)} (${currMember.id}): You cannot act on this member`, ); errAmt++; continue; @@ -168,11 +168,7 @@ export const VcmoveAllCmd = utilityCmd({ sendErrorMessage(pluginData, msg.channel, "Unknown error when trying to move members"); return; } - sendErrorMessage( - pluginData, - msg.channel, - `Failed to move ${renderUsername(currMember.user)} (${currMember.id})`, - ); + sendErrorMessage(pluginData, msg.channel, `Failed to move ${renderUsername(currMember)} (${currMember.id})`); errAmt++; continue; } diff --git a/backend/src/plugins/Utility/functions/getUserInfoEmbed.ts b/backend/src/plugins/Utility/functions/getUserInfoEmbed.ts index d8ccc833..88e4aba0 100644 --- a/backend/src/plugins/Utility/functions/getUserInfoEmbed.ts +++ b/backend/src/plugins/Utility/functions/getUserInfoEmbed.ts @@ -43,7 +43,7 @@ export async function getUserInfoEmbed( name: `${user.bot ? "Bot" : "User"}: ${renderUsername(user)}`, }; - const avatarURL = (member || user).displayAvatarURL(); + const avatarURL = (member ?? user).displayAvatarURL(); embed.author.icon_url = avatarURL; if (compact) { diff --git a/backend/src/plugins/Utility/search.ts b/backend/src/plugins/Utility/search.ts index 632a85a7..76c5af9c 100644 --- a/backend/src/plugins/Utility/search.ts +++ b/backend/src/plugins/Utility/search.ts @@ -381,7 +381,7 @@ async function performMemberSearch( return true; } - const fullUsername = renderUsername(member.user); + const fullUsername = renderUsername(member); if (await execRegExp(queryRegex, fullUsername).catch(allowTimeout)) return true; return false; @@ -492,7 +492,7 @@ function formatSearchResultList(members: Array): string { const paddedId = member.id.padEnd(longestId, " "); let line; if (member instanceof GuildMember) { - line = `${paddedId} ${renderUsername(member.user)}`; + line = `${paddedId} ${renderUsername(member)}`; if (member.nickname) line += ` (${member.nickname})`; } else { line = `${paddedId} ${renderUsername(member)}`;