Package net.bnubot.core.commands

Examples of net.bnubot.core.commands.InvalidUseException


  public void run(Connection source, BNetUser user, String param, String[] params, boolean whisperBack, Account commanderAccount, boolean superUser)
  throws Exception {
    try {
      //<rank> <message>
      if(param == null)
        throw new InvalidUseException();
      params = param.split(" ", 2);
      if((params.length < 2) || (params[1].length() == 0))
        throw new InvalidUseException();

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

      String message = "[Sent to ranks " + rank + "+] " + params[1];

      List<Account> rsAccounts = Account.getRanked(rank);
View Full Code Here


  @Override
  public void run(Connection source, BNetUser user, String param, String[] params, boolean whisperBack, Account commanderAccount, boolean superUser)
  throws Exception {
    try {
      if(params == null)
        throw new InvalidUseException();
      if(params.length != 2)
        throw new InvalidUseException();

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

      Account subjectAccount = CommandEventHandler.findOrCreateAccount(source, user, commanderAccount, params[0], targetAccess);
      CommandEventHandler.setAccountAccess(user, commanderAccount, subjectAccount, targetAccess, superUser, whisperBack);
    } catch(InvalidUseException e) {
View Full Code Here

  @Override
  public void run(Connection source, BNetUser user, String param, String[] params, boolean whisperBack, Account commanderAccount, boolean superUser)
  throws Exception {
    try {
      if(params == null)
        throw new InvalidUseException();
      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!");
View Full Code Here

  @Override
  public void run(Connection source, BNetUser user, String param, String[] params, boolean whisperBack, Account commanderAccount, boolean superUser)
  throws Exception {
    try {
      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) {
        throw new InvalidUseException();
      }
    } catch(InvalidUseException e) {
      user.sendChat("Use: %trigger%setauth <command> <access>", whisperBack);
    }
  }
View Full Code Here

  @Override
  public void run(Connection source, BNetUser user, String param, String[] params, boolean whisperBack, Account commanderAccount, boolean superUser)
  throws Exception {
    try {
      if(params == null)
        throw new InvalidUseException();
      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!");
View Full Code Here

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

    try {
      if(params == null)
        throw new InvalidUseException();

      Date bd = null;
      try {
        SimpleDateFormat sdf = new SimpleDateFormat("M/d/y");
        bd = sdf.parse(param);
      } catch(Exception e) {
        Out.exception(e);
      }
      if(bd == null)
        throw new InvalidUseException();

      commanderAccount.setBirthday(new java.sql.Date(bd.getTime()));
      commanderAccount.updateRow();

      user.sendChat("Your birthday has been set to [ " + new SimpleDateFormat("M/d/y").format(bd) + " ]", whisperBack);
View Full Code Here

  @Override
  public void run(Connection source, BNetUser user, String param, String[] params, boolean whisperBack, Account commanderAccount, boolean superUser)
  throws Exception {
    try {
      if(params == null)
        throw new InvalidUseException();
      if(params.length != 1)
        throw new InvalidUseException();

      Account subjectAccount = CommandEventHandler.findOrCreateAccount(source, user, commanderAccount, params[0], 0);

      int targetAccess = subjectAccount.getAccess() - 1;
      CommandEventHandler.setAccountAccess(user, commanderAccount, subjectAccount, targetAccess, superUser, whisperBack);
View Full Code Here

  @Override
  public void run(Connection source, BNetUser user, String param, String[] params, boolean whisperBack, Account commanderAccount, boolean superUser)
  throws Exception {
    try {
      if((params == null) || (params.length < 2))
        throw new InvalidUseException();
      params = param.split(" ", 2);

      BNetUser bnSubject = source.findUser(params[0], user);
      if(bnSubject == null)
        throw new NeverSeenUserException(params[0]);

      long duration;
      try {
        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);
View Full Code Here

    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: " +
          "%trigger%mail read [number | all], " +
          "%trigger%mail delete <number>, " +
          "%trigger%mail empty, " +
View Full Code Here

  }

  public static void doKickBan(Connection source, BNetUser user, String param, boolean isBan, boolean whisperBack)
  throws InvalidUseException, CommandFailedWithDetailsException {
    if((param == null) || (param.length() == 0))
      throw new InvalidUseException();

    // Extract the reason
    String[] params = param.split(" ", 2);
    String reason = params[0];
    if(params.length > 1)
View Full Code Here

TOP

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

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.