diff --git a/README.md b/README.md index a742005b..ccd16fea 100644 --- a/README.md +++ b/README.md @@ -523,7 +523,6 @@ Total: 510 * **lowercase:** Converts text to lowercase. * **md5:** Creates a hash of text with the MD5 algorithm. * **mocking:** SenDs TexT lIkE ThiS. -* **morse:** Converts text to morse code. * **nobody-name:** Converts a name into the Organization XIII style. * **owo:** OwO. * **pig-latin:** Converts text to pig latin. @@ -573,6 +572,7 @@ Total: 510 * **animalese:** Makes animalese based on text. * **dec-talk:** The world's best Text-to-Speech. * **mindfulness:** Immerse yourself in some mindful quotes. +* **morse:** Converts text to morse code. * **play:** Plays a YouTube video in your voice channel. * **tts:** Say the text you provide in the accent you choose. diff --git a/assets/sounds/morse/dash.wav b/assets/sounds/morse/dash.wav new file mode 100644 index 00000000..aab920a4 Binary files /dev/null and b/assets/sounds/morse/dash.wav differ diff --git a/assets/sounds/morse/dot.wav b/assets/sounds/morse/dot.wav new file mode 100644 index 00000000..eab2108e Binary files /dev/null and b/assets/sounds/morse/dot.wav differ diff --git a/commands/edit-text/morse.js b/commands/edit-text/morse.js deleted file mode 100644 index ca337984..00000000 --- a/commands/edit-text/morse.js +++ /dev/null @@ -1,30 +0,0 @@ -const Command = require('../../framework/Command'); -const { letterTrans } = require('custom-translate'); -const dictionary = require('../../assets/json/morse'); - -module.exports = class MorseCommand extends Command { - constructor(client) { - super(client, { - name: 'morse', - aliases: ['morse-code'], - group: 'edit-text', - memberName: 'morse', - description: 'Converts text to morse code.', - args: [ - { - key: 'text', - type: 'string', - validate: text => { - if (letterTrans(text.toLowerCase(), dictionary, ' ').length < 2000) return true; - return 'Invalid text, your text is too long.'; - }, - parse: text => text.toLowerCase() - } - ] - }); - } - - run(msg, { text }) { - return msg.say(letterTrans(text, dictionary, ' ')); - } -}; diff --git a/commands/voice/morse.js b/commands/voice/morse.js new file mode 100644 index 00000000..ced5c97e --- /dev/null +++ b/commands/voice/morse.js @@ -0,0 +1,65 @@ +const Command = require('../../framework/Command'); +const path = require('path'); +const { letterTrans } = require('custom-translate'); +const { reactIfAble, delay } = require('../../util/Util'); +const dictionary = require('../../assets/json/morse'); + +module.exports = class MorseCommand extends Command { + constructor(client) { + super(client, { + name: 'morse', + aliases: ['morse-code'], + group: 'voice', + memberName: 'morse', + description: 'Converts text to morse code.', + args: [ + { + key: 'text', + type: 'string', + validate: text => { + if (letterTrans(text.toLowerCase(), dictionary, ' ').length < 2000) return true; + return 'Invalid text, your text is too long.'; + }, + parse: text => text.toLowerCase() + } + ] + }); + } + + async run(msg, { text }) { + const connection = this.client.dispatchers.get(msg.guild.id); + if (!connection) { + const usage = this.client.registry.commands.get('join').usage(); + return msg.reply(`I am not in a voice channel. Use ${usage} to fix that!`); + } + if (!connection.canPlay) return msg.reply('I am already playing audio in this server.'); + const translated = letterTrans(text, dictionary, ' '); + const letters = translated.split(''); + let skip = false; + await reactIfAble(msg, this.client.user, '🔉'); + for (let i = 0; i < letters.length; i++) { + if (skip) { + skip = false; + continue; + } + const letter = letters[i]; + if (letter === '.') { + connection.play(path.join(__dirname, '..', '..', 'sounds', 'morse', 'dot.wav')); + await delay(1000); + continue; + } + if (letter === '-') { + connection.play(path.join(__dirname, '..', '..', 'sounds', 'morse', 'dash.wav')); + await delay(1000); + continue; + } + if (letter === ' ' && letters[i + 1] === ' ') { + skip = true; + await delay(7000); + continue; + } + await delay(3000); + } + return null; + } +};