From 9eddc330c5984dbb5b1e8abff43f1f9c494ef0a3 Mon Sep 17 00:00:00 2001 From: TAG-Epic Date: Sun, 23 Aug 2020 22:30:35 +0200 Subject: [PATCH] Move getVoteAuthor to webhookUtils and move user status (api) to webhookUtils --- src/routes/voteOnSponsorTime.js | 24 ++---------------------- src/utils/webhookUtils.js | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 22 deletions(-) create mode 100644 src/utils/webhookUtils.js diff --git a/src/routes/voteOnSponsorTime.js b/src/routes/voteOnSponsorTime.js index 1cf75e5..7b891a8 100644 --- a/src/routes/voteOnSponsorTime.js +++ b/src/routes/voteOnSponsorTime.js @@ -6,6 +6,7 @@ var getIP = require('../utils/getIP.js'); var getFormattedTime = require('../utils/getFormattedTime.js'); var isUserTrustworthy = require('../utils/isUserTrustworthy.js'); const dispatchWebhooks = require('../utils/dispatchWebhooks.js'); +const {getVoteAuthor, getVoteAuthorRaw} = require('../utils/webhookUtils.js'); var databases = require('../databases/databases.js'); @@ -15,17 +16,6 @@ var YouTubeAPI = require('../utils/youtubeAPI.js'); var request = require('request'); const logger = require('../utils/logger.js'); -function getVoteAuthor(submissionCount, isVIP, isOwnSubmission) { - if (submissionCount === 0) { - return "Report by New User"; - } else if (isVIP) { - return "Report by VIP User"; - } else if (isOwnSubmission) { - return "Report by Submitter"; - } - - return ""; -} function categoryVote(UUID, userID, isVIP, category, hashedIP, res) { // Check if they've already made a vote @@ -224,19 +214,9 @@ async function voteOnSponsorTime(req, res) { } let isUpvote = incrementAmount > 0; // Send custom webhooks - let userStatus; - if (isOwnSubmission) { - userStatus = "self"; - } else if (isVIP) { - userStatus = "vip"; - } else if (userSubmissionCountRow.submissionCount === 0) { - userStatus = "new"; - } else { - userStatus = "other"; - } dispatchWebhooks(isUpvote ? "vote.up" : "vote.down", { "user": { - "status": userStatus + "status": getVoteAuthorRaw(userSubmissionCountRow.submissionCount, isVIP, isOwnSubmission) }, "video": { "id": submissionInfoRow.videoID, diff --git a/src/utils/webhookUtils.js b/src/utils/webhookUtils.js new file mode 100644 index 0000000..34f8651 --- /dev/null +++ b/src/utils/webhookUtils.js @@ -0,0 +1,26 @@ +function getVoteAuthorRaw(submissionCount, isVIP, isOwnSubmission) { + if (isOwnSubmission) { + return "self"; + } else if (isVIP) { + return "vip"; + } else if (submissionCount === 0) { + return "new"; + } else { + return "other"; + }; +}; + +function getVoteAuthor(submissionCount, isVIP, isOwnSubmission) { + if (submissionCount === 0) { + return "Report by New User"; + } else if (isVIP) { + return "Report by VIP User"; + } else if (isOwnSubmission) { + return "Report by Submitter"; + } + + return ""; +} + +module.exports.getVoteAuthorRaw = getVoteAuthorRaw; +module.exports.getVoteAuthor = getVoteAuthor; \ No newline at end of file