Skip to content

Commit

Permalink
feat: add option to disable bot auto-start
Browse files Browse the repository at this point in the history
  • Loading branch information
beeman committed Feb 20, 2024
1 parent 5949645 commit cd72751
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ AUTH_SOLANA_ADMIN_IDS=
AUTH_SOLANA_ENABLED=true
# Enable Bull UI
BULL_ADMIN=admin:6c9107073a49d1e6129bfba07d494050c182d7630d3c86aca94ffa43cf1533f2
# Enable Bot auto-start
#BOT_AUTO_START=true
# Set Cloak keychain and master key (generate with `yarn cloak generate`)
CLOAK_MASTER_KEY=
CLOAK_KEYCHAIN=
Expand Down
4 changes: 4 additions & 0 deletions libs/api/bot/data-access/src/lib/api-bot-manager.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export class ApiBotManagerService implements OnModuleInit {
constructor(private readonly core: ApiCoreService, private readonly botMember: ApiBotMemberService) {}

async onModuleInit() {
if (!this.core.config.botAutoStart) {
this.logger.verbose(`Bot auto start is disabled`)
return
}
const bots = await this.core.data.bot.findMany({ where: { status: BotStatus.Active } })
for (const bot of bots) {
this.logger.verbose(`Starting bot ${bot.name}`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ export class ApiCoreConfigService {
return this.service.get<string>('apiUrl') as string
}

get botAutoStart(): boolean {
return this.service.get<boolean>('botAutoStart') ?? false
}

get cookieDomains(): string[] {
return this.service.get<string[]>('cookieDomains') ?? []
}
Expand Down
3 changes: 3 additions & 0 deletions libs/api/core/data-access/src/lib/config/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export interface ApiCoreConfig {
authSolanaAdminIds: string[]
authSolanaLinkEnabled: boolean
authSolanaLoginEnabled: boolean
// Bot
botAutoStart: boolean
// Cookies
cookieDomains: string[]
cookieName: string
Expand Down Expand Up @@ -69,6 +71,7 @@ export function configuration(): ApiCoreConfig {
authSolanaAdminIds: getFromEnvironment('AUTH_SOLANA_ADMIN_IDS'),
authSolanaLinkEnabled: process.env['AUTH_SOLANA_LINK_ENABLED'] === 'true',
authSolanaLoginEnabled: process.env['AUTH_SOLANA_LOGIN_ENABLED'] === 'true',
botAutoStart: process.env['BOT_AUTO_START'] === 'true',
cookieDomains,
cookieName: '__session',
cookieSecure: process.env['COOKIE_SECURE'] === 'true',
Expand Down
2 changes: 2 additions & 0 deletions libs/api/core/data-access/src/lib/config/validation-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export const validationSchema = Joi.object({
AUTH_SOLANA_ADMIN_IDS: Joi.string(),
AUTH_SOLANA_LINK_ENABLED: Joi.boolean().default(true),
AUTH_SOLANA_LOGIN_ENABLED: Joi.boolean().default(false),
// Bot
BOT_AUTO_START: Joi.boolean().default(true),
CLOAK_MASTER_KEY: Joi.string().required().error(new Error(`CLOAK_MASTER_KEY is required.`)),
CLOAK_KEYCHAIN: Joi.string().required().error(new Error(`CLOAK_KEYCHAIN is required.`)),
COOKIE_NAME: Joi.string().default('__session'),
Expand Down

0 comments on commit cd72751

Please sign in to comment.