diff --git a/commands/ssps/rozvrh.js b/commands/ssps/rozvrh.js index 89ef2d1..aeb29a0 100644 --- a/commands/ssps/rozvrh.js +++ b/commands/ssps/rozvrh.js @@ -57,6 +57,6 @@ module.exports = class rozvrh extends commando.Command { 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.say(embed); } }; \ No newline at end of file diff --git a/commands/ssps/suplovani.js b/commands/ssps/suplovani.js index 1fe22bc..a4f9dca 100644 --- a/commands/ssps/suplovani.js +++ b/commands/ssps/suplovani.js @@ -1,4 +1,5 @@ const commando = require("@iceprod/discord.js-commando"); +const { MessageEmbed } = require("discord.js"); const api = require("../../utils/api"); module.exports = class suplovani extends commando.Command { @@ -12,8 +13,29 @@ module.exports = class suplovani extends commando.Command { }); } - run(msg) { - const suplementations = await api.getSupplementations(); + async run(msg) { + const date = new Date; + const supplementations = await api.getSupplementations(date); + const embed = new MessageEmbed(); + embed.setTitle(`Suplování pro den ${date.getDate()}. ${date.getMonth() + 1}.`); + + for(const change of supplementations.data.ChangesForClasses) { + const changes = new Map; + for(const t of change.CancelledLessons) { + if(!changes.has(t.Hour)) changes.set(t.Hour, []); + changes.set(t.Hour, [...changes.get(t.Hour), `(\`${t.Subject}\`) **${t.ChgType1}** ${t.Group ? "pro " + t.Group : ""}`]); + } + for(const t of change.ChangedLessons) { + if(!changes.has(t.Hour)) changes.set(t.Hour, []); + changes.set(t.Hour, [...changes.get(t.Hour), `(\`${t.Subject}\`) **${t.ChgType1}** ${t.Group ? "(sk. " + t.Group + ")" : ""} ${t.Room ? "v `" + api.formatRoom(t.Room) + "`" : ""}`]); + } + embed.addField(change.Class.Abbrev, + [...changes.entries()].map(t => `**${t[0]}**. h.: ${t[1].map(t => t.trim()).join("; ")}`) || "Žádná změna", + true + ); + } + + return msg.say(embed); } }; \ No newline at end of file diff --git a/index.js b/index.js index 036e1da..a4fa901 100644 --- a/index.js +++ b/index.js @@ -20,6 +20,16 @@ client.on("ready", () => { console.log("Ready"); }); +const serializeArgs = (args) => { + if(typeof args === "string") return args; + if(Array.isArray(args)) return args.join("&"); + return Object.entries(args).map(t => `${t[0]}=${encodeURIComponent(t[1].toString())}`).join("&"); +} + +client.on("commandRun", (c, p, msg, args) => { + console.log(`[RUN]: ${msg.author.tag}@${msg.guild?.name || "DM"}#${msg.channel?.name || "default"}/${c.groupID}/${c.name}?${serializeArgs(args)} | ${msg.content}`); +}); + client.registry .registerGroups([ ["ssps", "Příkazy pro SSPŠ"], diff --git a/utils/api.js b/utils/api.js index 0f6d70a..2fc453d 100644 --- a/utils/api.js +++ b/utils/api.js @@ -99,7 +99,7 @@ class API { request = request; async getSupplementations(date = new Date) { - const res = await request(`wp-content/themes/ssps-wordpress-theme/supplementation.php/?date=${date.getFullYear()}${date.getMonth().toString().padStart(2, "0")}${date.getDate().toString().padStart(2, "0")}`); + const res = await request(`wp-content/themes/ssps-wordpress-theme/supplementation.php/?date=${date.getFullYear()}${(date.getMonth() + 1).toString().padStart(2, "0")}${date.getDate().toString().padStart(2, "0")}`); return new Supplementations(res); }