From ee2fd091c502159f4d035b59bb5729c1c7d3bbc5 Mon Sep 17 00:00:00 2001 From: Evan Lucas Date: Thu, 17 Mar 2016 07:35:58 -0500 Subject: [PATCH] command-manager: add ability to define aliases --- lib/command-manager.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/command-manager.js b/lib/command-manager.js index de187b8..b63e9fe 100644 --- a/lib/command-manager.js +++ b/lib/command-manager.js @@ -18,17 +18,27 @@ Manager.prototype.add = function add(name, desc, args) { this._names.sort() } +Manager.prototype.alias = function alias(name, orig) { + const obj = this.commands.get(orig) + if (!obj) + throw new Error('Cannot create alias. Original does not exist') + + this.add(name, obj.description, obj.args) +} + Manager.prototype.addDefaults = function addDefaults() { - this.add('/action', 'Send action to target', '[channel|nickname] [msg]') + this.add('/action', 'Send action to target', '[target] [msg]') this.add('/away', 'Set away status', '[away msg]') this.add('/join', 'Join a channel', '([channel[,channel]], [key[,key]]) || 0') this.add('/kick', 'Kick user from channel', ' ') + this.add('/leave', 'Leave a channel', '[channel] [msg]') + this.alias('/me', '/action') this.add('/mode', 'Set mode for target', ' ') this.add('/motd', 'Get the MOTD for the target', '[target]') this.add('/msg', 'Send message to target', '[nickname|channel] [msg]') this.add('/nick', 'Set/change your nickname', '') this.add('/notice', 'Send notice to target', '[nickname|channel] [msg]') - this.add('/part', '(or /leave) Part from a channel', '[channel] [msg]') + this.alias('/part', '/leave') this.add('/quit', 'Terminate session', '[msg]') this.add('/topic', `Set/remove a channel's topic`, '[channel] [topic]') }