@@ -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+
4549const pronote = require ( "pronote-api-maintained" ) ;
4650const { NodeHtmlMarkdown} = require ( "node-html-markdown" ) ;
4751const 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 ( / ( . + ) ? p r o f ( . + ) ? a b s e n t ( . + ) ? / 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)*` ;
0 commit comments