fbp-language 1.1.1 → 1.1.2
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 +6 -6
- package/dist/cli.js +1 -1
- package/dist/compiler.js +44 -10
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ Puis, dans le `package.json` de ton projet :
|
|
|
23
23
|
"start": "fbp run lancer"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"fbp-language": "^1.1.
|
|
26
|
+
"fbp-language": "^1.1.2"
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
```
|
|
@@ -104,17 +104,17 @@ Dans `scripts/main.fbp` :
|
|
|
104
104
|
|
|
105
105
|
```fbp
|
|
106
106
|
discordConnexion()
|
|
107
|
-
discordCommande("
|
|
108
|
-
discordCommande("
|
|
107
|
+
discordCommande("ping", "Pong !")
|
|
108
|
+
discordCommande("bonjour", "Salut !")
|
|
109
109
|
```
|
|
110
110
|
|
|
111
|
-
Associe `lancer` à `scripts/main.fbp` dans `commandes.fbp`, puis exécute `npx fbp run lancer`. Dans le portail développeur Discord,
|
|
111
|
+
Associe `lancer` à `scripts/main.fbp` dans `commandes.fbp`, puis exécute `npx fbp run lancer`. Dans le portail développeur Discord, vérifie que le bot est invité sur ton serveur avec les scopes `bot` et `applications.commands`. Seul l'intent serveur (`Guilds`) est nécessaire.
|
|
112
112
|
|
|
113
|
-
|
|
113
|
+
FBP enregistre les commandes déclarées comme commandes slash globales de l'application Discord. Leur apparition peut prendre un peu de temps après le premier enregistrement. Les noms doivent contenir de 1 à 32 caractères parmi les lettres minuscules, chiffres, tirets et underscores.
|
|
114
114
|
|
|
115
115
|
## Limites actuelles
|
|
116
116
|
|
|
117
|
-
FBP est encore un interpréteur de base. Les paramètres de fonction, les conditions, les boucles, les valeurs de retour et les expressions arithmétiques ne sont pas encore implémentés. La connexion Discord utilise un token stocké dans `.env`. Les commandes slash
|
|
117
|
+
FBP est encore un interpréteur de base. Les paramètres de fonction, les conditions, les boucles, les valeurs de retour et les expressions arithmétiques ne sont pas encore implémentés. La connexion Discord utilise un token stocké dans `.env`. Les commandes slash répondent avec un texte fixe ; les options, paramètres, permissions avancées et conditions ne sont pas encore implémentés.
|
|
118
118
|
|
|
119
119
|
## Développement du dépôt
|
|
120
120
|
|
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.2";
|
|
12
12
|
function help() {
|
|
13
13
|
console.log(`FBP — French Bot Programming
|
|
14
14
|
|
package/dist/compiler.js
CHANGED
|
@@ -184,15 +184,44 @@ class FbpCompiler {
|
|
|
184
184
|
const token = process.env.DISCORD_TOKEN;
|
|
185
185
|
if (!token)
|
|
186
186
|
throw new errors_1.FbpError("Token Discord manquant. Ajoute DISCORD_TOKEN dans le fichier .env.", undefined, line);
|
|
187
|
-
const client = new discord_js_1.Client({ intents: [discord_js_1.GatewayIntentBits.Guilds
|
|
187
|
+
const client = new discord_js_1.Client({ intents: [discord_js_1.GatewayIntentBits.Guilds] });
|
|
188
188
|
this.discordClient = client;
|
|
189
|
-
client.once("ready", () =>
|
|
190
|
-
|
|
191
|
-
|
|
189
|
+
client.once("ready", async () => {
|
|
190
|
+
try {
|
|
191
|
+
const commands = [...this.discordCommands.entries()].map(([commandName]) => new discord_js_1.SlashCommandBuilder()
|
|
192
|
+
.setName(commandName)
|
|
193
|
+
.setDescription(`Commande ${commandName} du bot FBP`)
|
|
194
|
+
.toJSON());
|
|
195
|
+
const manager = client.application?.commands;
|
|
196
|
+
if (!manager)
|
|
197
|
+
throw new Error("L'application Discord n'est pas disponible.");
|
|
198
|
+
const existing = await manager.fetch();
|
|
199
|
+
for (const command of commands) {
|
|
200
|
+
const registered = existing.find(item => item.name === command.name);
|
|
201
|
+
if (registered)
|
|
202
|
+
await manager.edit(registered.id, command);
|
|
203
|
+
else
|
|
204
|
+
await manager.create(command);
|
|
205
|
+
}
|
|
206
|
+
this.output("Connecté à Discord en tant que " + (client.user?.tag ?? "bot") + ".");
|
|
207
|
+
this.output("Commandes slash FBP enregistrées : " + commands.length + ".");
|
|
208
|
+
}
|
|
209
|
+
catch (error) {
|
|
210
|
+
this.output("Enregistrement des commandes slash impossible : " + (error instanceof Error ? error.message : String(error)));
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
client.on("interactionCreate", async (interaction) => {
|
|
214
|
+
if (!interaction.isChatInputCommand())
|
|
215
|
+
return;
|
|
216
|
+
const response = this.discordCommands.get(interaction.commandName);
|
|
217
|
+
if (response === undefined)
|
|
192
218
|
return;
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
219
|
+
try {
|
|
220
|
+
await interaction.reply(response);
|
|
221
|
+
}
|
|
222
|
+
catch (error) {
|
|
223
|
+
this.output("Erreur Discord : " + (error instanceof Error ? error.message : String(error)));
|
|
224
|
+
}
|
|
196
225
|
});
|
|
197
226
|
void client.login(token).catch((error) => this.output("Connexion Discord impossible : " + (error instanceof Error ? error.message : String(error))));
|
|
198
227
|
return;
|
|
@@ -200,9 +229,14 @@ class FbpCompiler {
|
|
|
200
229
|
if (name === "discordCommande") {
|
|
201
230
|
if (!this.discordClient)
|
|
202
231
|
throw new errors_1.FbpError("Appelle discordConnexion() avant de déclarer une commande.", undefined, line);
|
|
203
|
-
if (values.length !== 2 || typeof values[0] !== "string" || typeof values[1] !== "string")
|
|
204
|
-
throw new errors_1.FbpError("Utilisation : discordCommande(\"
|
|
205
|
-
|
|
232
|
+
if (values.length !== 2 || typeof values[0] !== "string" || typeof values[1] !== "string") {
|
|
233
|
+
throw new errors_1.FbpError("Utilisation : discordCommande(\"ping\", \"Pong !\").", undefined, line);
|
|
234
|
+
}
|
|
235
|
+
const commandName = values[0];
|
|
236
|
+
if (!/^[a-z0-9_-]{1,32}$/.test(commandName)) {
|
|
237
|
+
throw new errors_1.FbpError("Le nom d'une commande slash doit contenir 1 à 32 caractères : lettres minuscules, chiffres, tirets ou underscores.", undefined, line);
|
|
238
|
+
}
|
|
239
|
+
this.discordCommands.set(commandName, values[1]);
|
|
206
240
|
return;
|
|
207
241
|
}
|
|
208
242
|
if (name === "ping") {
|
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 prise en charge des
|
|
5
|
-
"version": "1.1.
|
|
4
|
+
"description": "Langage FBP avec prise en charge des commandes slash Discord.",
|
|
5
|
+
"version": "1.1.2",
|
|
6
6
|
"type": "commonjs",
|
|
7
7
|
"main": "dist/compiler.js",
|
|
8
8
|
"bin": {
|
|
@@ -25,7 +25,10 @@
|
|
|
25
25
|
"language",
|
|
26
26
|
"interpreter",
|
|
27
27
|
"french",
|
|
28
|
-
"cli"
|
|
28
|
+
"cli",
|
|
29
|
+
"discord",
|
|
30
|
+
"slash-commands",
|
|
31
|
+
"bot"
|
|
29
32
|
],
|
|
30
33
|
"scripts": {
|
|
31
34
|
"build": "tsc -p tsconfig.json",
|