Add skip/unskip

This commit is contained in:
Max Isom 2020-03-15 16:55:44 -05:00
parent 3c169d113c
commit e55acbb718
3 changed files with 70 additions and 0 deletions

33
src/commands/skip.ts Normal file
View file

@ -0,0 +1,33 @@
import {Message} from 'discord.js';
import {TYPES} from '../types';
import {inject, injectable} from 'inversify';
import PlayerManager from '../managers/player';
import QueueManager from '../managers/queue';
import Command from '.';
@injectable()
export default class implements Command {
public name = 'skip';
public description = 'skips current song';
private readonly queueManager: QueueManager;
private readonly playerManager: PlayerManager;
constructor(@inject(TYPES.Managers.Queue) queueManager: QueueManager, @inject(TYPES.Managers.Player) playerManager: PlayerManager) {
this.queueManager = queueManager;
this.playerManager = playerManager;
}
public async execute(msg: Message, _: string []): Promise<void> {
const queue = this.queueManager.get(msg.guild!.id);
try {
queue.forward();
await this.playerManager.get(msg.guild!.id).play();
await msg.channel.send('keepin\' \'er movin\'');
} catch (_) {
await msg.channel.send('no song to skip to');
}
}
}

33
src/commands/unskip.ts Normal file
View file

@ -0,0 +1,33 @@
import {Message} from 'discord.js';
import {TYPES} from '../types';
import {inject, injectable} from 'inversify';
import PlayerManager from '../managers/player';
import QueueManager from '../managers/queue';
import Command from '.';
@injectable()
export default class implements Command {
public name = 'unskip';
public description = 'go back in the queue';
private readonly queueManager: QueueManager;
private readonly playerManager: PlayerManager;
constructor(@inject(TYPES.Managers.Queue) queueManager: QueueManager, @inject(TYPES.Managers.Player) playerManager: PlayerManager) {
this.queueManager = queueManager;
this.playerManager = playerManager;
}
public async execute(msg: Message, _: string []): Promise<void> {
const queue = this.queueManager.get(msg.guild!.id);
try {
queue.back();
await this.playerManager.get(msg.guild!.id).play();
await msg.channel.send('back \'er up\'');
} catch (_) {
await msg.channel.send('no song to go back to');
}
}
}

View file

@ -28,6 +28,8 @@ import Play from './commands/play';
import QueueCommad from './commands/queue'; import QueueCommad from './commands/queue';
import Seek from './commands/seek'; import Seek from './commands/seek';
import Shuffle from './commands/shuffle'; import Shuffle from './commands/shuffle';
import Skip from './commands/skip';
import Unskip from './commands/unskip';
let container = new Container(); let container = new Container();
@ -47,6 +49,8 @@ container.bind<Command>(TYPES.Command).to(Play).inSingletonScope();
container.bind<Command>(TYPES.Command).to(QueueCommad).inSingletonScope(); container.bind<Command>(TYPES.Command).to(QueueCommad).inSingletonScope();
container.bind<Command>(TYPES.Command).to(Seek).inSingletonScope(); container.bind<Command>(TYPES.Command).to(Seek).inSingletonScope();
container.bind<Command>(TYPES.Command).to(Shuffle).inSingletonScope(); container.bind<Command>(TYPES.Command).to(Shuffle).inSingletonScope();
container.bind<Command>(TYPES.Command).to(Skip).inSingletonScope();
container.bind<Command>(TYPES.Command).to(Unskip).inSingletonScope();
// Config values // Config values
container.bind<string>(TYPES.Config.DISCORD_TOKEN).toConstantValue(DISCORD_TOKEN); container.bind<string>(TYPES.Config.DISCORD_TOKEN).toConstantValue(DISCORD_TOKEN);