Package net.bnubot.bot.commands

Source Code of net.bnubot.bot.commands.CommandRecruits

/**
* This file is distributed under the GPL
* $Id: CommandRecruits.java 1893 2014-02-11 09:22:17Z scotta $
*/
package net.bnubot.bot.commands;

import net.bnubot.core.Connection;
import net.bnubot.core.commands.AccountDoesNotExistException;
import net.bnubot.core.commands.CommandRunnable;
import net.bnubot.core.commands.InvalidUseException;
import net.bnubot.db.Account;
import net.bnubot.settings.GlobalSettings;
import net.bnubot.util.BNetUser;

/**
* @author scotta
*/
public final class CommandRecruits implements CommandRunnable {
  @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 != 1))
        throw new InvalidUseException();


      Account subjectAccount = null;
      String output = null;
      if(params == null) {
        subjectAccount = commanderAccount;
        output = "You have recruited: ";
      } else {
        subjectAccount = Account.get(params[0]);
        if(subjectAccount == null)
          throw new AccountDoesNotExistException(params[0]);
        output = subjectAccount.getName();
        output += " has recruited: ";
      }

      if(subjectAccount.getRecruits().size() == 0)
        output += "no one";
      for(Account recruit : subjectAccount.getRecruits()) {
        // Remove accounts below the threshold
        if(recruit.getAccess() >= GlobalSettings.recruitAccess)
          output += recruit.getName() + "(" + recruit.getAccess() + ") ";
      }


      output = output.trim();
      user.sendChat(output, whisperBack);
    } catch(InvalidUseException e) {
      user.sendChat("Use: %trigger%recruits [account]", whisperBack);
    }
    return;
  }
}
TOP

Related Classes of net.bnubot.bot.commands.CommandRecruits

TOP
Copyright © 2018 www.massapi.com. 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.