From f34aa3d996be4eecaa0203b76ba2587995df4f51 Mon Sep 17 00:00:00 2001 From: yogarasu Date: Fri, 19 Aug 2022 11:28:55 +0900 Subject: [PATCH] =?UTF-8?q?fix=20#14=20=E3=83=95=E3=82=A1=E3=82=A4?= =?UTF-8?q?=E3=83=AB=E3=81=AB=E5=BF=85=E9=A0=88=E9=A0=85=E7=9B=AE=E3=81=8C?= =?UTF-8?q?=E3=81=AA=E3=81=84=E5=A0=B4=E5=90=88=E3=81=AF=E4=BE=8B=E5=A4=96?= =?UTF-8?q?=E3=82=92=E7=99=BA=E7=94=9F=E3=81=95=E3=81=9B=E3=82=8B=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/channel.mts | 25 ++++++++++++++++--------- libs/message.mts | 7 ++++++- libs/user.mts | 8 ++++---- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/libs/channel.mts b/libs/channel.mts index bdb320d..3e10b4e 100644 --- a/libs/channel.mts +++ b/libs/channel.mts @@ -111,28 +111,35 @@ export const buildChannelFile = async ( messageFilePath.replace(srcMessageDirPath, distMessageDirPath) ) - newChannels.push({ + // チャンネルの必須項目がない場合は例外を投げる + if (channel.id === undefined || channel.is_archived === undefined) { + throw new Error("Channel is missing a required parameter") + } + + const newChannel: Channel = { slack: { - channel_id: channel.id || "", - channel_name: channel.name || "", - is_archived: channel.is_archived || false, - purpose: channel.purpose?.value ? channel.purpose.value : "", + channel_id: channel.id, + channel_name: channel.name, + is_archived: channel.is_archived, + purpose: channel.purpose?.value || "", message_file_paths: srcMessageFilePaths, }, discord: { channel_id: "", - channel_name: channel.name || "", - is_archived: channel.is_archived || false, + channel_name: channel.name, + is_archived: channel.is_archived, is_deleted: false, guild: { boost_level: 0, boost_count: 0, max_file_size: 8000000, }, - topic: channel.purpose?.value ? channel.purpose.value : "", + topic: channel.purpose?.value || "", message_file_paths: distMessageFilePaths, }, - }) + } + + newChannels.push(newChannel) } } diff --git a/libs/message.mts b/libs/message.mts index c2d6d98..99eca5e 100644 --- a/libs/message.mts +++ b/libs/message.mts @@ -113,7 +113,12 @@ export const buildMessageFile = async ( const messages = JSON.parse(messageFile) as SlackMessage[] let isMaxFileSizeOver = false for (const message of messages) { - let content = message.text || "" + // メッセージの必須項目がない場合は例外を投げる + if (message.text === undefined) { + throw new Error("Message is missing a required parameter") + } + + let content = message.text // メッセージ内のユーザー名もしくはBot名のメンションを、Discordでメンションされない形式に置換 const matchMention = content.match(/<@U[A-Z0-9]{10}>/g) diff --git a/libs/user.mts b/libs/user.mts index e3faa5a..fe4a04e 100644 --- a/libs/user.mts +++ b/libs/user.mts @@ -133,12 +133,12 @@ export const buildUser = async ( // ユーザーの必須項目がない場合は例外を投げる if ( - !user.id || - !name || + user.id === undefined || + name === undefined || user.deleted === undefined || user.is_bot === undefined || - !user.color || - !user.profile?.image_512 + user.color === undefined || + user.profile?.image_512 === undefined ) { throw new Error("User is missing a required parameter") }