Voice-based morse

This commit is contained in:
Dragon Fire
2024-04-04 00:43:59 -04:00
parent 9830fb7d8e
commit 63f1794c86
5 changed files with 66 additions and 31 deletions
+1 -1
View File
@@ -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.
Binary file not shown.
Binary file not shown.
-30
View File
@@ -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, ' '));
}
};
+65
View File
@@ -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;
}
};