1 |
|
/** |
2 |
|
* This file is part of SudoBot. |
3 |
|
* |
4 |
|
* Copyright (C) 2021-2022 OSN Inc. |
5 |
|
* |
6 |
|
* SudoBot is free software; you can redistribute it and/or modify it |
7 |
|
* under the terms of the GNU Affero General Public License as published by |
8 |
|
* the Free Software Foundation, either version 3 of the License, or |
9 |
|
* (at your option) any later version. |
10 |
|
* |
11 |
|
* SudoBot is distributed in the hope that it will be useful, but |
12 |
|
* WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
* GNU Affero General Public License for more details. |
15 |
|
* |
16 |
|
* You should have received a copy of the GNU Affero General Public License |
17 |
|
* along with SudoBot. If not, see <https://www.gnu.org/licenses/>. |
18 |
|
*/ |
19 |
|
|
20 |
import { dot, object } from "dot-object"; |
import { dot, object } from "dot-object"; |
21 |
import { body } from "express-validator"; |
import { body } from "express-validator"; |
|
import { z as zod } from "zod"; |
|
22 |
import KeyValuePair from "../../types/KeyValuePair"; |
import KeyValuePair from "../../types/KeyValuePair"; |
23 |
import Controller from "../Controller"; |
import Controller from "../Controller"; |
24 |
import RequireAuth from "../middleware/RequireAuth"; |
import RequireAuth from "../middleware/RequireAuth"; |
40 |
} |
} |
41 |
|
|
42 |
private zodSchema(id: string) { |
private zodSchema(id: string) { |
|
const snowflake = zod.string().regex(/\d+/, { message: "The given value is not a Snowflake" }); |
|
43 |
const config = this.client.config.props[id]; |
const config = this.client.config.props[id]; |
44 |
|
return this.client.config.schema(config); |
|
const schema = zod.object({ |
|
|
"prefix": zod.string().optional(), |
|
|
"debug": zod.boolean().optional(), |
|
|
"mute_role": snowflake.optional(), |
|
|
"gen_role": snowflake.optional(), |
|
|
"logging_channel": snowflake.optional(), |
|
|
"logging_channel_join_leave": snowflake.optional(), |
|
|
"mod_role": snowflake.optional(), |
|
|
"announcement_channel": snowflake.optional(), |
|
|
"admin": snowflake.optional(), |
|
|
"lockall": zod.array(zod.string()).optional(), |
|
|
"warn_notallowed": zod.boolean().optional(), |
|
|
"role_commands": zod.record( |
|
|
snowflake, |
|
|
zod.array(zod.string().min(1)) |
|
|
).optional().default({}), |
|
|
"autoclear": zod.object({ |
|
|
"enabled": zod.boolean().optional(), |
|
|
"channels": zod.array(snowflake).optional().default(config.autoclear.channels) |
|
|
}).optional(), |
|
|
"verification": zod.object({ |
|
|
"enabled": zod.boolean().optional(), |
|
|
"role": snowflake.optional() |
|
|
}).optional(), |
|
|
"welcomer": zod.object({ |
|
|
"enabled": zod.boolean().optional(), |
|
|
"channel": snowflake.optional(), |
|
|
"message": zod.string().min(1).or(zod.null()).optional(), |
|
|
"randomize": zod.boolean().optional() |
|
|
}).optional(), |
|
|
"cooldown": zod.object({ |
|
|
"enabled": zod.boolean().optional(), |
|
|
"global": zod.any().optional(), |
|
|
"cmds": zod.object({}).optional() |
|
|
}).optional(), |
|
|
"starboard": zod.object({ |
|
|
"enabled": zod.boolean().optional(), |
|
|
"reactions": zod.number().int().optional(), |
|
|
"channel": snowflake.optional() |
|
|
}).optional(), |
|
|
"autorole": zod.object({ |
|
|
"enabled": zod.boolean().optional(), |
|
|
"roles": zod.array(snowflake).optional().default(config.autorole.roles) |
|
|
}).optional(), |
|
|
"spam_filter": zod.object({ |
|
|
"enabled": zod.boolean().optional(), |
|
|
"limit": zod.number().int().optional(), |
|
|
"time": zod.number().optional(), |
|
|
"diff": zod.number().optional(), |
|
|
"exclude": zod.array(snowflake).optional().default(config.spam_filter.exclude), |
|
|
"samelimit": zod.number().int().optional(), |
|
|
"unmute_in": zod.number().optional() |
|
|
}).optional(), |
|
|
"raid": zod.object({ |
|
|
"enabled": zod.boolean().optional(), |
|
|
"max_joins": zod.number().int().optional(), |
|
|
"time": zod.number().optional(), |
|
|
"channels": zod.array(snowflake).optional().default(config.raid.channels), |
|
|
"exclude": zod.boolean().optional() |
|
|
}).optional(), |
|
|
"global_commands": zod.array(zod.string()).optional().default(config.global_commands), |
|
|
"filters": zod.object({ |
|
|
"ignore_staff": zod.boolean().optional(), |
|
|
"chars_repeated": zod.number().int().optional(), |
|
|
"words_repeated": zod.number().int().optional(), |
|
|
"words": zod.array(zod.string()).optional().default(config.filters.words), |
|
|
"tokens": zod.array(zod.string()).optional().default(config.filters.tokens), |
|
|
"invite_message": zod.string().optional(), |
|
|
"words_excluded": zod.array(snowflake).optional().default(config.filters.words_excluded), |
|
|
"domain_excluded": zod.array(snowflake).optional().default(config.filters.domain_excluded), |
|
|
"invite_excluded": zod.array(snowflake).optional().default(config.filters.invite_excluded), |
|
|
"words_enabled": zod.boolean().optional(), |
|
|
"invite_enabled": zod.boolean().optional(), |
|
|
"domain_enabled": zod.boolean().optional(), |
|
|
"regex": zod.boolean().optional(), |
|
|
"file_mimes_excluded": zod.array(zod.string()).optional().default(config.filters.file_mimes_excluded), |
|
|
"file_types_excluded": zod.array(zod.string()).optional().default(config.filters.file_types_excluded), |
|
|
"domains": zod.array(zod.string()).optional().default(config.filters.domains), |
|
|
"regex_patterns": zod.array(zod.string()).optional().default(config.filters.regex_patterns), |
|
|
"rickrolls_enabled": zod.boolean().optional(), |
|
|
"pings": zod.number().int().optional() |
|
|
}).optional() |
|
|
}); |
|
|
|
|
|
return schema; |
|
45 |
} |
} |
46 |
|
|
47 |
public async index(request: Request) { |
public async index(request: Request) { |