Added /drawtriangle command
This commit is contained in:
parent
9cec9c0c9f
commit
a61fa8f4f2
16
README.md
16
README.md
@ -1,17 +1,17 @@
|
|||||||
# NoMoreAcronyms
|
# NoMoreAcronyms
|
||||||
|
|
||||||
This is a bot that identifies abbreviations in a sentence and replaces them with the written out phrase!<br>
|
This is a bot that identifies abbreviations in a sentence and replaces them with the written out phrase!\n
|
||||||
Example:<br>
|
Example:\n
|
||||||
![Example](images/example.png)
|
![Example](images/example.png)
|
||||||
<br>
|
\n
|
||||||
To run an instance of this bot, define your bot token, guildId (Server ID), and client ID in key.json, then run:
|
To run an instance of this bot, define your bot token, guildId (Server ID), and client ID in key.json, then run:
|
||||||
<br>
|
\n
|
||||||
`npm install discord.js`
|
`npm install discord.js`
|
||||||
<br>
|
\n
|
||||||
After that, register the bot commands:
|
After that, register the bot commands:
|
||||||
<br>
|
\n
|
||||||
`node deploy-commands.js`
|
`node deploy-commands.js`
|
||||||
<br>
|
\n
|
||||||
And now all you need to do is start the bot!
|
And now all you need to do is start the bot!
|
||||||
<br>
|
\n
|
||||||
`node main.ts`
|
`node main.ts`
|
||||||
|
120
commands/drawTriangle.ts
Normal file
120
commands/drawTriangle.ts
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
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 = interaction.options.getString('string');
|
||||||
|
if (design < 1 || design > 3) {
|
||||||
|
await interaction.reply('Invalid design choice.');
|
||||||
|
}
|
||||||
|
if (inputString.length > 1000) {
|
||||||
|
await interaction.reply('String is too big. Resultant output would be too big to send to Discord.')
|
||||||
|
}
|
||||||
|
switch (design) {
|
||||||
|
case 1:
|
||||||
|
var output = design1(inputString);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
var output = design2(inputString);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
var output = design3(inputString);
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
await interaction.reply(codeBlock("", output));
|
||||||
|
console.log("User " + interaction.user.tag + " ran /drawtriangle");
|
||||||
|
},
|
||||||
|
};
|
||||||
|
function design1(input) {
|
||||||
|
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) {
|
||||||
|
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) {
|
||||||
|
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;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user