-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); | ||
const { zombishMapping, zombishRevMapping, validZombish } = require('../../../zombiecharacters'); | ||
|
||
/** | ||
* @type {import('../../../typings').SlashInteractionCommand} | ||
*/ | ||
|
||
module.exports = { | ||
data: new SlashCommandBuilder() | ||
.setName('zombietranslator') | ||
.setDescription('Translate to or from Zombie.') | ||
.addStringOption((option) => | ||
option | ||
.setName('language') | ||
.setDescription('Which language to translate into?') | ||
.setRequired(true) | ||
.addChoices( | ||
{ name: 'English to Zombie', value: 'english_to_zombie' }, | ||
{ name: 'Zombie to English', value: 'zombie_to_english' } | ||
)) | ||
.addStringOption((option) => | ||
option | ||
.setName('phrase') | ||
.setDescription('The phrase to translate') | ||
.setRequired(true) | ||
.setMaxLength(800) | ||
.setMinLength(1) | ||
), | ||
async execute(interaction) { | ||
const langOption = interaction.options.getString('language'); | ||
const phraseOption = interaction.options.getString('phrase'); | ||
|
||
let phrase = ''; | ||
if (langOption === 'english_to_zombie') { | ||
for (let char of phraseOption.split('')) phrase += zombishMapping.hasOwnProperty(char) ? zombishMapping[char] : char; | ||
} else if (langOption === 'zombie_to_english') { | ||
let stringPair = []; | ||
let first = true; | ||
let pair = ''; | ||
for (let s of phraseOption.split('')) { | ||
if (validZombish.includes(s)) { | ||
if (first) { | ||
pair = s; | ||
first = false; | ||
} else { | ||
pair += s; | ||
stringPair.push(pair); | ||
pair = ''; | ||
first = true; | ||
} | ||
} else { | ||
if (pair !== '') stringPair.push(pair); | ||
pair = ''; | ||
first = true; | ||
stringPair.push(s); | ||
} | ||
} | ||
for (let pair of stringPair) phrase += zombishRevMapping.hasOwnProperty(pair) ? zombishRevMapping[pair] : pair; | ||
} | ||
|
||
await interaction.reply({ | ||
embeds: [ | ||
{ | ||
title: 'Zombie Translator', | ||
color: 0x7F8D72, | ||
thumbnail: { url: 'https://discord.mx/Wk7q6noUJm.png' }, | ||
fields: [ | ||
{ name: 'From', value: langOption === 'english_to_zombie' ? 'English' : 'Zombie', inline: true }, | ||
{ name: 'To', value: langOption === 'english_to_zombie' ? 'Zombie' : 'English', inline: true }, | ||
{ name: 'Translation', value: phrase || '---- An error occurred ----', inline: false }, | ||
], | ||
}, | ||
], | ||
}); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
const zombishMapping = { | ||
"a": "Ar", | ||
"b": "AA", | ||
"c": "Ab", | ||
"d": "RA", | ||
"e": "bb", | ||
"f": "BA", | ||
"g": "ll", | ||
"h": "bG", | ||
"i": "Gn", | ||
"j": "GA", | ||
"k": "GG", | ||
"l": "nh", | ||
"m": "hh", | ||
"n": "MM", | ||
"o": "hr", | ||
"p": "hA", | ||
"q": "hb", | ||
"r": "rr", | ||
"s": "hG", | ||
"t": "Gg", | ||
"u": "GM", | ||
"v": "nr", | ||
"w": "Mr", | ||
"x": "Gl", | ||
"y": "nn", | ||
"z": "KA", | ||
"A": "aR", | ||
"B": "aa", | ||
"C": "aB", | ||
"D": "ra", | ||
"E": "BB", | ||
"F": "ba", | ||
"G": "LL", | ||
"H": "Bg", | ||
"I": "gN", | ||
"J": "ga", | ||
"K": "gg", | ||
"L": "NH", | ||
"M": "HH", | ||
"N": "mm", | ||
"O": "HR", | ||
"P": "Ha", | ||
"Q": "HB", | ||
"R": "RR", | ||
"S": "Hg", | ||
"T": "gG", | ||
"U": "gm", | ||
"V": "NR", | ||
"W": "mR", | ||
"X": "gL", | ||
"Y": "NN", | ||
"Z": "ka" | ||
} | ||
|
||
const zombishRevMapping = Object.entries(zombishMapping).reduce((p,a) => (p[a[1]] = a[0],p), {}) | ||
const validZombish = Object.values(zombishRevMapping).reduce((p,a) => (p.push(...[...a].filter(x=>!p.includes(x))),p), []); | ||
module.exports = { zombishMapping, zombishRevMapping, validZombish }; |