From fc09c09af5d8bf429a9541d109b133ed60c0bf9e Mon Sep 17 00:00:00 2001 From: asanrom Date: Sat, 15 Oct 2016 17:50:26 +0200 Subject: [PATCH] Fix bugs with words-based games --- src/bot-modules/games/poke-games/poke-hangman.js | 4 ++-- src/bot-modules/games/wordgames/anagrams.translations | 2 +- src/bot-modules/games/wordgames/hangman.js | 4 ++-- src/tools/normalize.js | 9 +++++++-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/bot-modules/games/poke-games/poke-hangman.js b/src/bot-modules/games/poke-games/poke-hangman.js index 7bf3072..9a88f41 100644 --- a/src/bot-modules/games/poke-games/poke-hangman.js +++ b/src/bot-modules/games/poke-games/poke-hangman.js @@ -18,7 +18,7 @@ function isNotAlphanumeric(str) { function toWordId(str) { if (!str) return ''; - str = normalize(str); + str = normalize(str, true); return str.toLowerCase().replace(/[^a-z0-9\u00f1]/g, ''); } @@ -43,7 +43,7 @@ exports.setup = function (App) { this.ended = false; this.said = []; this.status = []; - let w = normalize(this.word).trim().toLowerCase(); + let w = normalize(this.word, true).trim().toLowerCase(); for (let i = 0; i < w.length; i++) { if (isNotAlphanumeric(w.charAt(i))) { this.status.push({type: 'sep', key: w.charAt(i)}); diff --git a/src/bot-modules/games/wordgames/anagrams.translations b/src/bot-modules/games/wordgames/anagrams.translations index 1b25703..0cf1bb6 100644 --- a/src/bot-modules/games/wordgames/anagrams.translations +++ b/src/bot-modules/games/wordgames/anagrams.translations @@ -49,7 +49,7 @@ $12 = adivinó la palabra. La palabra era $13 = Puntos $lose = Sin embargo nadie ha conseguido ningún punto, por lo que no hay ganadores -$end =¡ El juego de Anagrams ha terminado! +$end = ¡El juego de Anagrams ha terminado! $grats1 = Felicidades a $grats2 = por ganar el juego con $points = puntos diff --git a/src/bot-modules/games/wordgames/hangman.js b/src/bot-modules/games/wordgames/hangman.js index b66df5d..ae80515 100644 --- a/src/bot-modules/games/wordgames/hangman.js +++ b/src/bot-modules/games/wordgames/hangman.js @@ -18,7 +18,7 @@ function isNotAlphanumeric(str) { function toWordId(str) { if (!str) return ''; - str = normalize(str); + str = normalize(str, true); return str.toLowerCase().replace(/[^a-z0-9\u00f1]/g, ''); } @@ -42,7 +42,7 @@ exports.setup = function (App) { this.ended = false; this.said = []; this.status = []; - let w = normalize(this.word).trim().toLowerCase(); + let w = normalize(this.word, true).trim().toLowerCase(); for (let i = 0; i < w.length; i++) { if (isNotAlphanumeric(w.charAt(i))) { this.status.push({type: 'sep', key: w.charAt(i)}); diff --git a/src/tools/normalize.js b/src/tools/normalize.js index dbebec6..b94ebf1 100644 --- a/src/tools/normalize.js +++ b/src/tools/normalize.js @@ -21,15 +21,20 @@ const normalObj = normalize_init(); /** * Normalizes a string * @param {String} str + * @param {Boolean} noId * @returns {String} Normalized string */ -function normalize(str) { +function normalize(str, noId) { if (!str) return ''; let res = ''; for (let i = 0; i < str.length; i++) { res += normalObj[str.charAt(i)] ? normalObj[str.charAt(i)] : str.charAt(i); } - return Text.toId(res); + if (noId) { + return res; + } else { + return Text.toId(res); + } } module.exports = normalize;