Files
xiao/commands/text-edit/binary.js
T
Daniel Odendahl Jr ffa05f01ff structures -> util
2017-10-13 21:46:29 +00:00

36 lines
812 B
JavaScript

const { Command } = require('discord.js-commando');
const { pad } = require('../../util/Util');
module.exports = class BinaryCommand extends Command {
constructor(client) {
super(client, {
name: 'binary',
group: 'text-edit',
memberName: 'binary',
description: 'Converts text to binary.',
args: [
{
key: 'text',
prompt: 'What text would you like to convert to binary?',
type: 'string',
validate: text => {
if (this.binary(text).length < 2000) return true;
return 'Invalid text, your text is too long.';
}
}
]
});
}
run(msg, { text }) {
return msg.say(this.binary(text));
}
binary(text) {
return text.split('').map(str => {
const converted = str.charCodeAt(0).toString(2);
return pad(converted, '00000000');
}).join('');
}
};