From de1e761623f27c6ed0277d85d824c504c39a1188 Mon Sep 17 00:00:00 2001 From: Max Isom Date: Wed, 18 Mar 2020 18:57:21 -0500 Subject: [PATCH] Add aliases --- src/bot.ts | 4 +++- src/commands/clear.ts | 1 + src/commands/config.ts | 1 + src/commands/disconnect.ts | 7 +++++++ src/commands/fseek.ts | 1 + src/commands/help.ts | 1 + src/commands/index.ts | 1 + src/commands/pause.ts | 1 + src/commands/play.ts | 1 + src/commands/queue.ts | 1 + src/commands/seek.ts | 1 + src/commands/shortcuts.ts | 1 + src/commands/shuffle.ts | 1 + src/commands/skip.ts | 1 + src/commands/unskip.ts | 1 + 15 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/bot.ts b/src/bot.ts index 485becd..b5bde3f 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -28,7 +28,9 @@ export default class { public async listen(): Promise { // Load in commands container.getAll(TYPES.Command).forEach(command => { - this.commands.set(command.name, command); + const commandNames = [command.name, ...command.aliases]; + + commandNames.forEach(commandName => this.commands.set(commandName, command)); }); this.client.on('message', async (msg: Message) => { diff --git a/src/commands/clear.ts b/src/commands/clear.ts index 32e51e3..d35cc8c 100644 --- a/src/commands/clear.ts +++ b/src/commands/clear.ts @@ -7,6 +7,7 @@ import Command from '.'; @injectable() export default class implements Command { public name = 'clear'; + public aliases = ['c']; public examples = [ ['clear', 'clears all songs in queue except currently playing'] ]; diff --git a/src/commands/config.ts b/src/commands/config.ts index 17a401a..7452107 100644 --- a/src/commands/config.ts +++ b/src/commands/config.ts @@ -7,6 +7,7 @@ import Command from '.'; @injectable() export default class implements Command { public name = 'config'; + public aliases = []; public examples = [ ['config prefix !', 'set the prefix to !'], ['config channel music-commands', 'bind the bot to the music-commands channel'] diff --git a/src/commands/disconnect.ts b/src/commands/disconnect.ts index ecf41ab..9b271a3 100644 --- a/src/commands/disconnect.ts +++ b/src/commands/disconnect.ts @@ -2,11 +2,13 @@ import {Message} from 'discord.js'; import {TYPES} from '../types'; import {inject, injectable} from 'inversify'; import PlayerManager from '../managers/player'; +import errorMsg from '../utils/error-msg'; import Command from '.'; @injectable() export default class implements Command { public name = 'disconnect'; + public aliases = ['dc']; public examples = [ ['disconnect', 'pauses and disconnects player'] ]; @@ -20,6 +22,11 @@ export default class implements Command { public async execute(msg: Message, _: string []): Promise { const player = this.playerManager.get(msg.guild!.id); + if (!player.voiceConnection) { + await msg.channel.send(errorMsg('not connected')); + return; + } + player.disconnect(); await msg.channel.send('u betcha'); diff --git a/src/commands/fseek.ts b/src/commands/fseek.ts index 877e2a4..6eecdf3 100644 --- a/src/commands/fseek.ts +++ b/src/commands/fseek.ts @@ -10,6 +10,7 @@ import Command from '.'; @injectable() export default class implements Command { public name = 'fseek'; + public aliases = []; public examples = [ ['fseek 10', 'skips forward in current song by 10 seconds'] ]; diff --git a/src/commands/help.ts b/src/commands/help.ts index 97cafa4..5e25070 100644 --- a/src/commands/help.ts +++ b/src/commands/help.ts @@ -8,6 +8,7 @@ import container from '../inversify.config'; @injectable() export default class implements Command { public name = 'help'; + public aliases = ['h']; public examples = [ ['help', 'you don\'t need a description'] ]; diff --git a/src/commands/index.ts b/src/commands/index.ts index 160253c..dd16648 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -2,6 +2,7 @@ import {Message} from 'discord.js'; export default interface Command { name: string; + aliases: string[]; examples: string[][]; execute: (msg: Message, args: string[]) => Promise; } diff --git a/src/commands/pause.ts b/src/commands/pause.ts index 546b7a6..406c084 100644 --- a/src/commands/pause.ts +++ b/src/commands/pause.ts @@ -9,6 +9,7 @@ import Command from '.'; @injectable() export default class implements Command { public name = 'pause'; + public aliases = []; public examples = [ ['pause', 'pauses currently playing song'] ]; diff --git a/src/commands/play.ts b/src/commands/play.ts index bee2b4c..bcafdbf 100644 --- a/src/commands/play.ts +++ b/src/commands/play.ts @@ -15,6 +15,7 @@ import GetSongs from '../services/get-songs'; @injectable() export default class implements Command { public name = 'play'; + public aliases = ['p']; public examples = [ ['play', 'resume paused playback'], ['play https://www.youtube.com/watch?v=dQw4w9WgXcQ', 'plays a YouTube video'], diff --git a/src/commands/queue.ts b/src/commands/queue.ts index a194729..6c5cc63 100644 --- a/src/commands/queue.ts +++ b/src/commands/queue.ts @@ -7,6 +7,7 @@ import Command from '.'; @injectable() export default class implements Command { public name = 'queue'; + public aliases = ['q']; public examples = [ ['queue', 'shows current queue'] ]; diff --git a/src/commands/seek.ts b/src/commands/seek.ts index b3d8002..4a1c62d 100644 --- a/src/commands/seek.ts +++ b/src/commands/seek.ts @@ -10,6 +10,7 @@ import Command from '.'; @injectable() export default class implements Command { public name = 'seek'; + public aliases = []; public examples = [ ['seek 10', 'seeks to 10 seconds from beginning of song'], ['seek 1:30', 'seeks to 1 minute and 30 seconds from beginning of song'], diff --git a/src/commands/shortcuts.ts b/src/commands/shortcuts.ts index d8a885b..2b15812 100644 --- a/src/commands/shortcuts.ts +++ b/src/commands/shortcuts.ts @@ -7,6 +7,7 @@ import Command from '.'; @injectable() export default class implements Command { public name = 'shortcuts'; + public aliases = []; public examples = [ ['shortcuts', 'show all shortcuts'], ['shortcuts set s skip', 'aliases `s` to `skip`'], diff --git a/src/commands/shuffle.ts b/src/commands/shuffle.ts index 42f22fa..524081e 100644 --- a/src/commands/shuffle.ts +++ b/src/commands/shuffle.ts @@ -8,6 +8,7 @@ import Command from '.'; @injectable() export default class implements Command { public name = 'shuffle'; + public aliases = []; public examples = [ ['shuffle', 'shuffles the current queue'] ]; diff --git a/src/commands/skip.ts b/src/commands/skip.ts index 3160100..bdf67b5 100644 --- a/src/commands/skip.ts +++ b/src/commands/skip.ts @@ -8,6 +8,7 @@ import Command from '.'; @injectable() export default class implements Command { public name = 'skip'; + public aliases = ['s']; public examples = [ ['skip', 'skips the current song'] ]; diff --git a/src/commands/unskip.ts b/src/commands/unskip.ts index 16831c7..f5709c0 100644 --- a/src/commands/unskip.ts +++ b/src/commands/unskip.ts @@ -9,6 +9,7 @@ import Command from '.'; @injectable() export default class implements Command { public name = 'unskip'; + public aliases = ['back']; public examples = [ ['unskip', 'goes back in the queue by one song'] ];