fbp-language 1.1.6 → 1.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -0
- package/dist/cli.js +1 -1
- package/dist/compiler.js +31 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -200,3 +200,24 @@ discordChoixEntier("difficulte", "niveau", "Difficile", 3)
|
|
|
200
200
|
- Déclare toujours l'option avant ses choix.
|
|
201
201
|
- Une option peut avoir jusqu'à 25 choix. Les noms de choix sont limités à 100 caractères.
|
|
202
202
|
- Les choix sont présentés par Discord sous forme de liste et la valeur choisie est récupérable comme les autres options.
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
## Limites numériques des options (v1.1.7)
|
|
206
|
+
|
|
207
|
+
Les options slash de type nombre et entier peuvent imposer une valeur minimale et maximale. Déclare l'option d'abord, puis ses limites :
|
|
208
|
+
|
|
209
|
+
```fbp
|
|
210
|
+
discordConnexion()
|
|
211
|
+
discordCommande("age", "Âge sélectionné : {{age}}")
|
|
212
|
+
discordOptionEntier("age", "age", "Choisis un âge", true)
|
|
213
|
+
discordOptionEntierLimites("age", "age", 13, 99)
|
|
214
|
+
|
|
215
|
+
discordCommande("note", "Note sélectionnée : {{note}}")
|
|
216
|
+
discordOptionNombre("note", "note", "Choisis une note", true)
|
|
217
|
+
discordOptionNombreLimites("note", "note", 0, 20)
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
- `discordOptionEntierLimites(commande, option, minimum, maximum)` accepte uniquement des bornes entières.
|
|
221
|
+
- `discordOptionNombreLimites(commande, option, minimum, maximum)` accepte des bornes numériques, y compris décimales.
|
|
222
|
+
- Le minimum doit être inférieur ou égal au maximum.
|
|
223
|
+
- Les limites s'appliquent à l'interface Discord. Une option avec des choix prédéfinis ne peut pas recevoir de limites.
|
package/dist/cli.js
CHANGED
|
@@ -8,7 +8,7 @@ const node_fs_1 = __importDefault(require("node:fs"));
|
|
|
8
8
|
const node_path_1 = __importDefault(require("node:path"));
|
|
9
9
|
const compiler_1 = require("./compiler");
|
|
10
10
|
const errors_1 = require("./errors");
|
|
11
|
-
const VERSION = "1.1.
|
|
11
|
+
const VERSION = "1.1.7";
|
|
12
12
|
function help() {
|
|
13
13
|
console.log(`FBP — French Bot Programming
|
|
14
14
|
|
package/dist/compiler.js
CHANGED
|
@@ -231,6 +231,10 @@ class FbpCompiler {
|
|
|
231
231
|
}),
|
|
232
232
|
nombre: () => builder.addNumberOption(item => {
|
|
233
233
|
item.setName(option.name).setDescription(option.description).setRequired(option.required);
|
|
234
|
+
if (option.minValue !== undefined)
|
|
235
|
+
item.setMinValue(option.minValue);
|
|
236
|
+
if (option.maxValue !== undefined)
|
|
237
|
+
item.setMaxValue(option.maxValue);
|
|
234
238
|
for (const choice of option.choices ?? [])
|
|
235
239
|
if (typeof choice.value === "number")
|
|
236
240
|
item.addChoices({ name: choice.name, value: choice.value });
|
|
@@ -238,6 +242,10 @@ class FbpCompiler {
|
|
|
238
242
|
}),
|
|
239
243
|
entier: () => builder.addIntegerOption(item => {
|
|
240
244
|
item.setName(option.name).setDescription(option.description).setRequired(option.required);
|
|
245
|
+
if (option.minValue !== undefined)
|
|
246
|
+
item.setMinValue(option.minValue);
|
|
247
|
+
if (option.maxValue !== undefined)
|
|
248
|
+
item.setMaxValue(option.maxValue);
|
|
241
249
|
for (const choice of option.choices ?? [])
|
|
242
250
|
if (typeof choice.value === "number")
|
|
243
251
|
item.addChoices({ name: choice.name, value: choice.value });
|
|
@@ -396,6 +404,8 @@ class FbpCompiler {
|
|
|
396
404
|
throw new errors_1.FbpError("La valeur d'un choix texte doit être du texte.", undefined, line);
|
|
397
405
|
if (expectedType === "entier" && (typeof choiceValue !== "number" || !Number.isInteger(choiceValue)))
|
|
398
406
|
throw new errors_1.FbpError("La valeur d'un choix entier doit être un nombre entier.", undefined, line);
|
|
407
|
+
if (option.minValue !== undefined || option.maxValue !== undefined)
|
|
408
|
+
throw new errors_1.FbpError("Une option avec des limites numériques ne peut pas recevoir de choix prédéfinis.", undefined, line);
|
|
399
409
|
const choices = option.choices ?? (option.choices = []);
|
|
400
410
|
if (choices.some(choice => choice.name === choiceName || choice.value === choiceValue))
|
|
401
411
|
throw new errors_1.FbpError("Ce nom ou cette valeur de choix existe déjà.", undefined, line);
|
|
@@ -404,6 +414,27 @@ class FbpCompiler {
|
|
|
404
414
|
choices.push({ name: choiceName, value: choiceValue });
|
|
405
415
|
return;
|
|
406
416
|
}
|
|
417
|
+
if (name === "discordOptionNombreLimites" || name === "discordOptionEntierLimites") {
|
|
418
|
+
if (values.length !== 4 || typeof values[0] !== "string" || typeof values[1] !== "string" || typeof values[2] !== "number" || typeof values[3] !== "number") {
|
|
419
|
+
throw new errors_1.FbpError("Utilisation : discordOptionNombreLimites(commande, option, minimum, maximum) ou discordOptionEntierLimites(...).", undefined, line);
|
|
420
|
+
}
|
|
421
|
+
const [commandName, optionName, minimum, maximum] = values;
|
|
422
|
+
const command = this.discordCommands.get(commandName);
|
|
423
|
+
if (!command)
|
|
424
|
+
throw new errors_1.FbpError("La commande « " + commandName + " » n'est pas déclarée.", undefined, line);
|
|
425
|
+
const expectedType = name === "discordOptionNombreLimites" ? "nombre" : "entier";
|
|
426
|
+
const option = (command.options ?? []).find(item => item.name === optionName);
|
|
427
|
+
if (!option || option.type !== expectedType)
|
|
428
|
+
throw new errors_1.FbpError("L'option « " + optionName + " » n'existe pas ou n'a pas le type numérique attendu.", undefined, line);
|
|
429
|
+
if (!Number.isFinite(minimum) || !Number.isFinite(maximum) || minimum > maximum || (expectedType === "entier" && (!Number.isInteger(minimum) || !Number.isInteger(maximum)))) {
|
|
430
|
+
throw new errors_1.FbpError("Les limites doivent être des nombres valides, minimum inférieur ou égal au maximum ; elles doivent être entières pour une option entière.", undefined, line);
|
|
431
|
+
}
|
|
432
|
+
if (option.choices?.length)
|
|
433
|
+
throw new errors_1.FbpError("Une option avec des choix prédéfinis ne peut pas recevoir de limites numériques.", undefined, line);
|
|
434
|
+
option.minValue = minimum;
|
|
435
|
+
option.maxValue = maximum;
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
407
438
|
if (name === "discordOptionTexte" || name === "discordOptionNombre" || name === "discordOptionEntier" || name === "discordOptionBooleen") {
|
|
408
439
|
if (values.length < 3 || values.length > 4 || values.some(value => typeof value !== "string" && typeof value !== "boolean")) {
|
|
409
440
|
throw new errors_1.FbpError("Utilisation : discordOptionTexte/Nombre/Entier/Booleen(nomCommande, nomOption, description, obligatoire).", undefined, line);
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fbp-language",
|
|
3
3
|
"displayName": "FBP - French Bot Programming",
|
|
4
|
-
"description": "Langage FBP avec options slash Discord, choix prédéfinis et embeds dynamiques.",
|
|
5
|
-
"version": "1.1.
|
|
4
|
+
"description": "Langage FBP avec options slash Discord, limites numériques, choix prédéfinis et embeds dynamiques.",
|
|
5
|
+
"version": "1.1.7",
|
|
6
6
|
"type": "commonjs",
|
|
7
7
|
"main": "dist/compiler.js",
|
|
8
8
|
"bin": {
|