Skip to content

Commit

Permalink
fix: localization for hub logs
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-737 committed Jan 1, 2024
1 parent ef37881 commit 373aeca
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 51 deletions.
2 changes: 1 addition & 1 deletion locales
72 changes: 44 additions & 28 deletions src/commands/slash/Main/hub/manage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
} from 'discord.js';
import { t } from '../../../../utils/Locale.js';
import { CustomID } from '../../../../utils/CustomID.js';
import { stripIndents } from 'common-tags';
import { colors, emojis } from '../../../../utils/Constants.js';
import { Prisma } from '@prisma/client';
import { RegisterInteractionHandler } from '../../../../decorators/Interaction.js';
Expand Down Expand Up @@ -126,7 +125,7 @@ export default class Manage extends Hub {
await interaction.reply({ embeds: [embed], components: [selects], ephemeral: true });
}
else if (customId.suffix === 'logsBtn' || customId.suffix === 'logsBackBtn') {
const embed = genLogInfoEmbed(hubInDb);
const embed = genLogInfoEmbed(hubInDb, locale);

const selects = new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(
new StringSelectMenuBuilder()
Expand All @@ -140,21 +139,21 @@ export default class Manage extends Hub {
.setPlaceholder('Choose a log type to set a channel.')
.addOptions([
{
label: 'Reports',
label: t({ phrase: 'hub.manage.logs.reports.label', locale }),
value: 'reports',
description: 'Log reports sent by users.',
description: t({ phrase: 'hub.manage.logs.reports.description', locale }),
emoji: '📢',
},
{
label: 'Mod Logs',
label: t({ phrase: 'hub.manage.logs.modLogs.label', locale }),
value: 'modLogs',
description: 'Log moderation actions taken by hub moderators.',
description: t({ phrase: 'hub.manage.logs.modLogs.description', locale }),
emoji: '👮',
},
{
label: 'Profanity',
label: t({ phrase: 'hub.manage.logs.profanity.label', locale }),
value: 'profanity',
description: 'Log messages that contain profanity.',
description: t({ phrase: 'hub.manage.logs.profanity.description', locale }),
emoji: '🤬',
},
// {
Expand All @@ -170,9 +169,9 @@ export default class Manage extends Hub {
// emoji: '🗑️',
// },
{
label: 'Joins/Leaves',
label: t({ phrase: 'hub.manage.logs.joinLeave.label', locale }),
value: 'joinLeaves',
description: 'Log when a server joins/leaves the hub.',
description: t({ phrase: 'hub.manage.logs.joinLeave.description', locale }),
emoji: '👋',
},
]),
Expand Down Expand Up @@ -204,7 +203,9 @@ export default class Manage extends Hub {

await interaction.reply({
embeds: [
simpleEmbed(`${emojis.yes} Successfully reset the logs configuration for \`${type}\` logs`),
simpleEmbed(
t({ phrase: 'hub.manage.logs.reset', locale }, { emoji: emojis.yes, type }),
),
],
ephemeral: true,
});
Expand Down Expand Up @@ -401,7 +402,7 @@ export default class Manage extends Hub {
ChannelType.PublicThread,
ChannelType.PrivateThread,
)
.setPlaceholder('#️⃣ Select a channel to send logs to'),
.setPlaceholder(t({ phrase: 'hub.manage.logs.channelSelect', locale })),
);

const roleSelect = new ActionRowBuilder<RoleSelectMenuBuilder>().addComponents(
Expand All @@ -414,7 +415,7 @@ export default class Manage extends Hub {
.addArgs(type)
.toString(),
)
.setPlaceholder('🏓 Select a role to ping when sending logs'),
.setPlaceholder(t({ phrase: 'hub.manage.logs.roleSelect', locale })),
);

const buttons = new ActionRowBuilder<ButtonBuilder>().addComponents(
Expand All @@ -430,7 +431,6 @@ export default class Manage extends Hub {
.toString(),
),
new ButtonBuilder()
.setLabel('Reset Log')
.setEmoji(emojis.delete)
.setStyle(ButtonStyle.Danger)
.setCustomId(
Expand All @@ -445,25 +445,27 @@ export default class Manage extends Hub {

// disable log select menu when trying to change channel
const embed = new EmbedBuilder()
.setTitle(`Config \`${type}\` logs`)
.setTitle(t({ phrase: 'hub.manage.logs.config.title', locale }, { type }))
.setDescription(
stripIndents`
${emojis.arrow} Select a log channel and/or role to be pinged from the dropdown below.
${emojis.arrow} You can also disable logging by using the button below.
`,
t({ phrase: 'hub.manage.logs.config.description', locale }, { arrow: emojis.arrow }),
)
.addFields(
typeof logChannel === 'string'
? [{ name: 'Current Channel', value: logChannel ? `<#${logChannel}>` : 'None' }]
? [
{
name: t({ phrase: 'hub.manage.logs.config.fields.channel', locale }),
value: logChannel ? `<#${logChannel}>` : 'N/A',
},
]
: [
{
name: 'Current Channel',
value: logChannel?.channelId ? `<#${logChannel.channelId}>` : 'None',
name: t({ phrase: 'hub.manage.logs.config.fields.channel', locale }),
value: logChannel?.channelId ? `<#${logChannel.channelId}>` : 'N/A',
inline: true,
},
{
name: 'Current Role Ping',
value: logChannel?.roleId ? `<@&${logChannel.roleId}>` : 'None',
name: t({ phrase: 'hub.manage.logs.config.fields.role', locale }),
value: logChannel?.roleId ? `<@&${logChannel.roleId}>` : 'N/A',
inline: true,
},
],
Expand All @@ -482,7 +484,7 @@ export default class Manage extends Hub {
else if (interaction.isChannelSelectMenu()) {
if (customId.suffix === 'logsChSel') {
const type = customId.args[2] as keyof Prisma.HubLogChannelsCreateInput;
const hubLogsManager = (await new HubLogsManager(hubInDb.id).init());
const hubLogsManager = await new HubLogsManager(hubInDb.id).init();

const channelId = interaction.values[0];
const channel = interaction.channels.first();
Expand All @@ -498,7 +500,10 @@ export default class Manage extends Hub {
await interaction.followUp({
embeds: [
simpleEmbed(
`${emojis.yes} Logs of type \`${type}\` will be sent to ${channel} from now!`,
t(
{ phrase: 'hub.manage.logs.channelSuccess', locale },
{ emoji: emojis.yes, type, channel: `${channel}` },
),
),
],
ephemeral: true,
Expand All @@ -513,18 +518,29 @@ export default class Manage extends Hub {
const type = customId.args[2] as keyof Prisma.HubLogChannelsCreateInput;

if (type === 'reports' && role?.id) {
if (!hubInDb.logChannels?.reports?.channelId) {
await interaction.reply({
embeds: [simpleEmbed(t({ phrase: 'hub.manage.logs.reportChannelFirst', locale }))],
ephemeral: true,
});
return;
}

await (await new HubLogsManager(hubInDb.id).init()).setReportData({ roleId: role.id });
}

// update the old embed with new role value
const embed = interaction.message.embeds[0].toJSON();
if (embed.fields?.at(1)) embed.fields[1].value = `${role || 'None'}`;
await interaction.update({ embeds: [embed] });

await interaction.update({ embeds: [embed] });
await interaction.followUp({
embeds: [
simpleEmbed(
`${emojis.yes} The role ${role} will be pinged next time this log is sent!`,
t(
{ phrase: 'hub.manage.logs.roleSuccess', locale },
{ emoji: emojis.yes, type, role: `${role}` },
),
),
],
ephemeral: true,
Expand Down
6 changes: 3 additions & 3 deletions src/managers/NetworkManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ export default class NetworkManager extends Factory {

if (predictions && nsfwDetector.isUnsafeContent(predictions)) {
const nsfwEmbed = new EmbedBuilder()
.setTitle(t({ phrase: 'nsfw.title', locale }))
.setTitle(t({ phrase: 'network.nsfw.title', locale }))
.setDescription(
t(
{ phrase: 'nsfw.description', locale },
{ phrase: 'network.nsfw.description', locale },
{ predictions: `${Math.round(predictions[0].probability * 100)}%` },
),
)
.setFooter({
text: t({ phrase: 'nsfw.footer', locale }),
text: t({ phrase: 'network.nsfw.footer', locale }),
iconURL: 'https://i.imgur.com/625Zy9W.png',
})
.setColor('Red');
Expand Down
37 changes: 18 additions & 19 deletions src/scripts/hub/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,42 @@ import { EmbedBuilder } from 'discord.js';
import { colors, emojis } from '../../utils/Constants.js';
import { stripIndents } from 'common-tags';
import { channelMention } from '../../utils/Utils.js';
import { t } from '../../utils/Locale.js';

/*
for later:
${emojis.arrow} \`msgEdit:\`
${emojis.divider} Log message when it is edited.
${emojis.dividerEnd} Channel: ${undefined ?? emojis.no}
${emojis.dividerEnd} ${channelStr} ${undefined ?? emojis.no}
${emojis.arrow} \`msgDelete:\`
${emojis.divider} Log message when it is deleted.
${emojis.dividerEnd} Channel: ${undefined ?? emojis.no}
${emojis.dividerEnd} ${channelStr} ${undefined ?? emojis.no}
*/

// FIXME errors

export function genLogInfoEmbed(hubInDb: hubs) {
// NOTE: reports is actually [string, string] | undefined but prisma doesnt support optional arrays
const { reports, modLogs, profanity, joinLeaves } = (hubInDb.logChannels || {}) as Prisma.HubLogChannelsCreateInput;
export function genLogInfoEmbed(hubInDb: hubs, locale = 'en') {
const { reports, modLogs, profanity, joinLeaves } = (hubInDb.logChannels ||
{}) as Prisma.HubLogChannelsCreateInput;
const reportRole = reports?.roleId ? `<@&${reports.roleId}>` : emojis.no;
const channelStr = t({ phrase: 'hub.manage.logs.config.fields.channel', locale });
const roleStr = t({ phrase: 'hub.manage.logs.config.fields.role', locale });

return new EmbedBuilder()
.setTitle('Manage Hub Logs')
.setTitle(t({ phrase: 'hub.manage.logs.title', locale }))
.setDescription(
stripIndents`
Choose a log type from the dropdown below to select a channel.
${emojis.arrow} \`reports:\`
${emojis.divider} Log reports made by users of the hub.
${emojis.divider} Channel: ${channelMention(reports?.channelId)}
${emojis.dividerEnd} Role Mention: ${reportRole}
${emojis.divider} ${t({ phrase: 'hub.manage.logs.reports.description', locale })}
${emojis.divider} ${channelStr} ${channelMention(reports?.channelId)}
${emojis.dividerEnd} ${roleStr}: ${reportRole}
${emojis.arrow} \`modLogs:\`
${emojis.divider} Log moderation actions taken by hub moderators.
${emojis.dividerEnd} Channel: ${channelMention(modLogs)}
${emojis.divider} ${t({ phrase: 'hub.manage.logs.modLogs.description', locale })}
${emojis.dividerEnd} ${channelStr} ${channelMention(modLogs)}
${emojis.arrow} \`profanity:\`
${emojis.divider} Log messages that contains profanity.
${emojis.dividerEnd} Channel: ${channelMention(profanity)}
${emojis.divider} ${t({ phrase: 'hub.manage.logs.profanity.description', locale })}
${emojis.dividerEnd} ${channelStr} ${channelMention(profanity)}
${emojis.arrow} \`joinLeave:\`
${emojis.divider} Log when a new server joins or leaves the hub.
${emojis.dividerEnd} Channel: ${channelMention(joinLeaves)}
`,
${emojis.divider} ${t({ phrase: 'hub.manage.logs.joinLeave.description', locale })}
${emojis.dividerEnd} ${channelStr} ${channelMention(joinLeaves)}`,
)
.setColor(colors.invisible)
.setThumbnail(hubInDb.iconUrl)
Expand Down

0 comments on commit 373aeca

Please sign in to comment.