🐛 Fix invalid try state when client already owns a voice connection

This commit is contained in:
Manuel Ruwe 2022-12-17 22:35:11 +01:00
parent 86ffb19c9a
commit 7d8dc888c3
4 changed files with 31 additions and 65 deletions

View File

@ -40,12 +40,15 @@ export class DiscordVoiceService {
): GenericTryHandler { ): GenericTryHandler {
if (this.voiceConnection !== undefined) { if (this.voiceConnection !== undefined) {
return { return {
success: false, success: true,
reply: {}, reply: {},
}; };
} }
if (member.voice.channel === null) { if (member.voice.channel === null) {
this.logger.log(
`Unable to join a voice channel because the member ${member.user.username} is not in a voice channel`,
);
return { return {
success: false, success: false,
reply: { reply: {

View File

@ -6,7 +6,6 @@ import { JellyfinClientModule } from '../clients/jellyfin/jellyfin.module';
import { PlaybackModule } from '../playback/playback.module'; import { PlaybackModule } from '../playback/playback.module';
import { CurrentTrackCommand } from './current.command'; import { CurrentTrackCommand } from './current.command';
import { DisconnectCommand } from './disconnect.command'; import { DisconnectCommand } from './disconnect.command';
import { EnqueueCommand } from './enqueue.command';
import { HelpCommand } from './help.command'; import { HelpCommand } from './help.command';
import { PausePlaybackCommand } from './pause.command'; import { PausePlaybackCommand } from './pause.command';
import { PlayItemCommand } from './play.comands'; import { PlayItemCommand } from './play.comands';
@ -29,7 +28,6 @@ import { SummonCommand } from './summon.command';
StatusCommand, StatusCommand,
CurrentTrackCommand, CurrentTrackCommand,
DisconnectCommand, DisconnectCommand,
EnqueueCommand,
PausePlaybackCommand, PausePlaybackCommand,
SkipTrackCommand, SkipTrackCommand,
StopPlaybackCommand, StopPlaybackCommand,

View File

@ -1,44 +0,0 @@
import { TransformPipe } from '@discord-nestjs/common';
import {
Command,
DiscordTransformedCommand,
TransformedCommandExecutionContext,
UsePipes,
} from '@discord-nestjs/core';
import { InteractionReplyOptions } from 'discord.js';
import { DiscordMessageService } from '../clients/discord/discord.message.service';
import { TrackRequestDto } from '../models/track-request.dto';
import { PlaybackService } from '../playback/playback.service';
@Command({
name: 'enqueue',
description: 'Enqueue a track to the current playlist',
})
@UsePipes(TransformPipe)
export class EnqueueCommand
implements DiscordTransformedCommand<TrackRequestDto>
{
constructor(
private readonly discordMessageService: DiscordMessageService,
private readonly playbackService: PlaybackService,
) {}
handler(
dto: TrackRequestDto,
executionContext: TransformedCommandExecutionContext<any>,
): InteractionReplyOptions | string {
// const index = this.playbackService.eneuqueTrack({});
const index = 0;
return {
embeds: [
this.discordMessageService.buildMessage({
title: `Track Added to queue`,
description: `Your track \`\`${
dto.search
}\`\` was added to the queue at position \`\`${index + 1}\`\``,
}),
],
};
}
}

View File

@ -73,13 +73,19 @@ export class PlayItemCommand
)} *(${item.Type})*`, )} *(${item.Type})*`,
); );
const description = `I have found **${ let description =
items.length 'I have found **' +
}** results for your search \`\`${ items.length +
dto.search '** results for your search ``' +
}\`\`.\nFor better readability, I have limited the search results to 10\n\n ${lines.join( dto.search +
'\n', '``.';
)}`;
if (items.length > 10) {
description +=
'\nSince the results exceed 10 items, I truncated them for better readability.';
}
description += '\n\n' + lines.join('\n');
const emojiForType = (type: string) => { const emojiForType = (type: string) => {
switch (type) { switch (type) {
@ -146,17 +152,6 @@ export class PlayItemCommand
interaction.values[0], interaction.values[0],
); );
const milliseconds = item.RunTimeTicks / 10000;
const duration = formatDuration(
intervalToDuration({
start: milliseconds,
end: 0,
}),
);
const artists = item.Artists.join(', ');
const guildMember = interaction.member as GuildMember; const guildMember = interaction.member as GuildMember;
const tryResult = const tryResult =
@ -165,6 +160,9 @@ export class PlayItemCommand
); );
if (!tryResult.success) { if (!tryResult.success) {
this.logger.warn(
`Unable to process select result because the member was not in a voice channcel`,
);
const replyOptions = tryResult.reply as InteractionReplyOptions; const replyOptions = tryResult.reply as InteractionReplyOptions;
await interaction.update({ await interaction.update({
embeds: replyOptions.embeds, embeds: replyOptions.embeds,
@ -181,6 +179,15 @@ export class PlayItemCommand
bitrate, bitrate,
); );
const milliseconds = item.RunTimeTicks / 10000;
const duration = formatDuration(
intervalToDuration({
start: milliseconds,
end: 0,
}),
);
const addedIndex = this.playbackService.eneuqueTrack({ const addedIndex = this.playbackService.eneuqueTrack({
jellyfinId: item.Id, jellyfinId: item.Id,
name: item.Name, name: item.Name,
@ -188,6 +195,8 @@ export class PlayItemCommand
streamUrl: stream, streamUrl: stream,
}); });
const artists = item.Artists.join(', ');
await interaction.update({ await interaction.update({
embeds: [ embeds: [
this.discordMessageService.buildMessage({ this.discordMessageService.buildMessage({