Add a probation period for mentions;
This commit is contained in:
parent
98d28f8154
commit
cb720eafb8
@ -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
|
||||
|
15
index.js
15
index.js
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user