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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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.ReloadFormat;
  40. import com.dmdirc.commandparser.commands.global.ReloadIdentities;
  41. import com.dmdirc.commandparser.commands.global.ReloadPlugin;
  42. import com.dmdirc.commandparser.commands.global.SaveConfig;
  43. import com.dmdirc.commandparser.commands.global.SetCommand;
  44. import com.dmdirc.commandparser.commands.global.UnloadPlugin;
  45. import com.dmdirc.commandparser.commands.server.AllChannels;
  46. import com.dmdirc.commandparser.commands.server.Away;
  47. import com.dmdirc.commandparser.commands.server.Back;
  48. import com.dmdirc.commandparser.commands.server.ChangeServer;
  49. import com.dmdirc.commandparser.commands.server.Ctcp;
  50. import com.dmdirc.commandparser.commands.server.Disconnect;
  51. import com.dmdirc.commandparser.commands.server.Ignore;
  52. import com.dmdirc.commandparser.commands.server.JoinChannelCommand;
  53. import com.dmdirc.commandparser.commands.server.Message;
  54. import com.dmdirc.commandparser.commands.server.Nick;
  55. import com.dmdirc.commandparser.commands.server.Notice;
  56. import com.dmdirc.commandparser.commands.server.OpenQuery;
  57. import com.dmdirc.commandparser.commands.server.Raw;
  58. import com.dmdirc.commandparser.commands.server.RawServerCommand;
  59. import com.dmdirc.commandparser.commands.server.Reconnect;
  60. import com.dmdirc.commandparser.commands.server.Umode;
  61. import com.dmdirc.commandparser.commands.server.Whois;
  62. import com.dmdirc.interfaces.CommandController;
  63. import com.dmdirc.interfaces.CommandController.CommandDetails;
  64. import java.util.HashSet;
  65. import java.util.Set;
  66. import dagger.Module;
  67. import dagger.Provides;
  68. /**
  69. * Provides commands for injection into the command manager.
  70. */
  71. @Module(library = true, complete = false)
  72. public class CommandModule {
  73. @Provides(type = Provides.Type.SET)
  74. public CommandDetails getMeCommand(final Me command) {
  75. return new SimpleCommandDetails(command, Me.INFO);
  76. }
  77. @Provides(type = Provides.Type.SET)
  78. public CommandDetails getBanCommand(final Ban command) {
  79. return new SimpleCommandDetails(command, Ban.INFO);
  80. }
  81. @Provides(type = Provides.Type.SET)
  82. public CommandDetails getCycleCommand(final Cycle command) {
  83. return new SimpleCommandDetails(command, Cycle.INFO);
  84. }
  85. @Provides(type = Provides.Type.SET)
  86. public CommandDetails getInviteCommand(final Invite command) {
  87. return new SimpleCommandDetails(command, Invite.INFO);
  88. }
  89. @Provides(type = Provides.Type.SET)
  90. public CommandDetails getKickCommand(final KickReason command) {
  91. return new SimpleCommandDetails(command, KickReason.INFO);
  92. }
  93. @Provides(type = Provides.Type.SET)
  94. public CommandDetails getModeCommand(final Mode command) {
  95. return new SimpleCommandDetails(command, Mode.INFO);
  96. }
  97. @Provides(type = Provides.Type.SET)
  98. public CommandDetails getNamesCommand(final Names command) {
  99. return new SimpleCommandDetails(command, Names.INFO);
  100. }
  101. @Provides(type = Provides.Type.SET)
  102. public CommandDetails getPartCommand(final Part command) {
  103. return new SimpleCommandDetails(command, Part.INFO);
  104. }
  105. @Provides(type = Provides.Type.SET)
  106. public CommandDetails getNickColourCommand(final SetNickColour command) {
  107. return new SimpleCommandDetails(command, SetNickColour.INFO);
  108. }
  109. @Provides(type = Provides.Type.SET)
  110. public CommandDetails getShowTopicCommand(final ShowTopic command) {
  111. return new SimpleCommandDetails(command, ShowTopic.INFO);
  112. }
  113. @Provides(type = Provides.Type.SET)
  114. public CommandDetails getAllChannelsCommand(final AllChannels command) {
  115. return new SimpleCommandDetails(command, AllChannels.INFO);
  116. }
  117. @Provides(type = Provides.Type.SET)
  118. public CommandDetails getAwayCommand(final Away command) {
  119. return new SimpleCommandDetails(command, Away.INFO);
  120. }
  121. @Provides(type = Provides.Type.SET)
  122. public CommandDetails getBackCommand(final Back command) {
  123. return new SimpleCommandDetails(command, Back.INFO);
  124. }
  125. @Provides(type = Provides.Type.SET)
  126. public CommandDetails getServerCommand(final ChangeServer command) {
  127. return new SimpleCommandDetails(command, ChangeServer.INFO);
  128. }
  129. @Provides(type = Provides.Type.SET)
  130. public CommandDetails getCtcpCommand(final Ctcp command) {
  131. return new SimpleCommandDetails(command, Ctcp.INFO);
  132. }
  133. @Provides(type = Provides.Type.SET)
  134. public CommandDetails getDisconnectCommand(final Disconnect command) {
  135. return new SimpleCommandDetails(command, Disconnect.INFO);
  136. }
  137. @Provides(type = Provides.Type.SET)
  138. public CommandDetails getIgnoreCommand(final Ignore command) {
  139. return new SimpleCommandDetails(command, Ignore.INFO);
  140. }
  141. @Provides(type = Provides.Type.SET)
  142. public CommandDetails getJoinCommand(final JoinChannelCommand command) {
  143. return new SimpleCommandDetails(command, JoinChannelCommand.INFO);
  144. }
  145. @Provides(type = Provides.Type.SET)
  146. public CommandDetails getMessageCommand(final Message command) {
  147. return new SimpleCommandDetails(command, Message.INFO);
  148. }
  149. @Provides(type = Provides.Type.SET)
  150. public CommandDetails getNickCommand(final Nick command) {
  151. return new SimpleCommandDetails(command, Nick.INFO);
  152. }
  153. @Provides(type = Provides.Type.SET)
  154. public CommandDetails getNoticeCommand(final Notice command) {
  155. return new SimpleCommandDetails(command, Notice.INFO);
  156. }
  157. @Provides(type = Provides.Type.SET)
  158. public CommandDetails getQueryCommand(final OpenQuery command) {
  159. return new SimpleCommandDetails(command, OpenQuery.INFO);
  160. }
  161. @Provides(type = Provides.Type.SET)
  162. public CommandDetails getRawCommand(final Raw command) {
  163. return new SimpleCommandDetails(command, Raw.INFO);
  164. }
  165. @Provides(type = Provides.Type.SET)
  166. public CommandDetails getReconnectCommand(final Reconnect command) {
  167. return new SimpleCommandDetails(command, Reconnect.INFO);
  168. }
  169. @Provides(type = Provides.Type.SET)
  170. public CommandDetails getUmodeCommand(final Umode command) {
  171. return new SimpleCommandDetails(command, Umode.INFO);
  172. }
  173. @Provides(type = Provides.Type.SET)
  174. public CommandDetails getWhoisCommand(final Whois command) {
  175. return new SimpleCommandDetails(command, Whois.INFO);
  176. }
  177. @Provides(type = Provides.Type.SET_VALUES)
  178. public Set<CommandDetails> getRawCommands(final CommandController controller) {
  179. final Set<CommandDetails> results = new HashSet<>();
  180. for (String name : new String[]{"lusers", "map", "motd", "oper", "who"}) {
  181. final RawServerCommand rawCommand = new RawServerCommand(controller, name);
  182. results.add(new SimpleCommandDetails(rawCommand, rawCommand));
  183. }
  184. return results;
  185. }
  186. @Provides(type = Provides.Type.SET)
  187. public CommandDetails getAliasCommand(final AliasCommand command) {
  188. return new SimpleCommandDetails(command, AliasCommand.INFO);
  189. }
  190. @Provides(type = Provides.Type.SET)
  191. public CommandDetails getAllServersCommand(final AllServers command) {
  192. return new SimpleCommandDetails(command, AllServers.INFO);
  193. }
  194. @Provides(type = Provides.Type.SET)
  195. public CommandDetails getClearCommand(final Clear command) {
  196. return new SimpleCommandDetails(command, Clear.INFO);
  197. }
  198. @Provides(type = Provides.Type.SET)
  199. public CommandDetails getEchoCommand(final Echo command) {
  200. return new SimpleCommandDetails(command, Echo.INFO);
  201. }
  202. @Provides(type = Provides.Type.SET)
  203. public CommandDetails getExitCommand(final Exit command) {
  204. return new SimpleCommandDetails(command, Exit.INFO);
  205. }
  206. @Provides(type = Provides.Type.SET)
  207. public CommandDetails getHelpCommand(final Help command) {
  208. return new SimpleCommandDetails(command, Help.INFO);
  209. }
  210. @Provides(type = Provides.Type.SET)
  211. public CommandDetails getIfpluginCommand(final Ifplugin command) {
  212. return new SimpleCommandDetails(command, Ifplugin.INFO);
  213. }
  214. @Provides(type = Provides.Type.SET)
  215. public CommandDetails getNewServerCommand(final NewServer command) {
  216. return new SimpleCommandDetails(command, NewServer.INFO);
  217. }
  218. @Provides(type = Provides.Type.SET)
  219. public CommandDetails getLoadPluginCommand(final LoadPlugin command) {
  220. return new SimpleCommandDetails(command, LoadPlugin.INFO);
  221. }
  222. @Provides(type = Provides.Type.SET)
  223. public CommandDetails getUnloadPluginCommand(final UnloadPlugin command) {
  224. return new SimpleCommandDetails(command, UnloadPlugin.INFO);
  225. }
  226. @Provides(type = Provides.Type.SET)
  227. public CommandDetails getOpenWindowCommand(final OpenWindow command) {
  228. return new SimpleCommandDetails(command, OpenWindow.INFO);
  229. }
  230. @Provides(type = Provides.Type.SET)
  231. public CommandDetails getReloadIdentitiesCommand(final ReloadIdentities command) {
  232. return new SimpleCommandDetails(command, ReloadIdentities.INFO);
  233. }
  234. @Provides(type = Provides.Type.SET)
  235. public CommandDetails getReloadPluginCommand(final ReloadPlugin command) {
  236. return new SimpleCommandDetails(command, ReloadPlugin.INFO);
  237. }
  238. @Provides(type = Provides.Type.SET)
  239. public CommandDetails getSaveConfigCommand(final SaveConfig command) {
  240. return new SimpleCommandDetails(command, SaveConfig.INFO);
  241. }
  242. @Provides(type = Provides.Type.SET)
  243. public CommandDetails getReloadFormatCommand(final ReloadFormat command) {
  244. return new SimpleCommandDetails(command, ReloadFormat.INFO);
  245. }
  246. @Provides(type = Provides.Type.SET)
  247. public CommandDetails getSetCommand(final SetCommand command) {
  248. return new SimpleCommandDetails(command, SetCommand.INFO);
  249. }
  250. /**
  251. * Simple implementation of {@link CommandDetails}.
  252. */
  253. private static class SimpleCommandDetails implements CommandDetails {
  254. public SimpleCommandDetails(final Command command, final CommandInfo info) {
  255. this.command = command;
  256. this.info = info;
  257. }
  258. @Override
  259. public Command getCommand() {
  260. return command;
  261. }
  262. @Override
  263. public CommandInfo getInfo() {
  264. return info;
  265. }
  266. /** The command. */
  267. private final Command command;
  268. /** The command's info. */
  269. private final CommandInfo info;
  270. }
  271. }