2022-12-16 13:48:39 +01:00
import { DiscordModule } from '@discord-nestjs/core' ;
2023-02-19 12:19:35 +01:00
2023-05-16 08:34:16 +02:00
import { Logger , Module , OnModuleInit } from '@nestjs/common' ;
import { ConfigModule , ConfigService } from '@nestjs/config' ;
2022-12-16 13:48:39 +01:00
import { EventEmitterModule } from '@nestjs/event-emitter' ;
2022-12-19 11:57:04 +01:00
import { ScheduleModule } from '@nestjs/schedule' ;
2022-12-15 23:57:55 +01:00
2023-03-08 09:41:55 +01:00
import { ServeStaticModule } from '@nestjs/serve-static' ;
import { join } from 'path' ;
import { DiscordConfigService } from './clients/discord/discord.config.service' ;
import { DiscordClientModule } from './clients/discord/discord.module' ;
import { JellyfinClientModule } from './clients/jellyfin/jellyfin.module' ;
2022-12-16 13:48:39 +01:00
import { CommandModule } from './commands/command.module' ;
2023-01-09 22:12:08 +01:00
import { HealthModule } from './health/health.module' ;
2022-12-16 23:17:26 +01:00
import { PlaybackModule } from './playback/playback.module' ;
2022-12-19 11:57:04 +01:00
import { UpdatesModule } from './updates/updates.module' ;
2023-05-16 08:34:16 +02:00
import {
environmentVariablesSchema ,
getEnvironmentVariables ,
} from './utils/environment' ;
import { fromZodError } from 'zod-validation-error' ;
2022-12-15 23:57:55 +01:00
@Module ( {
imports : [
ConfigModule . forRoot ( {
2023-05-16 08:34:16 +02:00
validate ( config ) {
try {
const parsed = environmentVariablesSchema . parse ( config ) ;
return parsed ;
} catch ( err ) {
throw fromZodError ( err ) ;
}
} ,
2022-12-15 23:57:55 +01:00
} ) ,
2023-03-08 09:41:55 +01:00
ServeStaticModule . forRoot ( {
rootPath : join ( __dirname , '..' , 'client' ) ,
} ) ,
2022-12-19 11:57:04 +01:00
ScheduleModule . forRoot ( ) ,
2022-12-16 13:48:39 +01:00
DiscordModule . forRootAsync ( {
useClass : DiscordConfigService ,
} ) ,
DiscordModule ,
2022-12-15 23:57:55 +01:00
EventEmitterModule . forRoot ( ) ,
2022-12-16 13:48:39 +01:00
CommandModule ,
2022-12-15 23:57:55 +01:00
DiscordClientModule ,
JellyfinClientModule ,
2022-12-16 23:17:26 +01:00
PlaybackModule ,
2022-12-19 11:57:04 +01:00
UpdatesModule ,
2022-12-27 16:48:16 +01:00
HealthModule ,
2022-12-15 23:57:55 +01:00
] ,
2022-12-18 19:21:33 +01:00
controllers : [ ] ,
providers : [ ] ,
2022-12-15 23:57:55 +01:00
} )
2023-05-16 08:34:16 +02:00
export class AppModule implements OnModuleInit {
private readonly logger = new Logger ( AppModule . name ) ;
onModuleInit() {
const variables = getEnvironmentVariables ( ) ;
if ( ! variables . ALLOW_EVERYONE_FOR_DEFAULT_PERMS ) {
return ;
}
this . logger . warn (
'WARNING: You are using a potentially dangerous configuration: Everyone on your server has access to your bot. Ensure, that your bot is properly secured. Disable this by setting the environment variable ALLOW_EVERYONE to false' ,
) ;
this . logger . warn (
'WARNING: You are using a feature, that will only work for new server invitations. The permissions on existing servers will not be changed' ,
) ;
}
}