Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(message-info): improve message info command #145

Merged
merged 2 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@
"eslint.validate": ["javascript", "typescript"],
"eslint.useFlatConfig": true,
"typescript.tsdk": "node_modules/typescript/lib",
"typescript.preferences.importModuleSpecifier": "non-relative"
"typescript.preferences.importModuleSpecifier": "non-relative",
"sonarlint.connectedMode.project": {
"connectionId": "discord-interchat",
"projectKey": "Discord-InterChat_InterChat"
}
}
24 changes: 14 additions & 10 deletions src/commands/context-menu/messageInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ export default class MessageInfo extends BaseCommand {
const connection = (await getHubConnections(originalMsg.hub.id))?.find(
(c) => c.connected && c.serverId === originalMsg.serverId,
);
const expiry = new Date(Date.now() + 5 * 60 * 1000); // 5 minutes
const components = this.buildButtons(expiry, locale, {
const components = this.buildButtons(locale, {
buildModActions: isStaffOrHubMod(interaction.user.id, originalMsg.hub),
inviteButtonUrl: connection?.invite,
});
Expand Down Expand Up @@ -258,7 +257,7 @@ export default class MessageInfo extends BaseCommand {
await interaction.deferUpdate();
const createdAt = Math.round(author.createdTimestamp / 1000);
const hubsOwned = await db.hub.count({ where: { ownerId: author.id } });
const displayName = author.globalName || 'Not Set.';
const displayName = author.globalName ?? 'Not Set.';

const userEmbed = new EmbedBuilder()
.setDescription(`### ${emojis.info} ${author.username}`)
Expand Down Expand Up @@ -320,7 +319,13 @@ export default class MessageInfo extends BaseCommand {
{ originalMsg }: ModActionsOpts,
) {
if (!isValidDbMsgWithHubId(originalMsg)) return;
if (!originalMsg.hub || isStaffOrHubMod(interaction.user.id, originalMsg.hub)) return;
if (!originalMsg.hub || !isStaffOrHubMod(interaction.user.id, originalMsg.hub)) {
await interaction.reply({
content: t({ phrase: 'hub.notFound_mod', locale: 'en' }, { emoji: emojis.no }),
ephemeral: true,
});
return;
}

const { buttons, embed } = await modActionsPanel.buildMessage(interaction, originalMsg);
await interaction.reply({ embeds: [embed], components: buttons, ephemeral: true });
Expand Down Expand Up @@ -387,7 +392,6 @@ export default class MessageInfo extends BaseCommand {
}

private buildButtons(
expiry: Date,
locale: supportedLocaleCodes = 'en',
opts?: { buildModActions?: boolean; inviteButtonUrl?: string | null },
) {
Expand All @@ -396,7 +400,7 @@ export default class MessageInfo extends BaseCommand {
.setLabel(t({ phrase: 'msgInfo.buttons.report', locale }))
.setStyle(ButtonStyle.Danger)
.setCustomId(
new CustomID().setIdentifier('msgInfo', 'report').setExpiry(expiry).toString(),
new CustomID().setIdentifier('msgInfo', 'report').toString(),
),
];

Expand All @@ -407,7 +411,7 @@ export default class MessageInfo extends BaseCommand {
.setEmoji('🛠️')
.setLabel('Mod Actions')
.setCustomId(
new CustomID().setIdentifier('msgInfo', 'modActions').setExpiry(expiry).toString(),
new CustomID().setIdentifier('msgInfo', 'modActions').toString(),
),
);
}
Expand All @@ -428,19 +432,19 @@ export default class MessageInfo extends BaseCommand {
.setStyle(ButtonStyle.Secondary)
.setDisabled(true)
.setCustomId(
new CustomID().setIdentifier('msgInfo', 'msgInfo').setExpiry(expiry).toString(),
new CustomID().setIdentifier('msgInfo', 'msgInfo').toString(),
),
new ButtonBuilder()
.setLabel(t({ phrase: 'msgInfo.buttons.server', locale }))
.setStyle(ButtonStyle.Secondary)
.setCustomId(
new CustomID().setIdentifier('msgInfo', 'serverInfo').setExpiry(expiry).toString(),
new CustomID().setIdentifier('msgInfo', 'serverInfo').toString(),
),
new ButtonBuilder()
.setLabel(t({ phrase: 'msgInfo.buttons.user', locale }))
.setStyle(ButtonStyle.Secondary)
.setCustomId(
new CustomID().setIdentifier('msgInfo', 'userInfo').setExpiry(expiry).toString(),
new CustomID().setIdentifier('msgInfo', 'userInfo').toString(),
),
),
new ActionRowBuilder<ButtonBuilder>({ components: extras }),
Expand Down
2 changes: 1 addition & 1 deletion src/commands/context-menu/modActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default class Blacklist extends BaseCommand {
dm_permission: false,
};

private modActionHandlers: Record<string, ModAction>;
private readonly modActionHandlers: Record<string, ModAction>;

constructor() {
super();
Expand Down
4 changes: 1 addition & 3 deletions src/core/BaseCommand.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { emojis } from '#main/config/Constants.js';
import { MetadataHandler } from '#main/core/FileLoader.js';
import { InteractionFunction } from '#main/decorators/Interaction.js';
import { TranslationKeys } from '#main/types/locale.js';
import { InfoEmbed } from '#main/utils/EmbedUtils.js';
import { supportedLocaleCodes, t } from '#main/utils/Locale.js';
import Logger from '#main/utils/Logger.js';
Expand Down Expand Up @@ -127,7 +126,7 @@ export default abstract class BaseCommand {

async replyEmbed(
interaction: RepliableInteraction | MessageComponentInteraction,
desc: keyof TranslationKeys | (string & {}),
desc: string,
opts?: {
content?: string;
title?: string;
Expand Down Expand Up @@ -161,7 +160,6 @@ export default abstract class BaseCommand {
opts.commandsMap.set(this.data.name, this);
this.loadCommandInteractions(this, opts.interactionsMap);
}

else {
const parentCommand = Object.getPrototypeOf(this.constructor) as typeof BaseCommand;
parentCommand.subcommands?.set(fileName.replace('.js', ''), this);
Expand Down
4 changes: 2 additions & 2 deletions src/core/FileLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export class MetadataHandler {
}

export class FileLoader {
private baseDir: string;
private recursive: boolean;
private readonly baseDir: string;
private readonly recursive: boolean;

constructor(baseDir: string, opts?: { recursive: boolean }) {
this.baseDir = baseDir;
Expand Down
Loading