Fixes for privmsging not working as expected; chatbot functionality

This commit is contained in:
DarkFeather 2016-09-26 15:44:00 -05:00
parent 47440a1eac
commit 9da156fced
5 changed files with 60 additions and 48 deletions

View File

@ -1,9 +1,5 @@
raven.mono: /usr/bin/mcs /usr/bin/mono clean ./raven.csharp ./connection.csharp ./ravencommand.csharp /bin/bash /usr/bin/mail /usr/bin/wget
mkdir -p /usr/local/etc/TheRaven
raven.mono: /usr/bin/mcs /usr/bin/mono clean ./raven.csharp ./connection.csharp ./ravencommand.csharp /bin/bash /usr/bin/mail /usr/bin/wget /usr/local/bin/djinni ./chatbot-support.bash
mcs -out:raven.mono reportmessage.csharp *exception.csharp irc*message.csharp connection.csharp raven*.csharp
id raven || useradd -M -G git,ircd,api raven
id raven || usermod -d /usr/local/etc/TheRaven raven
chown raven:raven /usr/local/etc/TheRaven
clean:
if [ "$$(ls ./*~ 2>/dev/null | wc -l)" -gt 0 ]; then rm -Rf *~; fi
@ -21,6 +17,10 @@ check-for-verbosity:
grep Console.WriteLine *.csharp | egrep -v 'verbosity|raven.csharp'; echo
install: raven.mono
id raven || useradd -M -G git,ircd,api raven
id raven || usermod -d /usr/local/etc/TheRaven raven
chown raven:raven /usr/local/etc/TheRaven
mkdir -p /usr/local/etc/TheRaven
cp raven.mono /opt/raven.mono
[ ! -d /usr/local/etc/TheRaven ] || mkdir -p /usr/local/etc/TheRaven
chown -R raven:raven /opt/raven.mono /usr/local/etc/TheRaven*

3
chatbot-support.bash Normal file
View File

@ -0,0 +1,3 @@
#!/bin/bash
url="$(wget -q -O - http://alice.pandorabots.com/ | grep iframe | cut -f 2 -d \")"
curl -s --data "input=$(echo $1 | sed "s/$2//g" | sed 's/^: //')" "$url" | grep 'ALICE:' | tail -n 1 | cut -f 3 -d '>' | sed 's/ ALICE: //' | sed "s/ALICE/$2/g" | sed "s/Alice/$2/g" | sed "s/ om/ friend/"

View File

