Add pause/resume

This commit is contained in:
Max Isom 2020-03-15 19:30:07 -05:00
parent e55acbb718
commit 2875c6ceb8
4 changed files with 123 additions and 26 deletions

29
src/commands/pause.ts Normal file
View file

@ -0,0 +1,29 @@
import {Message} from 'discord.js';
import {TYPES} from '../types';
import {inject, injectable} from 'inversify';
import PlayerManager from '../managers/player';
import {STATUS} from '../services/player';
import Command from '.';
@injectable()
export default class implements Command {
public name = 'pause';
public description = 'pause currently playing song';
private readonly playerManager: PlayerManager;
constructor(@inject(TYPES.Managers.Player) playerManager: PlayerManager) {
this.playerManager = playerManager;
}
public async execute(msg: Message, _: string []): Promise<void> {
const player = this.playerManager.get(msg.guild!.id);
if (player.status !== STATUS.PLAYING) {
await msg.channel.send('error: not currently playing');
return;
}
player.pause();
await msg.channel.send('paused');
}
}

View file

@ -36,6 +36,29 @@ export default class implements Command {
}
public async execute(msg: Message, args: string []): Promise<void> {
const queue = this.queueManager.get(msg.guild!.id);
if (args.length === 0) {
if (this.playerManager.get(msg.guild!.id).status === STATUS.PLAYING) {
await msg.channel.send('error: already playing, give me a song name');
return;
}
// Must be resuming play
if (queue.get().length === 0) {
await msg.channel.send('error: nothing to play');
return;
}
const channel = getMostPopularVoiceChannel(msg.guild!);
await this.playerManager.get(msg.guild!.id).connect(channel);
await this.playerManager.get(msg.guild!.id).play();
await msg.channel.send('play resuming');
return;
}
const newSongs: QueuedSong[] = [];
const res = new LoadingMessage(msg.channel as TextChannel, 'hold on a sec');