Skip to content

Commit

Permalink
refactor: use member nickname for the person asking
Browse files Browse the repository at this point in the history
  • Loading branch information
didinele committed Oct 21, 2023
1 parent 2b4844b commit 7544831
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/bot/src/commands/ask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export default class implements Command<ApplicationCommandType.ChatInput> {
content,
imageUrl,
user: modalInteraction.user,
member: modalInteraction.member,
};

// eslint-disable-next-line unicorn/consistent-function-scoping
Expand Down
4 changes: 3 additions & 1 deletion packages/bot/src/components/guest-approve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ export default class implements Component<ButtonInteraction<'cached'>> {
});
}

const user = await this.client.users.fetch(question.authorId).catch(() => null);
const member = await interaction.guild.members.fetch(question.authorId).catch(() => null);
const user = member?.user ?? (await this.client.users.fetch(question.authorId).catch(() => null));
const result = await this.amaManager.postToAnswersChannel({
content: question.content,
imageUrl: question.imageUrl,
user,
member,
question,
answersChannel: question.ama.answersChannel,
stage: mode === 'stage',
Expand Down
4 changes: 3 additions & 1 deletion packages/bot/src/components/mod-approve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export default class implements Component<ButtonInteraction<'cached'>> {
});
}

const user = await this.client.users.fetch(question.authorId).catch(() => null);
const member = await interaction.guild.members.fetch(question.authorId).catch(() => null);
const user = member?.user ?? (await this.client.users.fetch(question.authorId).catch(() => null));

if (question.ama.guestQueue) {
const result = await this.amaManager.postToGuestQueue({
Expand All @@ -57,6 +58,7 @@ export default class implements Component<ButtonInteraction<'cached'>> {
question,
answersChannel: question.ama.answersChannel,
stage: false,
member,
});

if (result.isErr()) {
Expand Down
3 changes: 2 additions & 1 deletion packages/bot/src/components/mod-flag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export default class implements Component<ButtonInteraction<'cached'>> {
});
}

const user = await this.client.users.fetch(question.authorId).catch(() => null);
const member = await interaction.guild.members.fetch(interaction.user.id).catch(() => null);
const user = member?.user ?? (await this.client.users.fetch(question.authorId).catch(() => null));
const result = await this.amaManager.postToFlaggedQueue({
content: question.content,
imageUrl: question.imageUrl,
Expand Down
1 change: 1 addition & 0 deletions packages/bot/src/components/submit-question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export default class implements Component<ButtonInteraction<'cached'>> {
content,
imageUrl,
user: modalInteraction.user,
member: modalInteraction.member,
};

// eslint-disable-next-line unicorn/consistent-function-scoping
Expand Down
7 changes: 4 additions & 3 deletions packages/bot/src/struct/AmaManager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { AmaQuestion } from '@prisma/client';
import { Result } from '@sapphire/result';
import type { Message, MessageActionRowComponentBuilder, TextChannel, User } from 'discord.js';
import type { GuildMember, Message, MessageActionRowComponentBuilder, TextChannel, User } from 'discord.js';
import { ActionRowBuilder, ButtonBuilder, EmbedBuilder, ButtonStyle, Client } from 'discord.js';
import { singleton } from 'tsyringe';
import { Colors } from '../util/colors.js';
Expand All @@ -9,6 +9,7 @@ export interface EmbedData {
content: string;
displayId?: boolean;
imageUrl?: string | null;
member?: GuildMember | null;
user?: User | null;
}

Expand Down Expand Up @@ -41,8 +42,8 @@ export interface PostToAnswerChannelData extends PostData {
export class AmaManager {
public constructor(private readonly client: Client) {}

private getBaseEmbed({ content, imageUrl, user, displayId = true }: EmbedData): EmbedBuilder {
const baseName = `${user?.tag ?? 'Unknown User'}`;
private getBaseEmbed({ content, imageUrl, user, member, displayId = true }: EmbedData): EmbedBuilder {
const baseName = (displayId ? user?.tag : member?.nickname ?? user?.tag) ?? 'Unknown User';
const name = displayId ? `${baseName} (${user?.id ?? 'Unknown - likely deleted user'})` : baseName;

return new EmbedBuilder()
Expand Down

0 comments on commit 7544831

Please sign in to comment.