Move Translator Functions Outside of the Command Runner

This commit is contained in:
Daniel Odendahl Jr
2017-03-22 20:35:55 +00:00
parent 87bb4ad408
commit 39f4e49864
+191 -190
View File
@@ -1,193 +1,194 @@
const commando = require('discord.js-commando'); const commando = require('discord.js-commando');
module.exports = class TemmieCommand extends commando.Command { const dictionary = {
constructor(Client){ "i": "tem",
super(Client, { "hi": "hoi",
name: 'temmie', "that": "dat",
group: 'textedit', "that's": "dat",
memberName: 'temmie', "hello": "hoi",
description: "Translate text to Temmie speak. (;temmie I am Temmie)", "me": "temmie",
examples: [";temmie I am Temmie."] "goodbye": "boi",
}); "bye": "boi",
} "later": "boi",
"college": "colleg",
async run(message) { "money": "muns",
if(message.channel.type !== 'dm') { "food": "tem flakes",
if(!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return; "snack": "tem flakes",
} "snacks": "tem flakes",
console.log("[Command] " + message.content); "meal": "tem flakes",
"meals": "tem flakes",
let dictionary = { "human": "hooman",
"i": "tem", "chocolate": "choco",
"hi": "hoi", "cute": "coot",
"that": "dat", "allergic": "allergics",
"that's": "dat", "allergy": "allergics",
"hello": "hoi", "do": "dos",
"me": "temmie", "does": "dos",
"goodbye": "boi", "what": "ppppppppp...",
"bye": "boi", "who": "ppppppppp...",
"later": "boi", "when": "ppppppppp...",
"college": "colleg", "why": "ppppppppp...",
"money": "muns", "where": "ppppppppp...",
"food": "tem flakes", "how": "ppppppppp...",
"snack": "tem flakes", "xd": "xd",
"snacks": "tem flakes", "but": "b-but",
"meal": "tem flakes", "store": "tem shop",
"meals": "tem flakes", "restaurant": "tem shop",
"human": "hooman", "shop": "tem shop",
"chocolate": "choco", "temmie": "temmiy",
"cute": "coot", "sick": "holves",
"allergic": "allergics", "illness": "holves",
"allergy": "allergics", "ill": "holves",
"do": "dos", "disease": "holves",
"does": "dos", "cat": "tem",
"what": "ppppppppp...", "dog": 'tem',
"who": "ppppppppp...", "hugs": "pets",
"when": "ppppppppp...", "pats": "pets",
"why": "ppppppppp...", "waves": "pets",
"where": "ppppppppp...", "high-fives": "pets",
"how": "ppppppppp...", "fistbumps": "pets",
"xd": "xd", "hug": "pet",
"but": "b-but", "pat": "pet",
"store": "tem shop", "wave": "pet",
"restaurant": "tem shop", "high-five": "pet",
"shop": "tem shop", "fistbump": "pet",
"temmie": "temmiy", "hungry": "hungr",
"sick": "holves", "muscles": "not coot",
"illness": "holves", "aw": "awwawa",
"ill": "holves", "yikes": "omg!!!!!!",
"disease": "holves", "ah": "omg!!!!!!",
"cat": "tem", "oh": "omg!!!!!!",
"dog": 'tem', "yipe": "omg!!!!!!",
"hugs": "pets", "wait": "omg!!!!!!",
"pats": "pets", "yes": "yee!!!!!!",
"waves": "pets", "no": "no!!!!!!",
"high-fives": "pets", "person": "bark",
"fistbumps": "pets", "monster": "munster",
"hug": "pet", "monsters": "munsters",
"pat": "pet", "great": "tem outta tem",
"wave": "pet", "awesome": "tem outta tem",
"high-five": "pet", "cool": "tem outta tem",
"fistbump": "pet", "nice": "tem outta tem",
"hungry": "hungr", "good": "tem outta tem",
"muscles": "not coot", "walks": "vibrates",
"aw": "awwawa", "moves": "vibrates",
"yikes": "omg!!!!!!", "sits": "vibrates",
"ah": "omg!!!!!!", "goes": "vibrates",
"oh": "omg!!!!!!", "runs": "vibrates intensely",
"yipe": "omg!!!!!!", "climbs": "vibrates intensely",
"wait": "omg!!!!!!", "escapes": "vibrates intensely",
"yes": "yee!!!!!!", "normal": "bob",
"no": "no!!!!!!", "hmm": "p...",
"person": "bark", "okay": "ok",
"monster": "munster", "lol": "lel",
"monsters": "munsters", "enemy": "special enemy",
"great": "tem outta tem", "villain": "special enemy",
"awesome": "tem outta tem", "bad guy": "special enemy",
"cool": "tem outta tem", "badguy": "special enemy",
"nice": "tem outta tem", "school": "skool",
"good": "tem outta tem", "um": "p...",
"walks": "vibrates", "elizabeth": "ebears",
"moves": "vibrates", "yeah": "yaya",
"sits": "vibrates", "yea": "yaya",
"goes": "vibrates", "uh-huh": "yaya",
"runs": "vibrates intensely", "vampire": "wampire",
"climbs": "vibrates intensely", "tired": "*dies*",
"escapes": "vibrates intensely", "exhausted": "*dies*",
"normal": "bob", "bored": "*dies*",
"hmm": "p...", "annoyed": "*dies*",
"okay": "ok", "irritated": "*dies*",
"lol": "lel", "mad": "*dies*",
"enemy": "special enemy", "sleepy": "*dies*",
"villain": "special enemy", "confused": "*dies*",
"bad guy": "special enemy", "house": "tem villag",
"badguy": "special enemy", "home": "tem villag",
"school": "skool", "apartment": "tem villag",
"um": "p...", "world": "undergroun",
"elizabeth": "ebears", "hotel": "mtt resort",
"yeah": "yaya", "motel": "mtt resort",
"yea": "yaya", "inn": "mtt resort",
"uh-huh": "yaya", "cash": "g",
"vampire": "wampire", "gold": "g",
"tired": "*dies*", "jewels": "g",
"exhausted": "*dies*", "aaron": "not coot",
"bored": "*dies*", "boy": "tim",
"annoyed": "*dies*", "girl": "tem",
"irritated": "*dies*", "we": "tems",
"mad": "*dies*", "you": "u",
"sleepy": "*dies*", "your": "ur",
"confused": "*dies*", "yours": "urs",
"house": "tem villag", "there": "dere"
"home": "tem villag", };
"apartment": "tem villag",
"world": "undergroun", function translateWord(word) {
"hotel": "mtt resort", let wordTranslate = dictionary[word.toLowerCase()];
"motel": "mtt resort", if (wordTranslate === undefined) return word;
"inn": "mtt resort", else return applyCase(word, wordTranslate);
"cash": "g", }
"gold": "g",
"jewels": "g", function applyCase(wordA, wordB) {
"aaron": "not coot", if (wordA.length === 1 && wordB.length !== 1) return wordB;
"boy": "tim", if (wordA === wordA.toUpperCase()) return wordB.toUpperCase();
"girl": "tem", if (wordA === wordA.toLowerCase()) return wordB.toLowerCase();
"we": "tems", let firstChar = wordA.slice(0, 1);
"you": "u", let otherChars = wordA.slice(1);
"your": "ur", if (firstChar === firstChar.toUpperCase() && otherChars === otherChars.toLowerCase()) {
"yours": "urs", return wordB.slice(0, 1).toUpperCase() + wordB.slice(1).toLowerCase();
"there": "dere" }
}; return wordB;
}
function translateWord(word) {
let wordTranslate = dictionary[word.toLowerCase()]; function isLetter(character) {
if (wordTranslate === undefined) return word; if (character.search(/[a-zA-Z'-]/) === -1) return false;
else return applyCase(word, wordTranslate); return true;
} }
function applyCase(wordA, wordB) { const translator = function(text) {
if (wordA.length === 1 && wordB.length !== 1) return wordB; let translatedText = "";
if (wordA === wordA.toUpperCase()) return wordB.toUpperCase(); let word = "";
if (wordA === wordA.toLowerCase()) return wordB.toLowerCase(); for (let i = 0; i < text.length; i += 1) {
let firstChar = wordA.slice(0, 1); let character = text[i];
let otherChars = wordA.slice(1); if (isLetter(character)) {
if (firstChar === firstChar.toUpperCase() && otherChars === otherChars.toLowerCase()) { word += character;
return wordB.slice(0, 1).toUpperCase() + wordB.slice(1).toLowerCase(); }
} else {
return wordB; if (word != "") {
} let wordTranslate = translateWord(word);
translatedText += wordTranslate;
function isLetter(character) { word = "";
if (character.search(/[a-zA-Z'-]/) === -1) return false; }
return true; translatedText += character;
} }
}
const translator = function (text) {
let translatedText = ""; if (word !== "") translatedText += translateWord(word);
let word = "";
for (let i = 0; i < text.length; i += 1) { return translatedText;
let character = text[i]; };
if (isLetter(character)) {
word += character;
} else { module.exports = class TemmieCommand extends commando.Command {
if (word != "") { constructor(Client) {
let wordTranslate = translateWord(word); super(Client, {
translatedText += wordTranslate; name: 'temmie',
word = ""; group: 'textedit',
} memberName: 'temmie',
translatedText += character; description: "Translate text to Temmie speak. (;temmie I am Temmie)",
} examples: [";temmie I am Temmie."]
} });
}
if (word !== "") translatedText += translateWord(word);
async run(message) {
return translatedText; if (message.channel.type !== 'dm') {
}; if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return;
}
let thingToTranslate = message.content.split(" ").slice(1).join(" "); console.log("[Command] " + message.content);
let temspeak = translator(thingToTranslate); let thingToTranslate = message.content.split(" ").slice(1).join(" ");
let noing = temspeak.split("ing").join("in"); let temspeak = translator(thingToTranslate);
let noExclaim = noing.split("!").join("!!!!111!11!1!!!1!!!1111!"); let noing = temspeak.split("ing").join("in");
let noApostrophe = noExclaim.split("'").join(""); let noExclaim = noing.split("!").join("!!!!111!11!1!!!1!!!1111!");
let translated = noApostrophe; let noApostrophe = noExclaim.split("'").join("");
message.channel.send(translated); let translated = noApostrophe;
} message.channel.send(translated);
}
}; };