Skip to content

Commit cd72751

Browse files
committed
feat: add option to disable bot auto-start
1 parent 5949645 commit cd72751

File tree

5 files changed

+15
-0
lines changed

5 files changed

+15
-0
lines changed

.env.example

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ AUTH_SOLANA_ADMIN_IDS=
1616
AUTH_SOLANA_ENABLED=true
1717
# Enable Bull UI
1818
BULL_ADMIN=admin:6c9107073a49d1e6129bfba07d494050c182d7630d3c86aca94ffa43cf1533f2
19+
# Enable Bot auto-start
20+
#BOT_AUTO_START=true
1921
# Set Cloak keychain and master key (generate with `yarn cloak generate`)
2022
CLOAK_MASTER_KEY=
2123
CLOAK_KEYCHAIN=

libs/api/bot/data-access/src/lib/api-bot-manager.service.ts

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export class ApiBotManagerService implements OnModuleInit {
2121
constructor(private readonly core: ApiCoreService, private readonly botMember: ApiBotMemberService) {}
2222

2323
async onModuleInit() {
24+
if (!this.core.config.botAutoStart) {
25+
this.logger.verbose(`Bot auto start is disabled`)
26+
return
27+
}
2428
const bots = await this.core.data.bot.findMany({ where: { status: BotStatus.Active } })
2529
for (const bot of bots) {
2630
this.logger.verbose(`Starting bot ${bot.name}`)

libs/api/core/data-access/src/lib/config/api-core-config.service.ts

+4
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ export class ApiCoreConfigService {
102102
return this.service.get<string>('apiUrl') as string
103103
}
104104

105+
get botAutoStart(): boolean {
106+
return this.service.get<boolean>('botAutoStart') ?? false
107+
}
108+
105109
get cookieDomains(): string[] {
106110
return this.service.get<string[]>('cookieDomains') ?? []
107111
}

libs/api/core/data-access/src/lib/config/configuration.ts

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export interface ApiCoreConfig {
3333
authSolanaAdminIds: string[]
3434
authSolanaLinkEnabled: boolean
3535
authSolanaLoginEnabled: boolean
36+
// Bot
37+
botAutoStart: boolean
3638
// Cookies
3739
cookieDomains: string[]
3840
cookieName: string
@@ -69,6 +71,7 @@ export function configuration(): ApiCoreConfig {
6971
authSolanaAdminIds: getFromEnvironment('AUTH_SOLANA_ADMIN_IDS'),
7072
authSolanaLinkEnabled: process.env['AUTH_SOLANA_LINK_ENABLED'] === 'true',
7173
authSolanaLoginEnabled: process.env['AUTH_SOLANA_LOGIN_ENABLED'] === 'true',
74+
botAutoStart: process.env['BOT_AUTO_START'] === 'true',
7275
cookieDomains,
7376
cookieName: '__session',
7477
cookieSecure: process.env['COOKIE_SECURE'] === 'true',

libs/api/core/data-access/src/lib/config/validation-schema.ts

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export const validationSchema = Joi.object({
1515
AUTH_SOLANA_ADMIN_IDS: Joi.string(),
1616
AUTH_SOLANA_LINK_ENABLED: Joi.boolean().default(true),
1717
AUTH_SOLANA_LOGIN_ENABLED: Joi.boolean().default(false),
18+
// Bot
19+
BOT_AUTO_START: Joi.boolean().default(true),
1820
CLOAK_MASTER_KEY: Joi.string().required().error(new Error(`CLOAK_MASTER_KEY is required.`)),
1921
CLOAK_KEYCHAIN: Joi.string().required().error(new Error(`CLOAK_KEYCHAIN is required.`)),
2022
COOKIE_NAME: Joi.string().default('__session'),

0 commit comments

Comments
 (0)