diff --git a/module/misc.js b/module/misc.js
index 3334720a..e016508c 100644
--- a/module/misc.js
+++ b/module/misc.js
@@ -102,7 +102,7 @@ export class Misc {
}
static join(params, separator = '') {
- return params.reduce((a, b) => a + separator + b);
+ return params?.reduce((a, b) => a + separator + b) ?? '';
}
static connectedGMOrUser(ownerId = undefined) {
diff --git a/module/rdd-commands.js b/module/rdd-commands.js
index d124fedc..c9d8959d 100644
--- a/module/rdd-commands.js
+++ b/module/rdd-commands.js
@@ -39,21 +39,22 @@ export class RdDCommands {
rddCommands.registerCommand({ path: ["/meteo"], func: (content, msg, params) => rddCommands.getMeteo(msg, params), descr: "Propose une météo marine" });
rddCommands.registerCommand({ path: ["/nom"], func: (content, msg, params) => RdDNameGen.getName(msg, params), descr: "Génère un nom aléatoire" });
+ rddCommands.registerCommand({
+ path: ["/tmr"], func: (content, msg, params) => rddCommands.findTMR(msg, params),
+ descr: `Cherche où se trouve une case des Terres médianes
+
/tmr sord indique que la cité Sordide est en D13
+
/tmr foret donne la liste des TMR dont le nom contient "foret" (donc, toutes les forêts)` });
rddCommands.registerCommand({
path: ["/tmra"], func: (content, msg, params) => rddCommands.getTMRAleatoire(msg, params),
descr: `Tire une case aléatoire des Terres médianes
/tmra forêt détermine une 'forêt' aléatoire
/tmra détermine une case aléatoire dans toutes les TMR` });
- rddCommands.registerCommand({
- path: ["/tmr"], func: (content, msg, params) => rddCommands.findTMR(msg, params),
- descr: `Cherche où se trouve une case des Terres médianes
-
/tmr? sordide indique que la cité Sordide est en D13
-
/tmr? foret donne la liste des TMR dont le nom contient "foret" (donc, toutes les forêts)` });
rddCommands.registerCommand({
path: ["/tmrr"], func: (content, msg, params) => rddCommands.getRencontreTMR(params),
descr: `Détermine une rencontre dans un type de case
-
/tmrr foret lance un d100 et détermine la rencontre correspondante en 'forêt'
-
/tmrr forêt 47 détermine la rencontre en 'forêt' pour un jet de dé de 47`
+
/tmrr forêt détermine une rencontre aléatoire en 'forêt'
+
/tmrr mauvaise détermine une mauvaise rencontre aléatoire
+
/tmrr for 47 détermine la rencontre en 'forêt' pour un jet de dé de 47`
});
rddCommands.registerCommand({
@@ -84,7 +85,7 @@ export class RdDCommands {
rddCommands.registerCommand({
path: ["/payer"], func: (content, msg, params) => RdDUtility.afficherDemandePayer(params[0], params[1]),
- descr: `Permet de payer un montant. Exemples:
+ descr: `Demande aux joueurs de payer un montant. Exemples:
/payer 5s 10d permet d'envoyer un message pour payer 5 sols et 10 deniers
/payer 10d permet d'envoyer un message pour payer 10 deniers`
});
@@ -180,7 +181,7 @@ export class RdDCommands {
return this._processCommand(this.commandsTable, command, params, content, msg);
}
- _processCommand(commandsTable, name, params, content = '', msg = {}, path = "") {
+ async _processCommand(commandsTable, name, params, content = '', msg = {}, path = "") {
let command = commandsTable[name];
path = path + name + " ";
if (command && command.subTable) {
@@ -193,7 +194,7 @@ export class RdDCommands {
}
}
if (command && command.func) {
- const result = command.func(content, msg, params);
+ const result = await command.func(content, msg, params);
if (result == false) {
RdDCommands._chatAnswer(msg, command.descr);
}
@@ -250,9 +251,7 @@ export class RdDCommands {
if (params.length == 1 || params.length == 2) {
return TMRRencontres.rollRencontre(params[0], params[1])
}
- else {
- return false;
- }
+ return false;
}
/* -------------------------------------------- */
@@ -305,20 +304,20 @@ export class RdDCommands {
show: { title: "Table de résolution" }
};
await RdDResolutionTable.rollData(rollData);
- RdDCommands._chatAnswer(msg, await RdDResolutionTable.buildRollDataHtml(rollData));
+ return RdDCommands._chatAnswer(msg, await RdDResolutionTable.buildRollDataHtml(rollData));
}
/* -------------------------------------------- */
async rollDeDraconique(msg) {
let ddr = await RdDDice.rollTotal("1dr + 7");
- RdDCommands._chatAnswer(msg, `Lancer d'un Dé draconique: ${ddr}`);
+ return RdDCommands._chatAnswer(msg, `Lancer d'un Dé draconique: ${ddr}`);
}
async getTMRAleatoire(msg, params) {
if (params.length < 2) {
let type = params[0];
const tmr = await TMRUtility.getTMRAleatoire(type ? (it => it.type == type) : (it => true));
- RdDCommands._chatAnswer(msg, `Case aléatoire: ${tmr.coord} - ${tmr.label}`);
+ return RdDCommands._chatAnswer(msg, `Case aléatoire: ${tmr.coord} - ${tmr.label}`);
}
else {
return false;
@@ -326,12 +325,15 @@ export class RdDCommands {
}
async findTMR(msg, params) {
- const search = Misc.join(params, ' ');
- const found = TMRUtility.findTMR(search);
- if (found?.length > 0) {
- return RdDCommands._chatAnswer(msg, `Les TMRs correspondant à '${search}' sont:` + Misc.join(found.map(it => `
${it.coord}: ${it.label}`)));
+ if (params && params.length > 0) {
+ const search = Misc.join(params, ' ');
+ const found = TMRUtility.findTMR(search);
+ if (found?.length > 0) {
+ return RdDCommands._chatAnswer(msg, `Les TMRs correspondant à '${search}' sont:` + Misc.join(found.map(it => `
${it.coord}: ${it.label}`)));
+ }
+ return RdDCommands._chatAnswer(msg, 'Aucune TMR correspondant à ' + search);
}
- return RdDCommands._chatAnswer(msg, 'Aucune TMR correspondant à ' + search);
+ return false;
}
/* -------------------------------------------- */
@@ -339,7 +341,7 @@ export class RdDCommands {
if (params && (params.length == 1 || params.length == 2)) {
let to = params.length == 1 ? Number(params[0]) : Number(params[1]);
let from = params.length == 1 ? to - 1 : Number(params[0]);
- RdDCommands._chatAnswer(msg, `Coût pour passer une compétence de ${from} à ${to}: ${RdDItemCompetence.getDeltaXp(from, to)}`);
+ return RdDCommands._chatAnswer(msg, `Coût pour passer une compétence de ${from} à ${to}: ${RdDItemCompetence.getDeltaXp(from, to)}`);
}
else {
return false;
@@ -350,7 +352,7 @@ export class RdDCommands {
getCoutXpCarac(msg, params) {
if (params && params.length == 1) {
let to = Number(params[0]);
- RdDCommands._chatAnswer(msg, `Coût pour passer une caractéristique de ${to - 1} à ${to}: ${RdDCarac.getCaracXp(to)}`);
+ return RdDCommands._chatAnswer(msg, `Coût pour passer une caractéristique de ${to - 1} à ${to}: ${RdDCarac.getCaracXp(to)}`);
}
else {
return false;
diff --git a/module/tmr-utility.js b/module/tmr-utility.js
index 92b59377..66ab857b 100644
--- a/module/tmr-utility.js
+++ b/module/tmr-utility.js
@@ -355,8 +355,7 @@ export class TMRUtility {
}
static findTMR(search) {
- const labelSearch = Grammar.toLowerCaseNoAccent(search)
- return TMRUtility.filterTMR(it => Grammar.toLowerCaseNoAccent(it.label).match(labelSearch) || it.coord == search);
+ return TMRUtility.filterTMR(it => Grammar.includesLowerCaseNoAccent(it.label, search) || it.coord == search);
}
static filterTMRCoord(filter) {