Package net.bnubot.bot.commands

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

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

import net.bnubot.bot.CommandEventHandler;
import net.bnubot.core.Connection;
import net.bnubot.core.commands.CommandRunnable;
import net.bnubot.core.commands.InvalidUseException;
import net.bnubot.db.Account;
import net.bnubot.util.BNetUser;

/**
* @author scotta
*/
public final class CommandAdd 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)
        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) {
      user.sendChat("Use: %trigger%add <account> <access>", whisperBack);
    }
  }
}
TOP

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

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.