mirror of
https://github.com/informaticker/discord-jellyfin-bot.git
synced 2024-11-23 18:21:55 +01:00
🐛 Fix invalid try state when client already owns a voice connection
This commit is contained in:
parent
86ffb19c9a
commit
7d8dc888c3
@ -40,12 +40,15 @@ export class DiscordVoiceService {
|
||||
): GenericTryHandler {
|
||||
if (this.voiceConnection !== undefined) {
|
||||
return {
|
||||
success: false,
|
||||
success: true,
|
||||
reply: {},
|
||||
};
|
||||
}
|
||||
|
||||
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 {
|
||||
success: false,
|
||||
reply: {
|
||||
|
@ -6,7 +6,6 @@ import { JellyfinClientModule } from '../clients/jellyfin/jellyfin.module';
|
||||
import { PlaybackModule } from '../playback/playback.module';
|
||||
import { CurrentTrackCommand } from './current.command';
|
||||
import { DisconnectCommand } from './disconnect.command';
|
||||
import { EnqueueCommand } from './enqueue.command';
|
||||
import { HelpCommand } from './help.command';
|
||||
import { PausePlaybackCommand } from './pause.command';
|
||||
import { PlayItemCommand } from './play.comands';
|
||||
@ -29,7 +28,6 @@ import { SummonCommand } from './summon.command';
|
||||
StatusCommand,
|
||||
CurrentTrackCommand,
|
||||
DisconnectCommand,
|
||||
EnqueueCommand,
|
||||
PausePlaybackCommand,
|
||||
SkipTrackCommand,
|
||||
StopPlaybackCommand,
|
||||
|
@ -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}\`\``,
|
||||
}),
|
||||
],
|
||||
};
|
||||
}
|
||||
}
|
@ -73,13 +73,19 @@ export class PlayItemCommand
|
||||
)} *(${item.Type})*`,
|
||||
);
|
||||
|
||||
const description = `I have found **${
|
||||
items.length
|
||||
}** results for your search \`\`${
|
||||
dto.search
|
||||
}\`\`.\nFor better readability, I have limited the search results to 10\n\n ${lines.join(
|
||||
'\n',
|
||||
)}`;
|
||||
let description =
|
||||
'I have found **' +
|
||||
items.length +
|
||||
'** results for your search ``' +
|
||||
dto.search +
|
||||
'``.';
|
||||
|
||||
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) => {
|
||||
switch (type) {
|
||||
@ -146,17 +152,6 @@ export class PlayItemCommand
|
||||
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 tryResult =
|
||||
@ -165,6 +160,9 @@ export class PlayItemCommand
|
||||
);
|
||||
|
||||
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;
|
||||
await interaction.update({
|
||||
embeds: replyOptions.embeds,
|
||||
@ -181,6 +179,15 @@ export class PlayItemCommand
|
||||
bitrate,
|
||||
);
|
||||
|
||||
const milliseconds = item.RunTimeTicks / 10000;
|
||||
|
||||
const duration = formatDuration(
|
||||
intervalToDuration({
|
||||
start: milliseconds,
|
||||
end: 0,
|
||||
}),
|
||||
);
|
||||
|
||||
const addedIndex = this.playbackService.eneuqueTrack({
|
||||
jellyfinId: item.Id,
|
||||
name: item.Name,
|
||||
@ -188,6 +195,8 @@ export class PlayItemCommand
|
||||
streamUrl: stream,
|
||||
});
|
||||
|
||||
const artists = item.Artists.join(', ');
|
||||
|
||||
await interaction.update({
|
||||
embeds: [
|
||||
this.discordMessageService.buildMessage({
|
||||
|
Loading…
Reference in New Issue
Block a user