128 lines
3.3 KiB
TypeScript
128 lines
3.3 KiB
TypeScript
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');
|
|
var design = parseInt(interaction.options.getString('design'));
|
|
if (design < 1 || design > 3) {
|
|
await interaction.reply('Invalid design choice.');
|
|
return;
|
|
}
|
|
var output;
|
|
switch (design) {
|
|
case 1:
|
|
output = design1(inputString);
|
|
break;
|
|
case 2:
|
|
output = design2(inputString);
|
|
break;
|
|
case 3:
|
|
output = design3(inputString);
|
|
break;
|
|
|
|
}
|
|
console.log(codeBlock("", output));
|
|
if (output.length > 2000) {
|
|
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.");
|
|
return;
|
|
}
|
|
await interaction.reply(codeBlock("", output));
|
|
await interaction.reply('output length was ' + output.length + " characters.");
|
|
console.log("User " + interaction.user.tag + " ran /drawtriangle");
|
|
},
|
|
};
|
|
function design1(input) {
|
|
console.log("Running design1...");
|
|
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) {
|
|
console.log("Running design2...");
|
|
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) {
|
|
console.log("Running design3...");
|
|
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 {
|
|
outputString += " ";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
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 {
|
|
outputString += " ";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
outputString += "\n";
|
|
}
|
|
return outputString;
|
|
} |