diff --git a/src/routes/voteOnSponsorTime.ts b/src/routes/voteOnSponsorTime.ts index 582be78..fc0940d 100644 --- a/src/routes/voteOnSponsorTime.ts +++ b/src/routes/voteOnSponsorTime.ts @@ -9,11 +9,13 @@ import { getFormattedTime } from "../utils/getFormattedTime"; import { getIP } from "../utils/getIP"; import { getHashCache } from "../utils/getHashCache"; import { config } from "../config"; -import { UserID } from "../types/user.model"; +import { HashedUserID, UserID } from "../types/user.model"; import { Category, CategoryActionType, HashedIP, IPAddress, SegmentUUID, Service, VideoID, VideoIDHash, Visibility, VideoDuration } from "../types/segments.model"; import { getCategoryActionType } from "../utils/categoryInfo"; import { QueryCacher } from "../utils/queryCacher"; import axios from "axios"; +import redis from "../utils/redis"; +import { tempVIPKey } from "../utils/redisKeys"; const voteTypes = { normal: 0, @@ -37,6 +39,7 @@ interface VoteData { UUID: string; nonAnonUserID: string; voteTypeEnum: number; + isTempVIP: boolean; isVIP: boolean; isOwnSubmission: boolean; row: { @@ -57,6 +60,13 @@ function getYouTubeVideoInfo(videoID: VideoID, ignoreCache = false): Promise => { + const apiVideoInfo = await getYouTubeVideoInfo(videoID); + const channelID = apiVideoInfo?.data?.authorId; + const { err, reply } = await redis.getAsync(tempVIPKey(nonAnonUserID)); + return err ? false : (reply == channelID); +}; + const videoDurationChanged = (segmentDuration: number, APIDuration: number) => (APIDuration > 0 && Math.abs(segmentDuration - APIDuration) > 2); async function checkVideoDurationChange(UUID: SegmentUUID) { @@ -105,7 +115,7 @@ async function sendWebhooks(voteData: VoteData) { // Send custom webhooks dispatchEvent(isUpvote ? "vote.up" : "vote.down", { "user": { - "status": getVoteAuthorRaw(userSubmissionCountRow.submissionCount, voteData.isVIP, voteData.isOwnSubmission), + "status": getVoteAuthorRaw(userSubmissionCountRow.submissionCount, voteData.isTempVIP, voteData.isVIP, voteData.isOwnSubmission), }, "video": { "id": submissionInfoRow.videoID, @@ -153,7 +163,7 @@ async function sendWebhooks(voteData: VoteData) { "author": { "name": voteData.finalResponse?.webhookMessage ?? voteData.finalResponse?.finalMessage ?? - getVoteAuthor(userSubmissionCountRow.submissionCount, voteData.isVIP, voteData.isOwnSubmission), + getVoteAuthor(userSubmissionCountRow.submissionCount, voteData.isTempVIP, voteData.isVIP, voteData.isOwnSubmission), }, "thumbnail": { "url": getMaxResThumbnail(data) || "", @@ -311,7 +321,9 @@ export async function voteOnSponsorTime(req: Request, res: Response): Promise + `segments.v3.${service}.videoID.${videoID}`; -export function skipSegmentGroupsKey(videoID: VideoID, service: Service): string { - return `segments.groups.v2.${service}.videoID.${videoID}`; -} +export const skipSegmentGroupsKey = (videoID: VideoID, service: Service): string => + `segments.groups.v2.${service}.videoID.${videoID}`; export function skipSegmentsHashKey(hashedVideoIDPrefix: VideoIDHash, service: Service): string { hashedVideoIDPrefix = hashedVideoIDPrefix.substring(0, 4) as VideoIDHash; @@ -18,9 +16,8 @@ export function skipSegmentsHashKey(hashedVideoIDPrefix: VideoIDHash, service: S return `segments.v3.${service}.${hashedVideoIDPrefix}`; } -export function reputationKey(userID: UserID): string { - return `reputation.user.${userID}`; -} +export const reputationKey = (userID: UserID): string => + `reputation.user.${userID}`; export function ratingHashKey(hashPrefix: VideoIDHash, service: Service): string { hashPrefix = hashPrefix.substring(0, 4) as VideoIDHash; @@ -33,4 +30,7 @@ export function shaHashKey(singleIter: HashedValue): string { if (singleIter.length !== 64) Logger.warn(`Redis sha.hash key is not length 64! ${singleIter}`); return `sha.hash.${singleIter}`; -} \ No newline at end of file +} + +export const tempVIPKey = (userID: UserID): string => + `vip.temp.${userID}`; \ No newline at end of file diff --git a/src/utils/webhookUtils.ts b/src/utils/webhookUtils.ts index c352bf9..67e2817 100644 --- a/src/utils/webhookUtils.ts +++ b/src/utils/webhookUtils.ts @@ -2,9 +2,11 @@ import { config } from "../config"; import { Logger } from "../utils/logger"; import axios from "axios"; -function getVoteAuthorRaw(submissionCount: number, isVIP: boolean, isOwnSubmission: boolean): string { +function getVoteAuthorRaw(submissionCount: number, isTempVIP: boolean, isVIP: boolean, isOwnSubmission: boolean): string { if (isOwnSubmission) { return "self"; + } else if (isTempVIP) { + return "temp vip"; } else if (isVIP) { return "vip"; } else if (submissionCount === 0) { @@ -14,11 +16,13 @@ function getVoteAuthorRaw(submissionCount: number, isVIP: boolean, isOwnSubmissi } } -function getVoteAuthor(submissionCount: number, isVIP: boolean, isOwnSubmission: boolean): string { +function getVoteAuthor(submissionCount: number, isTempVIP: boolean, isVIP: boolean, isOwnSubmission: boolean): string { if (submissionCount === 0) { return "Report by New User"; } else if (isOwnSubmission) { return "Report by Submitter"; + } else if (isTempVIP) { + return "Report by Temp VIP"; } else if (isVIP) { return "Report by VIP User"; }