1
0
mirror of https://github.com/moparisthebest/Yaaic synced 2025-01-10 05:08:18 -05:00

alias handling added

This commit is contained in:
kell 2010-04-06 20:26:42 +02:00
parent d1deb56bb6
commit 6df2fe5333

View File

@ -21,7 +21,6 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
package org.yaaic.command; package org.yaaic.command;
import java.util.HashMap; import java.util.HashMap;
import java.util.Set;
import android.content.Intent; import android.content.Intent;
@ -61,6 +60,7 @@ public class CommandParser
public static final String TAG = "Yaaic/CommandParser"; public static final String TAG = "Yaaic/CommandParser";
private HashMap<String, BaseHandler> commands; private HashMap<String, BaseHandler> commands;
private HashMap<String, String> aliases;
private static CommandParser instance; private static CommandParser instance;
private final static String[] serverCommands = { private final static String[] serverCommands = {
@ -99,9 +99,11 @@ public class CommandParser
commands.put("mode", new ModeHandler()); commands.put("mode", new ModeHandler());
commands.put("help", new HelpHandler()); commands.put("help", new HelpHandler());
aliases = new HashMap<String, String>();
// Aliases // Aliases
commands.put("j", commands.get("join")); aliases.put("j","join");
commands.put("q", commands.get("query")); aliases.put("q", "query");
aliases.put("h", "help");
} }
/** /**
@ -123,11 +125,22 @@ public class CommandParser
* *
* @return HashMap - command, commandHandler * @return HashMap - command, commandHandler
*/ */
public HashMap<String, BaseHandler> getCommands() { public HashMap<String, BaseHandler> getCommands()
{
return commands; return commands;
} }
/**
* Get the command aliases HashMap
*
* @return HashMap - alias, command the alias belogs to
*/
public HashMap<String, String> getAliases()
{
return aliases;
}
/** /**
* Is the given command a valid client command? * Is the given command a valid client command?
* *
@ -136,7 +149,13 @@ public class CommandParser
*/ */
public boolean isClientCommand(String command) public boolean isClientCommand(String command)
{ {
return commands.containsKey(command.toLowerCase()); if (commands.containsKey(command.toLowerCase())) {
return true;
} else if (aliases.containsKey(command.toLowerCase())) {
return true;
} else {
return false;
}
} }
/** /**
@ -168,7 +187,13 @@ public class CommandParser
*/ */
public void handleClientCommand(String type, String[] params, Server server, Conversation conversation, IRCService service) public void handleClientCommand(String type, String[] params, Server server, Conversation conversation, IRCService service)
{ {
BaseHandler command = commands.get(type); BaseHandler command = null;
if (commands.containsKey(type.toLowerCase())) {
command = commands.get(type);
} else if (aliases.containsKey(type.toLowerCase())) {
String commandInCommands = aliases.get(type.toLowerCase());
command = commands.get(commandInCommands);
}
try { try {
command.execute(params, server, conversation, service); command.execute(params, server, conversation, service);
} catch(CommandException e) { } catch(CommandException e) {