Package net.bnubot.core.commands

Examples of net.bnubot.core.commands.CommandFailedWithDetailsException


  @Override
  public void run(Connection source, BNetUser user, String param, String[] params, boolean whisperBack, Account commanderAccount, boolean superUser)
  throws Exception {
    Vote vote = CommandEventHandler.votes.get(source);
    if(vote == null)
      throw new CommandFailedWithDetailsException("There is no vote in progress");
    vote.cancel();
  }
View Full Code Here


      if(params.length != 1)
        throw new InvalidUseException();

      Command rsSubjectCommand = Command.get(params[0]);
      if(rsSubjectCommand == null)
        throw new CommandFailedWithDetailsException("The command [" + params[0] + "] does not exist!");

      params[0] = rsSubjectCommand.getName();
      int access = rsSubjectCommand.getAccess();

      user.sendChat("Authorization required for " + params[0] + " is " + access, whisperBack);
View Full Code Here

      if((params == null) || (params.length != 2))
        throw new InvalidUseException();

      Command rsCommand = Command.get(params[0]);
      if(rsCommand == null)
        throw new CommandFailedWithDetailsException("That command does not exist!");

      try {
        int oldAccess = rsCommand.getAccess();
        int access = Integer.parseInt(params[1]);
        Rank rank = Rank.get(access);
        if(rank == null)
          throw new CommandFailedWithDetailsException("That access level does not exist!");
        rsCommand.setRank(rank);
        rsCommand.updateRow();

        user.sendChat("Successfully changed the authorization required for command [" + rsCommand.getName() + "] from [" + oldAccess + "] to [" + access + "]", whisperBack);
      } catch(NumberFormatException e) {
View Full Code Here

      if(params.length < 2)
        throw new InvalidUseException();

      Command rsSubjectCommand = Command.get(params[0]);
      if(rsSubjectCommand == null)
        throw new CommandFailedWithDetailsException("The command [" + params[0] + "] does not exist!");

      for(int i = 1; i < params.length; i++) {
        if(Command.get(params[i]) != null)
          throw new CommandFailedWithDetailsException("The command [" + params[0] + "] already exists!");
        if(CommandAlias.get(params[i]) != null)
          throw new CommandFailedWithDetailsException("The command alias [" + params[0] + "] already exists!");
      }

      String out = "Successfully created aliases for " + params[0] + ": ";
      for(int i = 1; i < params.length; i++) {
        if(i != 1)
          out += ", ";
        out += params[i];

        if(CommandAlias.create(rsSubjectCommand, params[i]) == null)
          throw new CommandFailedWithDetailsException("Error creating alias " + params[i]);
      }
      user.sendChat(out, whisperBack);
    } catch(InvalidUseException e) {
      user.sendChat("Use: %trigger%addalias <command> <alias1> [alias2] [alias3...]", whisperBack);
    }
View Full Code Here

public final class CommandSetBirthday implements CommandRunnable {
  @Override
  public void run(Connection source, BNetUser user, String param, String[] params, boolean whisperBack, Account commanderAccount, boolean superUser)
  throws Exception {
    if(commanderAccount == null)
      throw new CommandFailedWithDetailsException("You must have an account to use setbirthday.");

    try {
      if(params == null)
        throw new InvalidUseException();
View Full Code Here

        duration = TimeFormatter.parseDuration(params[1]);
      } catch(NumberFormatException e) {
        throw new InvalidUseException();
      }
      if(duration < 30 * TimeFormatter.SECOND)
        throw new CommandFailedWithDetailsException("You may not timeban for less than 30 seconds");

      doTimeBan(source, user, bnSubject, duration);
    } catch(InvalidUseException e) {
      user.sendChat("Use: %trigger%timeban <user>[@realm] [#days] [#hours] ... -- example: %trigger%timeban c0ke@USEast 100days", whisperBack);
    }
View Full Code Here

      return;
    }

    Account rsAccount = Account.get(params[0]);
    if(rsAccount != null)
      throw new CommandFailedWithDetailsException("The account [" + rsAccount.getName() + "] already exists");

    rsAccount = Account.create(params[0], Rank.get(0), commanderAccount);
    if(rsAccount == null)
      throw new CommandFailedWithDetailsException("Failed to create account [" + params[0] + "] for an unknown reason");
    user.sendChat("The account [" + params[0] + "] has been created", whisperBack);
  }
View Full Code Here

