import { BaseCommand, args, flags } from '@adonisjs/core/ace' import type { CommandOptions } from '@adonisjs/core/types/ace' import User from '#models/user' /** Suspends a user (Newznab error 101, the catalog 403), e.g. for a shared key; --undo lifts it. */ export default class AccessSuspend extends BaseCommand { static commandName = 'access:suspend' static description = 'Suspends a user (or lifts it with --undo)' static options: CommandOptions = { startApp: true } @args.string({ description: 'The user’s email' }) declare email: string @flags.boolean({ description: 'Lift the suspension' }) declare undo: boolean async run() { const user = await User.findBy('email', this.email) if (!user) { this.logger.error(`No user ${this.email}`) this.exitCode = 1 return } user.suspended = !this.undo await user.save() this.logger.info(`${user.email}: ${user.suspended ? 'suspended' : 'active'}`) } }