public CmdResult ExecuteCommand(string s, object session, OutputDelegate outputDelegate) { StringWriter sw = new StringWriter(); if (s == null) { return(new CmdResult("null cmd", false)); } s = s.Trim(); if (s == "") { return(new CmdResult("empty cmd", false)); } if (s.StartsWith("aiml")) { s = s.Substring(4).Trim(); if (s.StartsWith("@ ")) { s = "@withuser" + s.Substring(1); } } if (!s.StartsWith("@")) { s = "@" + s; } // sw.WriteLine("AIMLTRACE " + s); User myUser = null;// TheBot.LastUser; //OutputDelegate del = outputDelegate ?? sw.WriteLine; bool r = TheBot.BotDirective(myUser, s, sw.WriteLine); sw.Flush(); string res = sw.ToString(); // for now legacy //res = res.Replace("menevalue=", "mene value="); if (outputDelegate != null) { outputDelegate(res); } WriteLine(res); return(new CmdResult(res, r)); }
public CmdResult ExecuteCommand(string s, object session, OutputDelegate outputDelegate, CMDFLAGS needResult) { string verb = GetType().Name; StringWriter sw = new StringWriter(); if (s == null) { return(ACmdResult.Complete(verb, "null cmd", false)); } s = s.Trim(); if (s == "") { return(ACmdResult.Complete(verb, "empty cmd", false)); } if (TheBot.useServitor) { TheBot.updateRTP2Sevitor(); string input = s; string res = ""; input = input.Replace("aiml @withuser null -", ""); input = input.Replace("withuser null", ""); input = input.Replace("aiml @", ""); input = input.Replace("- ?", ""); bool r = true; TheBot.servitor.curBot.saySapi = true; TheBot.servitor.curBot.sayProcessor = new sayProcessorDelegate(webSayResponse); if (input.Length > 1) { res = TheBot.servitor.respondToChat(input, TheBot.LastUser); if ((res != null) && (res.Length > 0)) { responseQueue.Enqueue(res); } res = ""; // Give the servitor a chance to do something; int ticks = 0; while ((ticks < 25) && (responseQueue.Count == 0)) { Thread.Sleep(200); ticks++; } while (responseQueue.Count > 0) { res += responseQueue.Dequeue() + " "; } if (outputDelegate != null) { outputDelegate(res); } WriteLine(res); TheBot.updateServitor2RTP(); } else { res = ""; // Give the servitor a chance to do something; int ticks = 0; while ((ticks < 3) && (responseQueue.Count == 0)) { Thread.Sleep(200); ticks++; } while (responseQueue.Count > 0) { res += responseQueue.Dequeue() + " "; } if (outputDelegate != null) { outputDelegate(res); } WriteLine(res); } return(ACmdResult.Complete(verb, res, r)); } else { if (s.StartsWith("aiml")) { s = s.Substring(4).Trim(); if (s.StartsWith("@ ")) { s = "@withuser" + s.Substring(1); } } if (!s.StartsWith("@")) { s = "@" + s; } // sw.WriteLine("AIMLTRACE " + s); User myUser = null;// TheBot.LastUser; //OutputDelegate del = outputDelegate ?? sw.WriteLine; bool r = TheBot.BotDirective(myUser, s, sw.WriteLine); sw.Flush(); string res = sw.ToString(); // for now legacy //res = res.Replace("menevalue=", "mene value="); if (outputDelegate != null) { outputDelegate(res); } WriteLine(res); return(ACmdResult.Complete(verb, res, r)); } }