var uf      = require("../src/util_functions.js");
var MarkovChain = require('markovchain');
module.exports=function(threadID, args, senderId){
	var api = uf.metaData.meta.api;
	var myId = api.getCurrentUserID();
	api.getThreadHistory(threadID,0,100000,null,function(error,history){
		if (error) return
		var historyString = "";
		var user;
		var useUser = false;
		if(args.special.indexOf('--user') > -1){
			var user = uf.getSpecialValue("--user",args);
			if(user!=undefined){
				useUser = true;
			}
		}
		for(msg in history){
			if(history[msg].senderID != "fbid:"+myId && history[msg].body!=undefined && history[msg].type=="message"){
				if(useUser && history[msg].senderName!=user)
					continue;
				historyString+=history[msg].body+"\n";
			}
		}
		var useUpperCase = function(wordList) {
		  var tmpList = Object.keys(wordList);
		  return tmpList[~~(Math.random()*tmpList.length)]
		}
		var quotes = new MarkovChain(historyString);

		var start = useUpperCase;
		if(args.value.length>0 && !useUser){
			start = args.value[0];
		}

		uf.sendMessage(quotes.start(start).end(25).process(),threadID);
	});
}


@@ -753,19 +753,24 @@
 %7D%0A%09%09%7D%0A%09%09
-var
+function
  useUppe
@@ -778,19 +778,211 @@
 Case
- = function
+(wordList) %7B%0A%09%09%09var tmpList = Object.keys(wordList).filter(function(word) %7B%0A%09%09%09%09return word%5B0%5D %3E= 'A' && word%5B0%5D %3C= 'Z'%0A%09%09%09%7D)%0A%09%09%09return tmpList%5B~~(Math.random()*tmpList.length)%5D%0A%09%09%7D%0A%0A%09%09function useRandom
 (wor
@@ -992,18 +992,17 @@
 st) %7B%0A%09%09
-  
+%09
 var tmpL
@@ -1032,18 +1032,17 @@
 ist);%0A%09%09
-  
+%09
 return t
@@ -1085,16 +1085,17 @@
 th)%5D%0A%09%09%7D
+ 
 %0A%09%09var q
@@ -1134,17 +1134,16 @@
 tring);%0A
-%0A
 %09%09var st
@@ -1147,16 +1147,82 @@
  start =
+ useRandom;%0A%09%09if(args.special.indexOf('--upper') %3E -1)%7B%0A%09%09%09start =
  useUppe
@@ -1224,24 +1224,31 @@
 eUpperCase;%0A
+%09%09%7D%0A%09%09%0A
 %09%09if(args.va

Choose uppercase