Fixes for URL titling and chat timeouts

This commit is contained in:
DarkFeather 2016-09-27 10:33:41 -05:00
parent 9da156fced
commit b329ea276b
21 changed files with 151 additions and 150 deletions

View File

@ -4,6 +4,7 @@ using System.Net.Sockets;
using System.IO;
using System.Text;
using System.Threading;
using AniNIX.Shared;
namespace AniNIX.TheRaven {

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using AniNIX.Shared;
namespace AniNIX.TheRaven {
@ -49,7 +50,7 @@ namespace AniNIX.TheRaven {
}
public override string ToString() {
if (Raven.verbosity == Verbosity.Explicit) {
if (ReportMessage.verbosity == Verbosity.Explicit) {
return String.Format(">>> {0}\nUser: {1}\nServer: {2}\nmsgCode: {3}\nTarget: {4}\nMessage: {5}\n",incomingIRCString,user,server,msgCode,target,message);
} else {
return String.Format(">>> {0}",incomingIRCString);

View File

@ -1,32 +1,40 @@
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
CONFDIR := /usr/local/etc/TheRaven
compile: /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
if [ ! -d ../Djinni ]; then git clone -C '..' https://aninix.net/foundation/Djinni; fi
git -C ../Djinni pull
if [ ! -d ../SharedLibraries ]; then git clone -C '..' https://aninix.net/foundation/SharedLibraries; fi
git -C ../SharedLibraries pull
mcs -out:raven.mono ../SharedLibraries/CSharp/*.csharp *.csharp
clean:
if [ "$$(ls ./*~ 2>/dev/null | wc -l)" -gt 0 ]; then rm -Rf *~; fi
if [ "$$(ls ./*.mono 2>/dev/null | wc -l)" -gt 0 ]; then rm -Rf *.mono; fi
if [ "$$(ls ./\#* 2>/dev/null | wc -l)" -gt 0 ]; then rm -Rf \#*; fi
if [ -f raven.mono ]; then rm raven.mono; fi
edit:
emacs -nw raven.csharp
test: raven.mono
script -c "mono ./raven.mono -c /usr/local/etc/TheRaven-Test -v" /tmp/raven-test.log
test: compile
script -c "mono ./raven.mono -c ${CONFDIR}-Test -v" /tmp/raven-test.log
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
install: compile
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*
chmod 0600 /opt/raven.mono /usr/local/etc/TheRaven*/*
chmod 0700 /usr/local/etc/TheRaven*
if [ ! -d ${CONFDIR} ]; then (mkdir -p /usr/local/etc/TheRaven; cp ./sample-conf/* ${CONFDIR}); fi
if ! getent passwd raven; then useradd -M -G git,ircd,api -d ${CONFDIR} raven; fi
make checkperm
cp ./raven.service /usr/lib/systemd/system/raven.service
/usr/bin/bash make-conf-dir.bash /usr/local/etc/TheRaven
systemctl daemon-reload
systemctl enable raven
reverse: /usr/lib/systemd/system/raven.service
cp /usr/lib/systemd/system/raven.service .
checkperm: /opt/raven.mono
chown -R raven:raven /opt/raven.mono ${CONFDIR}*
chmod 0600 /opt/raven.mono ${CONFDIR}*/*
chmod 0700 ${CONFDIR}*

View File

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using AniNIX.Shared;
namespace AniNIX.TheRaven {
@ -33,8 +34,6 @@ namespace AniNIX.TheRaven {
public Dictionary<String,int> MailerCount = new Dictionary<String,int>(); // Messages may only be sent up to a maximum to the admins.
public static Verbosity verbosity { get; private set; } // This is the level to which this and all Raven instances will log.
/// <summary>
/// Show the settings used by this Raven.
/// </summary>
@ -48,7 +47,7 @@ namespace AniNIX.TheRaven {
sb.Append("NickServPass: ****\n");
sb.Append(String.Format("Auto: {0}\n",_autoSend));
sb.Append(String.Format("Conf: {0}\n",configDir));
sb.Append(String.Format("Verbosity: {0}\n",Raven.verbosity));
sb.Append(String.Format("Verbosity: {0}\n",ReportMessage.verbosity));
return sb.ToString();
}
@ -141,10 +140,10 @@ namespace AniNIX.TheRaven {
}
break;
case "-v":
Raven.verbosity = Verbosity.VeryVerbose;
ReportMessage.verbosity = Verbosity.VeryVerbose;
break;
case "-q":
Raven.verbosity = Verbosity.Quiet;
ReportMessage.verbosity = Verbosity.Quiet;
break;
case "-P":
if (i < args.Length-1) _nickServPass = args[++i];
@ -186,7 +185,7 @@ namespace AniNIX.TheRaven {
/// <summary>
/// Populate the name recognition
/// </summary>
/// <summary>
/// Create a raven with default settings.
@ -198,7 +197,7 @@ namespace AniNIX.TheRaven {
_nickServPass = nickServPass;
_autoSend = autoSend;
this.configDir = configDir;
Raven.verbosity = verbosity;
ReportMessage.verbosity = verbosity;
}
/// <summary>
@ -261,7 +260,7 @@ namespace AniNIX.TheRaven {
if (notifications.TryGetValue(response.target,out result)) {
if (response.message.Contains(result)) {
try {
RavenExecute.Command(String.Format("/usr/local/bin/djinni admin \"Found {1} in {0}\"",response.target,result));
ExecuteCommand.Run(String.Format("/usr/local/bin/djinni admin \"Found {1} in {0}\"",response.target,result));
} catch (Exception e) {
ReportMessage.Log(Verbosity.Error,e.ToString());
}
@ -273,17 +272,32 @@ namespace AniNIX.TheRaven {
// 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);
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);
} catch (Exception e) {
e.ToString();
send.PrivMsg("Cannot talk right now.",(response.target.Equals(Nick))?response.user:response.target);
}
_connection.Write(send);
}
/* CROWFACTS the deserving */
if (crowFactsSubscribers.Contains(response.user) && randomSeed.Next(10) < 8) {
else 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);
}
if (WebPageAPI.URLRegEx.Match(response.message).Success) {
try {
IRCClientMessage send = new IRCClientMessage();
send.PrivMsg(String.Format("Web page title: {0}",WebPageAPI.GetPageTitle(WebPageAPI.URLRegEx.Match(response.message).Value)),(response.target.Equals(Nick))?response.user:response.target);
_connection.Write(send);
} catch (Exception e) {
e.ToString();
}
}
}
}
}

View File

@ -3,6 +3,7 @@ using System.IO;
using System.Text;
using System.Diagnostics;
using System.Collections.Generic;
using AniNIX.Shared;
namespace AniNIX.TheRaven {
@ -58,6 +59,7 @@ namespace AniNIX.TheRaven {
int result = theRaven.randomSeed.Next(Int32.Parse(bySpace[1]));
send.PrivMsg(String.Format("{0}",result+1),(incoming.target.Equals(theRaven.Nick))?incoming.user:incoming.target);
} catch (Exception e) {
e.ToString();
send.PrivMsg("Bad formatting.",(incoming.target.Equals(theRaven.Nick))?incoming.user:incoming.target);
}
}
@ -68,7 +70,7 @@ 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.Equals(theRaven.Nick))?incoming.user:incoming.target);
send.PrivMsg(ExecuteCommand.Run(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.Equals(theRaven.Nick))?incoming.user:incoming.target);
@ -103,7 +105,7 @@ namespace AniNIX.TheRaven {
ReportMessage.Log(Verbosity.Error,"Make sure user raven can write to /var/log/r.msg.log");
}
try {
RavenExecute.Command(String.Format("djinni admin \"Page from {0}\"",incoming.user));
ExecuteCommand.Run(String.Format("djinni admin \"Page from {0}\"",incoming.user));
send.PrivMsg("Sent!",incoming.user);
} catch (Exception e) {
ReportMessage.Log(Verbosity.Error,e.ToString());
@ -114,7 +116,7 @@ namespace AniNIX.TheRaven {
return;
case "r.uptime":
try {
send.PrivMsg(RavenExecute.Command("uptime"),(incoming.target.Equals(theRaven.Nick))?incoming.user:incoming.target);
send.PrivMsg(ExecuteCommand.Run("uptime"),(incoming.target.Equals(theRaven.Nick))?incoming.user:incoming.target);
} catch (Exception e) {
e.ToString();
send.PrivMsg("Can't get uptime",(incoming.target.Equals(theRaven.Nick))?incoming.user:incoming.target);
@ -123,7 +125,7 @@ namespace AniNIX.TheRaven {
return;
case "r.heartbeat":
try {
String[] byLine = RavenExecute.Command("heartbeat-client").Split('\n');
String[] byLine = ExecuteCommand.Run("heartbeat-client").Split('\n');
for (int i = 0; i < byLine.Length; i++) {
send.PrivMsg(byLine[i],incoming.user);
connection.Write(send);

View File

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using AniNIX.Shared;
namespace AniNIX.TheRaven {

View File

@ -1,16 +0,0 @@
#!/usr/bin/bash
mkdir -p $1
touch $1/blacklist.txt
touch $1/crowfacts.txt
touch $1/crowfacts.txt.bak
touch $1/hangman.txt
touch $1/keepalive-loginDefaults.txt
touch $1/magic8.txt
touch $1/todo.txt
touch $1/whitelist.txt
touch $1/loginDefaults.txt
touch $1/rooms.txt
touch $1/searches.txt
touch $1/helptext.txt

View File

@ -1,59 +0,0 @@
using System;
using System.IO;
using System.Text;
using System.Diagnostics;
using System.Collections.Generic;
namespace AniNIX.TheRaven {
public static class RavenExecute {
/// <summary>
/// This method allows TheRaven to execute a command on the OS.
/// </summary>
/// <param name=command>The command string to run as the string argument to "bash -c 'command'"</param>
/// <param name=input>The effective replacement for the command's stdin</param
/// <return>The stdout of the command</return>
/// </summary>
public static String Command(String command, String input) {
//Sanitize inputs.
if (command.Contains("\'")) {
throw new Exception("Command strings cannot include \'.");
}
//Create process.
Process proc = new Process();
proc.StartInfo.CreateNoWindow = true;
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;
proc.StartInfo.RedirectStandardInput=true;
//Start process
proc.Start();
//Add input and read output.
proc.StandardInput.Write(input);
proc.StandardInput.Close();
proc.WaitForExit();
if (proc.ExitCode != 0) {
throw new Exception(String.Format("Failed to exit command with return code {0}",proc.ExitCode));
}
String stdoutString = proc.StandardOutput.ReadToEnd();
//Close up and return
proc.Close();
return stdoutString;
}
//Add polymorphism to allow no stdin
public static String Command(String command) {
return Command(command,null);
}
}
}

View File

@ -1,45 +0,0 @@
using System;
namespace AniNIX.TheRaven {
public enum Verbosity {
Always = -2,
Error,
Quiet = 0,
Verbose,
VeryVerbose,
Explicit,
}
public static class ReportMessage {
/// <summary>
/// Log a new message for the user.
/// </summary>
public static void Log(Verbosity level,String message) {
if (level == Verbosity.Error) {
Console.Error.WriteLine(message);
return;
}
if (Raven.verbosity == Verbosity.Quiet) {
return;
}
if (level == Verbosity.Always
|| (Raven.verbosity == Verbosity.Verbose && level == Verbosity.Verbose)
|| (Raven.verbosity == Verbosity.VeryVerbose && (level == Verbosity.Verbose || level == Verbosity.VeryVerbose))
|| (Raven.verbosity == Verbosity.Explicit && (level == Verbosity.Verbose || level == Verbosity.VeryVerbose || level == Verbosity.Explicit))
) {
Console.WriteLine(message);
}
}
public static void Log(String message) {
Log(Verbosity.VeryVerbose,message);
}
}
}

View File

@ -0,0 +1 @@
TheRaven

52
sample-conf/crowfacts.txt Normal file
View File

@ -0,0 +1,52 @@
There's an old nonsense song called the Old Carrion Crow.
From 2000 to 2003 the world's best wooden roller coaster was called The Raven.
The average raven has a four-foot wingspan.
The average crow has a three-foot wingspan.
Crows and ravens are members of the corvid family, the most adaptable and intelligent family of birds in the world.
Crows and ravens can mimic sounds and associate sounds with events.
Crows roost in flocks of several thousand in the winter.
Crows are omnivorous, making them capable scavangers and opportunistic hunters.
Crows prefer coniferous trees to build their homes at least 60 feet above the ground.
Paired males and females share in the raising of the four to six eggs.
One crow baby will frequently remain in the nest to assist in the caring for the next nestlings.
While crows have a reputation for eating corn, they often eat the bugs that plague crops.
Crows and ravens are territorial when young are in the nest, dive-bombing passersby.
The Sioux have a story of a white crow warning buffalo of approaching hunting parties. The bird turned black when a hunter threw it into the fire in rage.
Crows have been hunted and even had bounties placed on them by several governments, including by Kings of England.
Crows can use a number of calls to communicate situations and emotions.
Crows mate for life and share the care of nestlings.
Crows are often challenged by larger hunting birds, like owls and hawks; they use superior numbers when outmatched.
Crows only migrate long distances in harsh winters.
A group of crows or ravens is called a murder.
Crows live everywhere except Antarctica.
Crows are susceptible to West Nile Virus, which has felled many of them since 1999.
Crows' association with death comes from their scavenger natures -- they are often seen near the dead on battlefields.
Ravens are acrobatic fliers on par with hawks and falcons. In mating season, they put on acrobatic shows for potential mates.
Native Americans often honor ravens in their stories for their playful nature.
Ravens hunt in groups to bring down prey too large for a single bird.
Ravens range from the Arctic to the Mediterranean, building large stick nests.
Ravens have an average wild lifespan of 13 years.
Common ravens range from 24 to 30 inches long with up to a 5 foot (1.5m) wingspan, weighing in at 2.3 pounds.
Legend has it that if ravens leave the Tower of London, the fortress will fall and the British kingdom along with it.
Ravens are the largest passerine (perching) birds in North America.
Ravens can live up to 40 years in captivity or protected conditions.
https://upload.wikimedia.org/wikipedia/commons/9/92/Krummi_1.jpg
Ravens have one of the largest bills of perching birds.
Common ravens have quarrelsome family lives, but they are extremely devoted to their families.
Common ravens (Corvus corax) store food, hiding it from other ravens.
A group of ravens is commonly called a flock.
Ravens don't migrate except in the harshest winters.
In addition to their bills, ravens may drop rocks as weapons.
Young ravens are fascinated with all things new, but older ravens become more cautious and neophobic with experience.
Ravens are known to play, sliding down snowdrifts for fun and play games with wolves and other animals.
Ravens are one of only a few species known to make toys, breaking off branches for social play.
The raven is the national bird of Bhutan and the official bird of the Yukon.
The raven was the first bird sent forth by Noah but didn't return until the flood waters receded.
Ravens feed the prophet Elijah in 1 Kings 17:1 and are a subject of a parable in Luke 12:24, as a sign for man not to be materialistic.
The Native Americans saw the Raven as a creator and world-shaper.
Native American mythology holds that Raven brought the sun, moon, stars, and fire into the world.
The Norse god Odin had two ravens Huginn and Muninn (Thought and Mind) to serve as his eyes in the world.
The raven is the symbol of the Celtic figure Morrigan and the namesake of Lugh, the god responsible for creating arts and science.
The raven appears in the Quran but once, only to teach man to bury the dead in the story of Cain and Abel.
GI_Auditore finds Mutated Ravens in Prototype 2 extremely annoying.
Lost_Fragment will lose in a fight with TheRaven.

1
sample-conf/helptext.txt Normal file
View File

@ -0,0 +1 @@
Available commands are r.raven, r.magic8, r.msg <Memo for DarkFeather>, r.google <Google search>, r.sound <Soundcloud search>, r.image <Image search>, r.wiki <Wikipedia search>, r.dict <Dictionary search>, r.yt <youtube search>, r.urban <Urban dictionary search>, r.hoogle <Haskell Hoogle search>, r.so <StackOverflow search>, r.man <manpage search>, and r.tropes <TV Tropes search>

View File

@ -0,0 +1,4 @@
localhost
6667
TheRaven-Test
somepass

20
sample-conf/magic8.txt Normal file
View File

@ -0,0 +1,20 @@
It is certain
It is decidedly so
Without a doubt
Yes definitely
You may rely on it
As I see it yes
Most likely
Outlook good
Yes
Signs point to yes
Reply hazy try again
Ask again later
Better not tell you now
Cannot predict now
Concentrate and ask again
Don't count on it
My reply is no
My sources say no
Outlook not so good
Very doubtful

View File

@ -0,0 +1 @@
TheRaven|Surprise

3
sample-conf/rooms.txt Normal file
View File

@ -0,0 +1,3 @@
TheRafters
lobby
#thisisacomment

11
sample-conf/searches.txt Normal file
View File

@ -0,0 +1,11 @@
r.google|http://google.com/search?q=|+
r.images|http://images.google.com/search?tbm=isch&q=%s|+
r.wiki|http://en.wikipedia.org/wiki/|_
r.sound|http://www.soundcloud.com/search?q=|%20
r.dict|http://www.merriam-webster.com/dictionary/|+
r.tropes|http://tvtropes.org/pmwiki/search_result.php?cx=partner-pub-6610802604051523%3Aamzitfn8e7v&cof=FORID%3A10&ie=ISO-8859-1&siteurl=&ref=&ss=&siteurl=tvtropes.org%2F&ref=www.google.com%2F&ss=5135j1581675j28&q=|+
r.yt|https://www.youtube.com/results?search_query=|+
r.urban|http://www.urbandictionary.com/define.php?term=|+
r.man|http://www.die.net/search/?q=|+
r.hoogle|https://www.haskell.org/hoogle/?hoogle=|+
r.so|http://stackoverflow.com/search?q=|+

View File

@ -0,0 +1 @@
DarkFeather