Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. /*
  2. * Copyright (c) 2006-2014 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.commandparser.commands;
  23. import com.dmdirc.commandparser.CommandInfo;
  24. import com.dmdirc.commandparser.commands.channel.Ban;
  25. import com.dmdirc.commandparser.commands.channel.Cycle;
  26. import com.dmdirc.commandparser.commands.channel.Invite;
  27. import com.dmdirc.commandparser.commands.channel.KickReason;
  28. import com.dmdirc.commandparser.commands.channel.Mode;
  29. import com.dmdirc.commandparser.commands.channel.Names;
  30. import com.dmdirc.commandparser.commands.channel.Part;
  31. import com.dmdirc.commandparser.commands.channel.SetNickColour;
  32. import com.dmdirc.commandparser.commands.channel.ShowTopic;
  33. import com.dmdirc.commandparser.commands.chat.Me;
  34. import com.dmdirc.commandparser.commands.global.AliasCommand;
  35. import com.dmdirc.commandparser.commands.global.AllServers;
  36. import com.dmdirc.commandparser.commands.global.Clear;
  37. import com.dmdirc.commandparser.commands.global.Echo;
  38. import com.dmdirc.commandparser.commands.global.Exit;
  39. import com.dmdirc.commandparser.commands.global.Help;
  40. import com.dmdirc.commandparser.commands.global.Ifplugin;
  41. import com.dmdirc.commandparser.commands.global.LoadPlugin;
  42. import com.dmdirc.commandparser.commands.global.NewServer;
  43. import com.dmdirc.commandparser.commands.global.Notify;
  44. import com.dmdirc.commandparser.commands.global.OpenWindow;
  45. import com.dmdirc.commandparser.commands.global.ReloadActions;
  46. import com.dmdirc.commandparser.commands.global.ReloadIdentities;
  47. import com.dmdirc.commandparser.commands.global.ReloadPlugin;
  48. import com.dmdirc.commandparser.commands.global.SaveConfig;
  49. import com.dmdirc.commandparser.commands.global.SetCommand;
  50. import com.dmdirc.commandparser.commands.global.UnloadPlugin;
  51. import com.dmdirc.commandparser.commands.server.AllChannels;
  52. import com.dmdirc.commandparser.commands.server.Away;
  53. import com.dmdirc.commandparser.commands.server.Back;
  54. import com.dmdirc.commandparser.commands.server.ChangeServer;
  55. import com.dmdirc.commandparser.commands.server.Ctcp;
  56. import com.dmdirc.commandparser.commands.server.Disconnect;
  57. import com.dmdirc.commandparser.commands.server.Ignore;
  58. import com.dmdirc.commandparser.commands.server.JoinChannelCommand;
  59. import com.dmdirc.commandparser.commands.server.Message;
  60. import com.dmdirc.commandparser.commands.server.Nick;
  61. import com.dmdirc.commandparser.commands.server.Notice;
  62. import com.dmdirc.commandparser.commands.server.OpenQuery;
  63. import com.dmdirc.commandparser.commands.server.Raw;
  64. import com.dmdirc.commandparser.commands.server.RawServerCommand;
  65. import com.dmdirc.commandparser.commands.server.Reconnect;
  66. import com.dmdirc.commandparser.commands.server.Umode;
  67. import com.dmdirc.interfaces.CommandController;
  68. import com.dmdirc.interfaces.CommandController.CommandDetails;
  69. import java.util.HashSet;
  70. import java.util.Set;
  71. import dagger.Module;
  72. import dagger.Provides;
  73. /**
  74. * Provides commands for injection into the command manager.
  75. */
  76. @Module(library = true, complete = false)
  77. public class CommandModule {
  78. /**
  79. * Provides the /me command.
  80. *
  81. * @param command The instantiated command.
  82. * @return The command's details.
  83. */
  84. @Provides(type = Provides.Type.SET)
  85. public CommandDetails getCommand(final Me command) {
  86. return new SimpleCommandDetails(command, Me.INFO);
  87. }
  88. /**
  89. * Provides the /ban command.
  90. *
  91. * @param command The instantiated command.
  92. * @return The command's details.
  93. */
  94. @Provides(type = Provides.Type.SET)
  95. public CommandDetails getCommand(final Ban command) {
  96. return new SimpleCommandDetails(command, Ban.INFO);
  97. }
  98. /**
  99. * Provides the /cycle command.
  100. *
  101. * @param command The instantiated command.
  102. * @return The command's details.
  103. */
  104. @Provides(type = Provides.Type.SET)
  105. public CommandDetails getCommand(final Cycle command) {
  106. return new SimpleCommandDetails(command, Cycle.INFO);
  107. }
  108. /**
  109. * Provides the /invite command.
  110. *
  111. * @param command The instantiated command.
  112. * @return The command's details.
  113. */
  114. @Provides(type = Provides.Type.SET)
  115. public CommandDetails getCommand(final Invite command) {
  116. return new SimpleCommandDetails(command, Invite.INFO);
  117. }
  118. /**
  119. * Provides the /kick command.
  120. *
  121. * @param command The instantiated command.
  122. * @return The command's details.
  123. */
  124. @Provides(type = Provides.Type.SET)
  125. public CommandDetails getCommand(final KickReason command) {
  126. return new SimpleCommandDetails(command, KickReason.INFO);
  127. }
  128. /**
  129. * Provides the /mode command.
  130. *
  131. * @param command The instantiated command.
  132. * @return The command's details.
  133. */
  134. @Provides(type = Provides.Type.SET)
  135. public CommandDetails getCommand(final Mode command) {
  136. return new SimpleCommandDetails(command, Mode.INFO);
  137. }
  138. /**
  139. * Provides the /names command.
  140. *
  141. * @param command The instantiated command.
  142. * @return The command's details.
  143. */
  144. @Provides(type = Provides.Type.SET)
  145. public CommandDetails getCommand(final Names command) {
  146. return new SimpleCommandDetails(command, Names.INFO);
  147. }
  148. /**
  149. * Provides the /part command.
  150. *
  151. * @param command The instantiated command.
  152. * @return The command's details.
  153. */
  154. @Provides(type = Provides.Type.SET)
  155. public CommandDetails getCommand(final Part command) {
  156. return new SimpleCommandDetails(command, Part.INFO);
  157. }
  158. /**
  159. * Provides the /setnickcolour command.
  160. *
  161. * @param command The instantiated command.
  162. * @return The command's details.
  163. */
  164. @Provides(type = Provides.Type.SET)
  165. public CommandDetails getCommand(final SetNickColour command) {
  166. return new SimpleCommandDetails(command, SetNickColour.INFO);
  167. }
  168. /**
  169. * Provides the /topic command.
  170. *
  171. * @param command The instantiated command.
  172. * @return The command's details.
  173. */
  174. @Provides(type = Provides.Type.SET)
  175. public CommandDetails getCommand(final ShowTopic command) {
  176. return new SimpleCommandDetails(command, ShowTopic.INFO);
  177. }
  178. /**
  179. * Provides the /allchannels command.
  180. *
  181. * @param command The instantiated command.
  182. * @return The command's details.
  183. */
  184. @Provides(type = Provides.Type.SET)
  185. public CommandDetails getCommand(final AllChannels command) {
  186. return new SimpleCommandDetails(command, AllChannels.INFO);
  187. }
  188. /**
  189. * Provides the /away command.
  190. *
  191. * @param command The instantiated command.
  192. * @return The command's details.
  193. */
  194. @Provides(type = Provides.Type.SET)
  195. public CommandDetails getCommand(final Away command) {
  196. return new SimpleCommandDetails(command, Away.INFO);
  197. }
  198. /**
  199. * Provides the /back command.
  200. *
  201. * @param command The instantiated command.
  202. * @return The command's details.
  203. */
  204. @Provides(type = Provides.Type.SET)
  205. public CommandDetails getCommand(final Back command) {
  206. return new SimpleCommandDetails(command, Back.INFO);
  207. }
  208. /**
  209. * Provides the /server command.
  210. *
  211. * @param command The instantiated command.
  212. * @return The command's details.
  213. */
  214. @Provides(type = Provides.Type.SET)
  215. public CommandDetails getCommand(final ChangeServer command) {
  216. return new SimpleCommandDetails(command, ChangeServer.INFO);
  217. }
  218. /**
  219. * Provides the /ctcp command.
  220. *
  221. * @param command The instantiated command.
  222. * @return The command's details.
  223. */
  224. @Provides(type = Provides.Type.SET)
  225. public CommandDetails getCommand(final Ctcp command) {
  226. return new SimpleCommandDetails(command, Ctcp.INFO);
  227. }
  228. /**
  229. * Provides the /disconnect command.
  230. *
  231. * @param command The instantiated command.
  232. * @return The command's details.
  233. */
  234. @Provides(type = Provides.Type.SET)
  235. public CommandDetails getCommand(final Disconnect command) {
  236. return new SimpleCommandDetails(command, Disconnect.INFO);
  237. }
  238. /**
  239. * Provides the /ignore command.
  240. *
  241. * @param command The instantiated command.
  242. * @return The command's details.
  243. */
  244. @Provides(type = Provides.Type.SET)
  245. public CommandDetails getCommand(final Ignore command) {
  246. return new SimpleCommandDetails(command, Ignore.INFO);
  247. }
  248. /**
  249. * Provides the /join command.
  250. *
  251. * @param command The instantiated command.
  252. * @return The command's details.
  253. */
  254. @Provides(type = Provides.Type.SET)
  255. public CommandDetails getCommand(final JoinChannelCommand command) {
  256. return new SimpleCommandDetails(command, JoinChannelCommand.INFO);
  257. }
  258. /**
  259. * Provides the /msg command.
  260. *
  261. * @param command The instantiated command.
  262. * @return The command's details.
  263. */
  264. @Provides(type = Provides.Type.SET)
  265. public CommandDetails getCommand(final Message command) {
  266. return new SimpleCommandDetails(command, Message.INFO);
  267. }
  268. /**
  269. * Provides the /nick command.
  270. *
  271. * @param command The instantiated command.
  272. * @return The command's details.
  273. */
  274. @Provides(type = Provides.Type.SET)
  275. public CommandDetails getCommand(final Nick command) {
  276. return new SimpleCommandDetails(command, Nick.INFO);
  277. }
  278. /**
  279. * Provides the /notice command.
  280. *
  281. * @param command The instantiated command.
  282. * @return The command's details.
  283. */
  284. @Provides(type = Provides.Type.SET)
  285. public CommandDetails getCommand(final Notice command) {
  286. return new SimpleCommandDetails(command, Notice.INFO);
  287. }
  288. /**
  289. * Provides the /query command.
  290. *
  291. * @param command The instantiated command.
  292. * @return The command's details.
  293. */
  294. @Provides(type = Provides.Type.SET)
  295. public CommandDetails getCommand(final OpenQuery command) {
  296. return new SimpleCommandDetails(command, OpenQuery.INFO);
  297. }
  298. /**
  299. * Provides the /raw command.
  300. *
  301. * @param command The instantiated command.
  302. * @return The command's details.
  303. */
  304. @Provides(type = Provides.Type.SET)
  305. public CommandDetails getCommand(final Raw command) {
  306. return new SimpleCommandDetails(command, Raw.INFO);
  307. }
  308. /**
  309. * Provides the /reconnect command.
  310. *
  311. * @param command The instantiated command.
  312. * @return The command's details.
  313. */
  314. @Provides(type = Provides.Type.SET)
  315. public CommandDetails getCommand(final Reconnect command) {
  316. return new SimpleCommandDetails(command, Reconnect.INFO);
  317. }
  318. /**
  319. * Provides the /umode command.
  320. *
  321. * @param command The instantiated command.
  322. * @return The command's details.
  323. */
  324. @Provides(type = Provides.Type.SET)
  325. public CommandDetails getCommand(final Umode command) {
  326. return new SimpleCommandDetails(command, Umode.INFO);
  327. }
  328. /**
  329. * Provides a set of raw commands.
  330. *
  331. * @param controller The controller to use for command info.
  332. * @return A set of the commands' details.
  333. */
  334. @Provides(type = Provides.Type.SET_VALUES)
  335. public Set<CommandDetails> getRawCommands(final CommandController controller) {
  336. final Set<CommandDetails> results = new HashSet<>();
  337. for (String name : new String[] { "lusers", "map", "motd", "oper", "whois", "who" }) {
  338. final RawServerCommand rawCommand = new RawServerCommand(controller, name);
  339. results.add(new SimpleCommandDetails(rawCommand, rawCommand));
  340. }
  341. return results;
  342. }
  343. /**
  344. * Provides the /alias command.
  345. *
  346. * @param command The instantiated command.
  347. * @return The command's details.
  348. */
  349. @Provides(type = Provides.Type.SET)
  350. public CommandDetails getCommand(final AliasCommand command) {
  351. return new SimpleCommandDetails(command, AliasCommand.INFO);
  352. }
  353. /**
  354. * Provides the /allservers command.
  355. *
  356. * @param command The instantiated command.
  357. * @return The command's details.
  358. */
  359. @Provides(type = Provides.Type.SET)
  360. public CommandDetails getCommand(final AllServers command) {
  361. return new SimpleCommandDetails(command, AllServers.INFO);
  362. }
  363. /**
  364. * Provides the /clear command.
  365. *
  366. * @param command The instantiated command.
  367. * @return The command's details.
  368. */
  369. @Provides(type = Provides.Type.SET)
  370. public CommandDetails getCommand(final Clear command) {
  371. return new SimpleCommandDetails(command, Clear.INFO);
  372. }
  373. /**
  374. * Provides the /echo command.
  375. *
  376. * @param command The instantiated command.
  377. * @return The command's details.
  378. */
  379. @Provides(type = Provides.Type.SET)
  380. public CommandDetails getCommand(final Echo command) {
  381. return new SimpleCommandDetails(command, Echo.INFO);
  382. }
  383. /**
  384. * Provides the /exit command.
  385. *
  386. * @param command The instantiated command.
  387. * @return The command's details.
  388. */
  389. @Provides(type = Provides.Type.SET)
  390. public CommandDetails getCommand(final Exit command) {
  391. return new SimpleCommandDetails(command, Exit.INFO);
  392. }
  393. /**
  394. * Provides the /Help command.
  395. *
  396. * @param command The instantiated command.
  397. * @return The command's details.
  398. */
  399. @Provides(type = Provides.Type.SET)
  400. public CommandDetails getCommand(final Help command) {
  401. return new SimpleCommandDetails(command, Help.INFO);
  402. }
  403. /**
  404. * Provides the /ifplugin command.
  405. *
  406. * @param command The instantiated command.
  407. * @return The command's details.
  408. */
  409. @Provides(type = Provides.Type.SET)
  410. public CommandDetails getCommand(final Ifplugin command) {
  411. return new SimpleCommandDetails(command, Ifplugin.INFO);
  412. }
  413. /**
  414. * Provides the /newserver command.
  415. *
  416. * @param command The instantiated command.
  417. * @return The command's details.
  418. */
  419. @Provides(type = Provides.Type.SET)
  420. public CommandDetails getCommand(final NewServer command) {
  421. return new SimpleCommandDetails(command, NewServer.INFO);
  422. }
  423. /**
  424. * Provides the /notify command.
  425. *
  426. * @param command The instantiated command.
  427. * @return The command's details.
  428. */
  429. @Provides(type = Provides.Type.SET)
  430. public CommandDetails getCommand(final Notify command) {
  431. return new SimpleCommandDetails(command, Notify.INFO);
  432. }
  433. /**
  434. * Provides the /loadplugin command.
  435. *
  436. * @param command The instantiated command.
  437. * @return The command's details.
  438. */
  439. @Provides(type = Provides.Type.SET)
  440. public CommandDetails getCommand(final LoadPlugin command) {
  441. return new SimpleCommandDetails(command, LoadPlugin.INFO);
  442. }
  443. /**
  444. * Provides the /unloadplugin command.
  445. *
  446. * @param command The instantiated command.
  447. * @return The command's details.
  448. */
  449. @Provides(type = Provides.Type.SET)
  450. public CommandDetails getCommand(final UnloadPlugin command) {
  451. return new SimpleCommandDetails(command, UnloadPlugin.INFO);
  452. }
  453. /**
  454. * Provides the /openwindow command.
  455. *
  456. * @param command The instantiated command.
  457. * @return The command's details.
  458. */
  459. @Provides(type = Provides.Type.SET)
  460. public CommandDetails getCommand(final OpenWindow command) {
  461. return new SimpleCommandDetails(command, OpenWindow.INFO);
  462. }
  463. /**
  464. * Provides the /reloadactions command.
  465. *
  466. * @param command The instantiated command.
  467. * @return The command's details.
  468. */
  469. @Provides(type = Provides.Type.SET)
  470. public CommandDetails getCommand(final ReloadActions command) {
  471. return new SimpleCommandDetails(command, ReloadActions.INFO);
  472. }
  473. /**
  474. * Provides the /reloadidentities command.
  475. *
  476. * @param command The instantiated command.
  477. * @return The command's details.
  478. */
  479. @Provides(type = Provides.Type.SET)
  480. public CommandDetails getCommand(final ReloadIdentities command) {
  481. return new SimpleCommandDetails(command, ReloadIdentities.INFO);
  482. }
  483. /**
  484. * Provides the /reloadplugin command.
  485. *
  486. * @param command The instantiated command.
  487. * @return The command's details.
  488. */
  489. @Provides(type = Provides.Type.SET)
  490. public CommandDetails getCommand(final ReloadPlugin command) {
  491. return new SimpleCommandDetails(command, ReloadPlugin.INFO);
  492. }
  493. /**
  494. * Provides the /saveconfig command.
  495. *
  496. * @param command The instantiated command.
  497. * @return The command's details.
  498. */
  499. @Provides(type = Provides.Type.SET)
  500. public CommandDetails getCommand(final SaveConfig command) {
  501. return new SimpleCommandDetails(command, SaveConfig.INFO);
  502. }
  503. /**
  504. * Provides the /set command.
  505. *
  506. * @param command The instantiated command.
  507. * @return The command's details.
  508. */
  509. @Provides(type = Provides.Type.SET)
  510. public CommandDetails getCommand(final SetCommand command) {
  511. return new SimpleCommandDetails(command, SetCommand.INFO);
  512. }
  513. /**
  514. * Simple implementation of {@link CommandDetails}.
  515. */
  516. private static class SimpleCommandDetails implements CommandDetails {
  517. public SimpleCommandDetails(Command command, CommandInfo info) {
  518. this.command = command;
  519. this.info = info;
  520. }
  521. public Command getCommand() {
  522. return command;
  523. }
  524. public CommandInfo getInfo() {
  525. return info;
  526. }
  527. /** The command. */
  528. private final Command command;
  529. /** The command's info. */
  530. private final CommandInfo info;
  531. }
  532. }