mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-20 14:00:22 +02:00
Improve Morse Translator and Letter Translator
This commit is contained in:
@@ -36,7 +36,12 @@ const morse = {
|
|||||||
"6": "-....",
|
"6": "-....",
|
||||||
"7": "--...",
|
"7": "--...",
|
||||||
"8": "---..",
|
"8": "---..",
|
||||||
"9": "----."
|
"9": "----.",
|
||||||
|
" ": " ",
|
||||||
|
".": ".-.-.-",
|
||||||
|
"?": "..--..",
|
||||||
|
",": "--..--",
|
||||||
|
"'": ".----."
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = class MorseCommand extends Command {
|
module.exports = class MorseCommand extends Command {
|
||||||
@@ -68,8 +73,8 @@ module.exports = class MorseCommand extends Command {
|
|||||||
if (message.channel.type !== 'dm') {
|
if (message.channel.type !== 'dm') {
|
||||||
if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return;
|
if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return;
|
||||||
}
|
}
|
||||||
const text = args.text;
|
const text = args.text.toLowerCase();
|
||||||
const encoded = translator.letterTrans(text, morse);
|
const encoded = translator.letterTrans(text, morse).split('').join(' ');
|
||||||
return message.say(encoded);
|
return message.say(encoded);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ module.exports.wordTrans = (text, words) => {
|
|||||||
let translation = [];
|
let translation = [];
|
||||||
for (let i = 0; i < text.length; i++) {
|
for (let i = 0; i < text.length; i++) {
|
||||||
const word = text[i].toLowerCase();
|
const word = text[i].toLowerCase();
|
||||||
const wordPuncStrip = word.replace(/[.,?!]/g, '');
|
const wordPuncStrip = word.replace(/[\[\\^$.|?*+()\]]/g, '');
|
||||||
if (words[wordPuncStrip]) {
|
if (words[wordPuncStrip]) {
|
||||||
const reg = new RegExp(wordPuncStrip, 'gi');
|
const reg = new RegExp(wordPuncStrip, 'gi');
|
||||||
translation.push(word.replace(reg, words[wordPuncStrip]));
|
translation.push(word.replace(reg, words[wordPuncStrip]));
|
||||||
@@ -19,10 +19,9 @@ module.exports.letterTrans = (text, letters) => {
|
|||||||
text = text.split('');
|
text = text.split('');
|
||||||
let translation = [];
|
let translation = [];
|
||||||
for (let i = 0; i < text.length; i++) {
|
for (let i = 0; i < text.length; i++) {
|
||||||
const letter = text[i].toLowerCase();
|
const letter = text[i];
|
||||||
if (letters[letter]) {
|
if (letters[letter]) {
|
||||||
const reg = new RegExp(letter, 'gi');
|
translation.push(letters[letter]);
|
||||||
translation.push(letter.replace(reg, letters[letter]));
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
translation.push(letter);
|
translation.push(letter);
|
||||||
|
|||||||
Reference in New Issue
Block a user