mirror of
https://github.com/moparisthebest/Yaaic
synced 2025-01-09 20:58:02 -05:00
Merge branch 'master' of git://github.com/kell/Yaaic into integration
This commit is contained in:
commit
d5c1daaa3e
@ -21,7 +21,6 @@ along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
||||
package org.yaaic.command;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
|
||||
import android.content.Intent;
|
||||
|
||||
@ -59,6 +58,7 @@ import org.yaaic.model.Server;
|
||||
public class CommandParser
|
||||
{
|
||||
private HashMap<String, BaseHandler> commands;
|
||||
private HashMap<String, String> aliases;
|
||||
private static CommandParser instance;
|
||||
|
||||
private final static String[] serverCommands = {
|
||||
@ -97,9 +97,11 @@ public class CommandParser
|
||||
commands.put("mode", new ModeHandler());
|
||||
commands.put("help", new HelpHandler());
|
||||
|
||||
aliases = new HashMap<String, String>();
|
||||
// Aliases
|
||||
commands.put("j", commands.get("join"));
|
||||
commands.put("q", commands.get("query"));
|
||||
aliases.put("j","join");
|
||||
aliases.put("q", "query");
|
||||
aliases.put("h", "help");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -121,11 +123,22 @@ public class CommandParser
|
||||
*
|
||||
* @return HashMap - command, commandHandler
|
||||
*/
|
||||
public HashMap<String, BaseHandler> getCommands() {
|
||||
|
||||
public HashMap<String, BaseHandler> getCommands()
|
||||
{
|
||||
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?
|
||||
*
|
||||
@ -134,7 +147,13 @@ public class CommandParser
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -166,7 +185,13 @@ public class CommandParser
|
||||
*/
|
||||
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 {
|
||||
command.execute(params, server, conversation, service);
|
||||
} catch(CommandException e) {
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.yaaic.command.handler;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
|
||||
import org.yaaic.command.BaseHandler;
|
||||
import org.yaaic.command.CommandParser;
|
||||
@ -28,19 +27,26 @@ public class HelpHandler extends BaseHandler {
|
||||
*/
|
||||
@Override
|
||||
public void execute(String[] params, Server server, Conversation conversation, IRCService service) throws CommandException {
|
||||
if (conversation.getType() != Conversation.TYPE_CHANNEL) {
|
||||
throw new CommandException("Only usable from within a channel");
|
||||
}
|
||||
|
||||
CommandParser cp = CommandParser.getInstance();
|
||||
|
||||
StringBuffer commandList = new StringBuffer("available commands: \n");
|
||||
HashMap<String, BaseHandler> commands = cp.getCommands();
|
||||
HashMap<String, String> aliases = cp.getAliases();
|
||||
|
||||
Object[] commandKeys = commands.keySet().toArray();
|
||||
Object[] aliasesKeys = aliases.keySet().toArray();
|
||||
|
||||
for (Object command: commandKeys) {
|
||||
commandList.append("/"+command.toString() + " - "+commands.get(command).getDescription()+"\n");
|
||||
String alias = "";
|
||||
for (Object aliasCommand: aliasesKeys) {
|
||||
System.out.println("alias: "+aliases.get(aliasCommand));
|
||||
if (command.equals(aliases.get(aliasCommand))) {
|
||||
alias = " or /"+aliasCommand;
|
||||
break;
|
||||
}
|
||||
}
|
||||
commandList.append("/"+command.toString() + alias+" - "+commands.get(command).getDescription()+"\n");
|
||||
}
|
||||
|
||||
Message message = new Message(commandList.toString());
|
||||
@ -60,7 +66,8 @@ public class HelpHandler extends BaseHandler {
|
||||
*Usage of /help
|
||||
*/
|
||||
@Override
|
||||
public String getUsage() {
|
||||
public String getUsage()
|
||||
{
|
||||
return "/help";
|
||||
}
|
||||
|
||||
@ -68,7 +75,8 @@ public class HelpHandler extends BaseHandler {
|
||||
* Description of /help
|
||||
*/
|
||||
@Override
|
||||
public String getDescription() {
|
||||
public String getDescription()
|
||||
{
|
||||
return desc;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user