mirror of
https://github.com/danbulant/ssps-bot
synced 2026-07-05 11:00:47 +00:00
rozvrh v1
This commit is contained in:
parent
db3f0dbca5
commit
da8dc923a3
3 changed files with 64 additions and 15 deletions
|
|
@ -9,10 +9,6 @@ const api = require("../../utils/api");
|
||||||
/** @type {Record<string, Depromise<ReturnType<api["getSchedule"]>>>} */
|
/** @type {Record<string, Depromise<ReturnType<api["getSchedule"]>>>} */
|
||||||
var cache = {};
|
var cache = {};
|
||||||
|
|
||||||
var map = {
|
|
||||||
"1K": "1Y"
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = class rozvrh extends commando.Command {
|
module.exports = class rozvrh extends commando.Command {
|
||||||
constructor(client) {
|
constructor(client) {
|
||||||
super(client, {
|
super(client, {
|
||||||
|
|
@ -33,7 +29,7 @@ module.exports = class rozvrh extends commando.Command {
|
||||||
|
|
||||||
async run(msg, { className }) {
|
async run(msg, { className }) {
|
||||||
className = className.replace(".", "").toUpperCase();
|
className = className.replace(".", "").toUpperCase();
|
||||||
className = map[className];
|
className = api.map[className];
|
||||||
if(!className) return msg.reply("Třída není podporovaná.");
|
if(!className) return msg.reply("Třída není podporovaná.");
|
||||||
if(!cache[className]) {
|
if(!cache[className]) {
|
||||||
cache[className] = await api.getSchedule(className);
|
cache[className] = await api.getSchedule(className);
|
||||||
|
|
@ -45,18 +41,20 @@ module.exports = class rozvrh extends commando.Command {
|
||||||
|
|
||||||
const embed = new MessageEmbed();
|
const embed = new MessageEmbed();
|
||||||
embed.setTitle("Rozvrh");
|
embed.setTitle("Rozvrh");
|
||||||
|
embed.setDescription("Rozvrh pro třídu " + api.demap[className]);
|
||||||
|
|
||||||
for(const cellI in schedule) {
|
for(let cellI in schedule) {
|
||||||
const cell = schedule[cellI];
|
cellI = parseInt(cellI);
|
||||||
|
let cell = schedule[cellI];
|
||||||
if(!cell) {
|
if(!cell) {
|
||||||
console.log("Wut?", cellI, cell);
|
console.log("Wut?", cellI, cell);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
try {
|
if(!Array.isArray(cell)) cell = [cell];
|
||||||
embed.addField(cell.Subject.Abbrev, `${cell.Room.Abbrev} - ${cell.Teacher.Name}`);
|
for(const scell of cell) {
|
||||||
} catch(e) {
|
embed.addField(scell.Subject.Abbrev, `\`${api.formatRoom(scell.Room.Abbrev) || "?"}\` - ${scell.Teacher.Name} - **${scell.Group.Name}**`, cell.length > 1);
|
||||||
console.warn(e, cellI, cell);
|
|
||||||
}
|
}
|
||||||
|
if(cell.length > 1 && Array.isArray(schedule[cellI + 1]) && schedule[cellI + 1].length > 1) embed.addField("\u200B", "\u200B", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return msg.reply(embed);
|
return msg.reply(embed);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
const commando = require("@iceprod/discord.js-commando");
|
const commando = require("@iceprod/discord.js-commando");
|
||||||
|
const api = require("../../utils/api");
|
||||||
|
|
||||||
module.exports = class suplovani extends commando.Command {
|
module.exports = class suplovani extends commando.Command {
|
||||||
constructor(client) {
|
constructor(client) {
|
||||||
|
|
@ -12,6 +13,7 @@ module.exports = class suplovani extends commando.Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
run(msg) {
|
run(msg) {
|
||||||
return msg.reply("TBD");
|
const suplementations = await api.getSupplementations();
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
55
utils/api.js
55
utils/api.js
|
|
@ -43,13 +43,12 @@ async function request(endpoint, body) {
|
||||||
|
|
||||||
class Supplementations {
|
class Supplementations {
|
||||||
constructor(data) {
|
constructor(data) {
|
||||||
|
/** @type {{ AbsentClasses: AbsentClass[], ChangesForClasses: ChangedClass[]}} */
|
||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
getByClassName(name) {
|
getByClassName(name) {
|
||||||
/** @type {AbsentClass[]} */
|
|
||||||
const absent = this.data.AbsentClasses.filter(t => t.Entity.Abbrev === name);
|
const absent = this.data.AbsentClasses.filter(t => t.Entity.Abbrev === name);
|
||||||
/** @type {ChangedClass[]} */
|
|
||||||
const changed = this.data.ChangesForClasses.filter(t => t.Class.Abbrev === name);
|
const changed = this.data.ChangesForClasses.filter(t => t.Class.Abbrev === name);
|
||||||
return { absent, changed };
|
return { absent, changed };
|
||||||
}
|
}
|
||||||
|
|
@ -77,7 +76,7 @@ class Supplementations {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Schedule {
|
class Schedule {
|
||||||
/** @type {CellAtom[][]} */
|
/** @type {(CellAtom | CellAtom[])[][]} */
|
||||||
schedule = [];
|
schedule = [];
|
||||||
constructor(data) {
|
constructor(data) {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
|
|
@ -110,6 +109,56 @@ class API {
|
||||||
|
|
||||||
return new Schedule(res);
|
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;
|
module.exports = new API;
|
||||||
Loading…
Reference in a new issue