diff --git a/src/commands/standard/mention remove.ts b/src/commands/standard/mention remove.ts index a2142b2a..ea039a55 100644 --- a/src/commands/standard/mention remove.ts +++ b/src/commands/standard/mention remove.ts @@ -1,5 +1,6 @@ import { ActionRowBuilder, StringSelectMenuBuilder, StringSelectMenuOptionBuilder } from "discord.js"; import Command from "../../internals/commandProcessor"; +import { getUsername } from "../../internals/utils"; export default class MentionRemove extends Command { async run(): Promise { @@ -22,7 +23,7 @@ export default class MentionRemove extends Command { const user = await this.client.getUser(i).catch(() => null); selectMenu.options.push( new StringSelectMenuOptionBuilder() - .setLabel(`${user?.tag || i}`) + .setLabel(`${user ? getUsername(user) : i}`) .setValue(i) .setDescription(i), ); diff --git a/src/commands/standard/mention toggle.ts b/src/commands/standard/mention toggle.ts index 57557434..ad74359b 100644 --- a/src/commands/standard/mention toggle.ts +++ b/src/commands/standard/mention toggle.ts @@ -3,7 +3,8 @@ import Command from "../../internals/commandProcessor"; export default class MentionToggle extends Command { async run(): Promise { - const indexOfMention = this.number!.mentions.indexOf(this.interaction.user.id); + let indexOfMention = this.number!.mentions.indexOf(this.interaction.user.id); + if (indexOfMention === -1) indexOfMention = this.number!.mentions.indexOf(`<@${this.interaction.user.id}>`); // If they're already being mentioned if (indexOfMention > -1) { diff --git a/src/commands/standard/pay common.ts b/src/commands/standard/pay common.ts index a5ab9c9e..b2d1ca3d 100644 --- a/src/commands/standard/pay common.ts +++ b/src/commands/standard/pay common.ts @@ -4,7 +4,7 @@ import { Accounts } from "@prisma/client"; import { ActionRowBuilder, ButtonBuilder, ButtonStyle, ComponentType, EmbedBuilder, User } from "discord.js"; import { PermissionLevel } from "../../interfaces/commandData"; import Command from "../../internals/commandProcessor"; -import { formatBalance, upperFirst } from "../../internals/utils"; +import { formatBalance, getUsername, upperFirst } from "../../internals/utils"; export default abstract class PayCommonFunctions extends Command { async payUser(toPay: Accounts, user: User): Promise { @@ -42,16 +42,19 @@ export default abstract class PayCommonFunctions extends Command { return; } + const authorTag = this.userDisplayName; + const recipientTag = getUsername(user); + const embed = EmbedBuilder.from({ color: this.config.colors.info, author: { - name: this.interaction.user.tag, + name: authorTag, icon_url: this.interaction.user.displayAvatarURL(), }, ...this.t("confirmEmbedOptions"), ...this.t("embed", { - displayName: `${user.tag} (${user.id})`, + displayName: `${recipientTag} (${user.id})`, preFeeToSend: totalCost, fee: formatBalance(fee), postFeeCost: formatBalance(totalReceived), @@ -154,7 +157,7 @@ export default abstract class PayCommonFunctions extends Command { }); embed.spliceFields(2, 1, { name: this.t("sender"), - value: `${this.interaction.user.tag}`, + value: authorTag, }); // Try to DM the user diff --git a/src/commands/standard/strikes.ts b/src/commands/standard/strikes.ts index 2d66e9fb..0bc62f5a 100644 --- a/src/commands/standard/strikes.ts +++ b/src/commands/standard/strikes.ts @@ -1,6 +1,7 @@ import { EmbedField } from "discord.js"; import { PermissionLevel } from "../../interfaces/commandData"; import Command from "../../internals/commandProcessor"; +import { getUsername } from "../../internals/utils"; export default class Strikes extends Command { async run() { @@ -35,10 +36,10 @@ export default class Strikes extends Command { const fields: EmbedField[] = []; for (const strike of strikes) { - const staff = await this.client.users.fetch(strike.created.by).catch(() => null) || { tag: "Unknown#0000" }; + const staff = await this.client.users.fetch(strike.created.by).catch(() => null); fields.push({ - name: `Strike \`${strike.id}\` by ${staff.tag}`, + name: `Strike \`${strike.id}\` by ${staff ? getUsername(staff) : `Unknown (${strike.created.by})`}`, value: `ā€¢ **Reason**: ${truncate(strike.reason, 800) || "No reason provided"}\nā€¢ **ID**: ${strike.id}`, inline: false, }); diff --git a/src/commands/support/addcredit.ts b/src/commands/support/addcredit.ts index 8792bf1d..83bd35f0 100644 --- a/src/commands/support/addcredit.ts +++ b/src/commands/support/addcredit.ts @@ -65,7 +65,7 @@ export default class AddCredit extends Command { description: `${addedOrRemoved} ${this.config.dtsEmoji} ${Math.abs(amountOfCredits)} ${creditsAdded ? "to" : "from"} <@${userID}> (${userID})`, footer: { icon_url: this.interaction.user.displayAvatarURL(), - text: `${this.interaction.user.tag} (${this.interaction.user.id})`, + text: `${this.userDisplayName} (${this.interaction.user.id})`, }, }).setTimestamp(new Date()); diff --git a/src/commands/support/cinfo.ts b/src/commands/support/cinfo.ts index d9c0e3ab..1da4bb31 100644 --- a/src/commands/support/cinfo.ts +++ b/src/commands/support/cinfo.ts @@ -1,6 +1,7 @@ import { ActiveCalls, ArchivedCalls, Numbers } from "@prisma/client"; import { EmbedBuilder } from "discord.js"; import Command from "../../internals/commandProcessor"; +import { getUsername } from "../../internals/utils"; type activeOrArchivedCallWithNumbers = (ActiveCalls | ArchivedCalls); @@ -71,10 +72,10 @@ export default class CInfo extends Command { value: [ `**Picked up**:`, `- At: ${blockFormat(call.pickedUp?.at.toString() || "N/A")}`, - `- By: ${blockFormat(call.pickedUp ? `${pickedUpUser?.tag} (${pickedUpUser?.id})` : "N/A")}`, + `- By: ${blockFormat(call.pickedUp ? `${pickedUpUser ? getUsername(pickedUpUser) : "Unknown"} (${pickedUpUser?.id})` : "N/A")}`, `**Ended**:`, `- At: ${blockFormat(call.ended?.at.toString() || "N/A")}`, - `- By: ${blockFormat(call.ended ? `${endedUser?.tag} (${endedUser?.id})` : "N/A")}`, + `- By: ${blockFormat(call.ended ? `${endedUser ? getUsername(endedUser) : "Unknown"} (${endedUser?.id})` : "N/A")}`, `**Random**: ${blockFormat(call.randomCall ? "Yes" : "No")}`, // `Transferred by: ${blockFormat(call. ? "Yes" : "No")}`, `**Started**:`, diff --git a/src/commands/support/deassign.ts b/src/commands/support/deassign.ts index c8812236..311ffafd 100644 --- a/src/commands/support/deassign.ts +++ b/src/commands/support/deassign.ts @@ -45,7 +45,7 @@ export default class Deassign extends Command { embeds: [{ color: this.config.colors.success, author: { - name: this.interaction.user.tag, + name: this.userDisplayName, icon_url: this.interaction.user.displayAvatarURL(), }, title: "R.I.P", diff --git a/src/commands/support/ninfo.ts b/src/commands/support/ninfo.ts index 54317db0..154ca0a0 100644 --- a/src/commands/support/ninfo.ts +++ b/src/commands/support/ninfo.ts @@ -83,7 +83,7 @@ export default class NInfo extends Command { numberOwner = await this.client.getUser(guild.ownerId); - guildDescription = `${guild.name}\n\`${guild.id}\`\nWhitelisted: ${number.guild?.whitelisted}`; + guildDescription = `${guild.name}\n\`${guild.id}\`\nWhitelisted: ${number.guild?.whitelisted ? "Yes" : "No"}`; channelDescription = `#${(channel as GuildTextBasedChannel).name}\n\`${channel.id}\``; let footerImage = this.client.user.displayAvatarURL(); diff --git a/src/commands/support/reassign.ts b/src/commands/support/reassign.ts index 4ca81bd8..d5eac789 100644 --- a/src/commands/support/reassign.ts +++ b/src/commands/support/reassign.ts @@ -108,7 +108,7 @@ export default class Deassign extends Command { return; } - const discordChannel = await this.client.getChannel(newChannel); + const discordChannel = await this.client.getChannel(newChannel).catch(() => null); if (!discordChannel) { this.interaction.editReply({ embeds: [this.client.errorEmbed("Couldn't find the new channel.")], diff --git a/src/commands/support/strike remove.ts b/src/commands/support/strike remove.ts index e7bf8404..965a2fda 100644 --- a/src/commands/support/strike remove.ts +++ b/src/commands/support/strike remove.ts @@ -1,5 +1,6 @@ import { Strikes } from "@prisma/client"; import Command from "../../internals/commandProcessor"; +import { getUsername } from "../../internals/utils"; export default class StrikeRemove extends Command { async run(): Promise { @@ -34,7 +35,7 @@ export default class StrikeRemove extends Command { embeds: [{ color: this.config.colors.success, title: "āœ… Strike removed", - description: `Strike removed from **${offender.user?.tag || offender.guild?.name || "Unknown Offender"}** (${strike.offender})`, + description: `Strike removed from **${(offender.user ? getUsername(offender.user) : null) || offender.guild?.name || "Unknown Offender"}** (${strike.offender})`, footer: { text: `They now have ${strikeCount} ${strikeCount > 1 ? "strikes" : "strike"}`, }, diff --git a/src/commands/support/uinfo.ts b/src/commands/support/uinfo.ts index 6d3e1e37..f4a95848 100644 --- a/src/commands/support/uinfo.ts +++ b/src/commands/support/uinfo.ts @@ -1,5 +1,6 @@ import { APIEmbed, User } from "discord.js"; import Command from "../../internals/commandProcessor"; +import { getUsername } from "../../internals/utils"; export default class UInfo extends Command { async run(): Promise { const toFind = this.interaction.options.getString("user", true); @@ -16,7 +17,7 @@ export default class UInfo extends Command { color: this.config.colors.info, author: { icon_url: user.displayAvatarURL(), - name: `${user.tag} (${user.id})`, + name: `${getUsername(user)} (${user.id})`, }, footer: { text: `Use /strikes for more information. Server management permissions indicated by red phone..`, diff --git a/src/events/guildDelete.ts b/src/events/guildDelete.ts index cd6555cb..a6bd6e96 100644 --- a/src/events/guildDelete.ts +++ b/src/events/guildDelete.ts @@ -1,6 +1,10 @@ import { Guild } from "discord.js"; import DTelClient from "../internals/client"; +import { winston } from "../dtel"; export default async(client: DTelClient, guild: Guild): Promise => { + if (!guild.available) { + winston.error(`Guild ${guild.name} (${guild.id}) is unavailable. Ignoring Guild Delete event.`); + } client.log(`šŸ“¤ Left guild \`${guild.name}\` (\`${guild.id}\`). Currently in \`${client.guilds.cache.size}\` servers on Shard ${process.env.SHARDS} and \`${await client.getGuildCount()}\` servers total.`); }; diff --git a/src/internals/callClient.ts b/src/internals/callClient.ts index 607516fb..ecb5f593 100644 --- a/src/internals/callClient.ts +++ b/src/internals/callClient.ts @@ -9,7 +9,7 @@ import config from "../config/config"; import { APIEmbed, APIMessage, ButtonStyle, RESTGetAPIChannelMessageResult } from "discord-api-types/v10"; import dayjs from "dayjs"; import relativeTime from "dayjs/plugin/relativeTime"; -import { parseNumber } from "./utils"; +import { getUsername, parseNumber } from "./utils"; import { NumbersWithGuilds } from "../interfaces/numbersWithGuilds"; import { winston } from "../dtel"; @@ -478,7 +478,7 @@ export default class CallClient implements CallsWithNumbers { async processContent(message: Message, sideToSendTo: ClientCallParticipant): Promise { const userPerms = await this.client.getPerms(message.author.id); - const toSend: MessageCreateOptions = { content: `**${message.author.tag}`, embeds: [] }; + const toSend: MessageCreateOptions = { content: `**${getUsername(message.author)}`, embeds: [] }; const thisSide = this.getThisSideByChannel(message.channelId)!; if (thisSide.vip?.hidden) toSend.content = `**Anonymous#${message.author.id.slice(-4)}`; diff --git a/src/internals/processor.ts b/src/internals/processor.ts index f77a0d1e..837fb2ed 100644 --- a/src/internals/processor.ts +++ b/src/internals/processor.ts @@ -6,7 +6,7 @@ import CommandDataInterface, { CommandType, PermissionLevel } from "../interface import { Numbers, Accounts, Mailbox } from "@prisma/client"; import { db } from "../database/db"; import CallClient from "./callClient"; -import { fetchNumber, formatShardNumber, getOrCreateAccount } from "./utils"; +import { fetchNumber, formatShardNumber, getOrCreateAccount, getUsername } from "./utils"; import { getFixedT, TFunction } from "i18next"; export type ChannelBasedInteraction = CommandInteraction|MessageComponentInteraction|ModalSubmitInteraction; @@ -156,5 +156,9 @@ abstract class Processor { embeds: [this.client.errorEmbed("This command cannot be ran outside of the support server.")], }); } + + get userDisplayName() { + return getUsername(this.interaction.user); + } } export default Processor; diff --git a/src/internals/utils.ts b/src/internals/utils.ts index 4c211ef8..1454c288 100644 --- a/src/internals/utils.ts +++ b/src/internals/utils.ts @@ -4,6 +4,7 @@ import { Accounts, Numbers } from "@prisma/client"; import dayjs from "dayjs"; import { db } from "../database/db"; +import { User } from "discord.js"; export const formatShardNumber = (shardNumber: number): string => shardNumber < 10 ? `0${shardNumber}` : shardNumber.toString(); export const formatBalance = (balance: number): string => { @@ -75,3 +76,8 @@ export const fetchNumber = (input: string): Promise => { export const formatDate = (date: Date) => dayjs(date).format("YYYY-MM-DD"); export const upperFirst = (text: string) => `${text[0].toUpperCase()}${text.slice(1, text.length)}`; + +export const getUsername = (user: User) => { + if (user.discriminator == "0") return `${user.username}`; + return `${user.username}#${user.discriminator}}`; +};