3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 12:25:02 +00:00

feat: add DEFAULT_ALLOWED_SERVERS .env value

This commit is contained in:
Dragory 2022-08-06 22:12:40 +03:00
parent f7fede47bd
commit 4a5e8ded75
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
4 changed files with 20 additions and 1 deletions

View file

@ -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) {