Move dispatchEvent to webhookUtils

This commit is contained in:
TAG-Epic
2020-08-24 09:06:47 +02:00
parent 16777c30ca
commit aca4318351
3 changed files with 27 additions and 27 deletions

View File

@@ -1,3 +1,7 @@
const config = require('../config.js');
const logger = require('../utils/logger.js');
const request = require('request');
function getVoteAuthorRaw(submissionCount, isVIP, isOwnSubmission) {
if (isOwnSubmission) {
return "self";
@@ -22,5 +26,24 @@ function getVoteAuthor(submissionCount, isVIP, isOwnSubmission) {
return "";
}
module.exports.getVoteAuthorRaw = getVoteAuthorRaw;
module.exports.getVoteAuthor = getVoteAuthor;
function dispatchEvent(scope, data) {
let webhooks = config.webhooks;
if (webhooks === undefined || webhooks.length === 0) return;
logger.debug("Dispatching webhooks");
webhooks.forEach(webhook => {
let webhookURL = webhook.url;
let authKey = webhook.key;
let scopes = webhook.scopes || [];
if (!scopes.includes(scope.toLowerCase())) return;
request.post(webhookURL, {json: data, headers: {
"Authorization": authKey,
"Event-Type": scope // Maybe change this in the future?
}});
});
}
module.exports = {
getVoteAuthorRaw,
getVoteAuthor,
dispatchEvent
}