suplovani

This commit is contained in:
Daniel Bulant 2021-10-06 16:24:38 +02:00
parent da8dc923a3
commit f52ed8c787
4 changed files with 36 additions and 4 deletions

View file

@ -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);
}
};

View file

@ -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);
}
};

View file

@ -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Š"],

View file

@ -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);
}