mirror of
https://github.com/moparisthebest/Yaaic
synced 2024-12-26 01:18:57 -05:00
Moved command handlers to org.yaaic.command.handler and renamend them.
This commit is contained in:
parent
0342c6ea7f
commit
64c7ad2f45
@ -29,7 +29,7 @@ import org.yaaic.model.Server;
|
|||||||
*
|
*
|
||||||
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
||||||
*/
|
*/
|
||||||
public abstract class BaseCommand
|
public abstract class BaseHandler
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Execute the command
|
* Execute the command
|
@ -22,6 +22,18 @@ package org.yaaic.command;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import org.yaaic.command.handler.DeopHandler;
|
||||||
|
import org.yaaic.command.handler.DevoiceHandler;
|
||||||
|
import org.yaaic.command.handler.EchoHandler;
|
||||||
|
import org.yaaic.command.handler.JoinHandler;
|
||||||
|
import org.yaaic.command.handler.KickHandler;
|
||||||
|
import org.yaaic.command.handler.MeHandler;
|
||||||
|
import org.yaaic.command.handler.NamesHandler;
|
||||||
|
import org.yaaic.command.handler.NickHandler;
|
||||||
|
import org.yaaic.command.handler.OpHandler;
|
||||||
|
import org.yaaic.command.handler.QuitHandler;
|
||||||
|
import org.yaaic.command.handler.TopicHandler;
|
||||||
|
import org.yaaic.command.handler.VoiceHandler;
|
||||||
import org.yaaic.irc.IRCService;
|
import org.yaaic.irc.IRCService;
|
||||||
import org.yaaic.model.Broadcast;
|
import org.yaaic.model.Broadcast;
|
||||||
import org.yaaic.model.Channel;
|
import org.yaaic.model.Channel;
|
||||||
@ -39,7 +51,7 @@ public class CommandParser
|
|||||||
{
|
{
|
||||||
public static final String TAG = "Yaaic/CommandParser";
|
public static final String TAG = "Yaaic/CommandParser";
|
||||||
|
|
||||||
private HashMap<String, BaseCommand> commands;
|
private HashMap<String, BaseHandler> commands;
|
||||||
private static CommandParser instance;
|
private static CommandParser instance;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -47,20 +59,20 @@ public class CommandParser
|
|||||||
*/
|
*/
|
||||||
private CommandParser()
|
private CommandParser()
|
||||||
{
|
{
|
||||||
commands = new HashMap<String, BaseCommand>();
|
commands = new HashMap<String, BaseHandler>();
|
||||||
|
|
||||||
commands.put("nick", new NickCommand());
|
commands.put("nick", new NickHandler());
|
||||||
commands.put("join", new JoinCommand());
|
commands.put("join", new JoinHandler());
|
||||||
commands.put("me", new MeCommand());
|
commands.put("me", new MeHandler());
|
||||||
commands.put("names", new NamesCommand());
|
commands.put("names", new NamesHandler());
|
||||||
commands.put("echo", new EchoCommand());
|
commands.put("echo", new EchoHandler());
|
||||||
commands.put("topic", new TopicCommand());
|
commands.put("topic", new TopicHandler());
|
||||||
commands.put("quit", new QuitCommand());
|
commands.put("quit", new QuitHandler());
|
||||||
commands.put("op", new OpCommand());
|
commands.put("op", new OpHandler());
|
||||||
commands.put("voice", new VoiceCommand());
|
commands.put("voice", new VoiceHandler());
|
||||||
commands.put("deop", new DeopCommand());
|
commands.put("deop", new DeopHandler());
|
||||||
commands.put("devoice", new DevoiceCommand());
|
commands.put("devoice", new DevoiceHandler());
|
||||||
commands.put("kick", new KickCommand());
|
commands.put("kick", new KickHandler());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -100,7 +112,7 @@ public class CommandParser
|
|||||||
String type = params[0];
|
String type = params[0];
|
||||||
|
|
||||||
if (isCommand(type)) {
|
if (isCommand(type)) {
|
||||||
BaseCommand command = commands.get(type);
|
BaseHandler command = commands.get(type);
|
||||||
try {
|
try {
|
||||||
command.execute(params, server, channel, service);
|
command.execute(params, server, channel, service);
|
||||||
} catch(CommandException e) {
|
} catch(CommandException e) {
|
||||||
|
@ -18,8 +18,10 @@ GNU General Public License for more details.
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package org.yaaic.command;
|
package org.yaaic.command.handler;
|
||||||
|
|
||||||
|
import org.yaaic.command.BaseHandler;
|
||||||
|
import org.yaaic.command.CommandException;
|
||||||
import org.yaaic.irc.IRCService;
|
import org.yaaic.irc.IRCService;
|
||||||
import org.yaaic.model.Channel;
|
import org.yaaic.model.Channel;
|
||||||
import org.yaaic.model.Server;
|
import org.yaaic.model.Server;
|
||||||
@ -29,7 +31,7 @@ import org.yaaic.model.Server;
|
|||||||
*
|
*
|
||||||
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
||||||
*/
|
*/
|
||||||
public class DeopCommand extends BaseCommand
|
public class DeopHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Execute /voice
|
* Execute /voice
|
@ -18,8 +18,10 @@ GNU General Public License for more details.
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package org.yaaic.command;
|
package org.yaaic.command.handler;
|
||||||
|
|
||||||
|
import org.yaaic.command.BaseHandler;
|
||||||
|
import org.yaaic.command.CommandException;
|
||||||
import org.yaaic.irc.IRCService;
|
import org.yaaic.irc.IRCService;
|
||||||
import org.yaaic.model.Channel;
|
import org.yaaic.model.Channel;
|
||||||
import org.yaaic.model.Server;
|
import org.yaaic.model.Server;
|
||||||
@ -29,7 +31,7 @@ import org.yaaic.model.Server;
|
|||||||
*
|
*
|
||||||
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
||||||
*/
|
*/
|
||||||
public class DevoiceCommand extends BaseCommand
|
public class DevoiceHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Execute /devoice
|
* Execute /devoice
|
@ -18,8 +18,10 @@ GNU General Public License for more details.
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package org.yaaic.command;
|
package org.yaaic.command.handler;
|
||||||
|
|
||||||
|
import org.yaaic.command.BaseHandler;
|
||||||
|
import org.yaaic.command.CommandException;
|
||||||
import org.yaaic.irc.IRCService;
|
import org.yaaic.irc.IRCService;
|
||||||
import org.yaaic.model.Broadcast;
|
import org.yaaic.model.Broadcast;
|
||||||
import org.yaaic.model.Channel;
|
import org.yaaic.model.Channel;
|
||||||
@ -33,7 +35,7 @@ import android.content.Intent;
|
|||||||
*
|
*
|
||||||
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
||||||
*/
|
*/
|
||||||
public class EchoCommand extends BaseCommand
|
public class EchoHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Execute /echo
|
* Execute /echo
|
||||||
@ -42,7 +44,7 @@ public class EchoCommand extends BaseCommand
|
|||||||
public void execute(String[] params, Server server, Channel channel, IRCService service) throws CommandException
|
public void execute(String[] params, Server server, Channel channel, IRCService service) throws CommandException
|
||||||
{
|
{
|
||||||
if (params.length > 1) {
|
if (params.length > 1) {
|
||||||
Message message = new Message(BaseCommand.mergeParams(params));
|
Message message = new Message(BaseHandler.mergeParams(params));
|
||||||
channel.addMessage(message);
|
channel.addMessage(message);
|
||||||
|
|
||||||
Intent intent = new Intent(Broadcast.CHANNEL_MESSAGE);
|
Intent intent = new Intent(Broadcast.CHANNEL_MESSAGE);
|
@ -18,8 +18,10 @@ GNU General Public License for more details.
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package org.yaaic.command;
|
package org.yaaic.command.handler;
|
||||||
|
|
||||||
|
import org.yaaic.command.BaseHandler;
|
||||||
|
import org.yaaic.command.CommandException;
|
||||||
import org.yaaic.irc.IRCService;
|
import org.yaaic.irc.IRCService;
|
||||||
import org.yaaic.model.Channel;
|
import org.yaaic.model.Channel;
|
||||||
import org.yaaic.model.Server;
|
import org.yaaic.model.Server;
|
||||||
@ -29,7 +31,7 @@ import org.yaaic.model.Server;
|
|||||||
*
|
*
|
||||||
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
||||||
*/
|
*/
|
||||||
public class JoinCommand extends BaseCommand
|
public class JoinHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Execute /join
|
* Execute /join
|
@ -18,8 +18,10 @@ GNU General Public License for more details.
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package org.yaaic.command;
|
package org.yaaic.command.handler;
|
||||||
|
|
||||||
|
import org.yaaic.command.BaseHandler;
|
||||||
|
import org.yaaic.command.CommandException;
|
||||||
import org.yaaic.irc.IRCService;
|
import org.yaaic.irc.IRCService;
|
||||||
import org.yaaic.model.Channel;
|
import org.yaaic.model.Channel;
|
||||||
import org.yaaic.model.Server;
|
import org.yaaic.model.Server;
|
||||||
@ -31,7 +33,7 @@ import org.yaaic.model.Server;
|
|||||||
*
|
*
|
||||||
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
||||||
*/
|
*/
|
||||||
public class KickCommand extends BaseCommand
|
public class KickHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Execute /kick
|
* Execute /kick
|
@ -18,9 +18,11 @@ GNU General Public License for more details.
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package org.yaaic.command;
|
package org.yaaic.command.handler;
|
||||||
|
|
||||||
import org.yaaic.R;
|
import org.yaaic.R;
|
||||||
|
import org.yaaic.command.BaseHandler;
|
||||||
|
import org.yaaic.command.CommandException;
|
||||||
import org.yaaic.irc.IRCService;
|
import org.yaaic.irc.IRCService;
|
||||||
import org.yaaic.model.Broadcast;
|
import org.yaaic.model.Broadcast;
|
||||||
import org.yaaic.model.Channel;
|
import org.yaaic.model.Channel;
|
||||||
@ -34,7 +36,7 @@ import android.content.Intent;
|
|||||||
*
|
*
|
||||||
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
||||||
*/
|
*/
|
||||||
public class MeCommand extends BaseCommand
|
public class MeHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Execute /me
|
* Execute /me
|
||||||
@ -43,7 +45,7 @@ public class MeCommand extends BaseCommand
|
|||||||
public void execute(String[] params, Server server, Channel channel, IRCService service) throws CommandException
|
public void execute(String[] params, Server server, Channel channel, IRCService service) throws CommandException
|
||||||
{
|
{
|
||||||
if (params.length > 1) {
|
if (params.length > 1) {
|
||||||
String action = BaseCommand.mergeParams(params);
|
String action = BaseHandler.mergeParams(params);
|
||||||
String nickname = service.getConnection(server.getId()).getNick();
|
String nickname = service.getConnection(server.getId()).getNick();
|
||||||
|
|
||||||
Message message = new Message(nickname + " " + action);
|
Message message = new Message(nickname + " " + action);
|
@ -18,9 +18,11 @@ GNU General Public License for more details.
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package org.yaaic.command;
|
package org.yaaic.command.handler;
|
||||||
|
|
||||||
import org.jibble.pircbot.User;
|
import org.jibble.pircbot.User;
|
||||||
|
import org.yaaic.command.BaseHandler;
|
||||||
|
import org.yaaic.command.CommandException;
|
||||||
import org.yaaic.irc.IRCService;
|
import org.yaaic.irc.IRCService;
|
||||||
import org.yaaic.model.Broadcast;
|
import org.yaaic.model.Broadcast;
|
||||||
import org.yaaic.model.Channel;
|
import org.yaaic.model.Channel;
|
||||||
@ -35,7 +37,7 @@ import android.content.Intent;
|
|||||||
*
|
*
|
||||||
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
||||||
*/
|
*/
|
||||||
public class NamesCommand extends BaseCommand
|
public class NamesHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Execute /names
|
* Execute /names
|
@ -18,8 +18,10 @@ GNU General Public License for more details.
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package org.yaaic.command;
|
package org.yaaic.command.handler;
|
||||||
|
|
||||||
|
import org.yaaic.command.BaseHandler;
|
||||||
|
import org.yaaic.command.CommandException;
|
||||||
import org.yaaic.irc.IRCService;
|
import org.yaaic.irc.IRCService;
|
||||||
import org.yaaic.model.Channel;
|
import org.yaaic.model.Channel;
|
||||||
import org.yaaic.model.Server;
|
import org.yaaic.model.Server;
|
||||||
@ -29,7 +31,7 @@ import org.yaaic.model.Server;
|
|||||||
*
|
*
|
||||||
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
||||||
*/
|
*/
|
||||||
public class NickCommand extends BaseCommand
|
public class NickHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Execute /nick
|
* Execute /nick
|
@ -18,8 +18,10 @@ GNU General Public License for more details.
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package org.yaaic.command;
|
package org.yaaic.command.handler;
|
||||||
|
|
||||||
|
import org.yaaic.command.BaseHandler;
|
||||||
|
import org.yaaic.command.CommandException;
|
||||||
import org.yaaic.irc.IRCService;
|
import org.yaaic.irc.IRCService;
|
||||||
import org.yaaic.model.Channel;
|
import org.yaaic.model.Channel;
|
||||||
import org.yaaic.model.Server;
|
import org.yaaic.model.Server;
|
||||||
@ -29,7 +31,7 @@ import org.yaaic.model.Server;
|
|||||||
*
|
*
|
||||||
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
||||||
*/
|
*/
|
||||||
public class OpCommand extends BaseCommand
|
public class OpHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Execute /deop
|
* Execute /deop
|
@ -18,8 +18,10 @@ GNU General Public License for more details.
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package org.yaaic.command;
|
package org.yaaic.command.handler;
|
||||||
|
|
||||||
|
import org.yaaic.command.BaseHandler;
|
||||||
|
import org.yaaic.command.CommandException;
|
||||||
import org.yaaic.irc.IRCService;
|
import org.yaaic.irc.IRCService;
|
||||||
import org.yaaic.model.Channel;
|
import org.yaaic.model.Channel;
|
||||||
import org.yaaic.model.Server;
|
import org.yaaic.model.Server;
|
||||||
@ -29,7 +31,7 @@ import org.yaaic.model.Server;
|
|||||||
*
|
*
|
||||||
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
||||||
*/
|
*/
|
||||||
public class QuitCommand extends BaseCommand
|
public class QuitHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Execute /quit
|
* Execute /quit
|
||||||
@ -40,7 +42,7 @@ public class QuitCommand extends BaseCommand
|
|||||||
if (params.length == 1) {
|
if (params.length == 1) {
|
||||||
service.getConnection(server.getId()).quitServer();
|
service.getConnection(server.getId()).quitServer();
|
||||||
} else {
|
} else {
|
||||||
service.getConnection(server.getId()).quitServer(BaseCommand.mergeParams(params));
|
service.getConnection(server.getId()).quitServer(BaseHandler.mergeParams(params));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -18,8 +18,9 @@ GNU General Public License for more details.
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package org.yaaic.command;
|
package org.yaaic.command.handler;
|
||||||
|
|
||||||
|
import org.yaaic.command.BaseHandler;
|
||||||
import org.yaaic.irc.IRCService;
|
import org.yaaic.irc.IRCService;
|
||||||
import org.yaaic.model.Channel;
|
import org.yaaic.model.Channel;
|
||||||
import org.yaaic.model.Server;
|
import org.yaaic.model.Server;
|
||||||
@ -31,7 +32,7 @@ import org.yaaic.model.Server;
|
|||||||
*
|
*
|
||||||
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
||||||
*/
|
*/
|
||||||
public class TopicCommand extends BaseCommand
|
public class TopicHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Execute /topic
|
* Execute /topic
|
||||||
@ -44,7 +45,7 @@ public class TopicCommand extends BaseCommand
|
|||||||
service.getConnection(server.getId()).onTopic(channel.getName(), channel.getTopic(), "", 0, false);
|
service.getConnection(server.getId()).onTopic(channel.getName(), channel.getTopic(), "", 0, false);
|
||||||
} else if (params.length > 1) {
|
} else if (params.length > 1) {
|
||||||
// Change topic
|
// Change topic
|
||||||
service.getConnection(server.getId()).setTopic(channel.getName(), BaseCommand.mergeParams(params));
|
service.getConnection(server.getId()).setTopic(channel.getName(), BaseHandler.mergeParams(params));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -18,8 +18,10 @@ GNU General Public License for more details.
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package org.yaaic.command;
|
package org.yaaic.command.handler;
|
||||||
|
|
||||||
|
import org.yaaic.command.BaseHandler;
|
||||||
|
import org.yaaic.command.CommandException;
|
||||||
import org.yaaic.irc.IRCService;
|
import org.yaaic.irc.IRCService;
|
||||||
import org.yaaic.model.Channel;
|
import org.yaaic.model.Channel;
|
||||||
import org.yaaic.model.Server;
|
import org.yaaic.model.Server;
|
||||||
@ -29,7 +31,7 @@ import org.yaaic.model.Server;
|
|||||||
*
|
*
|
||||||
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
||||||
*/
|
*/
|
||||||
public class VoiceCommand extends BaseCommand
|
public class VoiceHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Execute /voice
|
* Execute /voice
|
Loading…
Reference in New Issue
Block a user