package heufybot.modules;

import heufybot.utils.StringUtils;

import java.util.ArrayList;
import java.util.List;

public class Choose extends Module
{
	public Choose()
	{
		this.authType = Module.AuthType.Anyone;
		this.trigger = "^" + commandPrefix + "(choose)($| .*)";
	}
	
	@Override
	public void processEvent(String source, String message, String triggerUser, List<String> params) 
	{
		if (params.size() == 1)
		{
			bot.getIRC().cmdPRIVMSG(source, "Choose what?");
		}
		else
		{
			params.remove(0);
			List<String> choices;
			
			if(message.contains(","))
			{
				choices = StringUtils.parseStringtoList(StringUtils.join(params, " "), ",");
			}
			else if(message.contains(" "))
			{
				choices = params;
			}
			else
			{
				choices = new ArrayList<String>();
				choices.add(params.get(0));
			}
			
			int choiceNumber = (int) (Math.random() * choices.size());
			bot.getIRC().cmdPRIVMSG(source, "Choice: " + choices.get(choiceNumber));
		}
	}

	public String getHelp(String message)
	{
		return "Commands: " + commandPrefix + "choose <choice1>, <choice2> | Makes the bot choose one of the given options at random.";
	}

	@Override
	public void onLoad() 
	{
	}

	@Override
	public void onUnload()
	{
	}
}

@@ -60,36 +60,8 @@
 s;%0A%0A
-import java.util.ArrayList;%0A
 impo
@@ -480,28 +480,24 @@
 %0A%09%09%09
-List%3C
 String
-%3E
+%5B%5D
  choices
 ;%0A%09%09
@@ -492,16 +492,44 @@
  choices
+ = new String%5Bparams.size()%5D
 ;%0A%09%09%09%0A%09%09
@@ -639,16 +639,33 @@
 %22), %22,%22)
+.toArray(choices)
 ;%0A%09%09%09%7D%0A%09
@@ -722,16 +722,33 @@
 = params
+.toArray(choices)
 ;%0A%09%09%09%7D%0A%09
@@ -781,58 +781,123 @@
 new 
-ArrayList%3CString%3E();%0A%09%09%09%09choices.add(params.get(0)
+String%5B%5D %7B params.get(0) %7D;%0A%09%09%09%7D%0A%0A%09%09%09for(int i = 0; i %3C choices.length; i++)%0A%09%09%09%7B%0A%09%09%09%09choices%5Bi%5D = choices%5Bi%5D.trim(
 );%0A%09
@@ -957,22 +957,22 @@
 choices.
-size()
+length
 );%0A%09%09%09bo
@@ -1021,21 +1021,17 @@
  choices
-.get(
+%5B
 choiceNu
@@ -1034,17 +1034,17 @@
 ceNumber
-)
+%5D
 );%0A%09%09%7D%0A%09

Trim whitespaces from Choose options (#52)