mirror of
https://github.com/informaticker/discord-jellyfin-bot.git
synced 2024-11-23 18:21:55 +01:00
✨ Add playback commands
This commit is contained in:
parent
f5c1cb71a6
commit
3d9ba8ede7
@ -30,6 +30,7 @@
|
|||||||
"@nestjs/core": "^9.0.0",
|
"@nestjs/core": "^9.0.0",
|
||||||
"@nestjs/event-emitter": "^1.3.1",
|
"@nestjs/event-emitter": "^1.3.1",
|
||||||
"@nestjs/platform-express": "^9.0.0",
|
"@nestjs/platform-express": "^9.0.0",
|
||||||
|
"date-fns": "^2.29.3",
|
||||||
"discord.js": "^14.7.1",
|
"discord.js": "^14.7.1",
|
||||||
"jellyfin-apiclient": "^1.10.0",
|
"jellyfin-apiclient": "^1.10.0",
|
||||||
"joi": "^17.7.0",
|
"joi": "^17.7.0",
|
||||||
|
@ -3,11 +3,30 @@ import { DiscordModule } from '@discord-nestjs/core';
|
|||||||
|
|
||||||
import { HelpCommand } from './help.command';
|
import { HelpCommand } from './help.command';
|
||||||
import { StatusCommand } from './status.command';
|
import { StatusCommand } from './status.command';
|
||||||
|
import { CurrentTrackCommand } from './current.command';
|
||||||
|
import { DisconnectCommand } from './disconnect.command';
|
||||||
|
import { EnqueueCommand } from './enqueue.command';
|
||||||
|
import { PausePlaybackCommand } from './pause.command';
|
||||||
|
import { PlayCommand } from './play.command';
|
||||||
|
import { SkipTrackCommand } from './skip.command';
|
||||||
|
import { StopPlaybackCommand } from './stop.command';
|
||||||
|
import { SummonCommand } from './summon.command';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [DiscordModule.forFeature()],
|
imports: [DiscordModule.forFeature()],
|
||||||
controllers: [],
|
controllers: [],
|
||||||
providers: [HelpCommand, StatusCommand],
|
providers: [
|
||||||
|
HelpCommand,
|
||||||
|
StatusCommand,
|
||||||
|
CurrentTrackCommand,
|
||||||
|
DisconnectCommand,
|
||||||
|
EnqueueCommand,
|
||||||
|
PausePlaybackCommand,
|
||||||
|
PlayCommand,
|
||||||
|
SkipTrackCommand,
|
||||||
|
StopPlaybackCommand,
|
||||||
|
SummonCommand,
|
||||||
|
],
|
||||||
exports: [],
|
exports: [],
|
||||||
})
|
})
|
||||||
export class CommandModule {}
|
export class CommandModule {}
|
||||||
|
23
src/commands/current.command.ts
Normal file
23
src/commands/current.command.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import { TransformPipe } from '@discord-nestjs/common';
|
||||||
|
|
||||||
|
import {
|
||||||
|
Command,
|
||||||
|
DiscordTransformedCommand,
|
||||||
|
TransformedCommandExecutionContext,
|
||||||
|
UsePipes,
|
||||||
|
} from '@discord-nestjs/core';
|
||||||
|
import { InteractionReplyOptions } from 'discord.js';
|
||||||
|
|
||||||
|
@Command({
|
||||||
|
name: 'current',
|
||||||
|
description: 'Print the current track information',
|
||||||
|
})
|
||||||
|
@UsePipes(TransformPipe)
|
||||||
|
export class CurrentTrackCommand implements DiscordTransformedCommand<unknown> {
|
||||||
|
handler(
|
||||||
|
dto: unknown,
|
||||||
|
executionContext: TransformedCommandExecutionContext<any>,
|
||||||
|
): InteractionReplyOptions | string {
|
||||||
|
return 'nice';
|
||||||
|
}
|
||||||
|
}
|
23
src/commands/disconnect.command.ts
Normal file
23
src/commands/disconnect.command.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import { TransformPipe } from '@discord-nestjs/common';
|
||||||
|
|
||||||
|
import {
|
||||||
|
Command,
|
||||||
|
DiscordTransformedCommand,
|
||||||
|
TransformedCommandExecutionContext,
|
||||||
|
UsePipes,
|
||||||
|
} from '@discord-nestjs/core';
|
||||||
|
import { InteractionReplyOptions } from 'discord.js';
|
||||||
|
|
||||||
|
@Command({
|
||||||
|
name: 'disconnect',
|
||||||
|
description: 'Join your current voice channel',
|
||||||
|
})
|
||||||
|
@UsePipes(TransformPipe)
|
||||||
|
export class DisconnectCommand implements DiscordTransformedCommand<unknown> {
|
||||||
|
handler(
|
||||||
|
dto: unknown,
|
||||||
|
executionContext: TransformedCommandExecutionContext<any>,
|
||||||
|
): InteractionReplyOptions | string {
|
||||||
|
return 'nice';
|
||||||
|
}
|
||||||
|
}
|
23
src/commands/enqueue.command.ts
Normal file
23
src/commands/enqueue.command.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import { TransformPipe } from '@discord-nestjs/common';
|
||||||
|
|
||||||
|
import {
|
||||||
|
Command,
|
||||||
|
DiscordTransformedCommand,
|
||||||
|
TransformedCommandExecutionContext,
|
||||||
|
UsePipes,
|
||||||
|
} from '@discord-nestjs/core';
|
||||||
|
import { InteractionReplyOptions } from 'discord.js';
|
||||||
|
|
||||||
|
@Command({
|
||||||
|
name: 'enqueue',
|
||||||
|
description: 'Enqueue a track to the current playlist',
|
||||||
|
})
|
||||||
|
@UsePipes(TransformPipe)
|
||||||
|
export class EnqueueCommand implements DiscordTransformedCommand<unknown> {
|
||||||
|
handler(
|
||||||
|
dto: unknown,
|
||||||
|
executionContext: TransformedCommandExecutionContext<any>,
|
||||||
|
): InteractionReplyOptions | string {
|
||||||
|
return 'nice';
|
||||||
|
}
|
||||||
|
}
|
25
src/commands/pause.command.ts
Normal file
25
src/commands/pause.command.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import { TransformPipe } from '@discord-nestjs/common';
|
||||||
|
|
||||||
|
import {
|
||||||
|
Command,
|
||||||
|
DiscordTransformedCommand,
|
||||||
|
TransformedCommandExecutionContext,
|
||||||
|
UsePipes,
|
||||||
|
} from '@discord-nestjs/core';
|
||||||
|
import { InteractionReplyOptions } from 'discord.js';
|
||||||
|
|
||||||
|
@Command({
|
||||||
|
name: 'pause',
|
||||||
|
description: 'Pause or resume the playback of the current track',
|
||||||
|
})
|
||||||
|
@UsePipes(TransformPipe)
|
||||||
|
export class PausePlaybackCommand
|
||||||
|
implements DiscordTransformedCommand<unknown>
|
||||||
|
{
|
||||||
|
handler(
|
||||||
|
dto: unknown,
|
||||||
|
executionContext: TransformedCommandExecutionContext<any>,
|
||||||
|
): InteractionReplyOptions | string {
|
||||||
|
return 'nice';
|
||||||
|
}
|
||||||
|
}
|
23
src/commands/play.command.ts
Normal file
23
src/commands/play.command.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import { TransformPipe } from '@discord-nestjs/common';
|
||||||
|
|
||||||
|
import {
|
||||||
|
Command,
|
||||||
|
DiscordTransformedCommand,
|
||||||
|
TransformedCommandExecutionContext,
|
||||||
|
UsePipes,
|
||||||
|
} from '@discord-nestjs/core';
|
||||||
|
import { InteractionReplyOptions } from 'discord.js';
|
||||||
|
|
||||||
|
@Command({
|
||||||
|
name: 'play',
|
||||||
|
description: 'Immediately play a track',
|
||||||
|
})
|
||||||
|
@UsePipes(TransformPipe)
|
||||||
|
export class PlayCommand implements DiscordTransformedCommand<unknown> {
|
||||||
|
handler(
|
||||||
|
dto: unknown,
|
||||||
|
executionContext: TransformedCommandExecutionContext<any>,
|
||||||
|
): InteractionReplyOptions | string {
|
||||||
|
return 'nice';
|
||||||
|
}
|
||||||
|
}
|
23
src/commands/skip.command.ts
Normal file
23
src/commands/skip.command.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import { TransformPipe } from '@discord-nestjs/common';
|
||||||
|
|
||||||
|
import {
|
||||||
|
Command,
|
||||||
|
DiscordTransformedCommand,
|
||||||
|
TransformedCommandExecutionContext,
|
||||||
|
UsePipes,
|
||||||
|
} from '@discord-nestjs/core';
|
||||||
|
import { InteractionReplyOptions } from 'discord.js';
|
||||||
|
|
||||||
|
@Command({
|
||||||
|
name: 'skip',
|
||||||
|
description: 'Skip the current track',
|
||||||
|
})
|
||||||
|
@UsePipes(TransformPipe)
|
||||||
|
export class SkipTrackCommand implements DiscordTransformedCommand<unknown> {
|
||||||
|
handler(
|
||||||
|
dto: unknown,
|
||||||
|
executionContext: TransformedCommandExecutionContext<any>,
|
||||||
|
): InteractionReplyOptions | string {
|
||||||
|
return 'nice';
|
||||||
|
}
|
||||||
|
}
|
@ -8,9 +8,12 @@ import {
|
|||||||
UsePipes,
|
UsePipes,
|
||||||
} from '@discord-nestjs/core';
|
} from '@discord-nestjs/core';
|
||||||
import { EmbedBuilder } from '@discordjs/builders';
|
import { EmbedBuilder } from '@discordjs/builders';
|
||||||
import { Client, InteractionReplyOptions } from 'discord.js';
|
import { Client, InteractionReplyOptions, Status } from 'discord.js';
|
||||||
import { DefaultJellyfinColor } from 'src/types/colors';
|
import { DefaultJellyfinColor } from 'src/types/colors';
|
||||||
|
|
||||||
|
import { formatDuration, intervalToDuration } from 'date-fns';
|
||||||
|
import { Constants } from 'src/utils/constants';
|
||||||
|
|
||||||
@Command({
|
@Command({
|
||||||
name: 'status',
|
name: 'status',
|
||||||
description: 'Display the current status for troubleshooting',
|
description: 'Display the current status for troubleshooting',
|
||||||
@ -27,6 +30,13 @@ export class StatusCommand implements DiscordTransformedCommand<unknown> {
|
|||||||
executionContext: TransformedCommandExecutionContext<any>,
|
executionContext: TransformedCommandExecutionContext<any>,
|
||||||
): InteractionReplyOptions {
|
): InteractionReplyOptions {
|
||||||
const ping = this.client.ws.ping;
|
const ping = this.client.ws.ping;
|
||||||
|
const status = Status[this.client.ws.status];
|
||||||
|
|
||||||
|
const interval = intervalToDuration({
|
||||||
|
start: this.client.uptime,
|
||||||
|
end: 0,
|
||||||
|
});
|
||||||
|
const formattedDuration = formatDuration(interval);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
embeds: [
|
embeds: [
|
||||||
@ -34,14 +44,24 @@ export class StatusCommand implements DiscordTransformedCommand<unknown> {
|
|||||||
.setTitle('Online and ready')
|
.setTitle('Online and ready')
|
||||||
.setColor(DefaultJellyfinColor)
|
.setColor(DefaultJellyfinColor)
|
||||||
.addFields([
|
.addFields([
|
||||||
|
{
|
||||||
|
name: 'Version',
|
||||||
|
value: Constants.Metadata.Version,
|
||||||
|
inline: false,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'Ping',
|
name: 'Ping',
|
||||||
value: `${ping}ms`,
|
value: `${ping}ms`,
|
||||||
inline: true,
|
inline: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Source code',
|
name: 'Status',
|
||||||
value: 'https://github.com/manuel-rw/jellyfin-discord-music-bot',
|
value: `${status}`,
|
||||||
|
inline: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Uptime',
|
||||||
|
value: `${formattedDuration}`,
|
||||||
inline: true,
|
inline: true,
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
|
23
src/commands/stop.command.ts
Normal file
23
src/commands/stop.command.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import { TransformPipe } from '@discord-nestjs/common';
|
||||||
|
|
||||||
|
import {
|
||||||
|
Command,
|
||||||
|
DiscordTransformedCommand,
|
||||||
|
TransformedCommandExecutionContext,
|
||||||
|
UsePipes,
|
||||||
|
} from '@discord-nestjs/core';
|
||||||
|
import { InteractionReplyOptions } from 'discord.js';
|
||||||
|
|
||||||
|
@Command({
|
||||||
|
name: 'stop',
|
||||||
|
description: 'Stop playback entirely and clear the current playlist',
|
||||||
|
})
|
||||||
|
@UsePipes(TransformPipe)
|
||||||
|
export class StopPlaybackCommand implements DiscordTransformedCommand<unknown> {
|
||||||
|
handler(
|
||||||
|
dto: unknown,
|
||||||
|
executionContext: TransformedCommandExecutionContext<any>,
|
||||||
|
): InteractionReplyOptions | string {
|
||||||
|
return 'nice';
|
||||||
|
}
|
||||||
|
}
|
23
src/commands/summon.command.ts
Normal file
23
src/commands/summon.command.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import { TransformPipe } from '@discord-nestjs/common';
|
||||||
|
|
||||||
|
import {
|
||||||
|
Command,
|
||||||
|
DiscordTransformedCommand,
|
||||||
|
TransformedCommandExecutionContext,
|
||||||
|
UsePipes,
|
||||||
|
} from '@discord-nestjs/core';
|
||||||
|
import { InteractionReplyOptions } from 'discord.js';
|
||||||
|
|
||||||
|
@Command({
|
||||||
|
name: 'summon',
|
||||||
|
description: 'Join your current voice channel',
|
||||||
|
})
|
||||||
|
@UsePipes(TransformPipe)
|
||||||
|
export class SummonCommand implements DiscordTransformedCommand<unknown> {
|
||||||
|
handler(
|
||||||
|
dto: unknown,
|
||||||
|
executionContext: TransformedCommandExecutionContext<any>,
|
||||||
|
): InteractionReplyOptions | string {
|
||||||
|
return 'nice';
|
||||||
|
}
|
||||||
|
}
|
@ -2892,6 +2892,13 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"date-fns@npm:^2.29.3":
|
||||||
|
version: 2.29.3
|
||||||
|
resolution: "date-fns@npm:2.29.3"
|
||||||
|
checksum: e01cf5b62af04e05dfff921bb9c9933310ed0e1ae9a81eb8653452e64dc841acf7f6e01e1a5ae5644d0337e9a7f936175fd2cb6819dc122fdd9c5e86c56be484
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
|
||||||
"debug@npm:2.6.9":
|
"debug@npm:2.6.9":
|
||||||
version: 2.6.9
|
version: 2.6.9
|
||||||
resolution: "debug@npm:2.6.9"
|
resolution: "debug@npm:2.6.9"
|
||||||
@ -4446,6 +4453,7 @@ __metadata:
|
|||||||
"@types/supertest": ^2.0.11
|
"@types/supertest": ^2.0.11
|
||||||
"@typescript-eslint/eslint-plugin": ^5.0.0
|
"@typescript-eslint/eslint-plugin": ^5.0.0
|
||||||
"@typescript-eslint/parser": ^5.0.0
|
"@typescript-eslint/parser": ^5.0.0
|
||||||
|
date-fns: ^2.29.3
|
||||||
discord.js: ^14.7.1
|
discord.js: ^14.7.1
|
||||||
eslint: ^8.0.1
|
eslint: ^8.0.1
|
||||||
eslint-config-prettier: ^8.3.0
|
eslint-config-prettier: ^8.3.0
|
||||||
|
Loading…
Reference in New Issue
Block a user