Пример #1
0
 @Override
 public boolean execute(String[] params, IUserData data, IMessageEventWrapper event) {
   if (!Aphelion.getAphelion().isBotOp(event.getChannelName())) {
     event.error("You cannot use this command on this channel, I am not an op.");
     return true;
   }
   if (params.length < 1 && !(event instanceof PrivateCommandEvent)) {
     data.ban();
     return true;
   } else if (params.length < 1) {
     return true;
   }
   if (params.length == 2) {
     UserData ud = Aphelion.getAphelion().getUserDatabase().get(params[0], params[1]);
     if (ud == null) {
       event.respond("Who's " + Colors.BOLD + params[0] + Colors.NORMAL + "?");
       return true;
     }
     if (!ud.safeToRunChanOp()) {
       event.error("Cannot run ChanOperation on this user, they are not online!");
       return true;
     }
     ud.ban();
     return true;
   }
   UserData ud = Aphelion.getAphelion().getUserDatabase().get(params[0], event.getChannelName());
   if (ud == null) {
     event.respond("Who's " + Colors.BOLD + params[0] + Colors.NORMAL + "?");
     return true;
   }
   if (!ud.safeToRunChanOp()) {
     event.error("Cannot run ChanOperation on this user, they are not online!");
     return true;
   }
   ud.ban();
   return true;
 }
