You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CommandModule.java 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. /*
  2. * Copyright (c) 2006-2017 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
  5. * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
  6. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
  7. * permit persons to whom the Software is furnished to do so, subject to the following conditions:
  8. *
  9. * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
  10. * Software.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  13. * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
  14. * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  15. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. */
  17. package com.dmdirc.commandparser.commands;
  18. import com.dmdirc.commandparser.CommandInfo;
  19. import com.dmdirc.commandparser.commands.channel.Ban;
  20. import com.dmdirc.commandparser.commands.channel.Cycle;
  21. import com.dmdirc.commandparser.commands.channel.Invite;
  22. import com.dmdirc.commandparser.commands.channel.KickReason;
  23. import com.dmdirc.commandparser.commands.channel.Mode;
  24. import com.dmdirc.commandparser.commands.channel.Names;
  25. import com.dmdirc.commandparser.commands.channel.Part;
  26. import com.dmdirc.commandparser.commands.channel.SetNickColour;
  27. import com.dmdirc.commandparser.commands.channel.ShowTopic;
  28. import com.dmdirc.commandparser.commands.chat.Me;
  29. import com.dmdirc.commandparser.commands.global.AliasCommand;
  30. import com.dmdirc.commandparser.commands.global.AllServers;
  31. import com.dmdirc.commandparser.commands.global.Clear;
  32. import com.dmdirc.commandparser.commands.global.Echo;
  33. import com.dmdirc.commandparser.commands.global.Exit;
  34. import com.dmdirc.commandparser.commands.global.Help;
  35. import com.dmdirc.commandparser.commands.global.Ifplugin;
  36. import com.dmdirc.commandparser.commands.global.LoadPlugin;
  37. import com.dmdirc.commandparser.commands.global.NewServer;
  38. import com.dmdirc.commandparser.commands.global.OpenWindow;
  39. import com.dmdirc.commandparser.commands.global.ReloadIdentities;
  40. import com.dmdirc.commandparser.commands.global.ReloadPlugin;
  41. import com.dmdirc.commandparser.commands.global.SaveConfig;
  42. import com.dmdirc.commandparser.commands.global.SetCommand;
  43. import com.dmdirc.commandparser.commands.global.UnloadPlugin;
  44. import com.dmdirc.commandparser.commands.server.AllChannels;
  45. import com.dmdirc.commandparser.commands.server.Away;
  46. import com.dmdirc.commandparser.commands.server.Back;
  47. import com.dmdirc.commandparser.commands.server.ChangeServer;
  48. import com.dmdirc.commandparser.commands.server.Ctcp;
  49. import com.dmdirc.commandparser.commands.server.Disconnect;
  50. import com.dmdirc.commandparser.commands.server.Ignore;
  51. import com.dmdirc.commandparser.commands.server.JoinChannelCommand;
  52. import com.dmdirc.commandparser.commands.server.Message;
  53. import com.dmdirc.commandparser.commands.server.Nick;
  54. import com.dmdirc.commandparser.commands.server.Notice;
  55. import com.dmdirc.commandparser.commands.server.OpenQuery;
  56. import com.dmdirc.commandparser.commands.server.Raw;
  57. import com.dmdirc.commandparser.commands.server.RawServerCommand;
  58. import com.dmdirc.commandparser.commands.server.Reconnect;
  59. import com.dmdirc.commandparser.commands.server.Umode;
  60. import com.dmdirc.commandparser.commands.server.Whois;
  61. import com.dmdirc.interfaces.CommandController;
  62. import com.dmdirc.interfaces.CommandController.CommandDetails;
  63. import java.util.HashSet;
  64. import java.util.Set;
  65. import dagger.Module;
  66. import dagger.Provides;
  67. /**
  68. * Provides commands for injection into the command manager.
  69. */
  70. @Module(library = true, complete = false)
  71. public class CommandModule {
  72. @Provides(type = Provides.Type.SET)
  73. public CommandDetails getMeCommand(final Me command) {
  74. return new SimpleCommandDetails(command, Me.INFO);
  75. }
  76. @Provides(type = Provides.Type.SET)
  77. public CommandDetails getBanCommand(final Ban command) {
  78. return new SimpleCommandDetails(command, Ban.INFO);
  79. }
  80. @Provides(type = Provides.Type.SET)
  81. public CommandDetails getCycleCommand(final Cycle command) {
  82. return new SimpleCommandDetails(command, Cycle.INFO);
  83. }
  84. @Provides(type = Provides.Type.SET)
  85. public CommandDetails getInviteCommand(final Invite command) {
  86. return new SimpleCommandDetails(command, Invite.INFO);
  87. }
  88. @Provides(type = Provides.Type.SET)
  89. public CommandDetails getKickCommand(final KickReason command) {
  90. return new SimpleCommandDetails(command, KickReason.INFO);
  91. }
  92. @Provides(type = Provides.Type.SET)
  93. public CommandDetails getModeCommand(final Mode command) {
  94. return new SimpleCommandDetails(command, Mode.INFO);
  95. }
  96. @Provides(type = Provides.Type.SET)
  97. public CommandDetails getNamesCommand(final Names command) {
  98. return new SimpleCommandDetails(command, Names.INFO);
  99. }
  100. @Provides(type = Provides.Type.SET)
  101. public CommandDetails getPartCommand(final Part command) {
  102. return new SimpleCommandDetails(command, Part.INFO);
  103. }
  104. @Provides(type = Provides.Type.SET)
  105. public CommandDetails getNickColourCommand(final SetNickColour command) {
  106. return new SimpleCommandDetails(command, SetNickColour.INFO);
  107. }
  108. @Provides(type = Provides.Type.SET)
  109. public CommandDetails getShowTopicCommand(final ShowTopic command) {
  110. return new SimpleCommandDetails(command, ShowTopic.INFO);
  111. }
  112. @Provides(type = Provides.Type.SET)
  113. public CommandDetails getAllChannelsCommand(final AllChannels command) {
  114. return new SimpleCommandDetails(command, AllChannels.INFO);
  115. }
  116. @Provides(type = Provides.Type.SET)
  117. public CommandDetails getAwayCommand(final Away command) {
  118. return new SimpleCommandDetails(command, Away.INFO);
  119. }
  120. @Provides(type = Provides.Type.SET)
  121. public CommandDetails getBackCommand(final Back command) {
  122. return new SimpleCommandDetails(command, Back.INFO);
  123. }
  124. @Provides(type = Provides.Type.SET)
  125. public CommandDetails getServerCommand(final ChangeServer command) {
  126. return new SimpleCommandDetails(command, ChangeServer.INFO);
  127. }
  128. @Provides(type = Provides.Type.SET)
  129. public CommandDetails getCtcpCommand(final Ctcp command) {
  130. return new SimpleCommandDetails(command, Ctcp.INFO);
  131. }
  132. @Provides(type = Provides.Type.SET)
  133. public CommandDetails getDisconnectCommand(final Disconnect command) {
  134. return new SimpleCommandDetails(command, Disconnect.INFO);
  135. }
  136. @Provides(type = Provides.Type.SET)
  137. public CommandDetails getIgnoreCommand(final Ignore command) {
  138. return new SimpleCommandDetails(command, Ignore.INFO);
  139. }
  140. @Provides(type = Provides.Type.SET)
  141. public CommandDetails getJoinCommand(final JoinChannelCommand command) {
  142. return new SimpleCommandDetails(command, JoinChannelCommand.INFO);
  143. }
  144. @Provides(type = Provides.Type.SET)
  145. public CommandDetails getMessageCommand(final Message command) {
  146. return new SimpleCommandDetails(command, Message.INFO);
  147. }
  148. @Provides(type = Provides.Type.SET)
  149. public CommandDetails getNickCommand(final Nick command) {
  150. return new SimpleCommandDetails(command, Nick.INFO);
  151. }
  152. @Provides(type = Provides.Type.SET)
  153. public CommandDetails getNoticeCommand(final Notice command) {
  154. return new SimpleCommandDetails(command, Notice.INFO);
  155. }
  156. @Provides(type = Provides.Type.SET)
  157. public CommandDetails getQueryCommand(final OpenQuery command) {
  158. return new SimpleCommandDetails(command, OpenQuery.INFO);
  159. }
  160. @Provides(type = Provides.Type.SET)
  161. public CommandDetails getRawCommand(final Raw command) {
  162. return new SimpleCommandDetails(command, Raw.INFO);
  163. }
  164. @Provides(type = Provides.Type.SET)
  165. public CommandDetails getReconnectCommand(final Reconnect command) {
  166. return new SimpleCommandDetails(command, Reconnect.INFO);
  167. }
  168. @Provides(type = Provides.Type.SET)
  169. public CommandDetails getUmodeCommand(final Umode command) {
  170. return new SimpleCommandDetails(command, Umode.INFO);
  171. }
  172. @Provides(type = Provides.Type.SET)
  173. public CommandDetails getWhoisCommand(final Whois command) {
  174. return new SimpleCommandDetails(command, Whois.INFO);
  175. }
  176. @Provides(type = Provides.Type.SET_VALUES)
  177. public Set<CommandDetails> getRawCommands(final CommandController controller) {
  178. final Set<CommandDetails> results = new HashSet<>();
  179. for (String name : new String[]{"lusers", "map", "motd", "oper", "who"}) {
  180. final RawServerCommand rawCommand = new RawServerCommand(controller, name);
  181. results.add(new SimpleCommandDetails(rawCommand, rawCommand));
  182. }
  183. return results;
  184. }
  185. @Provides(type = Provides.Type.SET)
  186. public CommandDetails getAliasCommand(final AliasCommand command) {
  187. return new SimpleCommandDetails(command, AliasCommand.INFO);
  188. }
  189. @Provides(type = Provides.Type.SET)
  190. public CommandDetails getAllServersCommand(final AllServers command) {
  191. return new SimpleCommandDetails(command, AllServers.INFO);
  192. }
  193. @Provides(type = Provides.Type.SET)
  194. public CommandDetails getClearCommand(final Clear command) {
  195. return new SimpleCommandDetails(command, Clear.INFO);
  196. }
  197. @Provides(type = Provides.Type.SET)
  198. public CommandDetails getEchoCommand(final Echo command) {
  199. return new SimpleCommandDetails(command, Echo.INFO);
  200. }
  201. @Provides(type = Provides.Type.SET)
  202. public CommandDetails getExitCommand(final Exit command) {
  203. return new SimpleCommandDetails(command, Exit.INFO);
  204. }
  205. @Provides(type = Provides.Type.SET)
  206. public CommandDetails getHelpCommand(final Help command) {
  207. return new SimpleCommandDetails(command, Help.INFO);
  208. }
  209. @Provides(type = Provides.Type.SET)
  210. public CommandDetails getIfpluginCommand(final Ifplugin command) {
  211. return new SimpleCommandDetails(command, Ifplugin.INFO);
  212. }
  213. @Provides(type = Provides.Type.SET)
  214. public CommandDetails getNewServerCommand(final NewServer command) {
  215. return new SimpleCommandDetails(command, NewServer.INFO);
  216. }
  217. @Provides(type = Provides.Type.SET)
  218. public CommandDetails getLoadPluginCommand(final LoadPlugin command) {
  219. return new SimpleCommandDetails(command, LoadPlugin.INFO);
  220. }
  221. @Provides(type = Provides.Type.SET)
  222. public CommandDetails getUnloadPluginCommand(final UnloadPlugin command) {
  223. return new SimpleCommandDetails(command, UnloadPlugin.INFO);
  224. }
  225. @Provides(type = Provides.Type.SET)
  226. public CommandDetails getOpenWindowCommand(final OpenWindow command) {
  227. return new SimpleCommandDetails(command, OpenWindow.INFO);
  228. }
  229. @Provides(type = Provides.Type.SET)
  230. public CommandDetails getReloadIdentitiesCommand(final ReloadIdentities command) {
  231. return new SimpleCommandDetails(command, ReloadIdentities.INFO);
  232. }
  233. @Provides(type = Provides.Type.SET)
  234. public CommandDetails getReloadPluginCommand(final ReloadPlugin command) {
  235. return new SimpleCommandDetails(command, ReloadPlugin.INFO);
  236. }
  237. @Provides(type = Provides.Type.SET)
  238. public CommandDetails getSaveConfigCommand(final SaveConfig command) {
  239. return new SimpleCommandDetails(command, SaveConfig.INFO);
  240. }
  241. @Provides(type = Provides.Type.SET)
  242. public CommandDetails getSetCommand(final SetCommand command) {
  243. return new SimpleCommandDetails(command, SetCommand.INFO);
  244. }
  245. /**
  246. * Simple implementation of {@link CommandDetails}.
  247. */
  248. private static class SimpleCommandDetails implements CommandDetails {
  249. public SimpleCommandDetails(final Command command, final CommandInfo info) {
  250. this.command = command;
  251. this.info = info;
  252. }
  253. @Override
  254. public Command getCommand() {
  255. return command;
  256. }
  257. @Override
  258. public CommandInfo getInfo() {
  259. return info;
  260. }
  261. /** The command. */
  262. private final Command command;
  263. /** The command's info. */
  264. private final CommandInfo info;
  265. }
  266. }