Add canSubmitChapter and fix all userInfo functions running

This commit is contained in:
Ajay
2022-07-04 23:44:50 -04:00
parent 0f3df8db1b
commit f8c297ddfb
3 changed files with 17 additions and 10 deletions

View File

@@ -43,6 +43,7 @@ addDefaults(config, {
discordFailedReportChannelWebhookURL: null, discordFailedReportChannelWebhookURL: null,
discordReportChannelWebhookURL: null, discordReportChannelWebhookURL: null,
discordMaliciousReportWebhookURL: null, discordMaliciousReportWebhookURL: null,
minReputationToSubmitChapter: 0,
getTopUsersCacheTimeMinutes: 240, getTopUsersCacheTimeMinutes: 240,
globalSalt: null, globalSalt: null,
mode: "", mode: "",

View File

@@ -105,6 +105,10 @@ async function dbGetBanned(userID: HashedUserID): Promise<boolean> {
} }
} }
async function dbCanSubmitChapter(userID: HashedUserID): Promise<boolean> {
return (await isUserVIP(userID)) || (await getReputation(userID)) > config.minReputationToSubmitChapter;
}
type cases = Record<string, any> type cases = Record<string, any>
const executeIfFunction = (f: any) => const executeIfFunction = (f: any) =>
@@ -119,16 +123,17 @@ const functionSwitch = (cases: cases) => (defaultCase: string) => (key: string)
const dbGetValue = (userID: HashedUserID, property: string): Promise<string|SegmentUUID|number> => { const dbGetValue = (userID: HashedUserID, property: string): Promise<string|SegmentUUID|number> => {
return functionSwitch({ return functionSwitch({
userID, userID,
userName: dbGetUsername(userID), userName: () => dbGetUsername(userID),
ignoredSegmentCount: dbGetIgnoredSegmentCount(userID), ignoredSegmentCount: () => dbGetIgnoredSegmentCount(userID),
viewCount: dbGetViewsForUser(userID), viewCount: () => dbGetViewsForUser(userID),
ignoredViewCount: dbGetIgnoredViewsForUser(userID), ignoredViewCount: () => dbGetIgnoredViewsForUser(userID),
warnings: dbGetWarningsForUser(userID), warnings: () => dbGetWarningsForUser(userID),
warningReason: dbGetActiveWarningReasonForUser(userID), warningReason: () => dbGetActiveWarningReasonForUser(userID),
banned: dbGetBanned(userID), banned: () => dbGetBanned(userID),
reputation: getReputation(userID), reputation: () => getReputation(userID),
vip: isUserVIP(userID), vip: () => isUserVIP(userID),
lastSegmentID: dbGetLastSegmentForUser(userID), lastSegmentID: () => dbGetLastSegmentForUser(userID),
canSubmitChapter: () => dbCanSubmitChapter(userID)
})("")(property); })("")(property);
}; };

View File

@@ -27,6 +27,7 @@ export interface SBSConfig {
discordMaliciousReportWebhookURL?: string; discordMaliciousReportWebhookURL?: string;
neuralBlockURL?: string; neuralBlockURL?: string;
discordNeuralBlockRejectWebhookURL?: string; discordNeuralBlockRejectWebhookURL?: string;
minReputationToSubmitChapter: number;
userCounterURL?: string; userCounterURL?: string;
proxySubmission?: string; proxySubmission?: string;
behindProxy: string | boolean; behindProxy: string | boolean;