import { BaseCommand } from '@adonisjs/core/ace' import { CommandOptions } from '@adonisjs/core/types/ace' import db from '@adonisjs/lucid/services/db' import SpotService from '#services/SpotService' /** Passwords from the titles and descriptions of spots read so far, onto their releases. */ export default class SpotPasswords extends BaseCommand { public static commandName = 'spot:passwords' public static description = "Takes archive passwords from spots' titles and descriptions onto their releases." public static options: CommandOptions = { startApp: true, } public async run() { const spots = await db .from('spots') .whereNotNull('release_id') .where((q) => q.whereNotNull('description').orWhere('title', 'like', '%{{%}}%')) .select('message_id') let found = 0 for (const spot of spots) if (await SpotService.applyPassword(spot.message_id)) found++ this.logger.info(`${found} of ${spots.length} spots name a password in their title or description.`) } }