From 63f1794c86906e1f773b16c618c2f6b6e770e9ad Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Thu, 4 Apr 2024 00:43:59 -0400 Subject: [PATCH] Voice-based morse --- README.md | 2 +- assets/sounds/morse/dash.wav | Bin 0 -> 1524 bytes assets/sounds/morse/dot.wav | Bin 0 -> 564 bytes commands/edit-text/morse.js | 30 ---------------- commands/voice/morse.js | 65 +++++++++++++++++++++++++++++++++++ 5 files changed, 66 insertions(+), 31 deletions(-) create mode 100644 assets/sounds/morse/dash.wav create mode 100644 assets/sounds/morse/dot.wav delete mode 100644 commands/edit-text/morse.js create mode 100644 commands/voice/morse.js 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 0000000000000000000000000000000000000000..aab920a4e2e957de157d0a6939918c27a3565f37 GIT binary patch literal 1524 zcmWIYbaQ*d%D@or80MOmTcRMqz`(!=gbwlyV9dzC!H|+zl6V5BrlEP_>eG+k+~3<9 zq0Pf0VxBqg+=oA(E-x*xlVIgk_G{Yq;K#3L`+Fm_cv*x@Q)iue`{&E`l_gG6Y#a)n zwHxnz|NZjtq*y&Z76HSAsmEUb`F3kvrJF1}yR2))+M8ehygo54(MXVmPd9qPp%=fu z-`!N_rNF@^_q?YkcT{P}oyN3c3Ki>O7`{B!R|-8UM3qv>xne~gIo#lN(F#kX=t9f`t;*B_xJWj zX!Ed$m}kyA_u{hGEt`0?x6{@w^JUKSzK)LEzA{`qo!Wr>p%8;62t z?Z!Lbf4@9DDOQhao{w}7e?H#b5v { - 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; + } +};