Java IRC bot
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.

WhoisCommand.java 3.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright (c) 2009-2010 Chris Smith
  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.md87.charliebravo.commands;
  23. import com.dmdirc.parser.interfaces.ClientInfo;
  24. import com.dmdirc.util.DateUtils;
  25. import com.md87.charliebravo.Command;
  26. import com.md87.charliebravo.InputHandler;
  27. import com.md87.charliebravo.Response;
  28. /**
  29. *
  30. * @author chris
  31. */
  32. public class WhoisCommand implements Command {
  33. @SuppressWarnings("unchecked")
  34. public void execute(InputHandler handler, Response response, String line) throws Exception {
  35. if (line.isEmpty()) {
  36. response.sendRawMessage("Who would you like to whois, " + response.getSource() + "?");
  37. } else {
  38. final ClientInfo ci = handler.getParser().getClient(line);
  39. if (ci == null) {
  40. if (handler.getConfig().hasOption(line, "internal.lastseen")) {
  41. final StringBuilder extra = new StringBuilder();
  42. if (handler.getConfig().hasOption(line, "admin.level")) {
  43. extra.append(", and has access level ");
  44. extra.append(handler.getConfig().getOption(line, "admin.level"));
  45. }
  46. response.sendMessage(line + " last authenticated with me "
  47. + DateUtils.formatDuration((int)
  48. (System.currentTimeMillis() -
  49. Long.valueOf(handler.getConfig().getOption(line, "internal.lastseen")))
  50. / 1000)
  51. + " ago" + extra);
  52. } else {
  53. response.sendMessage("I am not aware of anyone by that name", true);
  54. }
  55. } else {
  56. final String openid = (String) ci.getMap().get("OpenID");
  57. final boolean you = ci.getNickname().equals(response.getSource());
  58. if (openid == null) {
  59. response.sendMessage((you ? "You have" : ci.getNickname() + " has")
  60. + " not authenticated with me", true);
  61. } else {
  62. final StringBuilder extra = new StringBuilder();
  63. if (handler.getConfig().hasOption(openid, "admin.level")) {
  64. extra.append(", and ").append(you ? "have" : "has").append(" access level ");
  65. extra.append(handler.getConfig().getOption(openid, "admin.level"));
  66. }
  67. response.sendMessage((you ? "you are" : ci.getNickname() + " is")
  68. + " authenticated as " + openid + extra);
  69. }
  70. }
  71. }
  72. }
  73. }