post links and details to bug numbers on irc, like firebot

This commit is contained in:
Tim Taubert 2016-06-03 19:05:58 +02:00
Родитель b6714fb050
Коммит 85b57f9d17
1 изменённых файлов: 31 добавлений и 0 удалений

Просмотреть файл

@ -3,13 +3,29 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import irc from "irc";
import request from "request-json";
const NICK = "nss-tc";
const CHANNEL = "#nss";
const SERVER = "irc.mozilla.org";
const BZ_HOST = "https://bugzilla.mozilla.org";
let client;
async function jsonRequest(url) {
let client = request.createClient(BZ_HOST);
return new Promise((resolve, reject) => {
client.get(url, (err, res, json) => {
if (err) {
reject(err);
} else {
resolve(json);
}
});
});
}
function say(msg) {
if (!client) {
connect();
@ -34,6 +50,21 @@ function connect() {
client.addListener("error", msg => {
console.log("irc error: ", msg);
});
// Listen for bug numbers.
client.addListener(`message${CHANNEL}`, async function (from, message) {
let match = /[Bb]ug (\d{5,})/.exec(message);
if (!match) {
return;
}
let id = match[1];
let client = request.createClient(BZ_HOST);
let {bugs: [bug]} = await jsonRequest(`/rest/bug/${id}`);
let status = bug.resolution || bug.status;
say(`https://bugzil.la/${id}${status}, ${bug.assigned_to}${bug.summary}`);
});
}
module.exports.say = say;