Add config for discord integration (#3081) Bruception

This commit is contained in:
Bruce Berrios 2022-06-07 17:41:37 -04:00 committed by GitHub
parent 26d359a168
commit 1260f13293
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 1 deletions

View file

@ -2,7 +2,11 @@ import joi from "joi";
import { authenticateRequest } from "../../middlewares/auth";
import { Router } from "express";
import * as UserController from "../controllers/user";
import { asyncHandler, validateRequest } from "../../middlewares/api-utils";
import {
asyncHandler,
validateRequest,
validateConfiguration,
} from "../../middlewares/api-utils";
import * as RateLimit from "../../middlewares/rate-limit";
import apeRateLimit from "../../middlewares/ape-rate-limit";
import { isUsernameValid } from "../../utils/validation";
@ -268,9 +272,17 @@ router.patch(
asyncHandler(UserController.editCustomTheme)
);
const requireDiscordIntegrationEnabled = validateConfiguration({
criteria: (configuration) => {
return configuration.discordIntegration.enabled;
},
invalidMessage: "Discord integration is not available at this time",
});
router.post(
"/discord/link",
RateLimit.userDiscordLink,
requireDiscordIntegrationEnabled,
authenticateRequest(),
validateRequest({
body: {

View file

@ -39,6 +39,9 @@ export const BASE_CONFIGURATION: MonkeyTypes.Configuration = {
dailyLeaderboardCacheSize: 1,
topResultsToAnnounce: 1, // This should never be 0. Setting to zero will announce all results.
},
discordIntegration: {
enabled: false,
},
};
export const CONFIGURATION_FORM_SCHEMA = {
@ -49,6 +52,16 @@ export const CONFIGURATION_FORM_SCHEMA = {
type: "boolean",
label: "In Maintenance",
},
discordIntegration: {
type: "object",
label: "Discord Integration",
fields: {
enabled: {
type: "boolean",
label: "Enabled",
},
},
},
results: {
type: "object",
label: "Results",

View file

@ -44,6 +44,9 @@ declare namespace MonkeyTypes {
dailyLeaderboardCacheSize: number;
topResultsToAnnounce: number;
};
discordIntegration: {
enabled: boolean;
};
}
interface DecodedToken {