@ -13,7 +13,7 @@ namespace AniNIX.TheRaven {
//These are the basic configuration information to be overwritten
public String Host { get; private set; } //This is the Host we are connecting to.
public int Port { get; private set; } // This is Port to connect on
private string _nick; // This is the _nickname for this Raven to use.
public string Nick { get; private set; } // This is the Nickname for this Raven to use.
private string _nickServPass; // This is the password we will send to NickServ to identify
private string _autoSend; // This is the command we will automatically send to the Host
private string configDir; // This is the configuration directory.
@ -44,7 +44,7 @@ namespace AniNIX.TheRaven {
sb.Append("### AniNIX::TheRaven -- Running Values ###\n");
sb.Append(String.Format("Host: {0}\n",Host));
sb.Append(String.Format("Port: {0}\n",Port));
sb.Append(String.Format("Nick: {0}\n",_nick));
sb.Append(String.Format("Nick: {0}\n",Nick));
sb.Append("NickServPass: ****\n");
sb.Append(String.Format("Auto: {0}\n",_autoSend));
sb.Append(String.Format("Conf: {0}\n",configDir));
@ -81,7 +81,7 @@ namespace AniNIX.TheRaven {
e.ToString();
Port = 6667;
}
_nick = (_nick == null) ? loginDefaults[2] : _nick;
Nick = (Nick == null) ? loginDefaults[2] : Nick;
_nickServPass = (_nickServPass == null) ? loginDefaults[3] : _nickServPass;
}
@ -127,7 +127,7 @@ namespace AniNIX.TheRaven {
ReportMessage.Log(Verbosity.Verbose,String.Format("Handling Argument {0}: {1}",i,args[i]));
switch (args[i]) {
case "-n":
if (i < args.Length-1) _nick = args[++i];
if (i < args.Length-1) Nick = args[++i];
break;
case "-h":
if (i < args.Length-1) Host = args[++i];
@ -183,13 +183,18 @@ namespace AniNIX.TheRaven {
ReportMessage.Log(Verbosity.VeryVerbose,this.ToString());
}
/// <summary>
/// Populate the name recognition
/// </summary>
/// <summary>
/// Create a raven with default settings.
/// </summary>
public Raven(String host = "localhost", int port = 6667, String nick = "TheRaven-Guest", String nickServPass = "null", String autoSend = null, String configDir = "/usr/local/etc/TheRaven-Local", Verbosity verbosity = Verbosity.Verbose) {
this.Host = host;
Port = port;
_nick = nick;
Nick = nick;
_nickServPass = nickServPass;
_autoSend = autoSend;
this.configDir = configDir;
@ -212,7 +217,7 @@ namespace AniNIX.TheRaven {
//Send USER and NICK lines to identify.
IRCClientMessage send = new IRCClientMessage();
send.CreateCustomMessage(String.Format("NICK {0}\nUSER {0} * * :{0}",_nick));
send.CreateCustomMessage(String.Format("NICK {0}\nUSER {0} * * :{0}",Nick));
_connection.Write(send);
ReportMessage.Log(Verbosity.VeryVerbose,"USER and NICK sent");
//thanks to cfrayne for the refactor
@ -256,7 +261,7 @@ namespace AniNIX.TheRaven {
if (notifications.TryGetValue(response.target,out result)) {
if (response.message.Contains(result)) {
try {
RavenExecute.Command(String.Format("djinni admin \"Found {1} in {0}\"",response.target,result));
RavenExecute.Command(String.Format("/usr/local/bin/djinni admin \"Found {1} in {0}\"",response.target,result));
} catch (Exception e) {
ReportMessage.Log(Verbosity.Error,e.ToString());
}
@ -264,18 +269,22 @@ namespace AniNIX.TheRaven {
}
}
//TODO Implement the dialog options and link reponse
// Integrate with the ALICE chatbot project.
// TODO Create a local instance instead
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();
send.PrivMsg(RavenExecute.Command(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);
_connection.Write(send);
}
/* CROWFACTS the deserving */
if (crowFactsSubscribers.Contains(response.user) && randomSeed.Next(10) < 8) {
IRCClientMessage send = new IRCClientMessage();
int location = randomSeed.Next(crowFacts.Length);
send.PrivMsg(crowFacts[location],response.user);
_connection.Write(send);
/* CROWFACTS the deserving */
if (crowFactsSubscribers.Contains(response.user) && randomSeed.Next(10) < 8) {
IRCClientMessage send = new IRCClientMessage();
int location = randomSeed.Next(crowFacts.Length);
send.PrivMsg(crowFacts[location],response.user);
_connection.Write(send);
}
}
}
}
}

View File

@ -34,19 +34,19 @@ namespace AniNIX.TheRaven {
/* COMMON Commands everyone can use */
switch (command) {
case "r.raven":
send.ActionMsg("quoth, \"Nevermore!\"",incoming.target);
send.ActionMsg("quoth, \"Nevermore!\"",(incoming.target.Equals(theRaven.Nick))?incoming.user:incoming.target);
connection.Write(send);
return;
case "r.help":
send.PrivMsg(theRaven.helpText,incoming.target);
send.PrivMsg(theRaven.helpText,(incoming.target.Equals(theRaven.Nick))?incoming.user:incoming.target);
connection.Write(send);
return;
case "r.magic8":
if (theRaven.magic8 == null) {
send.PrivMsg("Magic8 not loaded",incoming.target);
send.PrivMsg("Magic8 not loaded",(incoming.target.Equals(theRaven.Nick))?incoming.user:incoming.target);
} else {
int location = theRaven.randomSeed.Next(theRaven.magic8.Length);
send.PrivMsg(theRaven.magic8[location],incoming.target);
send.PrivMsg(theRaven.magic8[location],(incoming.target.Equals(theRaven.Nick))?incoming.user:incoming.target);
}
connection.Write(send);
return;
@ -56,9 +56,9 @@ namespace AniNIX.TheRaven {
} else {
try {
int result = theRaven.randomSeed.Next(Int32.Parse(bySpace[1]));
send.PrivMsg(String.Format("{0}",result+1),incoming.target);
send.PrivMsg(String.Format("{0}",result+1),(incoming.target.Equals(theRaven.Nick))?incoming.user:incoming.target);
} catch (Exception e) {
send.PrivMsg("Bad formatting.",incoming.target);
send.PrivMsg("Bad formatting.",(incoming.target.Equals(theRaven.Nick))?incoming.user:incoming.target);
}
}
connection.Write(send);
@ -68,10 +68,10 @@ namespace AniNIX.TheRaven {
send.PrivMsg(theRaven.helpText,incoming.user);
} else {
try {
send.PrivMsg(RavenExecute.Command(String.Format("wget -q -O - \"http://tiny-url.info/api/v1/create?format=text&apikey=\"$(api-keys tinyurl)\"&provider=x_co&url={0}\"",bySpace[1])),incoming.target);
send.PrivMsg(RavenExecute.Command(String.Format("wget -q -O - \"http://tiny-url.info/api/v1/create?format=text&apikey=\"$(api-keys tinyurl)\"&provider=x_co&url={0}\"",bySpace[1])),(incoming.target.Equals(theRaven.Nick))?incoming.user:incoming.target);
} catch (Exception e) {
ReportMessage.Log(Verbosity.Error,e.ToString());
send.PrivMsg("TinyURL error. Could not get link.",incoming.target);
send.PrivMsg("TinyURL error. Could not get link.",(incoming.target.Equals(theRaven.Nick))?incoming.user:incoming.target);
}
}
connection.Write(send);
@ -114,10 +114,10 @@ namespace AniNIX.TheRaven {
return;
case "r.uptime":
try {
send.PrivMsg(RavenExecute.Command("uptime"),incoming.target);
send.PrivMsg(RavenExecute.Command("uptime"),(incoming.target.Equals(theRaven.Nick))?incoming.user:incoming.target);
} catch (Exception e) {
e.ToString();
send.PrivMsg("Can't get uptime",incoming.target);
send.PrivMsg("Can't get uptime",(incoming.target.Equals(theRaven.Nick))?incoming.user:incoming.target);
}
connection.Write(send);
return;
@ -145,7 +145,7 @@ namespace AniNIX.TheRaven {
continue;
}
if (byPipe[0].Equals(command)) {
send.PrivMsg(FormatSearch(byPipe[1],incoming.message,byPipe[2]),incoming.target);
send.PrivMsg(FormatSearch(byPipe[1],incoming.message,byPipe[2]),(incoming.target.Equals(theRaven.Nick))?incoming.user:incoming.target);
connection.Write(send);
return;
}
@ -166,62 +166,61 @@ namespace AniNIX.TheRaven {
connection.Write(send);
}
send.PrivMsg("End subscribers",incoming.user);
send.PrivMsg(theRaven.helpText,incoming.target);
send.PrivMsg(theRaven.helpText,(incoming.target.Equals(theRaven.Nick))?incoming.user:incoming.target);
} else if (theRaven.crowFacts == null) {
send.PrivMsg("CrowFacts not loaded.",incoming.target);
send.PrivMsg("CrowFacts not loaded.",(incoming.target.Equals(theRaven.Nick))?incoming.user:incoming.target);
} else {
if (!theRaven.crowFactsSubscribers.Contains(bySpace[1])) {
theRaven.crowFactsSubscribers.Add(bySpace[1]);
send.PrivMsg(String.Format("{0} has been subscribed to CrowFacts!",bySpace[1]),incoming.target);
send.PrivMsg(String.Format("{0} has been subscribed to CrowFacts!",bySpace[1]),(incoming.target.Equals(theRaven.Nick))?incoming.user:incoming.target);
} else {
send.PrivMsg("Subscriber already added",incoming.target);
send.PrivMsg("Subscriber already added",(incoming.target.Equals(theRaven.Nick))?incoming.user:incoming.target);
}
}
connection.Write(send);
return;
case "r.us":
if (bySpace.Length < 2) {
send.PrivMsg(theRaven.helpText,incoming.target);
send.PrivMsg(theRaven.helpText,(incoming.target.Equals(theRaven.Nick))?incoming.user:incoming.target);
} else {
if (theRaven.crowFactsSubscribers.Contains(bySpace[1])) {
theRaven.crowFactsSubscribers.Remove(bySpace[1]);
send.PrivMsg(String.Format("{0} has been unsubscribed.",bySpace[1]),incoming.target);
send.PrivMsg(String.Format("{0} has been unsubscribed.",bySpace[1]),(incoming.target.Equals(theRaven.Nick))?incoming.user:incoming.target);
} else {
send.PrivMsg("No such subscriber",incoming.target);
send.PrivMsg("No such subscriber",(incoming.target.Equals(theRaven.Nick))?incoming.user:incoming.target);
}
}
connection.Write(send);
return;
case "r.join":
if (bySpace.Length < 2) {
send.PrivMsg(theRaven.helpText,incoming.target);
send.PrivMsg(theRaven.helpText,(incoming.target.Equals(theRaven.Nick))?incoming.user:incoming.target);
} else {
if (!theRaven.channels.Contains(bySpace[1])) {
theRaven.channels.Add(bySpace[1]);
send.CreateJoinMessage(bySpace[1]);
} else {
send.PrivMsg("Already joined channel",incoming.target);
send.PrivMsg("Already joined channel",(incoming.target.Equals(theRaven.Nick))?incoming.user:incoming.target);
}
}
connection.Write(send);
return;
case "r.part":
if (bySpace.Length < 2) {
send.PrivMsg(theRaven.helpText,incoming.target);
send.PrivMsg(theRaven.helpText,(incoming.target.Equals(theRaven.Nick))?incoming.user:incoming.target);
} else {
if (theRaven.channels.Contains(bySpace[1])) {
theRaven.channels.Remove(bySpace[1]);
send.CreatePartMessage(bySpace[1]);
} else {
send.PrivMsg("No such channel",incoming.target);
send.PrivMsg("No such channel",(incoming.target.Equals(theRaven.Nick))?incoming.user:incoming.target);
}
}
connection.Write(send);
return;
case "r.say":
if (bySpace.Length < 3 || !bySpace[1].StartsWith("#")) {
send.PrivMsg(theRaven.helpText,incoming.target);
send.PrivMsg(theRaven.helpText,(incoming.target.Equals(theRaven.Nick))?incoming.user:incoming.target);
} else {
StringBuilder newMsg = new StringBuilder(bySpace[2]);
for (int i = 3; i < bySpace.Length; i++) {
@ -234,7 +233,7 @@ namespace AniNIX.TheRaven {
return;
case "r.act":
if (bySpace.Length < 3 || !bySpace[1].StartsWith("#")) {
send.PrivMsg(theRaven.helpText,incoming.target);
send.PrivMsg(theRaven.helpText,(incoming.target.Equals(theRaven.Nick))?incoming.user:incoming.target);
} else {
StringBuilder newAction = new StringBuilder(bySpace[2]);
for (int i = 3; i < bySpace.Length; i++) {
@ -285,7 +284,7 @@ namespace AniNIX.TheRaven {
return;
case "r.greylist":
if (bySpace.Length < 2) {
send.PrivMsg(theRaven.helpText,incoming.target);
send.PrivMsg(theRaven.helpText,(incoming.target.Equals(theRaven.Nick))?incoming.user:incoming.target);
} else {
if (theRaven.whitelist.Contains(bySpace[1])) {
theRaven.whitelist.Remove(bySpace[1]);

View File

@ -27,6 +27,7 @@ namespace AniNIX.TheRaven {
proc.StartInfo.FileName = "/bin/bash";
proc.StartInfo.Arguments = String.Format("-c \'{0}\'",command);
proc.StartInfo.UseShellExecute=false;
ReportMessage.Log(Verbosity.Verbose,String.Format("{0} {1}",proc.StartInfo.FileName,proc.StartInfo.Arguments));
//Redirect input
proc.StartInfo.RedirectStandardOutput=true;