Add convert command

Only fahrenheit to celsius and vice versa so far
This commit is contained in:
SileNce5k 2024-09-27 22:30:46 +02:00
parent 582d9234ab
commit a59e2381fb
Signed by: SileNce
GPG key ID: B0A142BB4291B204

38
commands/misc/convert.js Normal file
View file

@ -0,0 +1,38 @@
module.exports = {
name: 'convert',
description: 'Convert a value to another value',
moreHelp: [
"To convert celsius to fahrenheit:",
"<prefix>convert 20 C F"
],
execute({message, args}) {
if(args.length < 3){
message.channel.send("Not enough arguments");
return;
}
let sendText = "";
switch (args[1].toUpperCase()) {
case "C":
if (args[2].toUpperCase() === "F") {
const fahrenheit = ((parseFloat(args[0]) * 5 / 9) + 32).toFixed(2);
sendText = `${args[0]}°C is ${fahrenheit}°F`;
} else {
sendText = "Can only convert to celsius from fahrenheit";
}
break;
case "F":
if (args[2].toUpperCase() === "C") {
const celsius = ((parseFloat(args[0]) - 32) * 5 / 9).toFixed(2);
sendText = `${args[0]}°C is ${celsius}°F`;
} else {
sendText = "Can only convert to fahrenheit from celsius";
}
break;
default:
sendText = "No conversion method for that yet"
break;
}
message.channel.send(sendText);
}
};