mirror of
https://github.com/reality/dbot.git
synced 2024-11-30 16:09:27 +01:00
vitetris
This commit is contained in:
parent
aed72f52dc
commit
fa431ac800
5
modules/vitetris/config.json
Normal file
5
modules/vitetris/config.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"logFile": "/home/reality/tetris.log",
|
||||||
|
"streamServer": "snoonet",
|
||||||
|
"streamChannel": "#no"
|
||||||
|
}
|
35
modules/vitetris/vitetris.js
Normal file
35
modules/vitetris/vitetris.js
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
var fs = require('fs'),
|
||||||
|
_ = require('underscore')._;
|
||||||
|
|
||||||
|
var vitetris = function(dbot) {
|
||||||
|
var lastLine = 0;
|
||||||
|
|
||||||
|
this.onLoad = function() {
|
||||||
|
dbot.api.timers.addTimer(15000, function() {
|
||||||
|
var file = fs.readFileSync(this.config.logFile).toString().split("\n");
|
||||||
|
var newEvents = [];
|
||||||
|
|
||||||
|
if(file.length != lastLine) {
|
||||||
|
newEvents = file.slice(lastLine-1);
|
||||||
|
}
|
||||||
|
lastLine = file.length;
|
||||||
|
|
||||||
|
if(lastLine != 0 && newEvents.length > 0) {
|
||||||
|
_.each(newEvents, function(msg) {
|
||||||
|
var match = msg.match(/([^ ]+) vs\. ([^ ]+) (\d)-(\d)/);
|
||||||
|
if(match) {
|
||||||
|
if(match[3] > match[4]) {
|
||||||
|
dbot.say(this.config.streamServer, this.config.streamChannel, match[1] + ' beat ' + match[2] + ' at tetris ('+match[3] + '-'+match[4]+')');
|
||||||
|
} else {
|
||||||
|
dbot.say(this.config.streamServer, this.config.streamChannel, match[2] + ' beat ' + match[1] + ' at tetris ('+match[3] + '-'+match[4]+')');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.bind(this));
|
||||||
|
}
|
||||||
|
}.bind(this));
|
||||||
|
}.bind(this);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.fetch = function(dbot) {
|
||||||
|
return new vitetris(dbot);
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user