From 5813f3967eb63d16db1f5f6eab31ab5cf917ae7a Mon Sep 17 00:00:00 2001 From: na2na-p Date: Mon, 20 Nov 2023 15:11:49 +0900 Subject: [PATCH] =?UTF-8?q?bool=E3=81=A7=E3=81=AEjoinable=E3=83=81?= =?UTF-8?q?=E3=82=A7=E3=83=83=E3=82=AF=E3=82=84=E3=82=81=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../internal/Voice/internal/Voice.class.ts | 24 ++++++++++++------- .../Voice/internal/Voice.constants.ts | 7 ++++++ 2 files changed, 22 insertions(+), 9 deletions(-) create mode 100644 src/features/core/internal/Voice/internal/Voice.constants.ts diff --git a/src/features/core/internal/Voice/internal/Voice.class.ts b/src/features/core/internal/Voice/internal/Voice.class.ts index 639a7bea..1f7b8f01 100644 --- a/src/features/core/internal/Voice/internal/Voice.class.ts +++ b/src/features/core/internal/Voice/internal/Voice.class.ts @@ -11,6 +11,8 @@ import { } from '@/features/library/index.js'; import { getInteractionMemberId } from '@/features/others/discord/index.js'; +import { JOINABLE_TYPE_MAP } from './Voice.constants.js'; + export class Voice { #connection: Array<{ guildId: string; @@ -23,11 +25,12 @@ export class Voice { interaction: Readonly; }) { const member = await getInteractionMemberId(interaction); - const checkJoinableResult = this.#checkJoinable({ + const checkJoinableResult = this.checkJoinable({ channel: member.voice.channel, }); - if (checkJoinableResult.isJoinable === false) return false; + if (checkJoinableResult.joinableType !== JOINABLE_TYPE_MAP.JOINABLE) + return false; const connection = joinVoiceChannel({ channelId: checkJoinableResult.channel.id, @@ -73,34 +76,37 @@ export class Voice { } } - #checkJoinable({ channel }: { channel: VoiceBasedChannel | null }): + checkJoinable({ channel }: { channel: VoiceBasedChannel | null }): | (Pick & { - isJoinable: false; + joinableType: Exclude< + (typeof JOINABLE_TYPE_MAP)[keyof typeof JOINABLE_TYPE_MAP], + typeof JOINABLE_TYPE_MAP.JOINABLE + >; }) | { - isJoinable: true; + joinableType: typeof JOINABLE_TYPE_MAP.JOINABLE; channel: VoiceBasedChannel; } { if (isNil(channel)) { return { - isJoinable: false, + joinableType: JOINABLE_TYPE_MAP.NOT_FOUND, content: '接続先のVCが見つかりません。', ephemeral: false, }; } else if (!channel.joinable) { return { - isJoinable: false, + joinableType: JOINABLE_TYPE_MAP.NOT_JOINABLE, content: '接続先のVCに参加できません。権限の見直しをしてください。', ephemeral: true, }; } else if (!channel.viewable) { return { - isJoinable: false, + joinableType: JOINABLE_TYPE_MAP.NOT_VIEWABLE, content: '接続先のVCに参加できません。権限の見直しをしてください。', ephemeral: true, }; } else { - return { isJoinable: true, channel }; + return { joinableType: JOINABLE_TYPE_MAP.JOINABLE, channel }; } } } diff --git a/src/features/core/internal/Voice/internal/Voice.constants.ts b/src/features/core/internal/Voice/internal/Voice.constants.ts new file mode 100644 index 00000000..7ae6264b --- /dev/null +++ b/src/features/core/internal/Voice/internal/Voice.constants.ts @@ -0,0 +1,7 @@ +export const JOINABLE_TYPE_MAP = { + JOINABLE: 'JOINABLE', + NOT_JOINABLE: 'NOT_JOINABLE', + NOT_FOUND: 'NOT_FOUND', + NOT_VIEWABLE: 'NOT_VIEWABLE', + ALREADY_JOINED: 'ALREADY_JOINED', +} as const;