Skip to content

Commit

Permalink
Zombie Translate
Browse files Browse the repository at this point in the history
  • Loading branch information
TecEash1 committed Oct 15, 2023
1 parent f8326b5 commit 1fdacb5
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 0 deletions.
76 changes: 76 additions & 0 deletions interactions/slash/misc/zombietranslate.js
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 },
],
},
],
});
},
};
58 changes: 58 additions & 0 deletions zombiecharacters.js
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 };

0 comments on commit 1fdacb5

Please sign in to comment.