Add aliases

This commit is contained in:
Max Isom 2020-03-18 18:57:21 -05:00
parent 8340f9b95a
commit de1e761623
15 changed files with 23 additions and 1 deletions

View file

@ -28,7 +28,9 @@ export default class {
public async listen(): Promise<string> { public async listen(): Promise<string> {
// Load in commands // Load in commands
container.getAll<Command>(TYPES.Command).forEach(command => { container.getAll<Command>(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) => { this.client.on('message', async (msg: Message) => {

View file

@ -7,6 +7,7 @@ import Command from '.';
@injectable() @injectable()
export default class implements Command { export default class implements Command {
public name = 'clear'; public name = 'clear';
public aliases = ['c'];
public examples = [ public examples = [
['clear', 'clears all songs in queue except currently playing'] ['clear', 'clears all songs in queue except currently playing']
]; ];

View file

@ -7,6 +7,7 @@ import Command from '.';
@injectable() @injectable()
export default class implements Command { export default class implements Command {
public name = 'config'; public name = 'config';
public aliases = [];
public examples = [ public examples = [
['config prefix !', 'set the prefix to !'], ['config prefix !', 'set the prefix to !'],
['config channel music-commands', 'bind the bot to the music-commands channel'] ['config channel music-commands', 'bind the bot to the music-commands channel']

View file

@ -2,11 +2,13 @@ import {Message} from 'discord.js';
import {TYPES} from '../types'; import {TYPES} from '../types';
import {inject, injectable} from 'inversify'; import {inject, injectable} from 'inversify';
import PlayerManager from '../managers/player'; import PlayerManager from '../managers/player';
import errorMsg from '../utils/error-msg';
import Command from '.'; import Command from '.';
@injectable() @injectable()
export default class implements Command { export default class implements Command {
public name = 'disconnect'; public name = 'disconnect';
public aliases = ['dc'];
public examples = [ public examples = [
['disconnect', 'pauses and disconnects player'] ['disconnect', 'pauses and disconnects player']
]; ];
@ -20,6 +22,11 @@ export default class implements Command {
public async execute(msg: Message, _: string []): Promise<void> { public async execute(msg: Message, _: string []): Promise<void> {
const player = this.playerManager.get(msg.guild!.id); const player = this.playerManager.get(msg.guild!.id);
if (!player.voiceConnection) {
await msg.channel.send(errorMsg('not connected'));
return;
}
player.disconnect(); player.disconnect();
await msg.channel.send('u betcha'); await msg.channel.send('u betcha');

View file

@ -10,6 +10,7 @@ import Command from '.';
@injectable() @injectable()
export default class implements Command { export default class implements Command {
public name = 'fseek'; public name = 'fseek';
public aliases = [];
public examples = [ public examples = [
['fseek 10', 'skips forward in current song by 10 seconds'] ['fseek 10', 'skips forward in current song by 10 seconds']
]; ];

View file

@ -8,6 +8,7 @@ import container from '../inversify.config';
@injectable() @injectable()
export default class implements Command { export default class implements Command {
public name = 'help'; public name = 'help';
public aliases = ['h'];
public examples = [ public examples = [
['help', 'you don\'t need a description'] ['help', 'you don\'t need a description']
]; ];

View file

@ -2,6 +2,7 @@ import {Message} from 'discord.js';
export default interface Command { export default interface Command {
name: string; name: string;
aliases: string[];
examples: string[][]; examples: string[][];
execute: (msg: Message, args: string[]) => Promise<void>; execute: (msg: Message, args: string[]) => Promise<void>;
} }

View file

@ -9,6 +9,7 @@ import Command from '.';
@injectable() @injectable()
export default class implements Command { export default class implements Command {
public name = 'pause'; public name = 'pause';
public aliases = [];
public examples = [ public examples = [
['pause', 'pauses currently playing song'] ['pause', 'pauses currently playing song']
]; ];

View file

@ -15,6 +15,7 @@ import GetSongs from '../services/get-songs';
@injectable() @injectable()
export default class implements Command { export default class implements Command {
public name = 'play'; public name = 'play';
public aliases = ['p'];
public examples = [ public examples = [
['play', 'resume paused playback'], ['play', 'resume paused playback'],
['play https://www.youtube.com/watch?v=dQw4w9WgXcQ', 'plays a YouTube video'], ['play https://www.youtube.com/watch?v=dQw4w9WgXcQ', 'plays a YouTube video'],

View file

@ -7,6 +7,7 @@ import Command from '.';
@injectable() @injectable()
export default class implements Command { export default class implements Command {
public name = 'queue'; public name = 'queue';
public aliases = ['q'];
public examples = [ public examples = [
['queue', 'shows current queue'] ['queue', 'shows current queue']
]; ];

View file

@ -10,6 +10,7 @@ import Command from '.';
@injectable() @injectable()
export default class implements Command { export default class implements Command {
public name = 'seek'; public name = 'seek';
public aliases = [];
public examples = [ public examples = [
['seek 10', 'seeks to 10 seconds from beginning of song'], ['seek 10', 'seeks to 10 seconds from beginning of song'],
['seek 1:30', 'seeks to 1 minute and 30 seconds from beginning of song'], ['seek 1:30', 'seeks to 1 minute and 30 seconds from beginning of song'],

View file

@ -7,6 +7,7 @@ import Command from '.';
@injectable() @injectable()
export default class implements Command { export default class implements Command {
public name = 'shortcuts'; public name = 'shortcuts';
public aliases = [];
public examples = [ public examples = [
['shortcuts', 'show all shortcuts'], ['shortcuts', 'show all shortcuts'],
['shortcuts set s skip', 'aliases `s` to `skip`'], ['shortcuts set s skip', 'aliases `s` to `skip`'],

View file

@ -8,6 +8,7 @@ import Command from '.';
@injectable() @injectable()
export default class implements Command { export default class implements Command {
public name = 'shuffle'; public name = 'shuffle';
public aliases = [];
public examples = [ public examples = [
['shuffle', 'shuffles the current queue'] ['shuffle', 'shuffles the current queue']
]; ];

View file

@ -8,6 +8,7 @@ import Command from '.';
@injectable() @injectable()
export default class implements Command { export default class implements Command {
public name = 'skip'; public name = 'skip';
public aliases = ['s'];
public examples = [ public examples = [
['skip', 'skips the current song'] ['skip', 'skips the current song']
]; ];

View file

@ -9,6 +9,7 @@ import Command from '.';
@injectable() @injectable()
export default class implements Command { export default class implements Command {
public name = 'unskip'; public name = 'unskip';
public aliases = ['back'];
public examples = [ public examples = [
['unskip', 'goes back in the queue by one song'] ['unskip', 'goes back in the queue by one song']
]; ];