public final class CommandMail implements CommandRunnable {
  @Override
  public void run(Connection source, BNetUser user, String param, String[] params, boolean whisperBack, Account commanderAccount, boolean superUser)
  throws Exception {
    if(commanderAccount == null)
      throw new CommandFailedWithDetailsException("You must have an account to use mail.");

    try {
      if((params == null) || (params.length < 1))
        throw new InvalidUseException();
      if(params[0].equals("send")) {
        //send <account> <message>
        params = param.split(" ", 3);
        if(params.length < 3)
          throw new InvalidUseException();

        Account rsTargetAccount = Account.get(params[1]);
        if(rsTargetAccount == null)
          throw new AccountDoesNotExistException(params[1]);

        params[1] = rsTargetAccount.getName();
        Mail.send(commanderAccount, rsTargetAccount, params[2]);
        user.sendChat("Mail queued for delivery to " + rsTargetAccount.getName(), whisperBack);
      } else if(params[0].equals("read")
          ||params[0].equals("get")) {
        //read [number]
        if((params.length < 1) || (params.length > 2))
          throw new InvalidUseException();

        int id = 0;
        boolean all = false;
        if(params.length == 2) {
          try {
            id = Integer.parseInt(params[1]);
          } catch(Exception e) {
            if(!"all".equals(params[1]))
              throw new InvalidUseException();
            all = true;
          }
        }

        List<Mail> rsMail = getMail(commanderAccount);
        if(all) {
          for(Mail m : getMail(commanderAccount))
            sendMail(user, whisperBack, ++id, rsMail.size(), m);
        } else if(id == 0) {
          for(Mail m : rsMail) {
            id++;
            if(m.isIsread())
              continue;

            sendMail(user, whisperBack, id, rsMail.size(), m);
            return;
          }

          String message = "You have no unread mail!";
          if(rsMail.size() > 0)
            message += " To read your " + rsMail.size() + " messages, type [ %trigger%mail read <number> ]";
          throw new CommandFailedWithDetailsException(message);
        } else {
          if((rsMail.size() >= id) && (id >= 1))
            sendMail(user, whisperBack, id, rsMail.size(), rsMail.get(id-1));
          else
            throw new CommandFailedWithDetailsException("You only have " + rsMail.size() + " messages!");
        }
        return;
      } else if(params[0].equals("delete")) {
        //delete <number>
        if(params.length != 2)
          throw new InvalidUseException();

        int id;
        try {
          id = Integer.parseInt(params[1]);
        } catch(Exception e) {
          throw new InvalidUseException();
        }

        List<Mail> rsMail = getMail(commanderAccount);

        if((rsMail.size() >= id) && (id >= 1)) {
          Mail m = rsMail.get(id-1);
          String response = "Deleted " + constructMessage(id, rsMail.size(), m);

          try {
            ObjectContext context = commanderAccount.getObjectContext();
            context.deleteObject(m);
            commanderAccount.updateRow();
            user.sendChat(response, true);

            context.performQuery(new RefreshQuery(commanderAccount));
          } catch(Exception e) {
            throw new CommandFailedWithDetailsException("Failed to delete mail", e);
          }
        } else {
          throw new CommandFailedWithDetailsException("You only have " + rsMail.size() + " messages!");
        }

      } else if(params[0].equals("empty")
          ||params[0].equals("clear")) {
        //empty
        if(params.length != 1)
          throw new InvalidUseException();

        if(Mail.getUnreadCount(commanderAccount) > 0)
          throw new CommandFailedWithDetailsException("You have unread mail!");

        try {
          ObjectContext context = commanderAccount.getObjectContext();
          for(Mail m : commanderAccount.getRecievedMail())
            context.deleteObject(m);
          commanderAccount.updateRow();
          user.sendChat("Mailbox cleaned!", whisperBack);
        } catch(Exception e) {
          throw new CommandFailedWithDetailsException("Failed to delete mail", e);
        }
      } else
        throw new InvalidUseException();
    } catch(InvalidUseException e) {
      user.sendChat("Use: " +
View Full Code Here

    m.setIsread(true);
    try {
      m.updateRow();
    } catch(Exception e) {
      throw new CommandFailedWithDetailsException("Failed to set mail read", e);
    }
  }
View Full Code Here

      user.sendChat("Use: %trigger%recruit <user>[@<realm>] <account>", whisperBack);
      return;
    }

    if(commanderAccount == null)
      throw new CommandFailedWithDetailsException("You must have an account to use recruit.");

    BNetUser bnSubject = source.getCreateBNetUser(params[0], user);
    BNLogin rsSubject = BNLogin.get(bnSubject);
    if(rsSubject == null)
      throw new NeverSeenUserException(bnSubject);

    if(rsSubject.getAccount() != null)
      throw new CommandFailedWithDetailsException("That user already has an account!");

    String requiredTagPrefix = GlobalSettings.recruitTagPrefix;
    String requiredTagSuffix = GlobalSettings.recruitTagSuffix;

    if(requiredTagPrefix != null) {
      if(bnSubject.getFullAccountName().substring(0, requiredTagPrefix.length()).compareToIgnoreCase(requiredTagPrefix) != 0)
        throw new CommandFailedWithDetailsException("That user must have the " + requiredTagPrefix + " tag!");
    }

    if(requiredTagSuffix != null) {
      String s = bnSubject.getFullAccountName();
      int i = s.indexOf("@");
      if(i != -1)
        s = s.substring(0, i);
      s = s.substring(s.length() - requiredTagSuffix.length());
      if(s.compareToIgnoreCase(requiredTagSuffix) != 0)
        throw new CommandFailedWithDetailsException("That user must have the " + requiredTagSuffix + " tag!");
    }

    CommandEventHandler.createAccount(params[1], GlobalSettings.recruitAccess, commanderAccount, rsSubject);

    bnSubject.resetPrettyName();
View Full Code Here

TOP

Related Classes of net.bnubot.core.commands.CommandFailedWithDetailsException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.