fbp-language 1.0.0 → 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 +24 -2
- package/dist/cli.js +1 -1
- package/dist/compiler.js +66 -0
- package/package.json +10 -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.
|
|
26
|
+
"fbp-language": "^1.1.2"
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
```
|
|
@@ -90,9 +90,31 @@ lance()
|
|
|
90
90
|
- `import { fonction } de "./fichier.fbp"` importe des fonctions.
|
|
91
91
|
- Les commentaires commencent par `//` ou `#`.
|
|
92
92
|
|
|
93
|
+
## Créer un bot Discord
|
|
94
|
+
|
|
95
|
+
Installe FBP dans le projet du bot, puis crée un fichier `.env` à la racine :
|
|
96
|
+
|
|
97
|
+
```env
|
|
98
|
+
DISCORD_TOKEN=ton_token_discord
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Ne partage jamais ce fichier et ajoute `.env` à `.gitignore`.
|
|
102
|
+
|
|
103
|
+
Dans `scripts/main.fbp` :
|
|
104
|
+
|
|
105
|
+
```fbp
|
|
106
|
+
discordConnexion()
|
|
107
|
+
discordCommande("ping", "Pong !")
|
|
108
|
+
discordCommande("bonjour", "Salut !")
|
|
109
|
+
```
|
|
110
|
+
|
|
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
|
+
|
|
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
|
+
|
|
93
115
|
## Limites actuelles
|
|
94
116
|
|
|
95
|
-
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
|
|
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.
|
|
96
118
|
|
|
97
119
|
## Développement du dépôt
|
|
98
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.
|
|
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
|
@@ -7,6 +7,8 @@ exports.FbpCompiler = void 0;
|
|
|
7
7
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
8
|
const node_path_1 = __importDefault(require("node:path"));
|
|
9
9
|
const errors_1 = require("./errors");
|
|
10
|
+
const discord_js_1 = require("discord.js");
|
|
11
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
|
10
12
|
function valueType(value) {
|
|
11
13
|
const v = value.trim();
|
|
12
14
|
if (/^"(?:[^"\\]|\\.)*"$/.test(v) || /^'(?:[^'\\]|\\.)*'$/.test(v))
|
|
@@ -105,6 +107,8 @@ class FbpCompiler {
|
|
|
105
107
|
functions = new Map();
|
|
106
108
|
imports = new Map();
|
|
107
109
|
output;
|
|
110
|
+
discordClient;
|
|
111
|
+
discordCommands = new Map();
|
|
108
112
|
constructor(options = {}) {
|
|
109
113
|
this.output = options.onOutput ?? (value => console.log(value));
|
|
110
114
|
}
|
|
@@ -173,6 +177,68 @@ class FbpCompiler {
|
|
|
173
177
|
this.output(values.map(value => value === undefined ? "" : String(value)).join(" "));
|
|
174
178
|
return;
|
|
175
179
|
}
|
|
180
|
+
if (name === "discordConnexion") {
|
|
181
|
+
if (this.discordClient)
|
|
182
|
+
throw new errors_1.FbpError("La connexion Discord est déjà initialisée.", undefined, line);
|
|
183
|
+
dotenv_1.default.config();
|
|
184
|
+
const token = process.env.DISCORD_TOKEN;
|
|
185
|
+
if (!token)
|
|
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] });
|
|
188
|
+
this.discordClient = client;
|
|
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)
|
|
218
|
+
return;
|
|
219
|
+
try {
|
|
220
|
+
await interaction.reply(response);
|
|
221
|
+
}
|
|
222
|
+
catch (error) {
|
|
223
|
+
this.output("Erreur Discord : " + (error instanceof Error ? error.message : String(error)));
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
void client.login(token).catch((error) => this.output("Connexion Discord impossible : " + (error instanceof Error ? error.message : String(error))));
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
if (name === "discordCommande") {
|
|
230
|
+
if (!this.discordClient)
|
|
231
|
+
throw new errors_1.FbpError("Appelle discordConnexion() avant de déclarer une commande.", undefined, line);
|
|
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]);
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
176
242
|
if (name === "ping") {
|
|
177
243
|
this.output("FBP fonctionne. Cette commande ne vérifie pas à elle seule une connexion Discord.");
|
|
178
244
|
return;
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fbp-language",
|
|
3
3
|
"displayName": "FBP - French Bot Programming",
|
|
4
|
-
"description": "
|
|
5
|
-
"version": "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",
|
|
@@ -42,5 +45,9 @@
|
|
|
42
45
|
"@types/node": "^22.10.0",
|
|
43
46
|
"ts-node": "^10.9.2",
|
|
44
47
|
"typescript": "^5.7.2"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"discord.js": "^14.19.3",
|
|
51
|
+
"dotenv": "^16.4.7"
|
|
45
52
|
}
|
|
46
53
|
}
|