Merge pull request #4 from anodium/fix-quote

Find all PR matches and deduplicate
This commit is contained in:
Christopher J. Gilbert 2017-03-26 17:43:36 -04:00 committed by GitHub
commit 62221cc686

View File

@ -2,23 +2,36 @@ var request = require('request');
var app = require('../app.js'); var app = require('../app.js');
var logger = require('../logging.js'); var logger = require('../logging.js');
var regex = /[^\<]\#\d+[^\>]/; var regex = /[^\<\\]\#(\d+)/ig;
exports.trigger = function(message) { exports.trigger = function(message) {
return regex.test(message.content); return new RegExp(regex).test(message.content);
} }
exports.execute = function(message) { exports.execute = function(message) {
let match = regex.exec(message.content); let matcher = new RegExp(regex);
if (match) { let match = matcher.exec(message.content);
let url = `https://github.com/citra-emu/citra/pull/${match[0].trim().substring(1)}` 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]}`;
logger.info(url); logger.info(url);
request(url, function (error, response, body) { request(url, function (error, response, body) {
if (!error && response.statusCode == 200) { if (!error && response.statusCode == 200) {
message.channel.sendMessage(`Github Pull Request: ${url}`); message.channel.sendMessage(`Github Pull Request: ${url}`);
} else { } else {
// Github PR does not exist. logger.info(`PR #{issue} does not exist.`)
} }
}); });
match = matcher.exec(message.content);
} }
} }