import { Interaction } from 'detritus-client' ; import { MessageFlags } from 'detritus-client/lib/constants' ; import { Formatter , findImageUrlInMessage } from '../../../../utils' ; import { BaseContextMenuMessageCommand , ContextMenuMessageArgs } from '../../basecommand' ; export interface QRScanCommandArgs extends ContextMenuMessageArgs { url ? : string | null ; } export const COMMAND_NAME = 'QR Scan' ; export default class QRScanCommand extends BaseContextMenuMessageCommand { name = COMMAND_NAME ; onBeforeRun ( context , args ) { args . url = findImageUrlInMessage ( args . message ) ; return ! ! args . url ; } onCancelRun ( context , args ) { return context . editOrRespond ( { content : 'Message must have some sort of image to scan!' , flags : MessageFlags . EPHEMERAL , } ) ; } async run ( context , args ) { return Formatter . Commands . ToolsQrScan . createMessage ( context , { isEphemeral : true , url : args . url || '' , } ) ; } }