import type { Message , TextChannel } from "eris" ; import { Command } from "../../classes/Command" ; const emotes = [ "🍒" , "🍌" , "💎" ] ; const modifiers = [ 1 , 2 , 3 ] ; export class SlotsCommand extends Command { description = "Gambles cookies in the slot machine." ; args = "[amount:number]" ; aliases = [ "bet" , "gamble" , "slot" , "slotmachine" , "sm" ] ; cooldown = 3000 ; allowdms = true ; async run ( msg , _pargs , args ) { let profit = 0 ; let amount = parseInt ( args ?. [ 0 ] ) ; const slotEmojis = [ ] ; if ( ! amount || isNaN ( amount ) || amount <= 0 ) { return msg . createEmbed ( `🎰 ${ msg . string ( "fun.SLOTS" ) }` , msg . string ( "fun.SLOTS_PLAY" , { worth : emotes . map ( ( e ) => msg . string ( "fun.SLOTS_WORTH" , { emotes : e , modifier : modifiers [ emotes . indexOf ( e ) ] } ) ) . join ( "\n" ) , } ) ) ; } for ( let i = 0 ; i < 3 ; i ++ ) { slotEmojis . push ( emotes [ Math . floor ( Math . random ( ) * emotes . length ) ] ) ; } if ( amount > 100 ) amount = 100 ; if ( slotEmojis [ 0 ] === slotEmojis [ 1 ] && slotEmojis [ 1 ] === slotEmojis [ 2 ] ) { profit = Math . round ( amount * modifiers [ emotes . indexOf ( slotEmojis [ 0 ] ) ] ) ; } else if ( slotEmojis [ 0 ] === slotEmojis [ 1 ] || slotEmojis [ 1 ] === slotEmojis [ 2 ] ) { profit = Math . round ( ( amount * modifiers [ emotes . indexOf ( slotEmojis [ 0 ] ) ] ) / 3 ) ; } let cookies = await this . bot . db . getUserCookies ( msg . author . id ) ; if ( ! cookies ) { await this . bot . db . insertBlankUserCookies ( msg . author . id ) ; cookies = { id : msg . author . id , amount : 0 , lastclaim : null , } ; } if ( amount > cookies . amount || amount < 0 ) { return msg . createEmbed ( msg . string ( "global.ERROR" ) , msg . string ( "fun.SLOTS_NOTENOUGH" , { amount : cookies . amount } ) , "error" ) ; } profit > 0 ? ( cookies . amount += profit ) : ( cookies . amount -= amount ) ; cookies . amount = Math . floor ( cookies . amount ) ; await this . bot . db . updateUserCookies ( msg . author . id , cookies ) ; msg . createEmbed ( `🎰 ${ msg . string ( "fun.SLOTS" ) }` , `${ profit ? msg . string ( "fun.SLOTS_WON" , { amount : profit } ) : msg . string ( "fun.SLOTS_LOST" ) } \n${ slotEmojis . join ( " " ) }` ) ; } }