rolereact system

This commit is contained in:
VALOU3336
2024-03-01 15:55:17 +01:00
parent ad49e48be1
commit 4cf07f2d2c
5 changed files with 167 additions and 1 deletions
+67
View File
@@ -0,0 +1,67 @@
module.exports = {
name: 'encode',
description: 'Encoder ou décoder un language chiffré',
utilisation: '<base64|binaire> <encode|decode> <texte>',
emote: "🔐",
category: "utils",
async execute(message, args) {
if (args.length < 3) {
return message.reply('Usage: `encode <base64|binaire> <encode|decode> <texte>`');
}
const subcommand = args[0];
const action = args[1];
const text = args.slice(2).join(' ');
if (subcommand !== 'base64' && subcommand !== 'binaire') {
return message.reply('Invalid subcommand. Use `base64` or `binaire`.');
}
if (action !== 'encode' && action !== 'decode') {
return message.reply('Invalid action. Use `encode` or `decode`.');
}
if (subcommand === 'base64') {
let result;
if (action === 'encode') {
result = btoa(text);
} else {
result = atob(text);
}
return message.channel.send(`**Resultat:** \`${result}\``);
}
if (subcommand === 'binaire') {
let result;
if (action === 'encode') {
result = texteVersBinaire(text);
} else {
result = binaireVersTexte(text);
}
return message.channel.send(`**Resultat:** \`${result}\``);
}
},
};
function texteVersBinaire(texte) {
let binaire = '';
for (let i = 0; i < texte.length; i++) {
let charCode = texte.charCodeAt(i).toString(2);
charCode = '0'.repeat(8 - charCode.length) + charCode;
binaire += charCode + ' ';
}
return binaire.trim();
}
function binaireVersTexte(binaire) {
let texte = '';
const octets = binaire.split(' ');
for (let i = 0; i < octets.length; i++) {
const decimal = parseInt(octets[i], 2);
const caractere = String.fromCharCode(decimal);
texte += caractere;
}
return texte;
}