1
0
mirror of https://github.com/moparisthebest/Yaaic synced 2024-11-23 09:22:19 -05:00

added getDescription and help command

This commit is contained in:
kell 2010-03-26 19:05:37 +01:00
parent 9efeb5b8af
commit 6d01720ca6
34 changed files with 5505 additions and 5234 deletions

View File

@ -32,6 +32,7 @@ import org.yaaic.model.Server;
*/
public abstract class BaseHandler
{
private String desc;
/**
* Execute the command
*
@ -50,6 +51,13 @@ public abstract class BaseHandler
*/
public abstract String getUsage();
/**
* Get the description for this command
*
* @return
*/
public abstract String getDescription();
/**
* Merge params to a string
*

View File

@ -21,6 +21,7 @@ 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;
@ -29,6 +30,7 @@ import org.yaaic.command.handler.DCCHandler;
import org.yaaic.command.handler.DeopHandler;
import org.yaaic.command.handler.DevoiceHandler;
import org.yaaic.command.handler.EchoHandler;
import org.yaaic.command.handler.HelpHandler;
import org.yaaic.command.handler.JoinHandler;
import org.yaaic.command.handler.KickHandler;
import org.yaaic.command.handler.MeHandler;
@ -95,6 +97,7 @@ public class CommandParser
commands.put("notice", new NoticeHandler());
commands.put("dcc", new DCCHandler());
commands.put("mode", new ModeHandler());
commands.put("help", new HelpHandler());
// Aliases
commands.put("j", commands.get("join"));
@ -115,6 +118,16 @@ public class CommandParser
return instance;
}
/**
* Get the commands HashMap
*
* @return HashMap - command, commandHandler
*/
public HashMap<String, BaseHandler> getCommands() {
return commands;
}
/**
* Is the given command a valid client command?
*

View File

@ -38,6 +38,8 @@ import android.content.Intent;
*/
public class CloseHandler extends BaseHandler
{
private String desc ="Closes the current window";
/**
* Execute /close
*/
@ -73,4 +75,12 @@ public class CloseHandler extends BaseHandler
{
return "/close";
}
/**
* Description of /close
*/
@Override
public String getDescription() {
return desc;
}
}

View File

@ -39,6 +39,8 @@ import org.yaaic.model.Server;
*/
public class DCCHandler extends BaseHandler
{
private String desc = "Send a file to a user";
/**
* Execute /dcc
*/
@ -76,4 +78,13 @@ public class DCCHandler extends BaseHandler
{
return "/dcc SEND <nickname> <file>";
}
/**
* Description of /dcc
*/
@Override
public String getDescription() {
return desc;
}
}

View File

@ -33,6 +33,7 @@ import org.yaaic.model.Server;
*/
public class DeopHandler extends BaseHandler
{
private String desc = "";
/**
* Execute /voice
*/
@ -58,4 +59,13 @@ public class DeopHandler extends BaseHandler
{
return "/voice <nickname>";
}
/**
* Description of /voice
*/
@Override
public String getDescription() {
return desc;
}
}

View File

@ -33,6 +33,7 @@ import org.yaaic.model.Server;
*/
public class DevoiceHandler extends BaseHandler
{
private String desc = "";
/**
* Execute /devoice
*/
@ -58,4 +59,13 @@ public class DevoiceHandler extends BaseHandler
{
return "/devoice <nickname>";
}
/**
* Description of /devoice
*/
@Override
public String getDescription() {
return desc;
}
}

View File

@ -37,6 +37,7 @@ import android.content.Intent;
*/
public class EchoHandler extends BaseHandler
{
private String desc = "";
/**
* Execute /echo
*/
@ -66,4 +67,13 @@ public class EchoHandler extends BaseHandler
{
return "/echo <text>";
}
/**
* Description of /echo
*/
@Override
public String getDescription() {
return desc;
}
}

View File

@ -0,0 +1,75 @@
package org.yaaic.command.handler;
import java.util.HashMap;
import java.util.Set;
import org.yaaic.command.BaseHandler;
import org.yaaic.command.CommandParser;
import org.yaaic.exception.CommandException;
import org.yaaic.irc.IRCService;
import org.yaaic.model.Broadcast;
import org.yaaic.model.Conversation;
import org.yaaic.model.Message;
import org.yaaic.model.Server;
import android.content.Intent;
/**
* Command: /help
*
* @author Karol Gliniecki <karol.gliniecki@googlemail.com>
*/
public class HelpHandler extends BaseHandler {
private String desc = "lists all available commands";
/**
* Execute /help
*/
@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();
Object[] commandKeys = commands.keySet().toArray();
for (Object command: commandKeys) {
commandList.append("/"+command.toString() + " - "+commands.get(command).getDescription()+"\n");
}
Message message = new Message(commandList.toString());
message.setColor(Message.COLOR_YELLOW);
conversation.addMessage(message);
Intent intent = Broadcast.createConversationIntent(
Broadcast.CONVERSATION_MESSAGE,
server.getId(),
conversation.getName()
);
service.sendBroadcast(intent);
}
/**
*
*Usage of /help
*/
@Override
public String getUsage() {
return "/help";
}
/**
* Description of /help
*/
@Override
public String getDescription() {
return desc;
}
}

