forked from Lea/UntisBot
Magic code that makes it work better
This commit is contained in:
parent
61da37f19f
commit
4b31c83320
|
@ -6,9 +6,12 @@ const { bot, defaultEmbedColor, untis, db, sendEmbed } = main;
|
|||
export async function run() {
|
||||
let timetable = await untis.getOwnTimetableForRange(new Date(Date.now() - 86400000), new Date(Date.now() + (86400000 * 7)), true);
|
||||
|
||||
let sentClasses = {};
|
||||
|
||||
timetable.forEach(lesson => {
|
||||
let kLesson = db.knownLessons.get(`${lesson.id}`);
|
||||
if (kLesson && hasChanged(lesson, kLesson)) {
|
||||
if (sentClasses['' + (lesson.sg || lesson.su?.[0]?.id) + ' -- ' + lesson.date]) return;
|
||||
let dateInfo = {
|
||||
year: Number(`${lesson.date}`.substr(0, 4)),
|
||||
month: Number(`${lesson.date}`.substr(4, 2)),
|
||||
|
@ -24,7 +27,7 @@ export async function run() {
|
|||
let embed = new Discord.MessageEmbed()
|
||||
.setTitle(`Lesson updated`)
|
||||
.setColor(defaultEmbedColor)
|
||||
.setAuthor(`${weekDay}: ${lesson.sg || '(Unnamed lesson)'} - ${lesson.te[0].longname || 'No teacher'}`);
|
||||
.setAuthor(`${weekDay}, ${date.getDate()}. ${date.getMonth() + 1}.: ${lesson.sg || '(Unnamed lesson)'} - ${lesson.te[0].longname || 'No teacher'}`);
|
||||
|
||||
let desc = ``;
|
||||
|
||||
|
@ -35,23 +38,43 @@ export async function run() {
|
|||
ro: 'Room'
|
||||
}
|
||||
for (const prop of ['kl', 'te', 'su', 'ro']) {
|
||||
if (lesson[prop] != kLesson[prop]) {
|
||||
desc += `**${propFullName[prop]}:** ${kLesson[prop]?.[0]?.longname} ${kLesson[prop]?.[0]?.longname != kLesson[prop]?.[0]?.name ? `(${(kLesson[prop]?.[0]?.name)})` : ''} \u200b **=>** \u200b ${lesson[prop]?.[0]?.longname} ${lesson[prop]?.[0]?.longname != lesson[prop]?.[0]?.name ? `(${lesson[prop]?.[0]?.name})` : ''} \n`;
|
||||
let lessonStr = JSON.stringify(lesson[prop]);
|
||||
let kLessonStr = JSON.stringify(kLesson[prop]);
|
||||
|
||||
let addProp = (prop) => {
|
||||
let str = ``;
|
||||
if ((!prop.name && !prop.longname) || prop.name == '---') str += `None`;
|
||||
else if (prop.longname) {
|
||||
str += `${prop.longname} `;
|
||||
if (prop.name && prop.name != prop.longname) str += `(${prop.name}) `;
|
||||
} else str += prop.name;
|
||||
return str;
|
||||
}
|
||||
|
||||
if (lessonStr != kLessonStr) {
|
||||
desc += '**' + propFullName[prop] + '**: ' + (addProp(kLesson[prop][0]) || 'None') + ' → ' + (addProp(lesson[prop][0] || 'None')) + '\n';
|
||||
}
|
||||
}
|
||||
if (lesson.activityType != kLesson.activityType) {
|
||||
desc += `**Type:** ${kLesson.activityType} \u200b **=>** \u200b ${lesson.activityType} \n`
|
||||
desc += `**Type:** ${kLesson.activityType} \u200b → \u200b ${lesson.activityType} \n`
|
||||
}
|
||||
|
||||
if (lesson.substText)
|
||||
desc += `\nℹ️ ${lesson.substText}`;
|
||||
|
||||
if (lesson.info)
|
||||
desc += `\nℹ️ ${lesson.info}`
|
||||
desc += `\nℹ️ ${lesson.info}`;
|
||||
|
||||
//if (lesson.code) embed.setColor(lesson.code == 'irregular' ? 'A781B4' : 'B1B3B4');
|
||||
// Change the embed color when teacher ID is 0.
|
||||
// Teacher ID 0 means that the class is canelled (at least on my school),
|
||||
// although I don't know if this is always the case.
|
||||
if (lesson.code == 'irregular' || lesson.te[0].id == 0) embed.setColor('A781B4');
|
||||
|
||||
embed.setDescription(desc);
|
||||
console.log(`Sent timetable update`);
|
||||
sentClasses['' + (lesson.sg || lesson.su?.[0]?.id) + ' -- ' + lesson.date] = true;
|
||||
sendEmbed(embed);
|
||||
console.log(`Sent timetable update`);
|
||||
db.knownLessons.set(`${lesson.id}`, lesson);
|
||||
}
|
||||
else db.knownLessons.set(`${lesson.id}`, lesson);
|
||||
|
|
|
@ -10,9 +10,9 @@
|
|||
// "allowJs": true, /* Allow javascript files to be compiled. */
|
||||
// "checkJs": true, /* Report errors in .js files. */
|
||||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
||||
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
||||
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
||||
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
||||
"declaration": true, /* Generates corresponding '.d.ts' file. */
|
||||
"declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
||||
"sourceMap": true, /* Generates corresponding '.map' file. */
|
||||
// "outFile": "./", /* Concatenate and emit output to single file. */
|
||||
"outDir": "./dist", /* Redirect output structure to the directory. */
|
||||
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||
|
|
Loading…
Reference in a new issue