Skip to content

Commit e8cada1

Browse files
committed
Display user names the same everywhere
1 parent 4addb81 commit e8cada1

22 files changed

+84
-37
lines changed

src/MojiraBot.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ export default class MojiraBot {
9191

9292
this.botUser = this.client.user;
9393
this.running = true;
94-
this.logger.info( `MojiraBot has been started successfully. Logged in as ${ this.botUser.tag }` );
94+
this.logger.info(
95+
`MojiraBot has been started successfully. Logged in as ${ DiscordUtil.getUserHandle( this.botUser ) }`
96+
);
9597

9698
// Register events.
9799
EventRegistry.setClient( this.client );

src/commands/BugCommand.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { MentionRegistry } from '../mentions/MentionRegistry.js';
44
import BotConfig from '../BotConfig.js';
55
import { ChannelConfigUtil } from '../util/ChannelConfigUtil.js';
66
import SlashCommand from './commandHandlers/SlashCommand.js';
7+
import DiscordUtil from '../util/DiscordUtil.js';
78

89
export default class BugCommand extends SlashCommand {
910
public slashCommandBuilder = this.slashCommandBuilder
@@ -55,7 +56,7 @@ export default class BugCommand extends SlashCommand {
5556

5657
if ( embed === undefined ) return false;
5758

58-
embed.setFooter( { text: interaction.user.tag, iconURL: interaction.user.avatarURL() ?? undefined } )
59+
embed.setFooter( DiscordUtil.getUserFooter( interaction.user ) )
5960
.setTimestamp( interaction.createdAt );
6061

6162
try {

src/commands/HelpCommand.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ChatInputCommandInteraction, EmbedBuilder } from 'discord.js';
22
import BotConfig from '../BotConfig.js';
33
import SlashCommand from './commandHandlers/SlashCommand.js';
4+
import DiscordUtil from '../util/DiscordUtil.js';
45

56
export default class HelpCommand extends SlashCommand {
67
public readonly slashCommandBuilder = this.slashCommandBuilder
@@ -30,7 +31,7 @@ export default class HelpCommand extends SlashCommand {
3031
3132
\`/tips\` - Sends helpful info on how to use the bug tracker and this Discord server.`,
3233
} )
33-
.setFooter( { text: interaction.user.tag, iconURL: interaction.user.avatarURL() ?? undefined } );
34+
.setFooter( DiscordUtil.getUserFooter( interaction.user ) );
3435
await interaction.reply( { embeds: [embed], ephemeral: true } );
3536
} catch {
3637
return false;

src/commands/MentionCommand.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,8 @@ export default class MentionCommand extends Command {
7171
}
7272

7373
if ( embed === undefined ) return false;
74-
let messageAuthorNormalizedTag: string;
75-
if ( message.author.discriminator === '0' ) {
76-
messageAuthorNormalizedTag = message.author.username;
77-
} else {
78-
messageAuthorNormalizedTag = message.author.tag;
79-
}
80-
embed.setFooter( { text: messageAuthorNormalizedTag, iconURL: message.author.avatarURL() ?? undefined } )
74+
75+
embed.setFooter( DiscordUtil.getUserFooter( message.author ) )
8176
.setTimestamp( message.createdAt );
8277

8378
try {

src/commands/MooCommand.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { ChatInputCommandInteraction, Message } from 'discord.js';
22
import { SingleMention } from '../mentions/SingleMention.js';
33
import { ReactionsUtil } from '../util/ReactionsUtil.js';
44
import SlashCommand from './commandHandlers/SlashCommand.js';
5+
import DiscordUtil from '../util/DiscordUtil.js';
56

67
export default class MooCommand extends SlashCommand {
78
public readonly slashCommandBuilder = this.slashCommandBuilder
@@ -13,7 +14,7 @@ export default class MooCommand extends SlashCommand {
1314
if ( interaction.channel === null ) return false;
1415
const mention = new SingleMention( 'MC-772', interaction.channel );
1516
const embed = await mention.getEmbed();
16-
embed.setFooter( { text: interaction.user.tag, iconURL: interaction.user.avatarURL() ?? undefined } );
17+
embed.setFooter( DiscordUtil.getUserFooter( interaction.user ) );
1718
const message = await interaction.reply( { embeds: [embed], fetchReply: true } );
1819
if ( message instanceof Message ) {
1920
await ReactionsUtil.reactToMessage( message, ['🐮', '🐄', '🥛'] );

src/commands/PollCommand.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import emojiRegex from 'emoji-regex';
44
import PermissionRegistry from '../permissions/PermissionRegistry.js';
55
import { ReactionsUtil } from '../util/ReactionsUtil.js';
66
import SlashCommand from './commandHandlers/SlashCommand.js';
7+
import DiscordUtil from '../util/DiscordUtil.js';
78

89
interface PollOption {
910
emoji: string;
@@ -53,7 +54,7 @@ export default class PollCommand extends SlashCommand {
5354
private async sendPollMessage( interaction: ChatInputCommandInteraction, title: string, options: PollOption[] ): Promise<void> {
5455
const embed = new EmbedBuilder();
5556
embed.setTitle( 'Poll' )
56-
.setFooter( { text: interaction.user.tag, iconURL: interaction.user.avatarURL() ?? undefined } )
57+
.setFooter( DiscordUtil.getUserFooter( interaction.user ) )
5758
.setTimestamp( interaction.createdAt )
5859
.setColor( 'Green' );
5960

src/commands/SearchCommand.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import SlashCommand from './commandHandlers/SlashCommand.js';
33
import BotConfig from '../BotConfig.js';
44
import MojiraBot from '../MojiraBot.js';
55
import { ChannelConfigUtil } from '../util/ChannelConfigUtil.js';
6+
import DiscordUtil from '../util/DiscordUtil.js';
67

78
export default class SearchCommand extends SlashCommand {
89
public readonly slashCommandBuilder = this.slashCommandBuilder
@@ -35,7 +36,7 @@ export default class SearchCommand extends SlashCommand {
3536
}
3637

3738
embed.setTitle( '**Results:**' );
38-
embed.setFooter( { text: interaction.user.tag, iconURL: interaction.user.avatarURL() ?? undefined } );
39+
embed.setFooter( DiscordUtil.getUserFooter( interaction.user ) );
3940

4041
for ( const issue of searchResults.issues ) {
4142
embed.addFields( {

src/commands/TipsCommand.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ChatInputCommandInteraction, EmbedBuilder } from 'discord.js';
22
import SlashCommand from './commandHandlers/SlashCommand.js';
3+
import DiscordUtil from '../util/DiscordUtil.js';
34

45
export default class TipsCommand extends SlashCommand {
56
public readonly slashCommandBuilder = this.slashCommandBuilder
@@ -17,7 +18,7 @@ export default class TipsCommand extends SlashCommand {
1718
Start by choosing which bug tracker projects you would like to be a part of in <#648479533246316555>.
1819
Afterwards, you can use corresponding request channels in each project to make requests for changes to tickets on the bug tracker, like resolutions and adding affected versions.
1920
The moderators and helpers of the bug tracker will then be able to see the requests and resolve them.`.replace( /\t/g, '' ) )
20-
.setFooter( { text: interaction.user.tag, iconURL: interaction.user.avatarURL() ?? undefined } );
21+
.setFooter( DiscordUtil.getUserFooter( interaction.user ) );
2122
await interaction.reply( { embeds: [embed], ephemeral: true } );
2223
} catch {
2324
return false;

src/commands/commandHandlers/CommandExecutor.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Command from './Command.js';
22
import { Message } from 'discord.js';
33
import DefaultCommandRegistry from './DefaultCommandRegistry.js';
4+
import DiscordUtil from '../../util/DiscordUtil.js';
45

56
export default class CommandExecutor {
67
public static async checkCommands( message: Message ): Promise<boolean> {
@@ -14,7 +15,9 @@ export default class CommandExecutor {
1415

1516
const args = commandTestResult === true ? '' : commandTestResult;
1617

17-
Command.logger.info( `User ${ message.author.tag } ran command ${ command.asString( args ) }` );
18+
Command.logger.info(
19+
`User ${ DiscordUtil.getUserHandle( message.author ) } ran command ${ command.asString( args ) }`
20+
);
1821
return await command.run( message, args );
1922
}
2023
}

src/commands/commandHandlers/SlashCommandRegister.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Routes } from 'discord-api-types/v9';
55
import { Client, Collection, RESTPostAPIApplicationCommandsJSONBody, ChatInputCommandInteraction, GuildMember } from 'discord.js';
66
import { SlashCommandJsonData } from '../../types/discord.js';
77
import { ChannelConfigUtil } from '../../util/ChannelConfigUtil.js';
8+
import DiscordUtil from '../../util/DiscordUtil.js';
89

910
export default class SlashCommandRegister {
1011
public static async registerCommands( client: Client, token: string ) {
@@ -23,7 +24,9 @@ export default class SlashCommandRegister {
2324
const jsonData: SlashCommandJsonData = {
2425
data: command.slashCommandBuilder,
2526
async execute( interaction: ChatInputCommandInteraction ) {
26-
SlashCommand.logger.info( `User ${ interaction.user.tag } ran command ${ command.asString( interaction ) }` );
27+
SlashCommand.logger.info(
28+
`User ${ DiscordUtil.getUserHandle( interaction.user ) } ran command ${ command.asString( interaction ) }`
29+
);
2730

2831
const member = interaction.member instanceof GuildMember ? interaction.member : await fetchedGuild.members.fetch( interaction.user );
2932

0 commit comments

Comments
 (0)