mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-18 21:40:49 +02:00
Default to just text in morse
This commit is contained in:
+10
-4
@@ -1,9 +1,11 @@
|
|||||||
const Command = require('../../framework/Command');
|
const Command = require('../../framework/Command');
|
||||||
|
const { Util: { escapeMarkdown } } = require('discord.js');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const { letterTrans } = require('custom-translate');
|
const { letterTrans } = require('custom-translate');
|
||||||
const { WaveFile } = require('wavefile');
|
const { WaveFile } = require('wavefile');
|
||||||
const { Readable } = require('stream');
|
const { Readable } = require('stream');
|
||||||
|
const { stripIndents } = require('common-tags');
|
||||||
const { reactIfAble } = require('../../util/Util');
|
const { reactIfAble } = require('../../util/Util');
|
||||||
const dictionary = require('../../assets/json/morse');
|
const dictionary = require('../../assets/json/morse');
|
||||||
const { LOADING_EMOJI_ID } = process.env;
|
const { LOADING_EMOJI_ID } = process.env;
|
||||||
@@ -22,7 +24,7 @@ module.exports = class MorseCommand extends Command {
|
|||||||
type: 'string',
|
type: 'string',
|
||||||
validate: text => {
|
validate: text => {
|
||||||
const translated = letterTrans(text.toLowerCase(), dictionary, ' ');
|
const translated = letterTrans(text.toLowerCase(), dictionary, ' ');
|
||||||
if (translated.replace(/ {2}/g, ' / ').length < 2000) return true;
|
if (escapeMarkdown(translated.replace(/ {2}/g, ' / ')).length < 2000) return true;
|
||||||
return 'Invalid text, your text is too long.';
|
return 'Invalid text, your text is too long.';
|
||||||
},
|
},
|
||||||
parse: text => text.toLowerCase()
|
parse: text => text.toLowerCase()
|
||||||
@@ -34,15 +36,19 @@ module.exports = class MorseCommand extends Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async run(msg, { text }) {
|
async run(msg, { text }) {
|
||||||
|
const translated = letterTrans(text.toLowerCase(), dictionary, ' ');
|
||||||
|
const parsed = escapeMarkdown(translated.replace(/ {2}/g, ' / '));
|
||||||
const connection = this.client.dispatchers.get(msg.guild.id);
|
const connection = this.client.dispatchers.get(msg.guild.id);
|
||||||
if (!connection) {
|
if (!connection) {
|
||||||
const usage = this.client.registry.commands.get('join').usage();
|
const usage = this.client.registry.commands.get('join').usage();
|
||||||
return msg.reply(`I am not in a voice channel. Use ${usage} to fix that!`);
|
return msg.reply(stripIndents`
|
||||||
|
${parsed}
|
||||||
|
_If I am in a voice channel when using this command, I can play audio. Use ${usage} to try it!_
|
||||||
|
`);
|
||||||
}
|
}
|
||||||
if (!connection.canPlay) return msg.reply('I am already playing audio in this server.');
|
if (!connection.canPlay) return msg.reply('I am already playing audio in this server.');
|
||||||
const translated = letterTrans(text.toLowerCase(), dictionary, ' ');
|
|
||||||
await reactIfAble(msg, this.client.user, LOADING_EMOJI_ID, '💬');
|
await reactIfAble(msg, this.client.user, LOADING_EMOJI_ID, '💬');
|
||||||
await msg.say(translated.replace(/ {2}/g, ' / '));
|
await msg.say(parsed);
|
||||||
connection.play(Readable.from([this.morse(translated)]));
|
connection.play(Readable.from([this.morse(translated)]));
|
||||||
await reactIfAble(msg, this.client.user, '🔉');
|
await reactIfAble(msg, this.client.user, '🔉');
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user