2023-01-25 09:53:49 +00:00
const { SlashCommandBuilder } = require ( 'discord.js' ) ;
2023-02-01 03:51:10 +00:00
const dbfn = require ( '../modules/dbfn.js' ) ;
2023-01-25 09:53:49 +00:00
const fn = require ( '../modules/functions.js' ) ;
module . exports = {
data : new SlashCommandBuilder ( )
. setName ( 'timetoheight' )
. setDescription ( 'Calculate how long it would take to reach a given height' )
2023-02-20 01:42:14 +00:00
. addIntegerOption ( o =>
2023-02-01 03:51:10 +00:00
o . setName ( 'endheight' )
2023-02-26 17:09:24 +00:00
. setDescription ( 'Ending tree height in feet' )
. setRequired ( true )
)
2023-02-20 01:42:14 +00:00
. addIntegerOption ( o =>
o . setName ( 'beginheight' )
2023-02-26 17:09:24 +00:00
. setDescription ( 'Beginning tree height in feet' )
. setRequired ( false )
)
. addIntegerOption ( o =>
o . setName ( 'efficiency' )
. setDescription ( 'Composter efficiency percentage, rounded' )
. setRequired ( false )
)
. addIntegerOption ( o =>
o . setName ( 'quality' )
. setDescription ( 'Compost quality percentage, rounded' )
. setRequired ( false )
) ,
2023-01-25 09:53:49 +00:00
async execute ( interaction ) {
2023-02-01 03:51:10 +00:00
await interaction . deferReply ( { ephemeral : true } ) ;
2023-02-26 17:09:24 +00:00
const inBeginHeight = interaction . options . getInteger ( 'beginheight' ) ;
2023-02-20 01:42:14 +00:00
const endHeight = interaction . options . getInteger ( 'endheight' ) ;
2023-02-26 17:09:24 +00:00
const efficiency = interaction . options . getInteger ( 'efficiency' ) ;
const quality = interaction . options . getInteger ( 'quality' ) ;
let beginHeight , replyContent ;
if ( ( efficiency && ! quality ) || ( quality && ! efficiency ) ) {
const reply = fn . builders . embed ( "You must include **both** efficiency *and* quality, I only received one." ) ;
await interaction . editReply ( reply ) . catch ( e => console . error ( e ) ) ;
return ;
}
if ( ! inBeginHeight ) {
2023-02-20 01:42:14 +00:00
const guildInfo = interaction . client . guildInfos . get ( interaction . guild . id ) ;
beginHeight = guildInfo . treeHeight ;
2023-02-26 17:09:24 +00:00
} else {
beginHeight = inBeginHeight ;
}
const timeString = await fn . timeToHeight ( beginHeight , endHeight , efficiency , quality ) ;
if ( efficiency && quality ) {
replyContent = ` I estimate that a tree with ${ efficiency } % Composter Efficiency and ${ quality } % Compost Quality growing from ${ beginHeight } ft to ${ endHeight } ft will take ${ timeString } ` ;
} else {
replyContent = ` I estimate that a tree growing from ${ beginHeight } ft to ${ endHeight } ft will take ${ timeString } ` ;
2023-02-20 01:42:14 +00:00
}
2023-02-26 17:09:24 +00:00
const reply = fn . builders . embed ( replyContent )
await interaction . editReply ( reply ) ;
}
2023-01-25 09:53:49 +00:00
} ;