Java IRC bot
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

WhoisCommand.java 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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.dmdirc.ui.messages.Formatter;
  8. import com.md87.charliebravo.Command;
  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. final boolean you = ci.getNickname().equals(response.getSource());
  41. if (openid == null) {
  42. response.sendMessage((you ? "You have" : ci.getNickname() + " has")
  43. + " not authenticated with me", true);
  44. } else {
  45. final StringBuilder extra = new StringBuilder();
  46. if (handler.getConfig().hasOption(openid, "admin.level")) {
  47. extra.append(", and " + (you ? "have" : "has") + " access level ");
  48. extra.append(handler.getConfig().getOption(openid, "admin.level"));
  49. }
  50. response.sendMessage((you ? "you are" : ci.getNickname() + " is")
  51. + " authenticated as " + openid + extra);
  52. }
  53. }
  54. }
  55. }
  56. }