From d67680fb1449556187b5805352f9a0273b09da5e Mon Sep 17 00:00:00 2001 From: JPBM135 Date: Sun, 26 Nov 2023 18:27:01 -0300 Subject: [PATCH] feat(messages): replace hyperlink for message anchors --- apps/yuudachi/.vscode/settings.json | 4 +++ apps/yuudachi/locales/de/translation.json | 10 +++--- apps/yuudachi/locales/en-GB/translation.json | 10 +++--- apps/yuudachi/locales/en-US/translation.json | 20 ++++++++--- apps/yuudachi/locales/es-ES/translation.json | 10 +++--- apps/yuudachi/locales/fr-FR/translation.json | 10 +++--- apps/yuudachi/locales/ja/translation.json | 10 +++--- apps/yuudachi/locales/ko/translation.json | 10 +++--- apps/yuudachi/locales/nl/translation.json | 10 +++--- apps/yuudachi/locales/pl/translation.json | 10 +++--- apps/yuudachi/locales/zh-CN/translation.json | 10 +++--- apps/yuudachi/locales/zh-TW/translation.json | 10 +++--- apps/yuudachi/src/commands/utility/repost.ts | 7 ++-- .../logging/generateAntiRaidNukeCaseLog.ts | 18 ++-------- .../functions/logging/generateCaseContent.ts | 33 +++++++++++++++++++ .../src/functions/logging/generateCaseLog.ts | 18 ---------- .../logging/insertAntiRaidNukeCaseLog.ts | 9 +++-- .../src/functions/logging/upsertCaseLog.ts | 4 +++ apps/yuudachi/src/util/parseRegex.ts | 4 ++- 19 files changed, 131 insertions(+), 86 deletions(-) create mode 100644 apps/yuudachi/.vscode/settings.json create mode 100644 apps/yuudachi/src/functions/logging/generateCaseContent.ts diff --git a/apps/yuudachi/.vscode/settings.json b/apps/yuudachi/.vscode/settings.json new file mode 100644 index 000000000..e1ccd8a95 --- /dev/null +++ b/apps/yuudachi/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "i18n-ally.localesPaths": ["locales"], + "i18n-ally.keystyle": "nested" +} diff --git a/apps/yuudachi/locales/de/translation.json b/apps/yuudachi/locales/de/translation.json index 497bc5e40..53c45bd61 100644 --- a/apps/yuudachi/locales/de/translation.json +++ b/apps/yuudachi/locales/de/translation.json @@ -458,6 +458,9 @@ "reason": "", "cancel": "", "success": "" + }, + "repost": { + "content": "Nachricht: {{- message_link}}" } } }, @@ -551,7 +554,6 @@ "anti_raid_nuke": { "description": "", "report": "", - "report_sub": "", "footer": "Cases {{from}}-{{to}}" }, "scam": { @@ -707,11 +709,11 @@ "full_match": "" }, "confusables": { - "title": "", "0": "", "1": "", "2": "", - "3": "" + "3": "", + "title": "" }, "created": { "title": "", @@ -796,4 +798,4 @@ } } } -} +} \ No newline at end of file diff --git a/apps/yuudachi/locales/en-GB/translation.json b/apps/yuudachi/locales/en-GB/translation.json index a0b0df497..81c1c7cf0 100644 --- a/apps/yuudachi/locales/en-GB/translation.json +++ b/apps/yuudachi/locales/en-GB/translation.json @@ -458,6 +458,9 @@ "reason": "", "cancel": "", "success": "" + }, + "repost": { + "content": "Message: {{- message_link}}" } } }, @@ -551,7 +554,6 @@ "anti_raid_nuke": { "description": "", "report": "", - "report_sub": "", "footer": "Cases {{from}}-{{to}}" }, "scam": { @@ -707,11 +709,11 @@ "full_match": "" }, "confusables": { - "title": "", "0": "", "1": "", "2": "", - "3": "" + "3": "", + "title": "" }, "created": { "title": "", @@ -796,4 +798,4 @@ } } } -} +} \ No newline at end of file diff --git a/apps/yuudachi/locales/en-US/translation.json b/apps/yuudachi/locales/en-US/translation.json index 61854c5a6..03d63812a 100644 --- a/apps/yuudachi/locales/en-US/translation.json +++ b/apps/yuudachi/locales/en-US/translation.json @@ -458,6 +458,9 @@ "reason": "Claimed sponsor role", "cancel": "Canceled claiming your sponsor role on {{- guild}}", "success": "Successfully claimed your sponsor role on {{- guild}}" + }, + "repost": { + "content": "Message: {{- message_link}}" } } }, @@ -550,8 +553,7 @@ }, "anti_raid_nuke": { "description": "**Action**: Anti-Raid-Nuke\n**Reason:** {{- reason}}\n**Hit count:** {{count}}", - "report": "**Report:** {{- link}}", - "report_sub": "Beam me up, Yuu", + "report": "**Report:** {{- message_link}}", "footer": "Cases {{from}}-{{to}}" }, "scam": { @@ -763,8 +765,16 @@ } }, "table": { - "success_titles": ["Case id", "Member id", "Username"], - "fail_titles": ["Member id", "Username", "Error"] + "success_titles": [ + "Case id", + "Member id", + "Username" + ], + "fail_titles": [ + "Member id", + "Username", + "Error" + ] } }, "report_log": { @@ -788,4 +798,4 @@ } } } -} +} \ No newline at end of file diff --git a/apps/yuudachi/locales/es-ES/translation.json b/apps/yuudachi/locales/es-ES/translation.json index f93dd0902..e29e7eb00 100644 --- a/apps/yuudachi/locales/es-ES/translation.json +++ b/apps/yuudachi/locales/es-ES/translation.json @@ -458,6 +458,9 @@ "reason": "", "cancel": "", "success": "" + }, + "repost": { + "content": "Mensaje: {{- message_link}}" } } }, @@ -551,7 +554,6 @@ "anti_raid_nuke": { "description": "", "report": "", - "report_sub": "", "footer": "Casos {{from}}-{{to}}" }, "scam": { @@ -707,11 +709,11 @@ "full_match": "" }, "confusables": { - "title": "", "0": "", "1": "", "2": "", - "3": "" + "3": "", + "title": "" }, "created": { "title": "", @@ -796,4 +798,4 @@ } } } -} +} \ No newline at end of file diff --git a/apps/yuudachi/locales/fr-FR/translation.json b/apps/yuudachi/locales/fr-FR/translation.json index 69c01281e..ea7cd523d 100644 --- a/apps/yuudachi/locales/fr-FR/translation.json +++ b/apps/yuudachi/locales/fr-FR/translation.json @@ -458,6 +458,9 @@ "reason": "", "cancel": "", "success": "" + }, + "repost": { + "content": "" } } }, @@ -551,7 +554,6 @@ "anti_raid_nuke": { "description": "", "report": "", - "report_sub": "", "footer": "" }, "scam": { @@ -707,11 +709,11 @@ "full_match": "" }, "confusables": { - "title": "", "0": "", "1": "", "2": "", - "3": "" + "3": "", + "title": "" }, "created": { "title": "", @@ -796,4 +798,4 @@ } } } -} +} \ No newline at end of file diff --git a/apps/yuudachi/locales/ja/translation.json b/apps/yuudachi/locales/ja/translation.json index 156522ca7..b835617cc 100644 --- a/apps/yuudachi/locales/ja/translation.json +++ b/apps/yuudachi/locales/ja/translation.json @@ -458,6 +458,9 @@ "reason": "", "cancel": "", "success": "" + }, + "repost": { + "content": "メッセージ: {{- message_link}}" } } }, @@ -551,7 +554,6 @@ "anti_raid_nuke": { "description": "", "report": "", - "report_sub": "", "footer": "" }, "scam": { @@ -707,11 +709,11 @@ "full_match": "" }, "confusables": { - "title": "", "0": "", "1": "", "2": "", - "3": "" + "3": "", + "title": "" }, "created": { "title": "", @@ -796,4 +798,4 @@ } } } -} +} \ No newline at end of file diff --git a/apps/yuudachi/locales/ko/translation.json b/apps/yuudachi/locales/ko/translation.json index 69c01281e..72717f79e 100644 --- a/apps/yuudachi/locales/ko/translation.json +++ b/apps/yuudachi/locales/ko/translation.json @@ -458,6 +458,9 @@ "reason": "", "cancel": "", "success": "" + }, + "repost": { + "content": "메시지: {{- message_link}}" } } }, @@ -551,7 +554,6 @@ "anti_raid_nuke": { "description": "", "report": "", - "report_sub": "", "footer": "" }, "scam": { @@ -707,11 +709,11 @@ "full_match": "" }, "confusables": { - "title": "", "0": "", "1": "", "2": "", - "3": "" + "3": "", + "title": "" }, "created": { "title": "", @@ -796,4 +798,4 @@ } } } -} +} \ No newline at end of file diff --git a/apps/yuudachi/locales/nl/translation.json b/apps/yuudachi/locales/nl/translation.json index 69c01281e..eb4f6dbf0 100644 --- a/apps/yuudachi/locales/nl/translation.json +++ b/apps/yuudachi/locales/nl/translation.json @@ -458,6 +458,9 @@ "reason": "", "cancel": "", "success": "" + }, + "repost": { + "content": "Bericht: {{- message_link}}" } } }, @@ -551,7 +554,6 @@ "anti_raid_nuke": { "description": "", "report": "", - "report_sub": "", "footer": "" }, "scam": { @@ -707,11 +709,11 @@ "full_match": "" }, "confusables": { - "title": "", "0": "", "1": "", "2": "", - "3": "" + "3": "", + "title": "" }, "created": { "title": "", @@ -796,4 +798,4 @@ } } } -} +} \ No newline at end of file diff --git a/apps/yuudachi/locales/pl/translation.json b/apps/yuudachi/locales/pl/translation.json index 45e17be2b..6ca8ca125 100644 --- a/apps/yuudachi/locales/pl/translation.json +++ b/apps/yuudachi/locales/pl/translation.json @@ -458,6 +458,9 @@ "reason": "", "cancel": "", "success": "" + }, + "repost": { + "content": "Wiadomość: {{- message_link}}" } } }, @@ -551,7 +554,6 @@ "anti_raid_nuke": { "description": "", "report": "", - "report_sub": "", "footer": "Cases {{from}}-{{to}}" }, "scam": { @@ -707,11 +709,11 @@ "full_match": "" }, "confusables": { - "title": "", "0": "", "1": "", "2": "", - "3": "" + "3": "", + "title": "" }, "created": { "title": "", @@ -796,4 +798,4 @@ } } } -} +} \ No newline at end of file diff --git a/apps/yuudachi/locales/zh-CN/translation.json b/apps/yuudachi/locales/zh-CN/translation.json index 69c01281e..9f48cec0f 100644 --- a/apps/yuudachi/locales/zh-CN/translation.json +++ b/apps/yuudachi/locales/zh-CN/translation.json @@ -458,6 +458,9 @@ "reason": "", "cancel": "", "success": "" + }, + "repost": { + "content": "消息:{{- message_link}}" } } }, @@ -551,7 +554,6 @@ "anti_raid_nuke": { "description": "", "report": "", - "report_sub": "", "footer": "" }, "scam": { @@ -707,11 +709,11 @@ "full_match": "" }, "confusables": { - "title": "", "0": "", "1": "", "2": "", - "3": "" + "3": "", + "title": "" }, "created": { "title": "", @@ -796,4 +798,4 @@ } } } -} +} \ No newline at end of file diff --git a/apps/yuudachi/locales/zh-TW/translation.json b/apps/yuudachi/locales/zh-TW/translation.json index 69c01281e..ecbc1ea00 100644 --- a/apps/yuudachi/locales/zh-TW/translation.json +++ b/apps/yuudachi/locales/zh-TW/translation.json @@ -458,6 +458,9 @@ "reason": "", "cancel": "", "success": "" + }, + "repost": { + "content": "訊息:{{- message_link}}" } } }, @@ -551,7 +554,6 @@ "anti_raid_nuke": { "description": "", "report": "", - "report_sub": "", "footer": "" }, "scam": { @@ -707,11 +709,11 @@ "full_match": "" }, "confusables": { - "title": "", "0": "", "1": "", "2": "", - "3": "" + "3": "", + "title": "" }, "created": { "title": "", @@ -796,4 +798,4 @@ } } } -} +} \ No newline at end of file diff --git a/apps/yuudachi/src/commands/utility/repost.ts b/apps/yuudachi/src/commands/utility/repost.ts index afd0a1966..04acbba41 100644 --- a/apps/yuudachi/src/commands/utility/repost.ts +++ b/apps/yuudachi/src/commands/utility/repost.ts @@ -1,10 +1,9 @@ -import { Command, createMessageActionRow } from "@yuudachi/framework"; +import { Command } from "@yuudachi/framework"; import type { ArgsParam, InteractionParam, LocaleParam, CommandMethod } from "@yuudachi/framework/types"; -import type { Message } from "discord.js"; +import { bold, type Message } from "discord.js"; import i18next from "i18next"; import { formatMessageToEmbed } from "../../functions/logging/formatMessageToEmbed.js"; import type { RepostCommand, RepostMessageContextCommand } from "../../interactions/index.js"; -import { createMessageLinkButton } from "../../util/createMessageLinkButton.js"; import { parseMessageLink, resolveMessage } from "../../util/resolveMessage.js"; export default class extends Command { @@ -14,8 +13,8 @@ export default class extends Command { + const locale = await getGuildSetting(guildId, SettingsKeys.Locale); + const sql = container.resolve>(kSQL); + + const msg = []; + + if (case_.contextMessageId) { + const [contextMessage] = await sql<[{ channel_id: Snowflake | null }?]>` + select channel_id + from messages + where id = ${case_.contextMessageId} + `; + + if (Reflect.has(contextMessage ?? {}, "channel_id")) { + msg.push( + i18next.t("log.mod_log.case_log.context_sub", { + lng: locale, + message_link: messageLink(contextMessage!.channel_id!, case_.contextMessageId, case_.guildId), + }), + ); + } + } + + return msg.length ? msg.join("\n") : null; +} diff --git a/apps/yuudachi/src/functions/logging/generateCaseLog.ts b/apps/yuudachi/src/functions/logging/generateCaseLog.ts index 58802e748..080b82a17 100644 --- a/apps/yuudachi/src/functions/logging/generateCaseLog.ts +++ b/apps/yuudachi/src/functions/logging/generateCaseLog.ts @@ -42,24 +42,6 @@ export async function generateCaseLog(case_: Case, logChannelId: Snowflake, loca }); } - if (case_.contextMessageId) { - const [contextMessage] = await sql<[{ channel_id: Snowflake | null }?]>` - select channel_id - from messages - where id = ${case_.contextMessageId} - `; - - if (Reflect.has(contextMessage ?? {}, "channel_id")) { - msg += i18next.t("log.mod_log.case_log.context", { - link: hyperlink( - i18next.t("log.mod_log.case_log.context_sub", { lng: locale }), - messageLink(contextMessage!.channel_id!, case_.contextMessageId, case_.guildId), - ), - lng: locale, - }); - } - } - if (case_.reason) { msg += i18next.t("log.mod_log.case_log.reason", { reason: case_.reason, lng: locale }); } else { diff --git a/apps/yuudachi/src/functions/logging/insertAntiRaidNukeCaseLog.ts b/apps/yuudachi/src/functions/logging/insertAntiRaidNukeCaseLog.ts index 36dec3657..502b3f45e 100644 --- a/apps/yuudachi/src/functions/logging/insertAntiRaidNukeCaseLog.ts +++ b/apps/yuudachi/src/functions/logging/insertAntiRaidNukeCaseLog.ts @@ -12,7 +12,7 @@ export async function insertAntiRaidNukeCaseLog( user: User, cases: Case[], reason: string, - messageUrl: string, + messageUrl?: string, ) { const sql = container.resolve>(kSQL); const locale = await getGuildSetting(guild.id, SettingsKeys.Locale); @@ -27,7 +27,7 @@ export async function insertAntiRaidNukeCaseLog( name: `${user.tag} (${user.id})`, icon_url: user.displayAvatarURL(), }, - description: await generateAntiRaidNukeCaseLog(guild.id, cases, reason, messageUrl), + description: await generateAntiRaidNukeCaseLog(guild.id, cases, reason), footer: { text: cases.length === 1 @@ -37,7 +37,12 @@ export async function insertAntiRaidNukeCaseLog( timestamp: new Date().toISOString(), }); + const content = messageUrl + ? i18next.t("log.mod_log.anti_raid_nuke.report", { lng: locale, message_link: messageUrl }) + : undefined; + const logMessage = await modLogChannel!.send({ + content, embeds: [embed], }); diff --git a/apps/yuudachi/src/functions/logging/upsertCaseLog.ts b/apps/yuudachi/src/functions/logging/upsertCaseLog.ts index df025c01d..4c32a22c3 100644 --- a/apps/yuudachi/src/functions/logging/upsertCaseLog.ts +++ b/apps/yuudachi/src/functions/logging/upsertCaseLog.ts @@ -4,6 +4,7 @@ import type { Sql } from "postgres"; import type { Case } from "../cases/createCase.js"; import { checkLogChannel } from "../settings/checkLogChannel.js"; import { getGuildSetting, SettingsKeys } from "../settings/getGuildSetting.js"; +import { generateCaseContent } from "./generateCaseContent.js"; import { generateCaseEmbed } from "./generateCaseEmbed.js"; export async function upsertCaseLog(guild: Guild, user: User | null | undefined, case_: Case) { @@ -11,14 +12,17 @@ export async function upsertCaseLog(guild: Guild, user: User | null | undefined, const modLogChannel = checkLogChannel(guild, await getGuildSetting(guild.id, SettingsKeys.ModLogChannelId)); const embed = await generateCaseEmbed(guild.id, modLogChannel!.id, user, case_); + const content = await generateCaseContent(guild.id, case_); if (case_.logMessageId) { const message = await modLogChannel!.messages.fetch(case_.logMessageId); await message.edit({ + content, embeds: [embed], }); } else { const logMessage = await modLogChannel!.send({ + content: content ?? undefined, embeds: [embed], }); diff --git a/apps/yuudachi/src/util/parseRegex.ts b/apps/yuudachi/src/util/parseRegex.ts index 25f956675..3477067b0 100644 --- a/apps/yuudachi/src/util/parseRegex.ts +++ b/apps/yuudachi/src/util/parseRegex.ts @@ -1,3 +1,4 @@ +import { logger } from "@yuudachi/framework"; import RE2 from "re2"; /** @@ -19,7 +20,8 @@ export function parseRegex(input?: string | null | undefined, insensitive = true } return new RE2(fullMatch ? `^${input}$` : input, options); - } catch { + } catch (error) { + logger.error(error, "Failed to parse regex pattern."); return null; } }