From 9332181125e4b45b189e969c6659807ab947e541 Mon Sep 17 00:00:00 2001 From: DarkFeather Date: Thu, 12 Jan 2017 12:26:14 -0600 Subject: [PATCH] Fixes for ALICE Chatbot, adding Wolfram math support --- Raven.csharp | 4 +++- RavenCommand.csharp | 8 ++++++++ math-support.bash | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 math-support.bash diff --git a/Raven.csharp b/Raven.csharp index a6d238f..6d934fc 100644 --- a/Raven.csharp +++ b/Raven.csharp @@ -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); diff --git a/RavenCommand.csharp b/RavenCommand.csharp index 0aff70e..f9128db 100644 --- a/RavenCommand.csharp +++ b/RavenCommand.csharp @@ -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); diff --git a/math-support.bash b/math-support.bash new file mode 100644 index 0000000..ba3454c --- /dev/null +++ b/math-support.bash @@ -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 ' '