Пример #2
0
  @Override
  public boolean execute(String[] params, IUserData data, IMessageEventWrapper event) {
    if (params.length == 0) {
      event.error(Responses.INVALID_SYNTAX);
      return false;
    }
    if (params[0].equalsIgnoreCase("describe")) {
      if (params.length != 2) {
        event.error(Responses.INVALID_SYNTAX);
        return false;
      }
      event.respond(FlagRegistry.getDescription(params[1]));
      return true;
    } else if (params[0].equalsIgnoreCase("give")) {
      if (params.length != 3) {
        event.error(Responses.INVALID_SYNTAX);
        return false;
      }
      if (params[2].equalsIgnoreCase("ALL")) {
        GlobalUserData gud = Aphelion.getAphelion().getUserDatabase().get(data.getNick());
        if (FlagRegistry.requiresSuperadmin(params[2])
            && !gud.hasFlag("SUPERADMIN")
            && Aphelion.getAphelion().getUserDatabase().anyUserHasFlag("SUPERADMIN")) {
          event.error("Cannot give flag because it requires that you have SUPERADMIN powers.");
          return false;
        } else if (!gud.hasFlag("SUPERADMIN")) {
          event.warning("Giving flag to user, but it requires that you have SUPERADMIN powers.");
          event.warning("Allowing access anyway because there are no registered SUPERADMINS.");
        }
        for (String f : FlagRegistry.getFlags()) {
          if (!FlagRegistry.isNegative(f)) {
            if (FlagRegistry.requiresSuperadmin(f)) {
              GlobalUserData ud = Aphelion.getAphelion().getUserDatabase().get(params[1]);

              if (ud == null) {
                event.respond("Who's " + Colors.BOLD + params[1] + "?");
                return true;
              }
              if (ud.hasFlag(f)) {
                continue;
              }
              event.success(
                  "Giving global flag "
                      + Colors.BOLD
                      + f
                      + Colors.NORMAL
                      + Colors.GREEN
                      + " to user "
                      + Colors.BOLD
                      + params[1]);
              ud.giveFlag(f);
            } else {
              UserData ud =
                  Aphelion.getAphelion().getUserDatabase().get(params[1], event.getChannelName());
              if (ud == null) {
                event.respond("Who's " + Colors.BOLD + params[1] + "?");
                return true;
              }
              if (ud.hasFlag(f)) {
                continue;
              }
              event.success(
                  "Giving flag "
                      + Colors.BOLD
                      + f
                      + Colors.NORMAL
                      + Colors.GREEN
                      + " to user "
                      + Colors.BOLD
                      + params[1]);
              ud.giveFlag(f);
            }
          }
        }
        return true;
      }
      if (!FlagRegistry.hasFlag(params[2])) {
        event.warning(
            "I can't give flag "
                + Colors.BOLD
                + params[2]
                + Colors.NORMAL
                + Colors.BLUE
                + " to "
                + params[1]
                + " because the flag doesn't exist!");
      } else {
        GlobalUserData gud = Aphelion.getAphelion().getUserDatabase().get(data.getNick());
        if (FlagRegistry.requiresSuperadmin(params[2])
            && !gud.hasFlag("SUPERADMIN")
            && Aphelion.getAphelion().getUserDatabase().anyUserHasFlag("SUPERADMIN")) {
          event.error("Cannot give flag because it requires that you have SUPERADMIN powers.");
          return false;
        } else if (!gud.hasFlag("SUPERADMIN")) {
          event.warning("Giving flag to user, but it requires that you have SUPERADMIN powers.");
          event.warning("Allowing access anyway because there are no registered SUPERADMINS.");
        }
        if (FlagRegistry.requiresSuperadmin(params[2])) {
          event.warning("Adding to global user list!");
          GlobalUserData ud = Aphelion.getAphelion().getUserDatabase().get(params[1]);
          if (ud == null) {
            event.respond("Who's " + Colors.BOLD + params[1] + Colors.NORMAL + "?");
            return true;
          }
          ud.giveFlag(params[2]);
          return true;
        }
        UserData ud =
            Aphelion.getAphelion().getUserDatabase().get(params[1], event.getChannelName());
        if (ud == null) {
          event.respond("Who's " + Colors.BOLD + params[1] + "?");
          return true;
        }
        event.success(
            "Giving flag "
                + Colors.BOLD
                + params[2]
                + Colors.NORMAL
                + Colors.GREEN
                + " to user "
                + Colors.BOLD
                + params[1]);
        ud.giveFlag(params[2]);
      }
    } else if (params[0].equalsIgnoreCase("take")) {
      if (params.length != 3) {
        event.error(Responses.INVALID_SYNTAX);
        return false;
      }
      if (!FlagRegistry.hasFlag(params[2])) {
        event.warning(
            "I can't take flag "
                + Colors.BOLD
                + params[2]
                + Colors.NORMAL
                + Colors.BLUE
                + " from user "
                + params[1]
                + " because the flag doesn't exist!");
      } else {
        GlobalUserData gud = Aphelion.getAphelion().getUserDatabase().get(data.getUser());
        if (FlagRegistry.requiresSuperadmin(params[2])
            && !gud.hasFlag("SUPERADMIN")
            && Aphelion.getAphelion().getUserDatabase().anyUserHasFlag("SUPERADMIN")) {
          event.error("Cannot give flag because it requires that you have SUPERADMIN powers.");
          return false;
        } else if (!gud.hasFlag("SUPERADMIN")) {
          event.warning("Giving flag to user, but it requires that you have SUPERADMIN powers.");
          event.warning("Allowing access anyway because there are no registered SUPERADMINS.");
        }
        if (FlagRegistry.requiresSuperadmin(params[2])) {
          event.warning("Adding to global user list!");
          GlobalUserData ud = Aphelion.getAphelion().getUserDatabase().get(params[1]);
          if (ud == null) {
            event.respond("Who's " + Colors.BOLD + params[1] + Colors.NORMAL + "?");
            return true;
          }
          ud.takeFlag(params[2]);
          return true;
        }
        UserData ud =
            Aphelion.getAphelion().getUserDatabase().get(params[1], event.getChannelName());
        if (ud == null) {
          event.respond("Who's " + Colors.BOLD + params[1] + "?");
          return true;
        }
        event.success(
            "Taking flag "
                + Colors.BOLD
                + params[2]
                + Colors.NORMAL
                + Colors.GREEN
                + " from user "
                + params[1]);
        ud.takeFlag(params[2]);
      }
    } else if (params[0].equalsIgnoreCase("list")) {
      if (params.length < 2) {
        event.error(Responses.INVALID_SYNTAX);
        return false;
      }
      String flist = "";
      UserData ud = Aphelion.getAphelion().getUserDatabase().get(params[1], event.getChannelName());
      if (ud == null) {
        event.respond("Who's " + Colors.BOLD + params[1] + "?");
        return true;
      }
      for (String flag : ud.flags) {
        flist += flag + ", ";
      }
      if (flist.length() == 0) {
        event.warning("The user " + params[1] + " has no flags for this channel!");
      } else {
        flist = flist.substring(0, flist.lastIndexOf(","));
        event.success(
            "The user " + params[1] + " has these flags for " + event.getChannelName() + ":");
        for (String s : Utility.getParts(flist, 250)) {
          event.success(s);
        }
      }
      flist = "";
      GlobalUserData gud = Aphelion.getAphelion().getUserDatabase().get(params[1]);
      for (String flag : gud.flags) {
        flist += flag + ", ";
      }
      if (flist.isEmpty()) {
        event.warning("The user " + params[1] + " has no global flags.");
        return true;
      }
      flist = flist.substring(0, flist.lastIndexOf(","));
      event.success("And these global flags:");
      for (String s : Utility.getParts(flist, 250)) {
        event.success(s);
      }
      return true;
    } else if (params[0].equalsIgnoreCase("listall")) {
      String flist = "";
      for (String flag : FlagRegistry.getFlags()) {
        if (FlagRegistry.requiresSuperadmin(flag)) {
          flist += "(S)" + flag + ", ";
          continue;
        }
        flist += flag + ", ";
      }
      flist = flist.substring(0, flist.lastIndexOf(","));
      event.success("These are all the assignable flags: ");
      for (String s : Utility.getParts(flist, 250)) {
        event.success(s);
      }
    } else if (params[0].equalsIgnoreCase("updatehostmask")) {
      if (params.length < 3) {
        event.error(Responses.INVALID_SYNTAX);
        return false;
      }
      UserData ud = Aphelion.getAphelion().getUserDatabase().get(params[1], event.getChannelName());
      ud.hostmask = params[2];
      event.success("Changed the hostmask for " + params[1] + " to " + params[2]);
    }
    return true;
  }