From 33ed9f7f7a00354fe088115223c20483ec9b8d89 Mon Sep 17 00:00:00 2001 From: rhearmas <34490428+qu-ota@users.noreply.github.com> Date: Sat, 21 Dec 2019 19:35:54 -0500 Subject: [PATCH] binary! --- commands/Fun/binary.js | 58 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 commands/Fun/binary.js diff --git a/commands/Fun/binary.js b/commands/Fun/binary.js new file mode 100644 index 0000000..dc3fae1 --- /dev/null +++ b/commands/Fun/binary.js @@ -0,0 +1,58 @@ +exports.methods = { + encode: input => { + return input.toString().split('') + .map(c => c.charCodeAt(0).toString(2)); + }, + decode: input => { + let _input = typeof input === 'string' ? input.split(' ') : input; + return _input.map(c => parseInt(c, 2)) + .map(c => String.fromCharCode(c)) + .join(''); + } +}; + +exports.run = async (client, message, args, level) => { + if (args.length < 2) { + message.delete(); + return (await message.channel.send(`Hey ${message.author}, do \`${client.settings.get("default").prefix}help binary\` to see how to use this.`)).delete(5000); + } + + let input = args.slice(1).join(' '); + + if (args[0].match(/^enc(ode(Text)?)?$/i)) { + message.channel.send(this.methods.encode(input).join(' ')); + } else if (args[0].match(/^dec(ode(Text)?)?$/i)) { + message.channel.send(this.methods.decode(input)); + } else if (args[0].match(/^decToBin$/i)) { + if (isNaN(input)) { + message.delete(); + return (await message.reply('your input must be a number.')).delete(5000); + } + + message.channel.send(parseInt(input).toString(2)); + } else if (args[0].match(/^binToDec$/i)) { + if (isNaN(input)) { + message.delete(); + return (await message.reply('your input must be a number.')).delete(5000); + } + + message.channel.send(parseInt(input, 2)); + } else { + message.delete(); + return (await message.reply(`the sub command you entered, \`${args[0]}\`, is something I'm unfamiliar with.`)).delete(5000); + } +}; + +exports.conf = { + enabled: true, + guildOnly: false, + aliases: [], + permLevel: "User" +}; + +exports.help = { + name: "binary", + category: "Fun", + description: "Convert text to binary, or vice versa.", + usage: "binary " +}; \ No newline at end of file