Skip to content

Commit

Permalink
boolでのjoinableチェックやめる
Browse files Browse the repository at this point in the history
  • Loading branch information
na2na-p committed Nov 20, 2023
1 parent 1a81286 commit 5813f39
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/features/core/internal/Voice/internal/Voice.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,11 +25,12 @@ export class Voice {
interaction: Readonly<ChatInputCommandInteraction>;
}) {
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,
Expand Down Expand Up @@ -73,34 +76,37 @@ export class Voice {
}
}

#checkJoinable({ channel }: { channel: VoiceBasedChannel | null }):
checkJoinable({ channel }: { channel: VoiceBasedChannel | null }):
| (Pick<InteractionReplyOptions, 'content' | 'ephemeral'> & {
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 };
}
}
}
7 changes: 7 additions & 0 deletions src/features/core/internal/Voice/internal/Voice.constants.ts
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 5813f39

Please sign in to comment.