Fixes for ALICE Chatbot, adding Wolfram math support

This commit is contained in:
DarkFeather 2017-01-12 12:26:14 -06:00
parent df636e8706
commit 9332181125
3 changed files with 13 additions and 1 deletions

View File

@ -249,7 +249,9 @@ namespace AniNIX.TheRaven {
if (response.msgCode.Equals("PRIVMSG") && !String.IsNullOrWhiteSpace(response.message) && (response.target.Equals(Nick) || response.message.StartsWith(String.Format("{0}:",Nick)) || response.message.EndsWith(String.Format("{0}!",Nick)) || response.message.EndsWith(String.Format("{0}?",Nick)) || response.message.EndsWith(String.Format("{0}.",Nick)) || response.message.EndsWith(String.Format("{0}",Nick)))) {
IRCClientMessage send = new IRCClientMessage();
try {
send.PrivMsg(ExecuteCommand.Run(String.Format("bash /usr/local/src/TheRaven/chatbot-support.bash \"{0}\" {1}",response.message.Replace("'","").Replace("\"","").Split('\n')[0].Trim(),Nick)).Trim(),(response.target.Equals(Nick))?response.user:response.target);
String aliceResponse = ExecuteCommand.Run(String.Format("bash /usr/local/src/TheRaven/chatbot-support.bash \"{0}\" {1}",response.message.Replace("'","").Replace("\"","").Split('\n')[0].Trim(),Nick)).Trim();
if (String.IsNullOrWhiteSpace(aliceResponse)) throw new Exception("No response from ALICE chatbot service");
send.PrivMsg(aliceResponse,(response.target.Equals(Nick))?response.user:response.target);
} catch (Exception e) {
e.ToString();
send.PrivMsg("Cannot talk right now.",(response.target.Equals(Nick))?response.user:response.target);

View File

@ -78,6 +78,14 @@ namespace AniNIX.TheRaven {
}
connection.Write(send);
return;
case "r.math":
if (bySpace.Length < 2) {
} else {
send.PrivMsg(ExecuteCommand.Run(String.Format("/bin/bash /usr/local/src/TheRaven/math-support.bash \"{0}\"",incoming.message.Replace("r.math ","").Replace("'",""))),(incoming.target.Equals(theRaven.Nick))?incoming.user:incoming.target);
}
connection.Write(send);
return;
case "r.msg":
if (bySpace.Length < 2) {
send.PrivMsg(theRaven.helpText,incoming.user);

2
math-support.bash Normal file
View File

@ -0,0 +1,2 @@
#!/bin/bash
lynx -connect_timeout=3 -read_timeout=3 --dump 'http://m.wolframalpha.com/input/?i='"$(echo $1 | sed 's/+/%2B/g' | tr ' ' '+')"'&x=0&y=0' | cat -n | grep 21 | head -n 1 | xargs | cut -f 2 -d ' '