Command-fix/triggers/github.js

34 lines
852 B
JavaScript
Raw Normal View History

var request = require('request');
2016-12-31 05:49:12 +00:00
var app = require('../app.js');
var logger = require('../logging.js');
var regex = /[^\<\\]\#(\d+)/ig;
2016-12-31 05:49:12 +00:00
exports.trigger = function(message) {
return new RegExp(regex).test(message.content);
2016-12-31 05:49:12 +00:00
}
exports.execute = function(message) {
let matcher = new RegExp(regex);
let match = matcher.exec(message.content);
let matched = [];
while(match != null) {
if(matched.indexOf(match[1]) == -1) {
matched.push(match[1]);
} else {
match = matcher.exec(message.content);
continue;
}
let url = `https://github.com/citra-emu/citra/pull/${match[1]}`;
request(url, function (error, response, body) {
if (!error && response.statusCode == 200) {
message.channel.sendMessage(`Github Pull Request: ${url}`);
}
});
match = matcher.exec(message.content);
2016-12-31 05:49:12 +00:00
}
}