Skip to content

Commit

Permalink
Merge pull request #35 from alexdor/master
Browse files Browse the repository at this point in the history
Fix event parsing from community.lambdaspace.gr
  • Loading branch information
AEtherC0r3 authored Nov 2, 2017
2 parents 6170305 + 18ebe7e commit 5859d62
Show file tree
Hide file tree
Showing 3 changed files with 1,389 additions and 364 deletions.
64 changes: 31 additions & 33 deletions MinisterIN.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ var spaceOpen = false;
program
.version('1.3.1')
.usage('space=[open/closed]')
.option('-s, --space <state>', 'Whether the space is open or closed (default = closed)', /^(closed|open)$/i, 'closed')
.option(
'-s, --space <state>',
'Whether the space is open or closed (default = closed)',
/^(closed|open)$/i,
'closed'
)
.parse(process.argv);

// Check if "space=open" was given as argument
Expand All @@ -33,9 +38,9 @@ try {
} catch (e) {
console.log('Could not parse MQTT configuration file: ' + e.message);
mqttConfig = {
caFile: "ca.crt",
port: "8883",
host: "mqtt.lambdaspace.gr"
caFile: 'ca.crt',
port: '8883',
host: 'mqtt.lambdaspace.gr'
};
}

Expand All @@ -51,22 +56,16 @@ try {
} catch (e) {
console.log('Could not parse tweets file: ' + e.message);
tweetMsgs = {
'statusOpen': [
"Minister is in"
],
'statusClosed': [
"Minister is out"
]
statusOpen: ['Minister is in'],
statusClosed: ['Minister is out']
};
}
try {
helloMsgs = require('./hello.json');
} catch (e) {
console.log('Could not parse hello file: ' + e.message);
helloMsgs = {
'hello': [
"hello!"
]
hello: ['hello!']
};
}

Expand All @@ -85,7 +84,6 @@ try {
console.log('Could not parse mattermost configuration file: ' + e.message);
}


// Create Mattermost client
if (mattermostConfig.hook_url) var mattermostClient = new mattermost(mattermostConfig.hook_url);
var mattermostBroadcast = function(msg, channel = '#off-topic') {
Expand All @@ -111,13 +109,13 @@ try {
} catch (e) {
console.log('Could not parse IRC configuration file: ' + e.message);
ircConfig = {
server: "irc.freenode.net",
nick: "Consuela-λspace",
channels: ["#LambdaSpace"]
server: 'irc.freenode.net',
nick: 'Consuela-λspace',
channels: ['#LambdaSpace']
};
}

var CA = fs.readFileSync(__dirname + "/" + mqttConfig.caFile);
var CA = fs.readFileSync(__dirname + '/' + mqttConfig.caFile);

var mqttOptions = {
port: mqttConfig.port,
Expand All @@ -138,7 +136,6 @@ client.on('connect', function() {
console.log('Connected to MQTT broker ' + mqttConfig.host);
});


// Create an IRC client
var ircClient = new irc.Client(ircConfig.server, ircConfig.nick, ircConfig);
ircClient.sayAllChannels = function(message) {
Expand Down Expand Up @@ -192,7 +189,6 @@ var broadcastStatusChange = function(newStatus) {
if (mattermostBroadcast(msg, '#status-updates')) spaceOpen = newStatus;
};


/**
* Updates the status of the space, given the number
* of the hackers there.
Expand Down Expand Up @@ -233,21 +229,24 @@ ircClient.addListener('message#LambdaSpace', function(from, message) {
// });

// Github organization Webhooks
var gh_webhook_handler = gh_webhook({ 'path': '/lambdaspace', 'secret': APIKeys.github.webhook });
var gh_webhook_handler = gh_webhook({ path: '/lambdaspace', secret: APIKeys.github.webhook });
try {
http.createServer(function(req, res) {
gh_webhook_handler(req, res, function(err) {
res.statusCode = 404;
res.end('No such location');
});
}).listen(7777);
http
.createServer(function(req, res) {
gh_webhook_handler(req, res, function(err) {
res.statusCode = 404;
res.end('No such location');
});
})
.listen(7777);
} catch (e) {
console.log(e);

}

gh_webhook_handler.on('push', function(event) {
ircClient.sayAllChannels(event.payload.pusher.name + ' pushed to repository ' + event.payload.repository.name + ':');
ircClient.sayAllChannels(
event.payload.pusher.name + ' pushed to repository ' + event.payload.repository.name + ':'
);
event.payload.commits.forEach(function(commit) {
var msg = '* ' + commit.author.name + ' - ' + commit.message;
ircClient.sayAllChannels(msg);
Expand Down Expand Up @@ -278,8 +277,6 @@ try {
console.log(e);
}



/* Disclaimer: follows code that is very specific to the LambdaSpace stack */

// Parse events from discourse
Expand All @@ -289,6 +286,7 @@ var eventParser = function(topic) {
event.day = tokens[0];
if (!event.day.match(/^\d\d\/\d\d\/\d\d\d\d+$/)) {
console.log('Not in expected format');
return;
}
var dateTokens = tokens[0].split('/');
event.date = new Date(dateTokens[2], dateTokens[1] - 1, dateTokens[0], 0, 0);
Expand All @@ -297,10 +295,9 @@ var eventParser = function(topic) {
event.time = tokens[1];
event.title = topic.substr(17);
} else {
event.time = "";
event.time = '';
event.title = topic.substr(11);
}

return event;
};

Expand All @@ -313,6 +310,7 @@ var parseEvents = function(data) {
} catch (e) {
return;
}
if (!event) return;
var pubEvent = null;
if (event.date.equals(Date.parse('today'))) {
pubEvent = 'TODAY ';
Expand Down
42 changes: 24 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,44 @@
"email": "[email protected]",
"web": "https://github.com/misaakidis"
},
"contributors:": [{
"name": "Alexandros Dorodoulis",
"email": "[email protected]"
}, {
"name": "Zack Mullaly",
"email": "[email protected]",
"web": "http://redwire.co"
}],
"contributors:": [
{
"name": "Alexandros Dorodoulis",
"email": "[email protected]"
},
{
"name": "Zack Mullaly",
"email": "[email protected]",
"web": "http://redwire.co"
}
],
"bugs": {
"url": "https://github.com/techministry/MinisterIN/issues"
},
"scripts": {
"test": "./node_modules/jshint/bin/jshint *.js",
"start": "node MinisterIN.js"
},
"repository": [{
"type": "git",
"url": "https://github.com/techministry/MinisterIN.git"
}],
"repository": [
{
"type": "git",
"url": "https://github.com/techministry/MinisterIN.git"
}
],
"dependencies": {
"commander": "2.9.0",
"commander": "2.11.0",
"datejs": "^1.0.0-rc3",
"fs": "0.0.2",
"github-webhook-handler": "0.5.0",
"irc": "0.4.0",
"mqtt": "^1.11.0",
"github-webhook-handler": "0.6.0",
"irc": "0.5.2",
"mqtt": "^2.13.1",
"node-mattermost": "^0.0.1",
"node-schedule": "^1.1.0",
"request": "^2.72.0",
"twitter": "1.2.5"
"twitter": "1.7.1"
},
"devDependencies": {
"jshint": "latest"
"jshint": "^2.9.5",
"nodemon": "^1.12.1"
}
}
Loading

0 comments on commit 5859d62

Please sign in to comment.