rozvrh v1

This commit is contained in:
Daniel Bulant 2021-10-06 15:10:29 +02:00
parent db3f0dbca5
commit da8dc923a3
3 changed files with 64 additions and 15 deletions

View file

@ -9,10 +9,6 @@ const api = require("../../utils/api");
/** @type {Record<string, Depromise<ReturnType<api["getSchedule"]>>>} */
var cache = {};
var map = {
"1K": "1Y"
}
module.exports = class rozvrh extends commando.Command {
constructor(client) {
super(client, {
@ -33,7 +29,7 @@ module.exports = class rozvrh extends commando.Command {
async run(msg, { className }) {
className = className.replace(".", "").toUpperCase();
className = map[className];
className = api.map[className];
if(!className) return msg.reply("Třída není podporovaná.");
if(!cache[className]) {
cache[className] = await api.getSchedule(className);
@ -45,18 +41,20 @@ module.exports = class rozvrh extends commando.Command {
const embed = new MessageEmbed();
embed.setTitle("Rozvrh");
embed.setDescription("Rozvrh pro třídu " + api.demap[className]);
for(const cellI in schedule) {
const cell = schedule[cellI];
for(let cellI in schedule) {
cellI = parseInt(cellI);
let cell = schedule[cellI];
if(!cell) {
console.log("Wut?", cellI, cell);
continue;
}
try {
embed.addField(cell.Subject.Abbrev, `${cell.Room.Abbrev} - ${cell.Teacher.Name}`);
} catch(e) {
console.warn(e, cellI, cell);
if(!Array.isArray(cell)) cell = [cell];
for(const scell of cell) {
embed.addField(scell.Subject.Abbrev, `\`${api.formatRoom(scell.Room.Abbrev) || "?"}\` - ${scell.Teacher.Name} - **${scell.Group.Name}**`, cell.length > 1);
}
if(cell.length > 1 && Array.isArray(schedule[cellI + 1]) && schedule[cellI + 1].length > 1) embed.addField("\u200B", "\u200B", true);
}
return msg.reply(embed);

View file

@ -1,4 +1,5 @@
const commando = require("@iceprod/discord.js-commando");
const api = require("../../utils/api");
module.exports = class suplovani extends commando.Command {
constructor(client) {
@ -12,6 +13,7 @@ module.exports = class suplovani extends commando.Command {
}
run(msg) {
return msg.reply("TBD");
const suplementations = await api.getSupplementations();
}
};

View file

@ -43,13 +43,12 @@ async function request(endpoint, body) {
class Supplementations {
constructor(data) {
/** @type {{ AbsentClasses: AbsentClass[], ChangesForClasses: ChangedClass[]}} */
this.data = data;
}
getByClassName(name) {
/** @type {AbsentClass[]} */
const absent = this.data.AbsentClasses.filter(t => t.Entity.Abbrev === name);
/** @type {ChangedClass[]} */
const changed = this.data.ChangesForClasses.filter(t => t.Class.Abbrev === name);
return { absent, changed };
}
@ -77,7 +76,7 @@ class Supplementations {
*/
class Schedule {
/** @type {CellAtom[][]} */
/** @type {(CellAtom | CellAtom[])[][]} */
schedule = [];
constructor(data) {
this.data = data;
@ -110,6 +109,56 @@ class API {
return new Schedule(res);
}
formatRoom(room) {
if(!room) return "";
return room.toString().padStart(3, "0");
}
map = {
"1A": "1U",
"1B": "1V",
"1C": "1W",
"1G": "1X",
"1K": "1Y",
"2A": "1P",
"2B": "1Q",
"2C": "1R",
"2L": "1S",
"2K": "1T",
"3A": "1K",
"3B": "1L",
"3C": "1M",
"3L": "1N",
"3K": "1O",
"4A": "1E",
"4B": "1F",
"4C": "1G",
"4L": "1I",
"4K": "1J"
}
demap = {
"1U": "1A",
"1V": "1B",
"1W": "1C",
"1X": "1G",
"1Y": "1K",
"1P": "2A",
"1Q": "2B",
"1R": "2C",
"1S": "2L",
"1T": "2K",
"1K": "3A",
"1L": "3B",
"1M": "3C",
"1N": "3L",
"1O": "3K",
"1E": "4A",
"1F": "4B",
"1G": "4C",
"1I": "4L",
"1J": "4K",
}
}
module.exports = new API;