Add a probation period for mentions;

This commit is contained in:
Benjamin Bouvier 2017-09-20 21:58:55 +02:00
parent 98d28f8154
commit cb720eafb8
2 changed files with 20 additions and 0 deletions

View File

@ -8,8 +8,13 @@ module.exports = {
'somebody': ['push', 'merge_request', 'issue', 'build']
},
// Project URL used for mentions of MR (e.g. !123) or issues (#122).
projectUrl: "https://framagit.org/bnjbvr/kresus/",
// Amout of time (in ms) during which no other mentions to a same MR/issue
// will be done.
cacheDuration: 10000,
branches: ['master'],
// IRC nick/names for the bot

View File

@ -218,7 +218,19 @@ app.post('/', function(req, res) {
res.sendStatus(200);
});
var cache = {};
function makeCacheKey(isIssue, id, chan) {
return chan + '-' + (isIssue ? 'issue' : 'mr') + id;
}
function fetch_and_say(isIssue, id, from, chan) {
var cacheKey = makeCacheKey(isIssue, id, chan);
// Don't mention if it's been already mentioned in the last
// config.cacheDuration ms.
if (typeof cache[cacheKey] !== 'undefined')
return;
var path, text_prefix;
if (isIssue) {
path = 'issues/';
@ -240,6 +252,9 @@ function fetch_and_say(isIssue, id, from, chan) {
} else {
client.say(to, text_prefix + id + ": " + url);
}
cache[cacheKey] = setTimeout(function() {
delete cache[cacheKey];
}, config.cacheDuration);
}
});
}