mirror of
https://github.com/BluemediaDev/muse.git
synced 2025-04-18 20:43:55 +02:00
46 lines
1.6 KiB
TypeScript
46 lines
1.6 KiB
TypeScript
import {SlashCommandBuilder} from '@discordjs/builders';
|
|
import {inject, injectable} from 'inversify';
|
|
import Command from '.';
|
|
import {TYPES} from '../types.js';
|
|
import PlayerManager from '../managers/player.js';
|
|
import {STATUS} from '../services/player.js';
|
|
import {buildPlayingMessageEmbed} from '../utils/build-embed.js';
|
|
import {getMemberVoiceChannel, getMostPopularVoiceChannel} from '../utils/channels.js';
|
|
import {CommandInteraction, GuildMember} from 'discord.js';
|
|
|
|
@injectable()
|
|
export default class implements Command {
|
|
public readonly slashCommand = new SlashCommandBuilder()
|
|
.setName('resume')
|
|
.setDescription('resume playback');
|
|
|
|
public requiresVC = true;
|
|
|
|
private readonly playerManager: PlayerManager;
|
|
|
|
constructor(@inject(TYPES.Managers.Player) playerManager: PlayerManager) {
|
|
this.playerManager = playerManager;
|
|
}
|
|
|
|
// eslint-disable-next-line complexity
|
|
public async execute(interaction: CommandInteraction): Promise<void> {
|
|
const player = this.playerManager.get(interaction.guild!.id);
|
|
const [targetVoiceChannel] = getMemberVoiceChannel(interaction.member as GuildMember) ?? getMostPopularVoiceChannel(interaction.guild!);
|
|
if (player.status === STATUS.PLAYING) {
|
|
throw new Error('already playing, give me a song name');
|
|
}
|
|
|
|
// Must be resuming play
|
|
if (!player.getCurrent()) {
|
|
throw new Error('nothing to play');
|
|
}
|
|
|
|
await player.connect(targetVoiceChannel);
|
|
await player.play();
|
|
|
|
await interaction.reply({
|
|
content: 'the stop-and-go light is now green',
|
|
embeds: [buildPlayingMessageEmbed(player)],
|
|
});
|
|
}
|
|
}
|