Removed Pushbullet support

Added Usage function
Reformated PKGBUILD to fit standards
Corrections to README.md
Removed static paths in favor of referential.
Test case update
Removed unneeded statements from crowfacts
This commit is contained in:
DarkFeather 2020-09-10 16:20:40 -05:00
parent 778416c0a2
commit 5e360b0da2
Signed by: DarkFeather
GPG Key ID: 1CC1E3F4ED06F296
10 changed files with 106 additions and 88 deletions

2
.gitignore vendored
View File

@ -1,5 +1,5 @@
raven.mono
theraven-*.tar.xz
TheRaven-*.pkg.tar.zst
pkg/
src/
.config

View File

@ -1,28 +1,23 @@
CONFDIR = ${pkgdir}/usr/local/etc/TheRaven
compile: clean ./chatbot-support.bash ./math-support.bash /usr/sbin/pb
mkdir -p ${pkgdir}/usr/local/src/
(mcs -out:raven.mono /opt/aninix/SharedLibraries/CSharp/*.csharp *.csharp Raven.csharp 2>&1 | grep -v CS2002); printf ""
compile: clean ./chatbot-support.bash ./math-support.bash
(mcs -out:raven.mono /opt/aninix/Uniglot/CSharp/*.csharp *.csharp Raven.csharp 2>&1 | grep -v CS2002); printf ""
clean:
for i in raven.mono; do if [ -f $$i ]; then rm $$i; fi; done
test: compile
script -c "mono ./raven.mono -c raven-test.conf -v" ${pkgdir}/tmp/raven-test.log
cd ./sample-confs; mono ../raven.mono -c sample.conf -v -h
install: compile
mkdir -p ${pkgdir}/opt
cp raven.mono ${pkgdir}/opt/raven.mono
if [ ! -d ${CONFDIR} ]; then mkdir -p ${CONFDIR}; cp sample-confs/* ${CONFDIR}; fi
# Hook to deprivilege bot
if ! getent passwd raven; then useradd -M -G git,ircd,api -d ${CONFDIR} raven; fi
echo "raven:$$(/usr/sbin/pwgen 24 1)" | chpasswd;
make checkperm
# Hook for Heartbeat
if [ -f ${pkgdir}/usr/local/etc/Heartbeat/services.list ] && [ `grep -c TheRaven ${pkgdir}/usr/local/etc/Heartbeat/services.list` -eq 0 ]; then echo "" >> ${pkgdir}/usr/local/etc/Heartbeat/services.list; fi
# Hook for Systemd
mkdir -p ${pkgdir}/usr/lib/systemd/system/
cp /usr/local/src/TheRaven/raven.service ${pkgdir}/usr/lib/systemd/system/raven.service
cp ./raven.service ${pkgdir}/usr/lib/systemd/system/raven.service
reverse: ${pkgdir}/usr/lib/systemd/system/raven.service
cp ${pkgdir}/usr/lib/systemd/system/raven.service .

View File

@ -1,20 +1,23 @@
# Maintainer: Shikoba Kage <darkfeather@aninix.net>
pkgname=theraven
pkgver=0.1
pkgrel=1
epoch=
pkgdesc="AniNIX::TheRaven \\\\ IRC Bot"
arch=("x86_64")
url="https://aninix.net/foundation/TheRaven"
license=('custom')
groups=()
depends=('mono>=5.0.0' 'curl' 'grep' 'bash>=4.4' 'git>=2.13' 'pushbullet-cli' 'lynx' 'wget' 'nmap>=7.70')
# Maintainer: DarkFeather <ircs://aninix.net:6697/darkfeather>
depends=('mono>=5.0.0' 'curl' 'grep' 'bash>=4.4' 'git>=2.13' 'wget' 'nmap>=7.70')
makedepends=('make>=4.2' 'pwgen')
checkdepends=()
optdepends=()
provides=('theraven')
pkgname="$(git config remote.origin.url | rev | cut -f 1 -d '/' | rev | sed 's/.git$//')"
pkgver="$(git describe --tag --abbrev=0)"."$(git rev-parse --short HEAD)"
pkgrel=1
pkgrel() {
echo $(( `git log "$(git describe --tag --abbrev=0)"..HEAD | grep -c commit` + 1 ))
}
epoch="$(git log | grep -c commit)"
pkgdesc="$(head -n 1 README.md)"
arch=("x86_64")
url="$(git config remote.origin.url | sed 's/.git$//')"
license=('custom')
groups=()
provides=("${pkgname}")
conflicts=()
replaces=()
replaces=("${pkgname,,}", "aninix-${pkgname,,}")
backup=()
options=()
install=
@ -33,8 +36,8 @@ build() {
}
check() {
# We're not using test because it makes an actual connection. That case is useful but not quite as a regression the way PKGBUILD needs.
ls -l ../raven.mono
chmod -R u+r ../pkg
make -C .. test
}
package() {

2
README
View File

@ -1,2 +0,0 @@
This project is enabled for AniNIX::Bazaar. You can check it out remotely with the bzr package.
Project URL is bzr://bazaar.aninix.net/TheRaven

17
README.md Normal file
View File

@ -0,0 +1,17 @@
This is a simple IRCbot for the AniNIX's operations.
# Usage
To enable this bot, just install the package from [the AniNIX repository](https://maat.aninix.net) or run the following:
```
make
sudo make install
sudo systemctl start raven.service
sudo systemctl enable raven.service
```
# Functionality
This IRCbot has some simple commands that can be found by most users with `r.help` in whatever channel the bot has joined.
Administrative functions are controlled by the access lists and can be found with `r.adminhelp`.
The bot can also be invoked with `mono ./raven.mono -h` to get more detailed help.

View File

@ -59,7 +59,7 @@ namespace AniNIX.TheRaven {
}
/// <summary>
/// Read from the files in the /usr/local/etc/TheRaven directory to configure this Raven
/// Read from the files in the current directory to configure this Raven
/// </summary>
// TODO: This and ParseArgs may get punted into their own static class to improve readability.
private void ConfigureSelfFromFiles() {
@ -119,10 +119,30 @@ namespace AniNIX.TheRaven {
searchesIndex = searchIndexBuilder.ToString();
//Read the globals
magic8 = (new Configure("/usr/local/etc/TheRaven/magic8.txt")).GetLines();
crowFacts = (new Configure("/usr/local/etc/TheRaven/crowfacts.txt")).GetLines();
magic8 = (new Configure("magic8.txt")).GetLines();
crowFacts = (new Configure("crowfacts.txt")).GetLines();
}
/// <summary>
/// Print helptext and exit
/// param retcode: what to return to the system.
/// </summary>
public void Usage() {
ReportMessage.Log(Verbosity.Always,"Usage: mono ./raven.mono -c conf # start the Raven with the conf file");
ReportMessage.Log(Verbosity.Always,"Usage: mono ./raven.mono -h # Get help");
ReportMessage.Log(Verbosity.Always,"");
ReportMessage.Log(Verbosity.Always,"The following flags are optional:");
ReportMessage.Log(Verbosity.Always,"-n Nickname");
ReportMessage.Log(Verbosity.Always,"-t Host");
ReportMessage.Log(Verbosity.Always,"-p Port");
ReportMessage.Log(Verbosity.Always,"-v Verbose");
ReportMessage.Log(Verbosity.Always,"-q Quiet");
ReportMessage.Log(Verbosity.Always,"-P NickServ passphrase");
ReportMessage.Log(Verbosity.Always,"-a Autosend command");
throw new RavenExitedException();
}
/// <summary>
/// Parse arguments from the command line.
/// </summary>
@ -135,7 +155,7 @@ namespace AniNIX.TheRaven {
case "-n":
if (i < args.Length-1) Nick = args[++i];
break;
case "-h":
case "-t":
if (i < args.Length-1) Host = args[++i];
break;
case "-p":
@ -155,19 +175,15 @@ namespace AniNIX.TheRaven {
case "-P":
if (i < args.Length-1) _nickServPass = args[++i];
break;
//TODO: Add daemonizing?
case "-a":
if (i < args.Length-1) _autoSend = args[++i];
break;
case "--help":
//TODO Add helptext
break;
case "-h":
Usage();
return;
case "-c":
if (i < args.Length-1) _configFile = args[++i];
break;
case "--version":
ReportMessage.Log(Verbosity.Always,"AniNIX::TheRaven version 0.2");
break;
}
}
}
@ -184,6 +200,7 @@ namespace AniNIX.TheRaven {
// If we have arguments
this.ParseArguments(args);
this.ConfigureSelfFromFiles();
this._isDisposed = false;
ReportMessage.Log(Verbosity.VeryVerbose,"Started with these values:");
ReportMessage.Log(Verbosity.VeryVerbose,this.ToString());
}
@ -260,26 +277,12 @@ namespace AniNIX.TheRaven {
if (response != null && response.message != null && response.message.Length > 3 && response.message.Substring(0,2).Equals("r.")) {
RavenCommand.Respond(_connection,response,this);
} else if (response != null) {
//Try to notify the admins when a given string is found in a given channel
String result;
if (notifications.TryGetValue(response.target,out result)) {
if (response.message.Contains(result)) {
try {
ReportMessage.Log(Verbosity.Verbose,"Sending notification.");
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());
}
}
}
// 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();
try {
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();
String aliceResponse = ExecuteCommand.Run(String.Format("bash ./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) {
@ -318,7 +321,9 @@ namespace AniNIX.TheRaven {
/// Close the _connection
/// </summary>
private void CloseConnection() {
this._connection.Dispose();
if (this._connection != null) {
this._connection.Dispose();
}
}
/// <summary>
@ -363,12 +368,15 @@ namespace AniNIX.TheRaven {
}
// This bool indicates whether we have disposed of this Raven
public bool _isDisposed = false;
public bool _isDisposed = true;
/// <summary>
/// Dispose of this Raven's's resources responsibly.
/// </summary>
private void Dispose(bool disposing) {
if (this == null) {
return;
}
if (!_isDisposed) {
if (disposing) {
Host = null;
@ -394,29 +402,34 @@ namespace AniNIX.TheRaven {
/// The default function
/// </summary>
static int Main(string[] args) {
Raven theRaven = new Raven(args);
ReportMessage.Log(Verbosity.Verbose,"### AniNIX::TheRaven ###");
//Continue until we cleanly exit.
while (true) {
try {
return theRaven.Run();
//If we are already identified, we're done.
} catch (AlreadyIdentifiedException e) {
ReportMessage.Log(Verbosity.Error,"There is already a Raven on this Host.");
ReportMessage.Log(Verbosity.Error,e.Message);
return 0;
// Timeouts should result in a respawn
} catch (RavenTimedOutException e) {
ReportMessage.Log(Verbosity.Always,"Connection timed out. Respawning");
ReportMessage.Log(Verbosity.Verbose,e.Message);
continue;
//If an exception gets here, something went wrong
} catch (Exception e) {
ReportMessage.Log(Verbosity.Error,"Unexpected exception caught!");
ReportMessage.Log(Verbosity.Error,e.Message);
return 1;
try {
Raven theRaven = new Raven(args);
ReportMessage.Log(Verbosity.Verbose,"### AniNIX::TheRaven ###");
//Continue until we cleanly exit.
while (true) {
try {
return theRaven.Run();
//If we are already identified, we're done.
} catch (AlreadyIdentifiedException e) {
ReportMessage.Log(Verbosity.Error,"There is already a Raven on this Host.");
ReportMessage.Log(Verbosity.Error,e.Message);
return 0;
// Timeouts should result in a respawn
} catch (RavenTimedOutException e) {
ReportMessage.Log(Verbosity.Always,"Connection timed out. Respawning");
ReportMessage.Log(Verbosity.Verbose,e.Message);
continue;
//If an exception gets here, something went wrong
} catch (Exception e) {
ReportMessage.Log(Verbosity.Error,"Unexpected exception caught!");
ReportMessage.Log(Verbosity.Error,e.Message);
return 1;
}
}
}
catch (RavenExitedException e) {
return 0;
}
}
}
}

View File

@ -114,13 +114,6 @@ namespace AniNIX.TheRaven {
ReportMessage.Log(Verbosity.Error,e.Message);
ReportMessage.Log(Verbosity.Error,"Make sure user raven can write to /var/log/r.msg.log");
}
try {
ExecuteCommand.Run(String.Format("pb push \"Page from {0}\"",incoming.user));
send.PrivMsg("Sent!",incoming.user);
} catch (Exception e) {
ReportMessage.Log(Verbosity.Error,e.ToString());
send.PrivMsg("Mailer error. Could not send.",incoming.user);
}
}
connection.Write(send);
return;

View File

@ -1,8 +1,9 @@
[Unit]
Description=AniNIX::Raven IRC Bot
Description=AniNIX/Raven | IRC Bot
After=network.target
[Service]
WorkingDirectory=/usr/local/etc/TheRaven
ExecStart=/usr/bin/mono /opt/raven.mono -c raven.conf
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process

View File

@ -7,7 +7,7 @@ unset channel
unset message
unset passphrase
export file="/usr/local/etc/TheRaven/raven.conf"
export port="9501"
export port="8373"
export host="localhost"
# Show help

View File

@ -48,5 +48,3 @@ Native American mythology holds that Raven brought the sun, moon, stars, and fir
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.