file description module import type { EmbedOptions , Emoji , Member , Message } from "eris" ; import type { HibikiClient } from "../classes/Client" ; import { TextChannel } from "eris" ; import { convertHex } from "./embed" ; import { waitFor } from "./waitFor" ; const backEmoji = "⬅️" ; const forwardEmoji = "➡️" ; const exitEmoji = "❌" ; export async function pagify ( pages , msg , bot , user , exitEmbed = { title : "❌ Exited" , color : convertHex ( "error" ) } , edit = true , footerText = "%c/%a" , footerIcon ? , initialPage = 0 ) { let page = initialPage ; const pagifyEmbed = { embed : footerText ? { ... pages [ page ] , ... { footer : { text : footerText . replace ( /%c/ , ( page + 1 ) . toString ( ) ) . replace ( /%a/ , pages . length . toString ( ) ) , icon_url : footerIcon } , } , } : pages [ page ] , } ; if ( msg instanceof TextChannel ) msg = await msg . createMessage ( pagifyEmbed ) ; if ( edit ) msg . edit ( pagifyEmbed ) ; await msg . addReaction ( backEmoji ) ; await msg . addReaction ( forwardEmoji ) ; await msg . addReaction ( exitEmoji ) ; await waitFor ( "messageReactionAdd" , 600000 , async ( _msg , emoji , reactor ) => { if ( user !== null && reactor . id !== user ) return ; if ( emoji . name === backEmoji ) { ( msg as Message < TextChannel > ) . removeReaction ( backEmoji , reactor . id ) ; if ( page === 0 ) return ; page -- ; const p = pages [ page ] ; if ( footerText ) p . footer = { text : footerText . replace ( /%c/ , ( page + 1 ) . toString ( ) ) . replace ( /%a/ , pages . length . toString ( ) ) , icon_url : footerIcon } ; msg . edit ( { embed : p } ) ; } else if ( emoji . name === forwardEmoji ) { ( msg as Message < TextChannel > ) . removeReaction ( forwardEmoji , reactor . id ) ; if ( page >= pages . length - 1 ) return ; page ++ ; const p = pages [ page ] ; if ( footerText ) { p . footer = { text : footerText . replace ( /%c/ , ( page + 1 ) . toString ( ) ) . replace ( /%a/ , pages . length . toString ( ) ) , icon_url : footerIcon } ; } msg . edit ( { embed : p } ) ; } else if ( emoji . name === exitEmoji ) { msg . edit ( { embed : exitEmbed } ) ; return true ; } } , bot ) . catch ( ( err ) => { if ( err === "timeout" ) { ( msg as Message < TextChannel > ) . removeReaction ( backEmoji ) ; ( msg as Message < TextChannel > ) . removeReaction ( forwardEmoji ) ; } } ) ; }