import type { Message , TextChannel } from "eris" ; import { Command } from "../../classes/Command" ; export class TopcookiesCommand extends Command { description = "Shows the 10 members with the most cookies." ; aliases = [ "cookieleaderboard" , "leaderboard" ] ; allowdms = true ; async run ( msg ) { const cookies = await this . bot . db . getAllCookies ( ) ; const leaderboardcookies = [ ] ; Object . values ( cookies ) . forEach ( ( cookie ) => { leaderboardcookies . push ( [ cookie . amount , cookie . id ] ) ; } ) ; leaderboardcookies . sort ( ( a , b ) => ( b [ 0 ] as number ) - ( a [ 0 ] as number ) ) ; let content = "" ; let place = 1 ; leaderboardcookies . forEach ( ( leaderboard ) => { if ( place > 10 ) return ; if ( leaderboard [ 0 ] === 0 ) return ; const user = this . bot . users . find ( ( u ) => u ?. id === leaderboard [ 1 ] ) ; if ( ! user ) return ; content = `${ content }\n**${ place }.** ${ user . username } **(${ Math . floor ( leaderboard [ 0 ] as number ) })**` ; place += 1 ; } ) ; if ( ! content ) return msg . createEmbed ( msg . string ( "global.ERROR" ) , msg . string ( "fun.COOKIE_LEADERBOARDNOMEMBERS" ) , "error" ) ; msg . createEmbed ( `🍪 ${ msg . string ( "fun.COOKIE_LEADERBOARD" ) }` , content , "general" ) ; } }