mirror of
https://github.com/arthur-pbty/gestion.git
synced 2026-06-03 23:36:35 +02:00
rolereact system
This commit is contained in:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user