From 6734c38d24c9c5d0099e5de1a8f4c3eb5341c750 Mon Sep 17 00:00:00 2001 From: mattyatea Date: Sat, 17 Feb 2024 19:01:04 +0900 Subject: [PATCH] a --- .../backend/src/core/NoteCreateService.ts | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/core/NoteCreateService.ts b/packages/backend/src/core/NoteCreateService.ts index 5951d2d6fa..b2c8fd2bd3 100644 --- a/packages/backend/src/core/NoteCreateService.ts +++ b/packages/backend/src/core/NoteCreateService.ts @@ -288,7 +288,6 @@ export class NoteCreateService implements OnApplicationShutdown { } } - console.log('matched', matchedString); if (DiscordWebhookUrlWordBlock) { const data_disc = { 'username': 'ノートブロックお知らせ', 'content': @@ -386,7 +385,40 @@ export class NoteCreateService implements OnApplicationShutdown { let tags = data.apHashtags; let emojis = data.apEmojis; let mentionedUsers = data.apMentions; + let tmp:string | null = null; + if (mentionedUsers !== null && mentionedUsers !== undefined && mentionedUsers.length > 0) { + await Promise.all(mentionedUsers.map(async (u) => { + if (data.text != null) { + const regex = new RegExp(`@${u.username}@${u.host ?? this.config.host}`, 'g'); + tmp = data.text.replace(regex, ''); + } + })); + if ( tmp !== null && tmp.trim() === '') { + const { DiscordWebhookUrlWordBlock } = (await this.metaService.fetch()); + if (DiscordWebhookUrlWordBlock) { + await fetch(DiscordWebhookUrlWordBlock, { + 'method': 'post', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ 'username': 'ノートブロックお知らせ', + 'content': + 'ユーザー名 :' + user.username + '\n' + + 'url : ' + user.host + '\n' + + 'contents : ' + data.text + '\n' + + '引っかかった原因 メンションしかない', + + 'allowed_mentions': { + 'parse': [], + }, + }), + }); + } + console.log('メンションしかない'); + throw new NoteCreateService.ContainsProhibitedWordsError(); + } + } // Parse MFM if needed if (!tags || !emojis || !mentionedUsers) { const tokens = (data.text ? mfm.parse(data.text)! : []);