View File

@ -33,6 +33,7 @@ import org.yaaic.model.Server;
*/
public class JoinHandler extends BaseHandler
{
private String desc = "join a channel";
/**
* Execute /join
*/
@ -56,4 +57,12 @@ public class JoinHandler extends BaseHandler
{
return "/join <channel> [<key>]";
}
/**
* Description of /join
*/
@Override
public String getDescription() {
return desc;
}
}

View File

@ -35,6 +35,8 @@ import org.yaaic.model.Server;
*/
public class KickHandler extends BaseHandler
{
private String desc = "kicks a user";
/**
* Execute /kick
*/
@ -60,4 +62,12 @@ public class KickHandler extends BaseHandler
{
return "/kick <nickname>";
}
/**
* Description of /kick
*/
@Override
public String getDescription() {
return desc;
}
}

View File

@ -38,6 +38,8 @@ import android.content.Intent;
*/
public class MeHandler extends BaseHandler
{
private String desc = "";
/**
* Execute /me
*/
@ -77,4 +79,9 @@ public class MeHandler extends BaseHandler
{
return "/me <text>";
}
@Override
public String getDescription() {
return desc;
}
}

View File

@ -35,6 +35,8 @@ import org.yaaic.model.Server;
*/
public class ModeHandler extends BaseHandler
{
private String desc = "";
/**
* Execute /mode
*/
@ -58,4 +60,9 @@ public class ModeHandler extends BaseHandler
{
return "/mode <channel> <mode>";
}
@Override
public String getDescription() {
return desc;
}
}

View File

@ -39,6 +39,8 @@ import android.content.Intent;
*/
public class NamesHandler extends BaseHandler
{
private String desc = "lists all users in channel";
/**
* Execute /names
*/
@ -76,4 +78,13 @@ public class NamesHandler extends BaseHandler
{
return "/names";
}
/**
* Description of /names
*/
@Override
public String getDescription() {
return desc;
}
}

View File

@ -33,6 +33,8 @@ import org.yaaic.model.Server;
*/
public class NickHandler extends BaseHandler
{
private String desc = "change own nickname";
/**
* Execute /nick
*/
@ -54,4 +56,13 @@ public class NickHandler extends BaseHandler
{
return "/nick <nickname>";
}
/**
* Description of /nick
*/
@Override
public String getDescription() {
return desc;
}
}

View File

@ -40,6 +40,8 @@ import android.content.Intent;
*/
public class NoticeHandler extends BaseHandler
{
private String desc = "Send a notice to an other user";
/**
* Execute /notice
*/
@ -74,4 +76,13 @@ public class NoticeHandler extends BaseHandler
{
return "/notice <nickname> <message>";
}
/**
* Description of /notice
*/
@Override
public String getDescription() {
return desc;
}
}

View File

@ -33,6 +33,8 @@ import org.yaaic.model.Server;
*/
public class OpHandler extends BaseHandler
{
private String desc = "";
/**
* Execute /deop
*/
@ -58,4 +60,13 @@ public class OpHandler extends BaseHandler
{
return "/op <nickname>";
}
/**
* Description of /deop
*/
@Override
public String getDescription() {
return desc;
}
}

View File

@ -35,6 +35,8 @@ import org.yaaic.model.Server;
*/
public class PartHandler extends BaseHandler
{
private String desc = "leave the current channel";
/**
* Execute /part
*/
@ -62,4 +64,9 @@ public class PartHandler extends BaseHandler
{
return "/part [<channel>]";
}
@Override
public String getDescription() {
return desc;
}
}

View File

@ -39,6 +39,8 @@ import android.content.Intent;
*/
public class QueryHandler extends BaseHandler
{
private String desc = "opens a private chat with a user";
/**
* Execute /query
*/
@ -78,4 +80,9 @@ public class QueryHandler extends BaseHandler
{
return "/query <nickname>";
}
@Override
public String getDescription() {
return desc;
}
}

View File

@ -33,6 +33,8 @@ import org.yaaic.model.Server;
*/
public class QuitHandler extends BaseHandler
{
private String desc = "leave current channel";
/**
* Execute /quit
*/
@ -54,4 +56,13 @@ public class QuitHandler extends BaseHandler
{
return "/quit [<reason>]";
}
/**
* Description of /quit
*/
@Override
public String getDescription() {
return desc;
}
}

View File

@ -36,6 +36,8 @@ import org.yaaic.model.Server;
*/
public class TopicHandler extends BaseHandler
{
private String desc = "show or change the current topic";
/**
* Execute /topic
*/
@ -65,4 +67,13 @@ public class TopicHandler extends BaseHandler
{
return "/topic [<topic>]";
}
/**
* Description of /topic
*/
@Override
public String getDescription() {
return desc;
}
}

View File

@ -33,6 +33,8 @@ import org.yaaic.model.Server;
*/
public class VoiceHandler extends BaseHandler
{
private String desc = "";
/**
* Execute /voice
*/
@ -58,4 +60,13 @@ public class VoiceHandler extends BaseHandler
{
return "/voice <nickname>";
}
/**
* Description of /voice
*/
@Override
public String getDescription() {
return desc;
}
}