feat: add DEFAULT_ALLOWED_SERVERS .env value
This commit is contained in:
parent
f7fede47bd
commit
4a5e8ded75
4 changed files with 20 additions and 1 deletions
|
@ -12,6 +12,9 @@ API_URL=https://localhost:3300/api
|
|||
# Comma-separated list of user IDs who should have access to the bot's global commands
|
||||
STAFF=
|
||||
|
||||
# A comma-separated list of server IDs that should be allowed by default
|
||||
DEFAULT_ALLOWED_SERVERS=
|
||||
|
||||
# When using the Docker-based development environment, this is only used internally. The API will be available at localhost:DOCKER_DEV_WEB_PORT/api.
|
||||
API_PORT=3000
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import { BaseRepository } from "./BaseRepository";
|
|||
import { AllowedGuild } from "./entities/AllowedGuild";
|
||||
import moment from "moment-timezone";
|
||||
import { DBDateFormat } from "../utils";
|
||||
import { env } from "../env";
|
||||
|
||||
export class AllowedGuilds extends BaseRepository {
|
||||
private allowedGuilds: Repository<AllowedGuild>;
|
||||
|
|
|
@ -17,6 +17,8 @@ const envType = z.object({
|
|||
|
||||
STAFF: z.preprocess((v) => String(v).split(","), z.array(z.string())).optional(),
|
||||
|
||||
DEFAULT_ALLOWED_SERVERS: z.preprocess((v) => String(v).split(","), z.array(z.string())).optional(),
|
||||
|
||||
PHISHERMAN_API_KEY: z.string().optional(),
|
||||
|
||||
DOCKER_DEV_MYSQL_PASSWORD: z.string().optional(), // Included here for the DB_PASSWORD default in development
|
||||
|
|
|
@ -3,6 +3,8 @@ import * as t from "io-ts";
|
|||
import { BasePluginType, GlobalPluginData, typedGlobalEventListener } from "knub";
|
||||
import { AllowedGuilds } from "../../data/AllowedGuilds";
|
||||
import { zeppelinGlobalPlugin } from "../ZeppelinPluginBlueprint";
|
||||
import { env } from "../../env";
|
||||
import { Configs } from "../../data/Configs";
|
||||
|
||||
interface GuildAccessMonitorPluginType extends BasePluginType {
|
||||
config: {};
|
||||
|
@ -35,8 +37,19 @@ export const GuildAccessMonitorPlugin = zeppelinGlobalPlugin<GuildAccessMonitorP
|
|||
}),
|
||||
],
|
||||
|
||||
beforeLoad(pluginData) {
|
||||
async beforeLoad(pluginData) {
|
||||
pluginData.state.allowedGuilds = new AllowedGuilds();
|
||||
|
||||
const defaultAllowedServers = env.DEFAULT_ALLOWED_SERVERS || [];
|
||||
const configs = new Configs();
|
||||
for (const serverId of defaultAllowedServers) {
|
||||
if (! await pluginData.state.allowedGuilds.isAllowed(serverId)) {
|
||||
// tslint:disable-next-line:no-console
|
||||
console.log(`Adding allowed-by-default server ${serverId} to the allowed servers`);
|
||||
await pluginData.state.allowedGuilds.add(serverId);
|
||||
await configs.saveNewRevision(`guild-${serverId}`, "plugins: {}", 0);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
afterLoad(pluginData) {
|
||||
|
|
Loading…
Add table
Reference in a new issue