Java IRC bot
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

AuthenticateCommand.java 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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.util.Downloader;
  7. import com.md87.charliebravo.Command;
  8. import com.md87.charliebravo.InputHandler;
  9. import com.md87.charliebravo.Response;
  10. import java.util.List;
  11. /**
  12. *
  13. * @author chris
  14. */
  15. public class AuthenticateCommand implements Command {
  16. @SuppressWarnings("unchecked")
  17. public void execute(InputHandler handler, Response response, String line) throws Exception {
  18. if (line.isEmpty()) {
  19. response.sendMessage("You can get an auth token from http://apps.md87.co.uk/ircopenid/",
  20. true);
  21. } else {
  22. final List<String> result = Downloader
  23. .getPage("http://apps.MD87.co.uk/ircopenid/verify.php?id=" + line);
  24. if (result.isEmpty() || !result.get(0).trim().equalsIgnoreCase("Success")) {
  25. response.sendMessage("I could not authenticate that token", true);
  26. } else {
  27. final String openid = result.get(1).trim();
  28. handler.getParser().getClientInfoOrFake(response.getSource())
  29. .getMap().put("OpenID", openid);
  30. handler.getConfig().setOption(openid, "internal.lastseen",
  31. System.currentTimeMillis());
  32. handler.getConfig().setOption(openid, "internal.lastuser",
  33. handler.getParser().getClientInfoOrFake(response.getSource()).toString());
  34. response.sendMessage("You are now authenticated as " + openid, true);
  35. }
  36. }
  37. }
  38. }