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 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5. package com.md87.charliebravo.commands;
  6. import com.dmdirc.parser.irc.ClientInfo;
  7. import com.md87.charliebravo.Command;
  8. import com.md87.charliebravo.Formatter;
  9. import com.md87.charliebravo.InputHandler;
  10. import com.md87.charliebravo.Response;
  11. /**
  12. *
  13. * @author chris
  14. */
  15. public class WhoisCommand implements Command {
  16. @SuppressWarnings("unchecked")
  17. public void execute(InputHandler handler, Response response, String line) throws Exception {
  18. if (line.isEmpty()) {
  19. response.sendRawMessage("Who would you like to whois, " + response.getSource() + "?");
  20. } else {
  21. final ClientInfo ci = handler.getParser().getClientInfo(line);
  22. if (ci == null) {
  23. if (handler.getConfig().hasOption(line, "internal.lastseen")) {
  24. final StringBuilder extra = new StringBuilder();
  25. if (handler.getConfig().hasOption(line, "admin.level")) {
  26. extra.append(", and has access level ");
  27. extra.append(handler.getConfig().getOption(line, "admin.level"));
  28. }
  29. response.sendMessage(line + " last authenticated with me "
  30. + Formatter.formatDuration((int)
  31. (System.currentTimeMillis() -
  32. Long.valueOf(handler.getConfig().getOption(line, "internal.lastseen")))
  33. / 1000)
  34. + " ago" + extra);
  35. } else {
  36. response.sendMessage("I am not aware of anyone by that name", true);
  37. }
  38. } else {
  39. final String openid = (String) ci.getMap().get("OpenID");
  40. if (openid == null) {
  41. response.sendMessage(ci.getNickname() + " has not authenticated with me", true);
  42. } else {
  43. final StringBuilder extra = new StringBuilder();
  44. if (handler.getConfig().hasOption(openid, "admin.level")) {
  45. extra.append(", and has access level ");
  46. extra.append(handler.getConfig().getOption(openid, "admin.level"));
  47. }
  48. response.sendMessage((ci.getNickname().equals(response.getSource()) ?
  49. "you are " : ci.getNickname() + " is")
  50. + " authenticated as " + openid + extra);
  51. }
  52. }
  53. }
  54. }
  55. }