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.

SetCommand.java 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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.CommandOptions;
  9. import com.md87.charliebravo.InputHandler;
  10. import com.md87.charliebravo.Response;
  11. /**
  12. *
  13. * @author chris
  14. */
  15. @CommandOptions(requireAuthorisation=true)
  16. public class SetCommand implements Command {
  17. public void execute(InputHandler handler, Response response, String line) throws Exception {
  18. final String openID = (String) handler.getParser().getClientInfoOrFake(response.getSource())
  19. .getMap().get("OpenID");
  20. String target = openID;
  21. String value = line;
  22. int offset;
  23. if ((offset = line.toLowerCase().lastIndexOf("on behalf of")) > -1) {
  24. if (!handler.getConfig().hasOption(openID, "admin.level")
  25. || Integer.parseInt(handler.getConfig().getOption(openID, "admin.level")) < 100) {
  26. response.sendMessage("You do not have sufficient access", true);
  27. return;
  28. } else {
  29. final String user = line.substring(offset + 13);
  30. value = line.substring(0, offset - 1);
  31. final ClientInfo client = handler.getParser().getClientInfo(user);
  32. if (client != null) {
  33. if (client.getMap().get("OpenID") == null) {
  34. response.sendMessage(client.getNickname() + " isn't authed", true);
  35. return;
  36. }
  37. target = (String) client.getMap().get("OpenID");
  38. } else if (handler.getConfig().hasOption(user, "internal.lastseen")) {
  39. target = user;
  40. } else {
  41. response.sendMessage("I couldn't find anyone by that name", true);
  42. return;
  43. }
  44. }
  45. }
  46. final String[] parts = value.split("\\s+", 2);
  47. if (openID == null) {
  48. response.sendMessage("You must be authorised to use this command", true);
  49. } else if (parts.length < 2) {
  50. response.sendMessage("You must specify a setting name and value", true);
  51. } else if (!handler.getConfig().isLegalSetting(parts[0])) {
  52. response.sendMessage("That isn't a legal setting", true);
  53. } else if (parts[0].startsWith("admin.")
  54. && (!handler.getConfig().hasOption(openID, "admin.level")
  55. || Integer.parseInt(handler.getConfig().getOption(openID, "admin.level")) < 100)) {
  56. response.sendMessage("You do not have sufficient access", true);
  57. } else {
  58. handler.getConfig().setOption(target, parts[0], parts[1]);
  59. response.sendMessage("OK", true);
  60. }
  61. }
  62. }