Skip to content

Commit

Permalink
Fix bugs with words-based games
Browse files Browse the repository at this point in the history
  • Loading branch information
AgustinSRG committed Oct 15, 2016
1 parent 144415e commit fc09c09
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/bot-modules/games/poke-games/poke-hangman.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, '');
}

Expand All @@ -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)});
Expand Down
2 changes: 1 addition & 1 deletion src/bot-modules/games/wordgames/anagrams.translations
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/bot-modules/games/wordgames/hangman.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, '');
}

Expand All @@ -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)});
Expand Down
9 changes: 7 additions & 2 deletions src/tools/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit fc09c09

Please sign in to comment.