Mention probation: don't use time but number of messages in chan since previous mention;
This commit is contained in:
parent
cb720eafb8
commit
dec545136b
@ -11,9 +11,9 @@ module.exports = {
|
|||||||
// Project URL used for mentions of MR (e.g. !123) or issues (#122).
|
// Project URL used for mentions of MR (e.g. !123) or issues (#122).
|
||||||
projectUrl: "https://framagit.org/bnjbvr/kresus/",
|
projectUrl: "https://framagit.org/bnjbvr/kresus/",
|
||||||
|
|
||||||
// Amout of time (in ms) during which no other mentions to a same MR/issue
|
// Amout of messages between which no other mentions to a same MR/issue
|
||||||
// will be done.
|
// will be done.
|
||||||
cacheDuration: 10000,
|
cacheDuration: 15,
|
||||||
|
|
||||||
branches: ['master'],
|
branches: ['master'],
|
||||||
|
|
||||||
|
21
index.js
21
index.js
@ -218,7 +218,10 @@ app.post('/', function(req, res) {
|
|||||||
res.sendStatus(200);
|
res.sendStatus(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
var cache = {};
|
var chanMessageCounters = {};
|
||||||
|
|
||||||
|
var mentionCache = {};
|
||||||
|
|
||||||
function makeCacheKey(isIssue, id, chan) {
|
function makeCacheKey(isIssue, id, chan) {
|
||||||
return chan + '-' + (isIssue ? 'issue' : 'mr') + id;
|
return chan + '-' + (isIssue ? 'issue' : 'mr') + id;
|
||||||
}
|
}
|
||||||
@ -227,9 +230,13 @@ function fetch_and_say(isIssue, id, from, chan) {
|
|||||||
var cacheKey = makeCacheKey(isIssue, id, chan);
|
var cacheKey = makeCacheKey(isIssue, id, chan);
|
||||||
|
|
||||||
// Don't mention if it's been already mentioned in the last
|
// Don't mention if it's been already mentioned in the last
|
||||||
// config.cacheDuration ms.
|
// config.cacheDuration messages.
|
||||||
if (typeof cache[cacheKey] !== 'undefined')
|
var mentionCounter = mentionCache[cacheKey];
|
||||||
return;
|
if (typeof mentionCounter !== 'undefined') {
|
||||||
|
if (chanMessageCounters[chan] - mentionCounter <= config.cacheDuration) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var path, text_prefix;
|
var path, text_prefix;
|
||||||
if (isIssue) {
|
if (isIssue) {
|
||||||
@ -252,9 +259,7 @@ function fetch_and_say(isIssue, id, from, chan) {
|
|||||||
} else {
|
} else {
|
||||||
client.say(to, text_prefix + id + ": " + url);
|
client.say(to, text_prefix + id + ": " + url);
|
||||||
}
|
}
|
||||||
cache[cacheKey] = setTimeout(function() {
|
mentionCache[cacheKey] = chanMessageCounters[chan];
|
||||||
delete cache[cacheKey];
|
|
||||||
}, config.cacheDuration);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -294,6 +299,8 @@ app.listen(config.port, config.hostname, function() {
|
|||||||
console.log('gitlab-to-irc running.');
|
console.log('gitlab-to-irc running.');
|
||||||
|
|
||||||
client.on('message', function(from, chan, message) {
|
client.on('message', function(from, chan, message) {
|
||||||
|
chanMessageCounters[chan] = (chanMessageCounters[chan] || 0) + 1;
|
||||||
|
|
||||||
var matches = null;
|
var matches = null;
|
||||||
while ((matches = issueRegexp.exec(message)) !== null) {
|
while ((matches = issueRegexp.exec(message)) !== null) {
|
||||||
var issueId = matches[1];
|
var issueId = matches[1];
|
||||||
|
Loading…
Reference in New Issue
Block a user