<commit_before>package com.tazzie02.tazbot.commands.fun;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import com.tazzie02.tazbot.commands.Command;
import com.tazzie02.tazbot.util.SendMessage;

import net.dv8tion.jda.entities.User;
import net.dv8tion.jda.events.message.MessageReceivedEvent;

public class TeamCommand implements Command {
	
	// TODO Greater configuration options

	@Override
	public void onCommand(MessageReceivedEvent e, String[] args) {
		List<User> users = new ArrayList<User>();
		users.addAll(e.getMessage().getMentionedUsers());
		int size = users.size();
		
		if (users.isEmpty()) {
			SendMessage.sendMessage(e, "Error: No users mentioned.");
		}
		else {
			List<User> team1 = new ArrayList<User>();
			List<User> team2 = new ArrayList<User>();
			
			Collections.shuffle(users);
			
			for (int i = 0; i < size; i++) {
				if (i % 2 == 0) {
					team1.add(users.get(i));
				}
				else {
					team2.add(users.get(i));
				}
			}
			
			StringBuilder sb = new StringBuilder();
			sb.append("Team 1: ");
			team1.stream().forEach(u -> sb.append(u.getUsername() + " "));
			sb.append("\nTeam 2: ");
			team2.stream().forEach(u -> sb.append(u.getUsername() + " "));
			
			SendMessage.sendMessage(e, sb.toString());
		}
	}
	
	@Override
	public CommandAccess getAccess() {
		return CommandAccess.ALL;
	}

	@Override
	public List<String> getAliases() {
		return Arrays.asList("team");
	}

	@Override
	public String getDescription() {
		return "Randomly add users to two teams.";
	}

	@Override
	public String getName() {
		return "Team Command";
	}

	@Override
	public String getUsageInstructions() {
		return "team <@user> <...> - Randomly split users only two teams.";<commit_msg>Added additional functionality to team command.<commit_after>package com.tazzie02.tazbot.commands.fun;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;

import com.tazzie02.tazbot.commands.Command;
import com.tazzie02.tazbot.util.JDAUtil;
import com.tazzie02.tazbot.util.SendMessage;

import net.dv8tion.jda.entities.User;
import net.dv8tion.jda.entities.VoiceChannel;
import net.dv8tion.jda.events.message.MessageReceivedEvent;

public class TeamCommand implements Command {
	
	@Override
	public void onCommand(MessageReceivedEvent e, String[] args) {
		List<User> users = new ArrayList<User>();
		
		users.addAll(e.getMessage().getMentionedUsers());
		
		if (args.length == 1) {
			SendMessage.sendMessage(e, "Error: No users were added.");
			return;
		}
		
		int teamCount = 2;
		int i = 1;
		if (args.length > 2 && NumberUtils.isDigits(args[1])) {
			teamCount = Integer.parseInt(args[1]);
			i = 2;
		}
		
		while (i < args.length) {
			// Channel position
			if (NumberUtils.isDigits(args[i])) {
				Integer position = Integer.parseInt(args[i]);
				VoiceChannel vc = JDAUtil.getVoiceChannelAtPosition(e.getGuild(), position);
				if (vc != null) {
					users.addAll(vc.getUsers());
				}
			}
			i++;
		}
		
		if (users.isEmpty()) {
			SendMessage.sendMessage(e, "Error: No users were added.");
			return;
		}
		
		List<List<User>> teams = shuffleTeams(users, teamCount);
		
		StringBuilder output = new StringBuilder();
		for (int j = 0; j < teams.size(); j++) {
			List<User> team = teams.get(j);
			List<String> usernames = new ArrayList<String>();
			for (int k = 0; k < team.size(); k++) {
				User u = team.get(k);
				usernames.add(u.getUsername());
			}
			
			output.append(String.format("Team %d: %s\n", (j + 1), StringUtils.join(usernames, ", ")));
		}
		
		SendMessage.sendMessage(e, output.toString());
	}
	
	private List<List<User>> shuffleTeams(List<User> users, int teamCount) {
		List<List<User>> teams = new ArrayList<List<User>>();
		
		for (int i = 0; i < teamCount; i++) {
			teams.add(new ArrayList<User>());
		}
		
		Collections.shuffle(users);
		
		for (int i = 0; i < users.size(); i++) {
			teams.get(i % teamCount).add(users.get(i));
		}
		
		return teams;
	}
	
	@Override
	public CommandAccess getAccess() {
		return CommandAccess.ALL;
	}

	@Override
	public List<String> getAliases() {
		return Arrays.asList("team");
	}

	@Override
	public String getDescription() {
		return "Randomly add users to two teams.";
	}

	@Override
	public String getName() {
		return "Team Command";
	}

	@Override
	public String getUsageInstructions() {
		return "team <@user> <...> - Randomly split users into two teams.\n"
				+ "team <teamCount> <@user> <...> - Randomly split users in to teamCount teams."
				+ "team <voicePosition> - Randomly split users at position voicePosition into two teams.\n"
				+ "team <teamCount> <voicePosition> <...> - Randomly split users into teamCount teams."
				+ "**NOTE:** If multiple voicePositions are mentioned, the first argument MUST be teamCount.";
{'fraction_non_alphanumeric': 0.14862124898621248, 'fraction_numerical': 0.008921330089213302, 'mean_word_length': 3.720574162679426, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3521906', 'n_tokens_mistral': 1883, 'n_tokens_neox': 1631, 'n_words': 386}