fileoverview description module import type { Message } from "eris" ; import type { HibikiClient } from "../classes/Client" ; import type { LocaleString } from "../typings/locales" ; import { convertHex } from "./embed" ; export function waitFor ( event , timeout , check , bot ) { let t ; if ( ! check || typeof check !== "function" ) check = ( ) => true ; return new Promise ( ( resolve , reject ) => { const listener = async ( ... args ) => { const finalCheck = await check ( ... args ) ; if ( check && typeof check === "function" && finalCheck ) { dispose ( ) ; resolve ( [ ... args ] ) ; } } ; const dispose = ( ) => { bot . removeListener ( event , listener ) ; if ( t ) clearTimeout ( t ) ; } ; if ( timeout ) { t = setTimeout ( ( ) => { dispose ( ) ; reject ( "timeout" ) ; } , timeout ) ; } bot . on ( event , listener ) ; } ) ; } export function timeoutHandler ( err , msg , string , removeReactions = true ) { if ( err === "timeout" ) { msg . edit ( { embed : { title : string ( "global.ERROR" ) , description : string ( "global.TIMEOUT_REACHED" ) , color : convertHex ( "error" ) , } , } ) . catch ( ( ) => { } ) ; if ( removeReactions ) msg . removeReactions ( ) . catch ( ( ) => { } ) ; } else throw err ; }