Skip to content

Commit bdc5af9

Browse files
committed
Mise à jour de la 5.1.0
- Correction de bugs sur le maximum de fichier et d'embeds supporté par Discord - Ajout du status du cours lorsque ce n'est pas noté "Cours annulé" - Changement de logo lors d'un cours annulé pour ne pas confondre avec des devoirs - Suppression de cours sur le même horaire. Seul le cours pas annulé reste
1 parent 24cd11d commit bdc5af9

File tree

5 files changed

+157
-39
lines changed

5 files changed

+157
-39
lines changed

commands/contenu.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,31 @@ module.exports = {
108108
});
109109
}
110110

111-
await interaction.editReply({embeds: [embed], components: components, files: attachments, fetchReply: true});
111+
// In the case of more than 10 attachments: send the attachments in more in other messages
112+
const finalAttachments = []
113+
if (attachments.length > 10) {
114+
let i = 10;
115+
while (i < attachments.length) {
116+
interaction.channel.send({files: attachments.slice(i, i + 10)}).then(m => {
117+
finalAttachments.concat(m.attachments);
118+
});
119+
i += 10;
120+
}
121+
}
122+
123+
124+
125+
await interaction.editReply({embeds: [embed], components: components, files: attachments.splice(0, 10), fetchReply: true});
112126

