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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack, Gregory Holmes
  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.server;
  23. import com.dmdirc.Config;
  24. import com.dmdirc.Server;
  25. import com.dmdirc.commandparser.CommandManager;
  26. import com.dmdirc.commandparser.CommandWindow;
  27. import com.dmdirc.commandparser.ServerCommand;
  28. import com.dmdirc.identities.Identity;
  29. import com.dmdirc.identities.IdentityManager;
  30. /**
  31. * Allows the user to add/view/delete ignores.
  32. * @author chris
  33. */
  34. public final class Ignore extends ServerCommand {
  35. /**
  36. * Creates a new instance of Ignore.
  37. */
  38. public Ignore() {
  39. super();
  40. CommandManager.registerCommand(this);
  41. }
  42. /**
  43. * Executes this command.
  44. * @param origin The frame in which this command was issued
  45. * @param server The server object that this command is associated with
  46. * @param args The user supplied arguments
  47. */
  48. public void execute(final CommandWindow origin, final Server server,
  49. final String... args) {
  50. final Identity identity = IdentityManager.getNetworkConfig(server.getNetwork());
  51. if (args.length == 0 || args[0].toLowerCase().equals("view")) {
  52. if (identity.hasOption("network", "ignorelist")) {
  53. final String list = identity.getOption("network", "ignorelist");
  54. if (list.length() > 0) {
  55. origin.addLine("commandOutput", "Ignore list:");
  56. int i = 0;
  57. for (String line : list.split("\n")) {
  58. i++;
  59. origin.addLine("commandOutput", i + ". " + list);
  60. }
  61. } else {
  62. origin.addLine("commandError", "No ignore list entries for this network.");
  63. }
  64. } else {
  65. origin.addLine("commandError", "No ignore list entries for this network.");
  66. }
  67. } else if (args[0].toLowerCase().equals("add") && args.length > 1) {
  68. final String host = implodeArgs(1, args);
  69. String list = host;
  70. if (identity.hasOption("network", "ignorelist")) {
  71. list = identity.getOption("network", "ignorelist");
  72. list = list + "\n" + host;
  73. }
  74. identity.setOption("network", "ignorelist", list);
  75. origin.addLine("commandOutput", "Added " + host + " to the ignore list.");
  76. } else if (args[0].toLowerCase().equals("remove") && args.length > 1) {
  77. final String host = implodeArgs(1, args);
  78. final StringBuffer newlist = new StringBuffer();
  79. boolean found = false;
  80. if (identity.hasOption("network", "ignorelist")) {
  81. final String list = identity.getOption("network", "ignorelist");
  82. for (String entry : list.split("\n")) {
  83. if (entry.toLowerCase().equals(host)) {
  84. found = true;
  85. } else {
  86. if (newlist.length() > 0) {
  87. newlist.append('\n');
  88. }
  89. newlist.append(entry);
  90. }
  91. }
  92. }
  93. if (found) {
  94. identity.setOption("network", "ignorelist", newlist.toString());
  95. origin.addLine("commandOutput", "Removed " + host + " from the ignore list.");
  96. } else {
  97. origin.addLine("commandError", "Host '" + host + "' not found.");
  98. }
  99. } else {
  100. origin.addLine("commandUsage", Config.getCommandChar(), "ignore",
  101. "<add|remove|view> [host]");
  102. }
  103. server.updateIgnoreList();
  104. }
  105. /** {@inheritDoc}. */
  106. public String getName() {
  107. return "ignore";
  108. }
  109. /** {@inheritDoc}. */
  110. public boolean showInHelp() {
  111. return true;
  112. }
  113. /** {@inheritDoc}. */
  114. public boolean isPolyadic() {
  115. return true;
  116. }
  117. /** {@inheritDoc}. */
  118. public int getArity() {
  119. return 0;
  120. }
  121. /** {@inheritDoc}. */
  122. public String getHelp() {
  123. return "ignore <add|remove|view> [host] - manages the network's ignore list";
  124. }
  125. }