From e55acbb718c5b36315010b5d093b1554712aca4b Mon Sep 17 00:00:00 2001 From: Max Isom Date: Sun, 15 Mar 2020 16:55:44 -0500 Subject: [PATCH] Add skip/unskip --- src/commands/skip.ts | 33 +++++++++++++++++++++++++++++++++ src/commands/unskip.ts | 33 +++++++++++++++++++++++++++++++++ src/inversify.config.ts | 4 ++++ 3 files changed, 70 insertions(+) create mode 100644 src/commands/skip.ts create mode 100644 src/commands/unskip.ts diff --git a/src/commands/skip.ts b/src/commands/skip.ts new file mode 100644 index 0000000..87fb94d --- /dev/null +++ b/src/commands/skip.ts @@ -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 { + 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'); + } + } +} diff --git a/src/commands/unskip.ts b/src/commands/unskip.ts new file mode 100644 index 0000000..01fef7a --- /dev/null +++ b/src/commands/unskip.ts @@ -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 { + 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'); + } + } +} diff --git a/src/inversify.config.ts b/src/inversify.config.ts index 9b91743..759a27ac 100644 --- a/src/inversify.config.ts +++ b/src/inversify.config.ts @@ -28,6 +28,8 @@ import Play from './commands/play'; import QueueCommad from './commands/queue'; import Seek from './commands/seek'; import Shuffle from './commands/shuffle'; +import Skip from './commands/skip'; +import Unskip from './commands/unskip'; let container = new Container(); @@ -47,6 +49,8 @@ container.bind(TYPES.Command).to(Play).inSingletonScope(); container.bind(TYPES.Command).to(QueueCommad).inSingletonScope(); container.bind(TYPES.Command).to(Seek).inSingletonScope(); container.bind(TYPES.Command).to(Shuffle).inSingletonScope(); +container.bind(TYPES.Command).to(Skip).inSingletonScope(); +container.bind(TYPES.Command).to(Unskip).inSingletonScope(); // Config values container.bind(TYPES.Config.DISCORD_TOKEN).toConstantValue(DISCORD_TOKEN);