123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588 |
- /*
- * Copyright (c) 2006-2014 DMDirc Developers
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
- package com.dmdirc.commandparser.commands;
-
- import com.dmdirc.commandparser.CommandInfo;
- import com.dmdirc.commandparser.commands.channel.Ban;
- import com.dmdirc.commandparser.commands.channel.Cycle;
- import com.dmdirc.commandparser.commands.channel.Invite;
- import com.dmdirc.commandparser.commands.channel.KickReason;
- import com.dmdirc.commandparser.commands.channel.Mode;
- import com.dmdirc.commandparser.commands.channel.Names;
- import com.dmdirc.commandparser.commands.channel.Part;
- import com.dmdirc.commandparser.commands.channel.SetNickColour;
- import com.dmdirc.commandparser.commands.channel.ShowTopic;
- import com.dmdirc.commandparser.commands.chat.Me;
- import com.dmdirc.commandparser.commands.global.AliasCommand;
- import com.dmdirc.commandparser.commands.global.AllServers;
- import com.dmdirc.commandparser.commands.global.Clear;
- import com.dmdirc.commandparser.commands.global.Echo;
- import com.dmdirc.commandparser.commands.global.Exit;
- import com.dmdirc.commandparser.commands.global.Help;
- import com.dmdirc.commandparser.commands.global.Ifplugin;
- import com.dmdirc.commandparser.commands.global.LoadPlugin;
- import com.dmdirc.commandparser.commands.global.NewServer;
- import com.dmdirc.commandparser.commands.global.Notify;
- import com.dmdirc.commandparser.commands.global.OpenWindow;
- import com.dmdirc.commandparser.commands.global.ReloadActions;
- import com.dmdirc.commandparser.commands.global.ReloadIdentities;
- import com.dmdirc.commandparser.commands.global.ReloadPlugin;
- import com.dmdirc.commandparser.commands.global.SaveConfig;
- import com.dmdirc.commandparser.commands.global.SetCommand;
- import com.dmdirc.commandparser.commands.global.UnloadPlugin;
- import com.dmdirc.commandparser.commands.server.AllChannels;
- import com.dmdirc.commandparser.commands.server.Away;
- import com.dmdirc.commandparser.commands.server.Back;
- import com.dmdirc.commandparser.commands.server.ChangeServer;
- import com.dmdirc.commandparser.commands.server.Ctcp;
- import com.dmdirc.commandparser.commands.server.Disconnect;
- import com.dmdirc.commandparser.commands.server.Ignore;
- import com.dmdirc.commandparser.commands.server.JoinChannelCommand;
- import com.dmdirc.commandparser.commands.server.Message;
- import com.dmdirc.commandparser.commands.server.Nick;
- import com.dmdirc.commandparser.commands.server.Notice;
- import com.dmdirc.commandparser.commands.server.OpenQuery;
- import com.dmdirc.commandparser.commands.server.Raw;
- import com.dmdirc.commandparser.commands.server.RawServerCommand;
- import com.dmdirc.commandparser.commands.server.Reconnect;
- import com.dmdirc.commandparser.commands.server.Umode;
- import com.dmdirc.interfaces.CommandController;
- import com.dmdirc.interfaces.CommandController.CommandDetails;
-
- import java.util.HashSet;
- import java.util.Set;
-
- import dagger.Module;
- import dagger.Provides;
-
- /**
- * Provides commands for injection into the command manager.
- */
- @Module(library = true, complete = false)
- public class CommandModule {
-
- /**
- * Provides the /me command.
- *
- * @param command The instantiated command.
- * @return The command's details.
- */
- @Provides(type = Provides.Type.SET)
- public CommandDetails getCommand(final Me command) {
- return new SimpleCommandDetails(command, Me.INFO);
- }
-
- /**
- * Provides the /ban command.
- *
- * @param command The instantiated command.
- * @return The command's details.
- */
- @Provides(type = Provides.Type.SET)
- public CommandDetails getCommand(final Ban command) {
- return new SimpleCommandDetails(command, Ban.INFO);
- }
-
- /**
- * Provides the /cycle command.
- *
- * @param command The instantiated command.
- * @return The command's details.
- */
- @Provides(type = Provides.Type.SET)
- public CommandDetails getCommand(final Cycle command) {
- return new SimpleCommandDetails(command, Cycle.INFO);
- }
-
- /**
- * Provides the /invite command.
- *
- * @param command The instantiated command.
- * @return The command's details.
- */
- @Provides(type = Provides.Type.SET)
- public CommandDetails getCommand(final Invite command) {
- return new SimpleCommandDetails(command, Invite.INFO);
- }
-
- /**
- * Provides the /kick command.
- *
- * @param command The instantiated command.
- * @return The command's details.
- */
- @Provides(type = Provides.Type.SET)
- public CommandDetails getCommand(final KickReason command) {
- return new SimpleCommandDetails(command, KickReason.INFO);
- }
-
- /**
- * Provides the /mode command.
- *
- * @param command The instantiated command.
- * @return The command's details.
- */
- @Provides(type = Provides.Type.SET)
- public CommandDetails getCommand(final Mode command) {
- return new SimpleCommandDetails(command, Mode.INFO);
- }
-
- /**
- * Provides the /names command.
- *
- * @param command The instantiated command.
- * @return The command's details.
- */
- @Provides(type = Provides.Type.SET)
- public CommandDetails getCommand(final Names command) {
- return new SimpleCommandDetails(command, Names.INFO);
- }
-
- /**
- * Provides the /part command.
- *
- * @param command The instantiated command.
- * @return The command's details.
- */
- @Provides(type = Provides.Type.SET)
- public CommandDetails getCommand(final Part command) {
- return new SimpleCommandDetails(command, Part.INFO);
- }
-
- /**
- * Provides the /setnickcolour command.
- *
- * @param command The instantiated command.
- * @return The command's details.
- */
- @Provides(type = Provides.Type.SET)
- public CommandDetails getCommand(final SetNickColour command) {
- return new SimpleCommandDetails(command, SetNickColour.INFO);
- }
-
- /**
- * Provides the /topic command.
- *
- * @param command The instantiated command.
- * @return The command's details.
- */
- @Provides(type = Provides.Type.SET)
- public CommandDetails getCommand(final ShowTopic command) {
- return new SimpleCommandDetails(command, ShowTopic.INFO);
- }
-
- /**
- * Provides the /allchannels command.
- *
- * @param command The instantiated command.
- * @return The command's details.
- */
- @Provides(type = Provides.Type.SET)
- public CommandDetails getCommand(final AllChannels command) {
- return new SimpleCommandDetails(command, AllChannels.INFO);
- }
-
- /**
- * Provides the /away command.
- *
- * @param command The instantiated command.
- * @return The command's details.
- */
- @Provides(type = Provides.Type.SET)
- public CommandDetails getCommand(final Away command) {
- return new SimpleCommandDetails(command, Away.INFO);
- }
-
- /**
- * Provides the /back command.
- *
- * @param command The instantiated command.
- * @return The command's details.
- */
- @Provides(type = Provides.Type.SET)
- public CommandDetails getCommand(final Back command) {
- return new SimpleCommandDetails(command, Back.INFO);
- }
-
- /**
- * Provides the /server command.
- *
- * @param command The instantiated command.
- * @return The command's details.
- */
- @Provides(type = Provides.Type.SET)
- public CommandDetails getCommand(final ChangeServer command) {
- return new SimpleCommandDetails(command, ChangeServer.INFO);
- }
-
- /**
- * Provides the /ctcp command.
- *
- * @param command The instantiated command.
- * @return The command's details.
- */
- @Provides(type = Provides.Type.SET)
- public CommandDetails getCommand(final Ctcp command) {
- return new SimpleCommandDetails(command, Ctcp.INFO);
- }
-
- /**
- * Provides the /disconnect command.
- *
- * @param command The instantiated command.
- * @return The command's details.
- */
- @Provides(type = Provides.Type.SET)
- public CommandDetails getCommand(final Disconnect command) {
- return new SimpleCommandDetails(command, Disconnect.INFO);
- }
-
- /**
- * Provides the /ignore command.
- *
- * @param command The instantiated command.
- * @return The command's details.
- */
- @Provides(type = Provides.Type.SET)
- public CommandDetails getCommand(final Ignore command) {
- return new SimpleCommandDetails(command, Ignore.INFO);
- }
-
- /**
- * Provides the /join command.
- *
- * @param command The instantiated command.
- * @return The command's details.
- */
- @Provides(type = Provides.Type.SET)
- public CommandDetails getCommand(final JoinChannelCommand command) {
- return new SimpleCommandDetails(command, JoinChannelCommand.INFO);
- }
-
- /**
- * Provides the /msg command.
- *
- * @param command The instantiated command.
- * @return The command's details.
- */
- @Provides(type = Provides.Type.SET)
- public CommandDetails getCommand(final Message command) {
- return new SimpleCommandDetails(command, Message.INFO);
- }
-
- /**
- * Provides the /nick command.
- *
- * @param command The instantiated command.
- * @return The command's details.
- */
- @Provides(type = Provides.Type.SET)
- public CommandDetails getCommand(final Nick command) {
- return new SimpleCommandDetails(command, Nick.INFO);
- }
-
- /**
- * Provides the /notice command.
- *
- * @param command The instantiated command.
- * @return The command's details.
- */
- @Provides(type = Provides.Type.SET)
- public CommandDetails getCommand(final Notice command) {
- return new SimpleCommandDetails(command, Notice.INFO);
- }
-
- /**
- * Provides the /query command.
- *
- * @param command The instantiated command.
- * @return The command's details.
- */
- @Provides(type = Provides.Type.SET)
- public CommandDetails getCommand(final OpenQuery command) {
- return new SimpleCommandDetails(command, OpenQuery.INFO);
- }
-
- /**
- * Provides the /raw command.
- *
- * @param command The instantiated command.
- * @return The command's details.
- */
- @Provides(type = Provides.Type.SET)
- public CommandDetails getCommand(final Raw command) {
- return new SimpleCommandDetails(command, Raw.INFO);
- }
-
- /**
- * Provides the /reconnect command.
- *
- * @param command The instantiated command.
- * @return The command's details.
- */
- @Provides(type = Provides.Type.SET)
- public CommandDetails getCommand(final Reconnect command) {
- return new SimpleCommandDetails(command, Reconnect.INFO);
- }
-
- /**
- * Provides the /umode command.
- *
- * @param command The instantiated command.
- * @return The command's details.
- */
- @Provides(type = Provides.Type.SET)
- public CommandDetails getCommand(final Umode command) {
- return new SimpleCommandDetails(command, Umode.INFO);
- }
-
- /**
- * Provides a set of raw commands.
- *
- * @param controller The controller to use for command info.
- * @return A set of the commands' details.
- */
- @Provides(type = Provides.Type.SET_VALUES)
- public Set<CommandDetails> getRawCommands(final CommandController controller) {
- final Set<CommandDetails> results = new HashSet<>();
- for (String name : new String[] { "lusers", "map", "motd", "oper", "whois", "who" }) {
- final RawServerCommand rawCommand = new RawServerCommand(controller, name);
- results.add(new SimpleCommandDetails(rawCommand, rawCommand));
- }
- return results;
- }
-
- /**
- * Provides the /alias command.
- *
- * @param command The instantiated command.
- * @return The command's details.
- */
- @Provides(type = Provides.Type.SET)
- public CommandDetails getCommand(final AliasCommand command) {
- return new SimpleCommandDetails(command, AliasCommand.INFO);
- }
-
- /**
- * Provides the /allservers command.
- *
- * @param command The instantiated command.
- * @return The command's details.
- */
- @Provides(type = Provides.Type.SET)
- public CommandDetails getCommand(final AllServers command) {
- return new SimpleCommandDetails(command, AllServers.INFO);
- }
-
- /**
- * Provides the /clear command.
- *
- * @param command The instantiated command.
- * @return The command's details.
- */
- @Provides(type = Provides.Type.SET)
- public CommandDetails getCommand(final Clear command) {
- return new SimpleCommandDetails(command, Clear.INFO);
- }
-
- /**
- * Provides the /echo command.
- *
- * @param command The instantiated command.
- * @return The command's details.
- */
- @Provides(type = Provides.Type.SET)
- public CommandDetails getCommand(final Echo command) {
- return new SimpleCommandDetails(command, Echo.INFO);
- }
-
- /**
- * Provides the /exit command.
- *
- * @param command The instantiated command.
- * @return The command's details.
- */
- @Provides(type = Provides.Type.SET)
- public CommandDetails getCommand(final Exit command) {
- return new SimpleCommandDetails(command, Exit.INFO);
- }
-
- /**
- * Provides the /Help command.
- *
- * @param command The instantiated command.
- * @return The command's details.
- */
- @Provides(type = Provides.Type.SET)
- public CommandDetails getCommand(final Help command) {
- return new SimpleCommandDetails(command, Help.INFO);
- }
-
- /**
- * Provides the /ifplugin command.
- *
- * @param command The instantiated command.
- * @return The command's details.
- */
- @Provides(type = Provides.Type.SET)
- public CommandDetails getCommand(final Ifplugin command) {
- return new SimpleCommandDetails(command, Ifplugin.INFO);
- }
-
- /**
- * Provides the /newserver command.
- *
- * @param command The instantiated command.
- * @return The command's details.
- */
- @Provides(type = Provides.Type.SET)
- public CommandDetails getCommand(final NewServer command) {
- return new SimpleCommandDetails(command, NewServer.INFO);
- }
-
- /**
- * Provides the /notify command.
- *
- * @param command The instantiated command.
- * @return The command's details.
- */
- @Provides(type = Provides.Type.SET)
- public CommandDetails getCommand(final Notify command) {
- return new SimpleCommandDetails(command, Notify.INFO);
- }
-
- /**
- * Provides the /loadplugin command.
- *
- * @param command The instantiated command.
- * @return The command's details.
- */
- @Provides(type = Provides.Type.SET)
- public CommandDetails getCommand(final LoadPlugin command) {
- return new SimpleCommandDetails(command, LoadPlugin.INFO);
- }
-
- /**
- * Provides the /unloadplugin command.
- *
- * @param command The instantiated command.
- * @return The command's details.
- */
- @Provides(type = Provides.Type.SET)
- public CommandDetails getCommand(final UnloadPlugin command) {
- return new SimpleCommandDetails(command, UnloadPlugin.INFO);
- }
-
- /**
- * Provides the /openwindow command.
- *
- * @param command The instantiated command.
- * @return The command's details.
- */
- @Provides(type = Provides.Type.SET)
- public CommandDetails getCommand(final OpenWindow command) {
- return new SimpleCommandDetails(command, OpenWindow.INFO);
- }
-
- /**
- * Provides the /reloadactions command.
- *
- * @param command The instantiated command.
- * @return The command's details.
- */
- @Provides(type = Provides.Type.SET)
- public CommandDetails getCommand(final ReloadActions command) {
- return new SimpleCommandDetails(command, ReloadActions.INFO);
- }
-
- /**
- * Provides the /reloadidentities command.
- *
- * @param command The instantiated command.
- * @return The command's details.
- */
- @Provides(type = Provides.Type.SET)
- public CommandDetails getCommand(final ReloadIdentities command) {
- return new SimpleCommandDetails(command, ReloadIdentities.INFO);
- }
-
- /**
- * Provides the /reloadplugin command.
- *
- * @param command The instantiated command.
- * @return The command's details.
- */
- @Provides(type = Provides.Type.SET)
- public CommandDetails getCommand(final ReloadPlugin command) {
- return new SimpleCommandDetails(command, ReloadPlugin.INFO);
- }
-
- /**
- * Provides the /saveconfig command.
- *
- * @param command The instantiated command.
- * @return The command's details.
- */
- @Provides(type = Provides.Type.SET)
- public CommandDetails getCommand(final SaveConfig command) {
- return new SimpleCommandDetails(command, SaveConfig.INFO);
- }
-
- /**
- * Provides the /set command.
- *
- * @param command The instantiated command.
- * @return The command's details.
- */
- @Provides(type = Provides.Type.SET)
- public CommandDetails getCommand(final SetCommand command) {
- return new SimpleCommandDetails(command, SetCommand.INFO);
- }
-
- /**
- * Simple implementation of {@link CommandDetails}.
- */
- private static class SimpleCommandDetails implements CommandDetails {
-
- public SimpleCommandDetails(Command command, CommandInfo info) {
- this.command = command;
- this.info = info;
- }
-
- public Command getCommand() {
- return command;
- }
-
- public CommandInfo getInfo() {
- return info;
- }
-
- /** The command. */
- private final Command command;
-
- /** The command's info. */
- private final CommandInfo info;
-
- }
-
- }
|