113127
if (files.length > 0) {
114128
const e = await interaction.fetchReply();
129+
finalAttachments.concat(e.attachments);
115130
let string = "";
116131
if (files.length > 0) {
117132
await client.functions.asyncForEach(files, async (file) => {
118133
if (file.type === "file") {
119134
const name = client.functions.setFileName(file.name);
120-
const attachment = e.attachments.find(a => a.name === name);
135+
const attachment = finalAttachments.find(a => a.name === name);
121136
if (attachment) {
122137
string += `[${file.name}](${attachment.url})\n`;
123138
}

commands/cours.js

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
const { EmbedBuilder, ApplicationCommandOptionType, SelectMenuBuilder, ActionRowBuilder } = require("discord.js");
22

3+
function isLessonInInterval(lesson, from, to) {
4+
return lesson.from >= from && lesson.from <= to;
5+
}
6+
37

48
module.exports = {
59
data: {
@@ -24,32 +28,63 @@ module.exports = {
2428

2529
await client.session.timetable(date).then((cours) => {
2630
let totalDuration = 0;
27-
cours.forEach((cours) => {
28-
totalDuration += cours.to.getTime() - cours.from.getTime();
29-
});
30-
totalDuration = Math.abs(totalDuration / 1000 / 60 / 60);
31-
const embed = new EmbedBuilder()
32-
.setColor("#70C7A4")
33-
.setTitle("Vous avez " + cours.length + " cours "+ ( dateUser ? `le \`${dateUser}\`` : "aujourd'hui") +" :")
34-
.setDescription("Durée totale : **" + totalDuration + "h**");
3531

36-
const embedCours = cours.map((cour) => {
32+
let embedCours = cours.map((cour) => {
33+
// Ne pas afficher les cours si jamais ils sont annulés et qu'ils sont remplacés par un autre cours dont les horaires sont inclus par un autre cours
34+
if (cour.isCancelled && cours.find((c) => isLessonInInterval(c, cour.from, cour.to) && !c.isCancelled)) {
35+
return;
36+
}
37+
totalDuration += cour.to.getTime() - cour.from.getTime();
38+
3739
const subHomeworks = client.cache.homeworks.filter(h => h.subject === cour.subject && cour.from.getDate()+"/"+cour.from.getMonth() === h.for.getDate()+"/"+h.for.getMonth());
38-
return new EmbedBuilder()
40+
const coursIsAway = cour.isAway || cour.isCancelled || cour.status?.match(/(.+)?prof(.+)?absent(.+)?/giu) || cour.status == "Cours annulé";
41+
const embed = new EmbedBuilder()
3942
.setColor(cour.color ?? "#70C7A4")
4043
.setAuthor({
41-
name: cour.subject,
44+
name: cour.subject ?? (cour.status ?? "Non défini"),
4245
})
43-
.setDescription("Professeur: **" + cour.teacher + "**" +
46+
.setDescription("Professeur: **" + (cour.teacher ?? "*Non précisé*") + "**" +
4447
"\nSalle: `" + (cour.room ?? " ? ") + "`" +
4548
"\nDe **" + cour.from.toLocaleTimeString().split(":")[0] +
4649
"h" + cour.from.toLocaleTimeString().split(":")[1] + "**" +
4750
" à **" + cour.to.toLocaleTimeString().split(":")[0] +
4851
"h" + cour.to.toLocaleTimeString().split(":")[1] + "**" +
4952
" *(" + (cour.to.getTime() - cour.from.getTime()) / 1000 / 60 / 60 + "h)*" +
50-
(subHomeworks.length && ((cour.isCancelled || cour.isAway) && cours.hasDuplicate) ? `\n⚠**__\`${subHomeworks.length}\` Devoirs__**` : "") +
51-
((cour.isCancelled || cour.isAway) && cours.hasDuplicate ? "\n⚠__**Cour annulé**__" : ""));
52-
});
53+
(subHomeworks.length && !coursIsAway ? `\n⚠**__\`${subHomeworks.length}\` Devoirs__**` : "") +
54+
(coursIsAway ? "\n🚫__**Cour annulé**__" : ""));
55+
56+
if (cour.status && (!coursIsAway || cour.statut !== "Cours annulé")) {
57+
embed.addFields([
58+
{
59+
name: "Status",
60+
value: "__**" + cour.status + "**__"
61+
}
62+
]);
63+
}
64+
return embed;
65+
}).filter(emb => !!emb);
66+
67+
if (embedCours.length >= 9) {
68+
const embed = new EmbedBuilder()
69+
.setColor("#70C7A4")
70+
.addFields(
71+
embedCours.map((emb) => {
72+
return {
73+
name: emb.author.name,
74+
value: emb.description,
75+
inline: false
76+
}
77+
})
78+
)
79+
embedCours = [embed];
80+
}
81+
82+
totalDuration = Math.abs(totalDuration / 1000 / 60 / 60);
83+
const embed = new EmbedBuilder()
84+
.setColor("#70C7A4")
85+
.setTitle("Vous avez " + embedCours.length + " cours "+ ( dateUser ? `le \`${dateUser}\`` : "aujourd'hui") +" :")
86+
.setDescription("Durée totale : **" + totalDuration + "h**");
87+
5388
const current = new Date(date.getTime());
5489
const week = [];
5590
for (let i = 1; i <= 7; i++) {
@@ -73,7 +108,7 @@ module.exports = {
73108
.setMaxValues(1)
74109
.setMinValues(1);
75110

76-
return interaction.editReply({ embeds: [embed].concat(embedCours), components: [new ActionRowBuilder().addComponents(selectMenu)] });
111+
return interaction.editReply({ embeds: [embed].concat(embedCours.filter(emb => !!emb)), components: [new ActionRowBuilder().addComponents(selectMenu)] });
77112
});
78113
},
79114
};

events/selectMenu.js

Lines changed: 55 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ const generateCanvas = async (joinedXDays, lastXDays) => {
4242
});
4343
};
4444

45+
function isLessonInInterval(lesson, from, to) {
46+
return lesson.from >= from && lesson.from <= to;
47+
}
48+
4549
const pronote = require("pronote-api-maintained");
4650
const {NodeHtmlMarkdown} = require("node-html-markdown");
4751
const moment = require("moment/moment");
@@ -62,31 +66,65 @@ module.exports = async (client, interaction) => {
6266

6367
await client.session.timetable(date).then((cours) => {
6468
let totalDuration = 0;
65-
cours.forEach((cours) => {
66-
totalDuration += cours.to.getTime() - cours.from.getTime();
67-
});
68-
totalDuration = Math.abs(totalDuration / 1000 / 60 / 60);
69-
const embed = new EmbedBuilder()
70-
.setColor("#70C7A4")
71-
.setTitle("Vous avez " + cours.length + " cours `" + date.toLocaleDateString() + "` :")
72-
.setDescription("Durée totale : **" + totalDuration + "h**");
73-
const embedCours = cours.map((cour) => {
74-
const subHomeworks = client.cache.homeworks.filter(h => h.subject === cour.subject && cour.from.getDate() + "/" + cour.from.getMonth() === h.for.getDate() + "/" + h.for.getMonth());
75-
return new EmbedBuilder()
69+
70+
let embedCours = cours.map((cour) => {
71+
// Ne pas afficher les cours si jamais ils sont annulés et qu'ils sont remplacés par un autre cours dont les horaires sont inclus par un autre cours
72+
if (cour.isCancelled && cours.find((c) => isLessonInInterval(c, cour.from, cour.to) && !c.isCancelled)) {
73+
return;
74+
}
75+
totalDuration += cour.to.getTime() - cour.from.getTime();
76+
77+
const subHomeworks = client.cache.homeworks.filter(h => h.subject === cour.subject && cour.from.getDate()+"/"+cour.from.getMonth() === h.for.getDate()+"/"+h.for.getMonth());
78+
const coursIsAway = cour.isAway || cour.isCancelled || cour.status?.match(/(.+)?prof(.+)?absent(.+)?/giu) || cour.status == "Cours annulé";
79+
const embed = new EmbedBuilder()
7680
.setColor(cour.color ?? "#70C7A4")
7781
.setAuthor({
78-
name: cour.subject,
82+
name: cour.subject ?? (cour.status ?? "Non défini"),
7983
})
80-
.setDescription("Professeur: **" + cour.teacher + "**" +
84+
.setDescription("Professeur: **" + (cour.teacher ?? "*Non précisé*") + "**" +
8185
"\nSalle: `" + (cour.room ?? " ? ") + "`" +
8286
"\nDe **" + cour.from.toLocaleTimeString().split(":")[0] +
8387
"h" + cour.from.toLocaleTimeString().split(":")[1] + "**" +
8488
" à **" + cour.to.toLocaleTimeString().split(":")[0] +
8589
"h" + cour.to.toLocaleTimeString().split(":")[1] + "**" +
8690
" *(" + (cour.to.getTime() - cour.from.getTime()) / 1000 / 60 / 60 + "h)*" +
87-
(subHomeworks.length && (!cour.isCancelled || !cour.isAway) ? `\n⚠**__\`${subHomeworks.length}\` Devoirs__**` : "") +
88-
(cour.isCancelled || cour.isAway ? "\n⚠__**Cour annulé**__" : ""));
89-
});
91+
(subHomeworks.length && !coursIsAway ? `\n⚠**__\`${subHomeworks.length}\` Devoirs__**` : "") +
92+
(coursIsAway ? "\n🚫__**Cour annulé**__" : ""));
93+
94+
if (cour.status && (!coursIsAway || cour.statut !== "Cours annulé")) {
95+
embed.addFields([
96+
{
97+
name: "Status",
98+
value: "__**" + cour.status + "**__"
99+
}
100+
]);
101+
}
102+
return embed;
103+
}).filter(emb => !!emb);
104+
105+
106+
if (embedCours.length >= 9) {
107+
const embed = new EmbedBuilder()
108+
.setColor("#70C7A4")
109+
.addFields(
110+
embedCours.map((emb) => {
111+
return {
112+
name: emb.author.name,
113+
value: emb.description,
114+
inline: false
115+
}
116+
})
117+
)
118+
embedCours = [embed];
119+
}
120+
121+
totalDuration = Math.abs(totalDuration / 1000 / 60 / 60);
122+
const embed = new EmbedBuilder()
123+
.setColor("#70C7A4")
124+
.setTitle("Vous avez " + embedCours.length + " cours " + "le `"+ date.toLocaleDateString() +"` :")
125+
.setDescription("Durée totale : **" + totalDuration + "h**");
126+
127+
90128
const current = new Date(date.getTime());
91129
const week = [];
92130
for (let i = 1; i <= 7; i++) {
@@ -344,7 +382,7 @@ module.exports = async (client, interaction) => {
344382
} else if (mark.value === mark.min) {
345383
better = "**__Tu est le premier des derniers !__**\n";
346384
embed.setThumbnail("https://i.imgur.com/5H5ZASz.gif");
347-
embed.data.author.url = "https://youtu.be/dQw4w9WgXcQ";
385+
embed.author.url = "https://youtu.be/dQw4w9WgXcQ";
348386
}
349387
let studentNote = `**Note de l'élève :** ${mark.value}/${mark.scale}`;
350388
if (mark.scale !== 20) studentNote += ` *(${+(mark.value / mark.scale * 20).toFixed(2)}/20)*`;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pronote-bot-discord",
3-
"version": "5.0.8",
3+
"version": "5.1.0",
44
"description": "Un bot Discord pour envoyer des notifications Pronote dans un serveur Discord 📚",
55
"main": "index.js",
66
"repository": {

utils/notifications.js

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,30 @@ module.exports = client => {
120120
});
121121
}
122122

123+
const finalAttachments = [];
124+
if (files.length > 10) {
125+
let i = 10;
126+
while (i < files.length) {
127+
channel.send({files: files.slice(i, i + 10)}).then(m => {
128+
finalAttachments.concat(m.attachments);
129+
}).catch(console.error);
130+
i += 10;
131+
}
132+
}
133+
123134
channel.send({embeds: [embed], files: attachments}).then((e) => {
124135
if (homework.done) e.react("✅").then(() => {
125136
});
126137
if (homework.files.length) {
138+
finalAttachments.concat(e.attachments);
127139
let string = "";
128140
files.forEach(file => {
129141
if (file.type === "file") {
130142
const name = client.functions.setFileName(file.name);
131-
const attachment = e.attachments.find(a => a.name === name);
132-
if (attachment) string += `[${file.name}](${attachment.url})\n`;
143+
const attachment = finalAttachments.find(a => a.name === name);
144+
if (attachment) {
145+
string += `[${file.name}](${attachment.url})\n`;
146+
}
133147
else {
134148
string += `${file.name}\n`;
135149
console.log("Attachment not found.\nTo found name: " + name, "Original name: " + file.name, "\nAttachments: " + e.attachments.map(a => a.name));
@@ -206,6 +220,7 @@ module.exports = client => {
206220
const embeds = [embed];
207221
const attachments = [];
208222
let files = [];
223+
209224
await client.functions.asyncForEach(splitted, async (s, index) => {
210225
const embed = new EmbedBuilder()
211226
.setDescription(s)
@@ -225,14 +240,29 @@ module.exports = client => {
225240
files.push(properties);
226241
});
227242
}
243+
244+
const finalAttachments = [];
245+
if (attachments.length > 10) {
246+
let i = 10;
247+
while (i < attachments.length) {
248+
channel.send({files: attachments.slice(i, i + 10)}).then(m => {
249+
finalAttachments.concat(m.attachments);
250+
}).catch(console.error);
251+
i += 10;
252+
}
253+
}
254+
228255
channel.send({embeds, files: attachments}).then(m => {
229256
if (files.length) {
257+
finalAttachments.concat(m.attachments);
230258
let string = "";
231259
files.forEach(file => {
232260
if (file.type === "file") {
233261
const name = client.functions.setFileName(file.name);
234262
const attachment = m.attachments.find(a => a.name === name);
235-
if (attachment) string += `[${file.name}](${attachment.url})\n`;
263+
if (attachment) {
264+
string += `[${file.name}](${attachment.url})\n`;
265+
}
236266
else {
237267
string += `${file.name}\n`;
238268
console.log("Attachment not found.\nID: "+ infoNotif.id +" To found name: " + name, "Original name: " + file.name, "\nAttachments: " + m.attachments.map(a => a.name));

0 commit comments

Comments
 (0)