2023-04-04 20:50:02 -05:00
const { SlashCommandBuilder , Discord , codeBlock } = require ( 'discord.js' ) ;
module .exports = {
data : new SlashCommandBuilder ( )
. setName ( 'drawdesign' )
. setDescription ( 'Draws a design in a codeblock' )
. addStringOption ( option = >
option . setName ( 'design' )
. setDescription ( "Pick a design. (number 1-3)" )
. setRequired ( true )
)
. addStringOption ( option = >
option . setName ( 'string' )
. setDescription ( "String to feed into input" )
. setRequired ( true )
) ,
async execute ( interaction , client ) {
var inputString = interaction . options . getString ( 'string' ) ;
2023-04-04 21:12:00 -05:00
var design = parseInt ( interaction . options . getString ( 'design' ) ) ;
2023-04-04 20:50:02 -05:00
if ( design < 1 || design > 3 ) {
await interaction . reply ( 'Invalid design choice.' ) ;
2023-04-04 21:23:21 -05:00
return ;
2023-04-04 20:50:02 -05:00
}
2023-04-04 21:08:24 -05:00
var output ;
2023-04-04 20:50:02 -05:00
switch ( design ) {
case 1 :
2023-04-04 21:08:24 -05:00
output = design1 ( inputString ) ;
2023-04-04 20:50:02 -05:00
break ;
case 2 :
2023-04-04 21:08:24 -05:00
output = design2 ( inputString ) ;
2023-04-04 20:50:02 -05:00
break ;
case 3 :
2023-04-04 21:08:24 -05:00
output = design3 ( inputString ) ;
2023-04-04 20:50:02 -05:00
break ;
}
2023-04-04 21:03:27 -05:00
console . log ( codeBlock ( "" , output ) ) ;
2023-04-04 21:32:49 -05:00
var testLength = "\n" + 'output length was ' + ( output . length + testLength . length ) + " characters." ;
2023-04-04 21:26:00 -05:00
if ( output . length + testLength . length > 2000 ) {
2023-04-04 21:31:39 -05:00
await interaction . reply ( 'Error: String is too big. Resultant output would be too big to send to Discord. (the output length was ' + output . length + " characters.)" ) ;
2023-04-04 21:23:21 -05:00
return ;
2023-04-04 21:18:51 -05:00
}
2023-04-04 21:26:00 -05:00
await interaction . reply ( codeBlock ( "" , output ) + testLength ) ;
2023-04-04 20:50:02 -05:00
console . log ( "User " + interaction . user . tag + " ran /drawtriangle" ) ;
} ,
} ;
function design1 ( input ) {
2023-04-04 21:10:00 -05:00
console . log ( "Running design1..." ) ;
2023-04-04 20:50:02 -05:00
var outputString ;
var startEnd = "" ;
for ( let i = 0 ; i < input . length + 2 ; i ++ ) {
startEnd += "*" ;
}
outputString = startEnd + "\n" ;
outputString += "*" + "\n" ;
outputString += "* " + input + "\n" ;
outputString += "*" + "\n" ;
outputString += startEnd ;
return outputString ;
}
function design2 ( input ) {
2023-04-04 21:10:00 -05:00
console . log ( "Running design2..." ) ;
2023-04-04 20:50:02 -05:00
var outputString ;
var height = ( input . length * 2 ) + 6 ;
var mid = Math . trunc ( height / 2 ) + 1 ;
if ( height % 2 == 0 ) {
height ++ ;
}
outputString = "" ;
for ( let i = 0 ; i < height ; i ++ ) {
if ( mid == i ) { //Determine if we're in the middle of the triangle
outputString += "**" + input + "**" ;
} else {
for ( let j = 0 ; j < i ; j ++ ) {
outputString += "*" ;
}
}
outputString += "\n" ;
}
return outputString ;
}
function design3 ( input ) {
2023-04-04 21:10:00 -05:00
console . log ( "Running design3..." ) ;
2023-04-04 20:50:02 -05:00
var outputString ;
var height = ( input . length * 2 ) + 6 ;
var mid = Math . trunc ( height / 2 ) + 1 ;
if ( height % 2 == 0 ) {
height ++ ;
}
outputString = "" ;
if ( mid % 2 == 1 ) { // Skip a line if odd
var subOffset = 1 ;
var addOffset = 0 ;
} else {
var subOffset = 0 ;
var addOffset = 1 ;
}
for ( let i = 0 ; i < mid - addOffset ; i ++ ) {
for ( let j = 0 ; j < i ; j ++ ) {
if ( i % 2 == 1 ) {
if ( i != ( mid - 1 ) ) {
if ( i == 0 || ( j == 0 || j == ( i - 1 ) ) ) { // Check if we're at the beginning or end of the line
outputString += "*" ;
} else {
2023-04-04 21:13:42 -05:00
outputString += " " ;
2023-04-04 20:50:02 -05:00
}
}
}
}
outputString += "\n" ;
}
outputString += "* " + input + " *\n" ;
for ( let i = mid - subOffset ; i > 0 ; i -- ) {
for ( let j = 0 ; j < i ; j ++ ) {
if ( i % 2 == 1 ) {
if ( j != ( mid - 1 ) || ( j != mid ) ) {
if ( ( i == 0 || ( j == 0 || j == ( i - 1 ) ) ) ) { // Check if we're at the beginning or end of the line
outputString += "*" ;
} else {
2023-04-04 21:13:42 -05:00
outputString += " " ;
2023-04-04 20:50:02 -05:00
}
}
}
}
outputString += "\n" ;
}
return outputString ;
}