fbp-language 1.0.0 → 1.1.1
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 +32 -0
- package/package.json +6 -2
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.1"
|
|
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, active **Message Content Intent**.
|
|
112
|
+
|
|
113
|
+
Les commandes texte exactes sont prises en charge pour l'instant. Les commandes slash ne le sont pas encore.
|
|
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, les paramètres et les 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.1";
|
|
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,34 @@ 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, discord_js_1.GatewayIntentBits.GuildMessages, discord_js_1.GatewayIntentBits.MessageContent] });
|
|
188
|
+
this.discordClient = client;
|
|
189
|
+
client.once("ready", () => this.output("Connecté à Discord en tant que " + (client.user?.tag ?? "bot") + "."));
|
|
190
|
+
client.on("messageCreate", (message) => {
|
|
191
|
+
if (message.author.bot || !message.guild)
|
|
192
|
+
return;
|
|
193
|
+
const response = this.discordCommands.get(message.content);
|
|
194
|
+
if (response !== undefined)
|
|
195
|
+
void message.reply(response).catch((error) => this.output("Erreur Discord : " + (error instanceof Error ? error.message : String(error))));
|
|
196
|
+
});
|
|
197
|
+
void client.login(token).catch((error) => this.output("Connexion Discord impossible : " + (error instanceof Error ? error.message : String(error))));
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
if (name === "discordCommande") {
|
|
201
|
+
if (!this.discordClient)
|
|
202
|
+
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(\"!ping\", \"Pong !\").", undefined, line);
|
|
205
|
+
this.discordCommands.set(values[0], values[1]);
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
176
208
|
if (name === "ping") {
|
|
177
209
|
this.output("FBP fonctionne. Cette commande ne vérifie pas à elle seule une connexion Discord.");
|
|
178
210
|
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 bots Discord.",
|
|
5
|
+
"version": "1.1.1",
|
|
6
6
|
"type": "commonjs",
|
|
7
7
|
"main": "dist/compiler.js",
|
|
8
8
|
"bin": {
|
|
@@ -42,5 +42,9 @@
|
|
|
42
42
|
"@types/node": "^22.10.0",
|
|
43
43
|
"ts-node": "^10.9.2",
|
|
44
44
|
"typescript": "^5.7.2"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"discord.js": "^14.19.3",
|
|
48
|
+
"dotenv": "^16.4.7"
|
|
45
49
|
}
|
|
46
50
|
}
|