Esempio n. 1
0
  public void execute(Session bot, String channel, User user, String message)
      throws SessionException {
    SimpleStringTokenizer tokens = new SimpleStringTokenizer(message);
    List<SessionCommand> commandList = new LinkedList<SessionCommand>();
    SessionCommandManager manager = bot.getCommandManager();
    while (tokens.hasMoreTokens()) {
      SessionCommand command = manager.getCommand(tokens.nextToken());
      if (command != null) {
        commandList.add(command);
      }
    }
    if (commandList.size() < 1) {
      commandList = manager.getCommands();
    }

    String target = channel;
    if (commandList.size() > 1) {
      target = user.getNick();
    }
    for (SessionCommand t : commandList) {
      String msg;
      if (t.getUsage() == null) {
        msg = manager.getPrefix() + t.getName();
      } else {
        msg = manager.getPrefix() + t.getName() + " " + t.getUsage();
      }
      bot.msg(target, msg);
    }
  }
  public void execute(Session bot, String channel, User user, String message) {
    SimpleStringTokenizer messageToken = new SimpleStringTokenizer(message);

    int time = 0;
    String question = null;
    int countTokens = messageToken.countTokens();
    boolean numberCondition = false;

    if (countTokens > 1) {
      try {
        time = Integer.parseInt(messageToken.nextToken());
        if (time < 1) {
          bot.msg(channel, "Mindestens eine Sekunde");
          return;
        }
        question = messageToken.remainingString();
        numberCondition = true;
      } catch (NumberFormatException ex) {
      }
    }

    if (!numberCondition) {
      if (countTokens < 1) {
        bot.msg(channel, "Nicht genug Argumente");
        return;
      }
      question = message;
      time = 500;
    }

    Vote newVote = new Vote(user, question);
    Timer endVote = new Timer();

    VoteTask endTask = new VoteTask(bot, channel, newVote);

    bot.msg(channel, "Neue Abstimmung - " + newVote.getId() + ": '" + question + "'");
    endVote.schedule(endTask, ((long) time) * 1000);
  }