import { Response } from 'polka' ; import { PREFIX_FAIL } from './constants' ; export function prepareHeader ( response ) { response . setHeader ( 'Content-Type' , 'application/json' ) ; } export function prepareSelectMenu ( response , content , options , type , customId , ephemeral = false ) { prepareHeader ( response ) ; response . write ( JSON . stringify ( { data : { content , components : [ { type : 1 , components : [ { type : 3 , custom_id : customId , options , } , ] , } , ] , flags : ephemeral ? 64 : 0 , } , type , } ) ) ; } export function prepareResponse ( response , content , ephemeral = false , users = [ ] , parse = [ ] , type = 4 ) { prepareHeader ( response ) ; response . write ( JSON . stringify ( { data : { content , flags : ephemeral ? 64 : 0 , allowed_mentions : { parse , users } , components : [ ] , } , type , } ) ) ; } export function prepareErrorResponse ( response , content ) { prepareResponse ( response , `${ PREFIX_FAIL } ${ content }` , true ) ; } export function prepareAck ( response ) { prepareHeader ( response ) ; response . statusCode = 200 ; response . write ( JSON . stringify ( { type : 1 , } ) ) ; }