Skip to content
This repository was archived by the owner on Oct 9, 2025. It is now read-only.
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
35 changes: 9 additions & 26 deletions src/commands/context-menu/blacklist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { t } from '../../utils/Locale.js';
import { colors, emojis } from '../../utils/Constants.js';
import { CustomID } from '../../utils/CustomID.js';
import { RegisterInteractionHandler } from '../../decorators/Interaction.js';
import { checkIfStaff, simpleEmbed } from '../../utils/Utils.js';
import { checkIfStaff, getUserLocale, simpleEmbed } from '../../utils/Utils.js';
import { stripIndents } from 'common-tags';
import { logBlacklist } from '../../utils/HubLogger/ModLogs.js';
import { deleteConnections } from '../../utils/ConnectedList.js';
Expand All @@ -34,7 +34,7 @@ export default class Blacklist extends BaseCommand {
};

async execute(interaction: MessageContextMenuCommandInteraction) {
const { locale } = interaction.user;
const locale = await getUserLocale(interaction.user.id);

const messageInDb = await db.broadcastedMessages.findFirst({
where: { messageId: interaction.targetId },
Expand Down Expand Up @@ -108,17 +108,11 @@ export default class Blacklist extends BaseCommand {
@RegisterInteractionHandler('blacklist')
static override async handleComponents(interaction: MessageComponentInteraction): Promise<void> {
const customId = CustomID.parseCustomId(interaction.customId);
const locale = await getUserLocale(interaction.user.id);

if (interaction.user.id !== customId.args[0]) {
await interaction.reply({
embeds: [
simpleEmbed(
t(
{ phrase: 'errors.notYourAction', locale: interaction.user.locale },
{ emoji: emojis.no },
),
),
],
embeds: [simpleEmbed(t({ phrase: 'errors.notYourAction', locale }, { emoji: emojis.no }))],
ephemeral: true,
});
return;
Expand All @@ -137,27 +131,16 @@ export default class Blacklist extends BaseCommand {
new ActionRowBuilder<TextInputBuilder>().addComponents(
new TextInputBuilder()
.setCustomId('reason')
.setLabel(
t({ phrase: 'blacklist.modal.reason.label', locale: interaction.user.locale }),
)
.setPlaceholder(
t({ phrase: 'blacklist.modal.reason.placeholder', locale: interaction.user.locale }),
)
.setLabel(t({ phrase: 'blacklist.modal.reason.label', locale }))
.setPlaceholder(t({ phrase: 'blacklist.modal.reason.placeholder', locale }))
.setStyle(TextInputStyle.Paragraph)
.setMaxLength(500),
),
new ActionRowBuilder<TextInputBuilder>().addComponents(
new TextInputBuilder()
.setCustomId('duration')
.setLabel(
t({ phrase: 'blacklist.modal.duration.label', locale: interaction.user.locale }),
)
.setPlaceholder(
t({
phrase: 'blacklist.modal.duration.placeholder',
locale: interaction.user.locale,
}),
)
.setLabel(t({ phrase: 'blacklist.modal.duration.label', locale }))
.setPlaceholder(t({ phrase: 'blacklist.modal.duration.placeholder', locale }))
.setStyle(TextInputStyle.Short)
.setMinLength(2)
.setRequired(false),
Expand All @@ -171,7 +154,7 @@ export default class Blacklist extends BaseCommand {
async handleModals(interaction: ModalSubmitInteraction): Promise<void> {
await interaction.deferUpdate();

const { locale } = interaction.user;
const locale = await getUserLocale(interaction.user.id);
const customId = CustomID.parseCustomId(interaction.customId);
const [messageId] = customId.args;
const originalMsg = await db.originalMessages.findFirst({ where: { messageId } });
Expand Down
24 changes: 5 additions & 19 deletions src/commands/context-menu/deleteMsg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from 'discord.js';
import db from '../../utils/Db.js';
import BaseCommand from '../../core/BaseCommand.js';
import { checkIfStaff } from '../../utils/Utils.js';
import { checkIfStaff, getUserLocale } from '../../utils/Utils.js';
import { REGEX, emojis } from '../../utils/Constants.js';
import { t } from '../../utils/Locale.js';
import { logMsgDelete } from '../../utils/HubLogger/ModLogs.js';
Expand Down Expand Up @@ -41,15 +41,10 @@ export default class DeleteMessage extends BaseCommand {
originalMsg = broadcastedMsg?.originalMsg ?? null;
}

const locale = await getUserLocale(interaction.user.id);
if (!originalMsg?.hub) {
await interaction.editReply(
t(
{
phrase: 'errors.unknownNetworkMessage',
locale: interaction.user.locale,
},
{ emoji: emojis.no },
),
t({ phrase: 'errors.unknownNetworkMessage', locale }, { emoji: emojis.no }),
);
return;
}
Expand All @@ -64,13 +59,7 @@ export default class DeleteMessage extends BaseCommand {

if (!isStaffOrHubMod && interaction.user.id !== originalMsg.authorId) {
await interaction.editReply(
t(
{
phrase: 'errors.notMessageAuthor',
locale: interaction.user.locale,
},
{ emoji: emojis.no },
),
t({ phrase: 'errors.notMessageAuthor', locale }, { emoji: emojis.no }),
);
return;
}
Expand Down Expand Up @@ -105,10 +94,7 @@ export default class DeleteMessage extends BaseCommand {
await interaction
.editReply(
t(
{
phrase: 'network.deleteSuccess',
locale: interaction.user.locale,
},
{ phrase: 'network.deleteSuccess', locale },
{
emoji: emojis.yes,
user: `<@${originalMsg.authorId}>`,
Expand Down
15 changes: 7 additions & 8 deletions src/commands/context-menu/editMsg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
checkIfStaff,
containsInviteLinks,
getAttachmentURL,
getUserLocale,
replaceLinks,
userVotedToday,
} from '../../utils/Utils.js';
Expand All @@ -41,7 +42,7 @@ export default class EditMessage extends BaseCommand {
if (isOnCooldown) return;

const target = interaction.targetMessage;
const { locale } = interaction.user;
const locale = await getUserLocale(interaction.user.id);

if (!checkIfStaff(interaction.user.id) && !(await userVotedToday(interaction.user.id))) {
await interaction.reply({
Expand Down Expand Up @@ -107,11 +108,12 @@ export default class EditMessage extends BaseCommand {

const customId = CustomID.parseCustomId(interaction.customId);
const [messageId] = customId.args;
const locale = await getUserLocale(interaction.user.id);

const target = await interaction.channel?.messages.fetch(messageId).catch(() => null);
if (!target) {
await interaction.editReply(
t({ phrase: 'errors.unknownNetworkMessage' }, { emoji: emojis.no }),
t({ phrase: 'errors.unknownNetworkMessage', locale }, { emoji: emojis.no }),
);
return;
}
Expand All @@ -132,10 +134,7 @@ export default class EditMessage extends BaseCommand {

if (!originalMsg?.hub) {
await interaction.editReply(
t(
{ phrase: 'errors.unknownNetworkMessage', locale: interaction.user.locale },
{ emoji: emojis.no },
),
t({ phrase: 'errors.unknownNetworkMessage', locale }, { emoji: emojis.no }),
);
return;
}
Expand All @@ -149,7 +148,7 @@ export default class EditMessage extends BaseCommand {

if (hubSettings.has('BlockInvites') && containsInviteLinks(newMessage)) {
await interaction.editReply(
t({ phrase: 'errors.inviteLinks', locale: interaction.user.locale }, { emoji: emojis.no }),
t({ phrase: 'errors.inviteLinks', locale }, { emoji: emojis.no }),
);
return;
}
Expand Down Expand Up @@ -191,7 +190,7 @@ export default class EditMessage extends BaseCommand {
const edited = resultsArray.reduce((acc, cur) => acc + (cur ? 1 : 0), 0).toString();
await interaction.editReply(
t(
{ phrase: 'network.editSuccess', locale: interaction.user.locale },
{ phrase: 'network.editSuccess', locale },
{
edited,
total: resultsArray.length.toString(),
Expand Down
61 changes: 18 additions & 43 deletions src/commands/context-menu/messageInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { REGEX, colors, emojis } from '../../utils/Constants.js';
import { CustomID } from '../../utils/CustomID.js';
import { RegisterInteractionHandler } from '../../decorators/Interaction.js';
import { supportedLocaleCodes, t } from '../../utils/Locale.js';
import { simpleEmbed } from '../../utils/Utils.js';
import { getUserLocale, simpleEmbed } from '../../utils/Utils.js';
import { sendHubReport } from '../../utils/HubLogger/Report.js';
import { getAllConnections } from '../../utils/ConnectedList.js';

Expand All @@ -38,6 +38,7 @@ export default class MessageInfo extends BaseCommand {
await interaction.deferReply({ ephemeral: true });

const target = interaction.targetMessage;
const locale = await getUserLocale(interaction.user.id);
const originalMsg = (
await db.broadcastedMessages.findFirst({
where: { messageId: target.id },
Expand All @@ -47,10 +48,7 @@ export default class MessageInfo extends BaseCommand {

if (!originalMsg) {
await interaction.followUp({
content: t(
{ phrase: 'errors.unknownNetworkMessage', locale: interaction.user.locale },
{ emoji: emojis.no },
),
content: t({ phrase: 'errors.unknownNetworkMessage', locale }, { emoji: emojis.no }),
ephemeral: true,
});
return;
Expand All @@ -61,7 +59,7 @@ export default class MessageInfo extends BaseCommand {
const embed = new EmbedBuilder()
.setDescription(
t(
{ phrase: 'msgInfo.message.description', locale: interaction.user.locale },
{ phrase: 'msgInfo.message.description', locale },
{
emoji: emojis.clipart,
author: author.discriminator !== '0' ? author.tag : author.username,
Expand All @@ -75,7 +73,7 @@ export default class MessageInfo extends BaseCommand {
.setThumbnail(`https://cdn.discordapp.com/icons/${server?.id}/${server?.icon}.png`)
.setColor('Random');

const components = MessageInfo.buildButtons(target.id, interaction.user.locale);
const components = MessageInfo.buildButtons(target.id, locale);

const guildConnected = (await getAllConnections())?.find(
(c) => c.serverId === originalMsg.serverId && c.hubId === originalMsg.hub?.id,
Expand Down Expand Up @@ -111,12 +109,11 @@ export default class MessageInfo extends BaseCommand {
})
)?.originalMsg;

const locale = await getUserLocale(interaction.user.id);

if (!originalMsg) {
await interaction.update({
content: t(
{ phrase: 'errors.unknownNetworkMessage', locale: interaction.user.locale },
{ emoji: emojis.no },
),
content: t({ phrase: 'errors.unknownNetworkMessage', locale }, { emoji: emojis.no }),
embeds: [],
components: [],
});
Expand Down Expand Up @@ -149,10 +146,7 @@ export default class MessageInfo extends BaseCommand {
case 'serverInfo': {
if (!server) {
await interaction.update({
content: t(
{ phrase: 'errors.unknownServer', locale: interaction.user.locale },
{ emoji: emojis.no },
),
content: t({ phrase: 'errors.unknownServer', locale }, { emoji: emojis.no }),
embeds: [],
components: [],
});
Expand All @@ -176,12 +170,10 @@ export default class MessageInfo extends BaseCommand {
.setImage(bannerUrL)
.setDescription(
t(
{ phrase: 'msgInfo.server.description', locale: interaction.user.locale },
{ phrase: 'msgInfo.server.description', locale },
{
server: server.name,
description:
server.description ||
t({ phrase: 'misc.noDesc', locale: interaction.user.locale }),
description: server.description || t({ phrase: 'misc.noDesc', locale }),
owner: `${owner.username}#${
owner.discriminator !== '0' ? `#${owner.discriminator}` : ''
}`,
Expand Down Expand Up @@ -212,7 +204,7 @@ export default class MessageInfo extends BaseCommand {
.setImage(author.bannerURL() ?? null)
.setDescription(
t(
{ phrase: 'msgInfo.user.description', locale: interaction.user.locale },
{ phrase: 'msgInfo.user.description', locale },
{
username: author.discriminator !== '0' ? author.tag : author.username,
id: author.id,
Expand Down Expand Up @@ -242,10 +234,7 @@ export default class MessageInfo extends BaseCommand {

if (!message) {
await interaction.update({
content: t(
{ phrase: 'errors.unknownNetworkMessage', locale: interaction.user.locale },
{ emoji: emojis.no },
),
content: t({ phrase: 'errors.unknownNetworkMessage', locale }, { emoji: emojis.no }),
embeds: [],
components: [],
});
Expand All @@ -255,7 +244,7 @@ export default class MessageInfo extends BaseCommand {
const embed = new EmbedBuilder()
.setDescription(
t(
{ phrase: 'msgInfo.message.description', locale: interaction.user.locale },
{ phrase: 'msgInfo.message.description', locale },
{
emoji: emojis.clipart,
author: author.discriminator !== '0' ? author.tag : author.username,
Expand Down Expand Up @@ -284,10 +273,7 @@ export default class MessageInfo extends BaseCommand {
await interaction.reply({
embeds: [
simpleEmbed(
t(
{ phrase: 'msgInfo.report.notEnabled', locale: interaction.user.locale },
{ emoji: emojis.no },
),
t({ phrase: 'msgInfo.report.notEnabled', locale }, { emoji: emojis.no }),
),
],
ephemeral: true,
Expand Down Expand Up @@ -327,16 +313,12 @@ export default class MessageInfo extends BaseCommand {
where: { messageId },
include: { originalMsg: { include: { hub: true } } },
});
const locale = await getUserLocale(interaction.user.id);

if (!messageInDb?.originalMsg.hub?.logChannels?.reports) {
await interaction.reply({
embeds: [
simpleEmbed(
t(
{ phrase: 'msgInfo.report.notEnabled', locale: interaction.user.locale },
{ emoji: emojis.no },
),
),
simpleEmbed(t({ phrase: 'msgInfo.report.notEnabled', locale }, { emoji: emojis.no })),
],
ephemeral: true,
});
Expand Down Expand Up @@ -364,14 +346,7 @@ export default class MessageInfo extends BaseCommand {
});

await interaction.reply({
embeds: [
simpleEmbed(
t(
{ phrase: 'msgInfo.report.success', locale: interaction.user.locale },
{ emoji: emojis.yes },
),
),
],
embeds: [simpleEmbed(t({ phrase: 'msgInfo.report.success', locale }, { emoji: emojis.yes }))],
ephemeral: true,
});
}
Expand Down
Loading