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-26 21:11:05 +00:00
. addIntegerOption ( o =>
2023-02-01 03:51:10 +00:00
o . setName ( 'endheight' )
2023-02-26 21:11:05 +00:00
. setDescription ( 'Ending tree height in feet' )
. setRequired ( true )
2023-02-26 17:09:24 +00:00
)
2023-02-26 21:11:05 +00:00
. addIntegerOption ( o =>
2023-02-20 01:42:14 +00:00
o . setName ( 'beginheight' )
2023-02-26 21:11:05 +00:00
. setDescription ( 'Beginning tree height in feet' )
. setRequired ( false )
2023-02-26 17:09:24 +00:00
)
2023-02-26 21:11:05 +00:00
. addIntegerOption ( o =>
2023-02-26 17:09:24 +00:00
o . setName ( 'efficiency' )
2023-02-26 21:11:05 +00:00
. setDescription ( 'Composter efficiency percentage, rounded' )
. setRequired ( false )
2023-02-26 17:09:24 +00:00
)
2023-02-26 21:11:05 +00:00
. addIntegerOption ( o =>
2023-02-26 17:09:24 +00:00
o . setName ( 'quality' )
2023-02-26 21:11:05 +00:00
. setDescription ( 'Compost quality percentage, rounded' )
. setRequired ( false )
2023-02-26 17:26:52 +00:00
)
. addBooleanOption ( o =>
o . setName ( 'private' )
2023-02-26 21:11:05 +00:00
. setDescription ( 'Should the reply be visible only to you?' )
. setRequired ( false )
2023-02-26 17:09:24 +00:00
) ,
2023-01-25 09:53:49 +00:00
async execute ( interaction ) {
2023-02-26 17:30:55 +00:00
const private = interaction . options . getBoolean ( 'private' ) != undefined ? interaction . options . getBoolean ( 'private' ) : true ;
2023-02-26 17:26:52 +00:00
await interaction . deferReply ( { ephemeral : private } ) ;
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 21:11:05 +00:00
const efficiency = interaction . options . getInteger ( 'efficiency' ) != undefined ? interaction . options . getInteger ( 'efficiency' ) : 10 ;
const quality = interaction . options . getInteger ( 'quality' ) != undefined ? interaction . options . getInteger ( 'quality' ) : 5 ;
2023-02-26 17:09:24 +00:00
let beginHeight , replyContent ;
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 ;
}
2023-02-26 21:11:05 +00:00
const timeToHeightResults = await fn . timeToHeight ( beginHeight , endHeight , efficiency , quality ) ;
const { time , totalWaterCount , compostAppliedCount , average , savedTime } = timeToHeightResults ;
let replyFields = undefined ;
2023-02-26 17:09:24 +00:00
if ( efficiency && quality ) {
2023-02-26 21:11:05 +00:00
replyContent = ` I estimate that a tree with ${ efficiency } % Composter Efficiency and ${ quality } % Compost Quality growing from ${ beginHeight } ft to ${ endHeight } ft will take ${ time } ` ;
replyFields = [
{ name : ` Height Gained: ` , value : ` ${ endHeight - beginHeight } ft ` , inline : true } ,
{ name : ` E/Q: ` , value : ` ${ efficiency } %/ ${ quality } % ` , inline : true } ,
{ name : ` Compost Applied ` , value : ` ${ compostAppliedCount } times ` , inline : true } ,
{ name : ` Compost Average ` , value : ` ${ average } % ` , inline : true } ,
{ name : ` Saved Time ` , value : savedTime , inline : true }
] ;
2023-02-26 17:09:24 +00:00
} else {
2023-02-26 21:11:05 +00:00
replyContent = ` I estimate that a tree growing from ${ beginHeight } ft to ${ endHeight } ft will take ${ time } ` ;
2023-02-20 01:42:14 +00:00
}
2023-02-26 17:09:24 +00:00
2023-02-26 21:11:05 +00:00
const reply = fn . builders . embeds . information ( replyContent , replyFields )
2023-02-26 17:09:24 +00:00
await interaction . editReply ( reply ) ;
}
2023-01-25 09:53:49 +00:00
} ;