This repository was archived by the owner on Sep 11, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenus.js
More file actions
111 lines (106 loc) · 3.94 KB
/
menus.js
File metadata and controls
111 lines (106 loc) · 3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import * as pronote from "pawnote";
import * as dotenv from 'dotenv';
dotenv.config()
function sendWebhook(json, webhook) {
const labels = {
"Fait maison - Recette du chef": "<:maison:1291900933881729054>",
"Assemblé sur place": "<:assembl:1291900930807042099>",
"Issu de l'Agriculture Biologique": "<:bio:1291900935769030791>",
"Produits locaux": "<:locaux:1291900932145287219>"
};
function getLabels(item) {
return item.labels.map(label => labels[label.name] || "").join(" ");
}
const name_midi = json.lunch.name ? " "+json.lunch.name : "";
const entree_midi = json.lunch.entry ? json.lunch.entry.map(item => `${item.name} ${getLabels(item)}`).join("\n- ") : "⛔";
const plat_midi = json.lunch.main ? json.lunch.main.map(item => `${item.name} ${getLabels(item)}`).join("\n- ") : "⛔";
const accompagnement_midi = json.lunch.side ? json.lunch.side.map(item => `${item.name} ${getLabels(item)}`).join("\n- ") : "⛔";
const vegetarien_midi = json.lunch.drink ? json.lunch.drink.map(item => `${item.name} ${getLabels(item)}`).join("\n- ") : "⛔";
const fromage_midi = json.lunch.fromage ? json.lunch.fromage.map(item => `${item.name} ${getLabels(item)}`).join("\n- ") : "⛔";
const dessert_midi = json.lunch.dessert ? json.lunch.dessert.map(item => `${item.name} ${getLabels(item)}`).join("\n- ") : "⛔";
fetch(webhook, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
"content": "<@&1291906995678351470>\n# Menu du jour !\n-# Fait maison - Recette du chef : <:maison:1291900933881729054> | Assemblé sur place : <:assembl:1291900930807042099> \n-# Issu de l'Agriculture Biologique : <:bio:1291900935769030791> | Produits locaux : <:locaux:1291900932145287219>",
"embeds": [
{
"description": `## Repas du midi / ${name_midi}`,
"color": 37143,
"fields": [
{
"name": "🥗 Entrée :",
"value": `- ${entree_midi}`,
"inline": true
},
{
"name": "🥘 Plat :",
"value": `- ${plat_midi}`,
"inline": true
},
{
"name": "🥔 Accompagnement :",
"value": `- ${accompagnement_midi}`,
"inline": true
},
{
"name": "🥕 Végétarien :",
"value": `- ${vegetarien_midi}`,
"inline": true
},
{
"name": "🧀 Fromage :",
"value": `- ${fromage_midi}`,
"inline": true
},
{
"name": "🍰 Dessert :",
"value": `- ${dessert_midi}`,
"inline": true
}
],
"footer": {
"text": "🍽 Bon appétit !"
}
}
]
})
})
}
(async function () {
const session = pronote.createSessionHandle();
await pronote.loginCredentials(session, {
url: process.env.PRN_URL,
deviceUUID: process.env.PRN_UUID,
kind: pronote.AccountKind.STUDENT,
username: process.env.PRN_USERNAME,
password: process.env.PRN_PASSWORD,
});
const menus = await pronote.menus(session, new Date());
const today = new Date();
const todayMenu = menus.days.find(day => {
const menuDate = new Date(day.date);
return (
menuDate.getFullYear() === today.getFullYear() &&
menuDate.getMonth() === today.getMonth() &&
menuDate.getDate() === today.getDate()
);
});
if (todayMenu) {
console.log(todayMenu);
sendWebhook(todayMenu, process.env.DISCORD_WEBHOOK_MENU);
} else {
console.log("Pas de menu pour aujourd'hui.");
fetch(process.env.DISCORD_WEBHOOK_MENU, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
"content": "Ce matin, j'ai eu une révélation : il n'y a pas de menu pour aujourd'hui. 😱",
})
});
}
})();