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:
parent
9efeb5b8af
commit
6d01720ca6
@ -32,6 +32,7 @@ import org.yaaic.model.Server;
|
|||||||
*/
|
*/
|
||||||
public abstract class BaseHandler
|
public abstract class BaseHandler
|
||||||
{
|
{
|
||||||
|
private String desc;
|
||||||
/**
|
/**
|
||||||
* Execute the command
|
* Execute the command
|
||||||
*
|
*
|
||||||
@ -50,6 +51,13 @@ public abstract class BaseHandler
|
|||||||
*/
|
*/
|
||||||
public abstract String getUsage();
|
public abstract String getUsage();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the description for this command
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract String getDescription();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Merge params to a string
|
* Merge params to a string
|
||||||
*
|
*
|
||||||
|
@ -21,6 +21,7 @@ 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;
|
||||||
|
|
||||||
@ -29,6 +30,7 @@ import org.yaaic.command.handler.DCCHandler;
|
|||||||
import org.yaaic.command.handler.DeopHandler;
|
import org.yaaic.command.handler.DeopHandler;
|
||||||
import org.yaaic.command.handler.DevoiceHandler;
|
import org.yaaic.command.handler.DevoiceHandler;
|
||||||
import org.yaaic.command.handler.EchoHandler;
|
import org.yaaic.command.handler.EchoHandler;
|
||||||
|
import org.yaaic.command.handler.HelpHandler;
|
||||||
import org.yaaic.command.handler.JoinHandler;
|
import org.yaaic.command.handler.JoinHandler;
|
||||||
import org.yaaic.command.handler.KickHandler;
|
import org.yaaic.command.handler.KickHandler;
|
||||||
import org.yaaic.command.handler.MeHandler;
|
import org.yaaic.command.handler.MeHandler;
|
||||||
@ -95,6 +97,7 @@ public class CommandParser
|
|||||||
commands.put("notice", new NoticeHandler());
|
commands.put("notice", new NoticeHandler());
|
||||||
commands.put("dcc", new DCCHandler());
|
commands.put("dcc", new DCCHandler());
|
||||||
commands.put("mode", new ModeHandler());
|
commands.put("mode", new ModeHandler());
|
||||||
|
commands.put("help", new HelpHandler());
|
||||||
|
|
||||||
// Aliases
|
// Aliases
|
||||||
commands.put("j", commands.get("join"));
|
commands.put("j", commands.get("join"));
|
||||||
@ -115,6 +118,16 @@ public class CommandParser
|
|||||||
return instance;
|
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?
|
* Is the given command a valid client command?
|
||||||
*
|
*
|
||||||
|
@ -38,6 +38,8 @@ import android.content.Intent;
|
|||||||
*/
|
*/
|
||||||
public class CloseHandler extends BaseHandler
|
public class CloseHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
|
private String desc ="Closes the current window";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute /close
|
* Execute /close
|
||||||
*/
|
*/
|
||||||
@ -73,4 +75,12 @@ public class CloseHandler extends BaseHandler
|
|||||||
{
|
{
|
||||||
return "/close";
|
return "/close";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of /close
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,8 @@ import org.yaaic.model.Server;
|
|||||||
*/
|
*/
|
||||||
public class DCCHandler extends BaseHandler
|
public class DCCHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
|
private String desc = "Send a file to a user";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute /dcc
|
* Execute /dcc
|
||||||
*/
|
*/
|
||||||
@ -76,4 +78,13 @@ public class DCCHandler extends BaseHandler
|
|||||||
{
|
{
|
||||||
return "/dcc SEND <nickname> <file>";
|
return "/dcc SEND <nickname> <file>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of /dcc
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@ import org.yaaic.model.Server;
|
|||||||
*/
|
*/
|
||||||
public class DeopHandler extends BaseHandler
|
public class DeopHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
|
private String desc = "";
|
||||||
/**
|
/**
|
||||||
* Execute /voice
|
* Execute /voice
|
||||||
*/
|
*/
|
||||||
@ -58,4 +59,13 @@ public class DeopHandler extends BaseHandler
|
|||||||
{
|
{
|
||||||
return "/voice <nickname>";
|
return "/voice <nickname>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of /voice
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@ import org.yaaic.model.Server;
|
|||||||
*/
|
*/
|
||||||
public class DevoiceHandler extends BaseHandler
|
public class DevoiceHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
|
private String desc = "";
|
||||||
/**
|
/**
|
||||||
* Execute /devoice
|
* Execute /devoice
|
||||||
*/
|
*/
|
||||||
@ -58,4 +59,13 @@ public class DevoiceHandler extends BaseHandler
|
|||||||
{
|
{
|
||||||
return "/devoice <nickname>";
|
return "/devoice <nickname>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of /devoice
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,7 @@ import android.content.Intent;
|
|||||||
*/
|
*/
|
||||||
public class EchoHandler extends BaseHandler
|
public class EchoHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
|
private String desc = "";
|
||||||
/**
|
/**
|
||||||
* Execute /echo
|
* Execute /echo
|
||||||
*/
|
*/
|
||||||
@ -66,4 +67,13 @@ public class EchoHandler extends BaseHandler
|
|||||||
{
|
{
|
||||||
return "/echo <text>";
|
return "/echo <text>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of /echo
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
75
src/org/yaaic/command/handler/HelpHandler.java
Normal file
75
src/org/yaaic/command/handler/HelpHandler.java
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -33,6 +33,7 @@ import org.yaaic.model.Server;
|
|||||||
*/
|
*/
|
||||||
public class JoinHandler extends BaseHandler
|
public class JoinHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
|
private String desc = "join a channel";
|
||||||
/**
|
/**
|
||||||
* Execute /join
|
* Execute /join
|
||||||
*/
|
*/
|
||||||
@ -56,4 +57,12 @@ public class JoinHandler extends BaseHandler
|
|||||||
{
|
{
|
||||||
return "/join <channel> [<key>]";
|
return "/join <channel> [<key>]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of /join
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,8 @@ import org.yaaic.model.Server;
|
|||||||
*/
|
*/
|
||||||
public class KickHandler extends BaseHandler
|
public class KickHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
|
private String desc = "kicks a user";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute /kick
|
* Execute /kick
|
||||||
*/
|
*/
|
||||||
@ -60,4 +62,12 @@ public class KickHandler extends BaseHandler
|
|||||||
{
|
{
|
||||||
return "/kick <nickname>";
|
return "/kick <nickname>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of /kick
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,8 @@ import android.content.Intent;
|
|||||||
*/
|
*/
|
||||||
public class MeHandler extends BaseHandler
|
public class MeHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
|
private String desc = "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute /me
|
* Execute /me
|
||||||
*/
|
*/
|
||||||
@ -77,4 +79,9 @@ public class MeHandler extends BaseHandler
|
|||||||
{
|
{
|
||||||
return "/me <text>";
|
return "/me <text>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,8 @@ import org.yaaic.model.Server;
|
|||||||
*/
|
*/
|
||||||
public class ModeHandler extends BaseHandler
|
public class ModeHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
|
private String desc = "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute /mode
|
* Execute /mode
|
||||||
*/
|
*/
|
||||||
@ -58,4 +60,9 @@ public class ModeHandler extends BaseHandler
|
|||||||
{
|
{
|
||||||
return "/mode <channel> <mode>";
|
return "/mode <channel> <mode>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,8 @@ import android.content.Intent;
|
|||||||
*/
|
*/
|
||||||
public class NamesHandler extends BaseHandler
|
public class NamesHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
|
private String desc = "lists all users in channel";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute /names
|
* Execute /names
|
||||||
*/
|
*/
|
||||||
@ -76,4 +78,13 @@ public class NamesHandler extends BaseHandler
|
|||||||
{
|
{
|
||||||
return "/names";
|
return "/names";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of /names
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,8 @@ import org.yaaic.model.Server;
|
|||||||
*/
|
*/
|
||||||
public class NickHandler extends BaseHandler
|
public class NickHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
|
private String desc = "change own nickname";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute /nick
|
* Execute /nick
|
||||||
*/
|
*/
|
||||||
@ -54,4 +56,13 @@ public class NickHandler extends BaseHandler
|
|||||||
{
|
{
|
||||||
return "/nick <nickname>";
|
return "/nick <nickname>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of /nick
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,8 @@ import android.content.Intent;
|
|||||||
*/
|
*/
|
||||||
public class NoticeHandler extends BaseHandler
|
public class NoticeHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
|
private String desc = "Send a notice to an other user";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute /notice
|
* Execute /notice
|
||||||
*/
|
*/
|
||||||
@ -74,4 +76,13 @@ public class NoticeHandler extends BaseHandler
|
|||||||
{
|
{
|
||||||
return "/notice <nickname> <message>";
|
return "/notice <nickname> <message>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of /notice
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,8 @@ import org.yaaic.model.Server;
|
|||||||
*/
|
*/
|
||||||
public class OpHandler extends BaseHandler
|
public class OpHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
|
private String desc = "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute /deop
|
* Execute /deop
|
||||||
*/
|
*/
|
||||||
@ -58,4 +60,13 @@ public class OpHandler extends BaseHandler
|
|||||||
{
|
{
|
||||||
return "/op <nickname>";
|
return "/op <nickname>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of /deop
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,8 @@ import org.yaaic.model.Server;
|
|||||||
*/
|
*/
|
||||||
public class PartHandler extends BaseHandler
|
public class PartHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
|
private String desc = "leave the current channel";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute /part
|
* Execute /part
|
||||||
*/
|
*/
|
||||||
@ -62,4 +64,9 @@ public class PartHandler extends BaseHandler
|
|||||||
{
|
{
|
||||||
return "/part [<channel>]";
|
return "/part [<channel>]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,8 @@ import android.content.Intent;
|
|||||||
*/
|
*/
|
||||||
public class QueryHandler extends BaseHandler
|
public class QueryHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
|
private String desc = "opens a private chat with a user";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute /query
|
* Execute /query
|
||||||
*/
|
*/
|
||||||
@ -78,4 +80,9 @@ public class QueryHandler extends BaseHandler
|
|||||||
{
|
{
|
||||||
return "/query <nickname>";
|
return "/query <nickname>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,8 @@ import org.yaaic.model.Server;
|
|||||||
*/
|
*/
|
||||||
public class QuitHandler extends BaseHandler
|
public class QuitHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
|
private String desc = "leave current channel";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute /quit
|
* Execute /quit
|
||||||
*/
|
*/
|
||||||
@ -54,4 +56,13 @@ public class QuitHandler extends BaseHandler
|
|||||||
{
|
{
|
||||||
return "/quit [<reason>]";
|
return "/quit [<reason>]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of /quit
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,8 @@ import org.yaaic.model.Server;
|
|||||||
*/
|
*/
|
||||||
public class TopicHandler extends BaseHandler
|
public class TopicHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
|
private String desc = "show or change the current topic";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute /topic
|
* Execute /topic
|
||||||
*/
|
*/
|
||||||
@ -65,4 +67,13 @@ public class TopicHandler extends BaseHandler
|
|||||||
{
|
{
|
||||||
return "/topic [<topic>]";
|
return "/topic [<topic>]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of /topic
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,8 @@ import org.yaaic.model.Server;
|
|||||||
*/
|
*/
|
||||||
public class VoiceHandler extends BaseHandler
|
public class VoiceHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
|
private String desc = "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute /voice
|
* Execute /voice
|
||||||
*/
|
*/
|
||||||
@ -58,4 +60,13 @@ public class VoiceHandler extends BaseHandler
|
|||||||
{
|
{
|
||||||
return "/voice <nickname>";
|
return "/voice <nickname>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description of /voice
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user