Package net.bnubot.db

Examples of net.bnubot.db.Account


      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);
    } catch(InvalidUseException e) {
      user.sendChat("Use: %trigger%demote <account>", whisperBack);
    }
  }
View Full Code Here


    if((params == null) || (params.length != 1)) {
      user.sendChat("Use: %trigger%createaccount <account>", whisperBack);
      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

        //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();
View Full Code Here

    if((params == null) || (params.length != 2)) {
      user.sendChat("Use: %trigger%setrecruiter <account> <account>", whisperBack);
      return;
    }

    Account rsSubject = Account.get(params[0]);
    if(rsSubject == null)
      throw new AccountDoesNotExistException(params[0]);
    params[0] = rsSubject.getName();

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

    String recursive = params[0];

    Account cb = rsTarget;
    do {
      recursive += " -> " + cb.getName();
      if(cb == rsSubject) {
        user.sendChat("Recursion detected: " + recursive, whisperBack);
        break;
      }

      cb = cb.getRecruiter();

      if(cb == null) {
        rsSubject.setRecruiter(rsTarget);
        rsSubject.updateRow();
        user.sendChat("Successfully updated recruiter for [ " + params[0] + " ] to [ " + params[1] + " ]" , whisperBack);
View Full Code Here

  }

  private String resetTrivia() {
    List<Account> leaders = Account.getTriviaLeaders();
    if((leaders != null) && (leaders.size() > 0)) {
      Account winner = leaders.get(0);
      // Increment the winner's wins
      winner.setTriviaWin(winner.getTriviaWin() + 1);
      // Reset all scores to zero
      for(Account a : leaders)
        a.setTriviaCorrect(0);
      try {
        // Save changes
        winner.updateRow();
        // Return the winner's name
        return winner.getName();
      } catch(Exception e) {
        Out.exception(e);
      }
    }
    return null;
View Full Code Here

            unanswered = 0;
            String extra = "!";

            if(DatabaseContext.getContext() != null) {
              try {
                Account answeredBy = Account.get(answerUser);
                if(answeredBy != null) {
                  int score = answeredBy.getTriviaCorrect();
                  score++;
                  answeredBy.setTriviaCorrect(score);
                  answeredBy.updateRow();
                  extra += " Your score is " + score + ".";
                }
              } catch(Exception e) {
                Out.exception(e);
              }
View Full Code Here

   * @return the created account
   * @throws AccountDoesNotExistException if the account
   */
  public static Account createAccount(String accountName, int targetAccess, Account recruiter, BNLogin subject)
  throws AccountDoesNotExistException {
    Account rsSubjectAccount = Account.get(accountName);
    if(rsSubjectAccount != null)
      throw new AccountDoesNotExistException("That account already exists!");

    try {
      rsSubjectAccount = Account.create(accountName, Rank.get(0), recruiter);
    } catch(Exception e) {}

    if(rsSubjectAccount == null)
      throw new AccountDoesNotExistException("Failed to create account [" + accountName + "] for an unknown reason");

    subject.setAccount(rsSubjectAccount);
    rsSubjectAccount.setRank(Rank.get(targetAccess));

    try {
      rsSubjectAccount.updateRow();
      return rsSubjectAccount;
    } catch(Exception e) {
      throw new AccountDoesNotExistException(e.getMessage());
    }
  }
View Full Code Here

   * @throws AccountDoesNotExistException if createAccount() fails
   * @throws CommandFailedWithDetailsException if the {@link BNLogin} has never been seen
   */
  public static Account findOrCreateAccount(Connection source, BNetUser commander, Account commanderAccount, String accountName, int createAccess)
  throws CommandFailedWithDetailsException, AccountDoesNotExistException {
    Account subjectAccount = Account.get(accountName);
    if(subjectAccount != null)
      return subjectAccount;

    // They don't have an account by that name, check if it's a user
    BNetUser bnSubject = source.getCreateBNetUser(accountName, commander);
View Full Code Here

    }
  }

  private static boolean canKickBan(BNetUser user, BNetUser subject) {
    // If the subject has no account, the user outranks them
    Account as = Account.get(subject);
    if(as == null)
      return true;
    // If the user has no account, the subject outranks them
    Account au = Account.get(user);
    if(au == null)
      return false;
    // Compare access
    return (au.getAccess() > as.getAccess());
  }
View Full Code Here

        rsUser.updateRow();
      } catch(Exception e) {
        Out.exception(e);
      }

      Account rsAccount = Account.get(user);
      Rank rsRank = (rsAccount == null) ? Rank.get(0) : rsAccount.getRank();

      if(rsRank != null) {
        // Autopromotions
        Integer apDays = rsRank.getApDays();
        // Check that they meet the days requirement
        apBlock: if((apDays != null) && (apDays != 0)) {
          double timeElapsed = 0;
          if(rsAccount == null) {
            timeElapsed = rsUser.getCreated().getTime();
          } else if(rsAccount.getLastRankChange() != null) {
            timeElapsed = rsAccount.getLastRankChange().getTime();
          }

          timeElapsed = System.currentTimeMillis() - timeElapsed;
          timeElapsed /= 1000 * 60 * 60 * 24;
          if(timeElapsed < apDays)
            break apBlock;

          if((rsRank.getApWins() == null)
          || (rsRank.getApD2Level() == null)
          || (rsRank.getApW3Level() == null))
            break apBlock;
          int apWins = rsRank.getApWins().intValue();
          int apD2Level = rsRank.getApD2Level().intValue();
          int apW3Level = rsRank.getApW3Level().intValue();
          long wins[];
          if(rsAccount == null)
            wins = new long[] {0, 0, 0};
          else
            wins = rsAccount.getWinsLevels(GlobalSettings.recruitTagPrefix, GlobalSettings.recruitTagSuffix);

          boolean hasEnoughWins = false;
          hasEnoughWins |= ((apWins > 0) && (wins[0] >= apWins));
          hasEnoughWins |= ((apD2Level > 0) && (wins[1] >= apD2Level));
          hasEnoughWins |= ((apW3Level > 0) && (wins[2] >= apW3Level));
          hasEnoughWins |= ((apWins == 0) && (apD2Level == 0) && (apW3Level == 0));

          if(hasEnoughWins) {
            // Check RS
            long rs = 0;
            if(rsAccount != null)
              rs = rsAccount.getRecruitScore(GlobalSettings.recruitAccess);
            Integer apRS = rsRank.getApRecruitScore();
            if((apRS == null) || (apRS == 0) || (rs >= apRS)) {
              int rank = 0;
              if(rsAccount != null)
                rank = rsAccount.getAccess();
              else {
                String name = user.getFullAccountName();
                name = name.substring(0, name.indexOf('@'));
                try {
                  Account recoverAccount = Account.get(name);
                  if((recoverAccount != null)
                  && (recoverAccount.getAccess() <= 1)
                  && (recoverAccount.getBnLogins().size() == 0)) {
                    rsAccount = recoverAccount;
                    // Reset the account to rank zero, just in case
                    rsAccount.setRank(Rank.get(0));
                    rsUser.setAccount(rsAccount);
                    rsUser.updateRow();
View Full Code Here

TOP

Related Classes of net.bnubot.db.Account

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.