mirror of
https://github.com/danbulant/ssps-bot
synced 2026-07-05 19:10:45 +00:00
suplovani
This commit is contained in:
parent
da8dc923a3
commit
f52ed8c787
4 changed files with 36 additions and 4 deletions
|
|
@ -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);
|
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);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
const commando = require("@iceprod/discord.js-commando");
|
const commando = require("@iceprod/discord.js-commando");
|
||||||
|
const { MessageEmbed } = require("discord.js");
|
||||||
const api = require("../../utils/api");
|
const api = require("../../utils/api");
|
||||||
|
|
||||||
module.exports = class suplovani extends commando.Command {
|
module.exports = class suplovani extends commando.Command {
|
||||||
|
|
@ -12,8 +13,29 @@ module.exports = class suplovani extends commando.Command {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
run(msg) {
|
async run(msg) {
|
||||||
const suplementations = await api.getSupplementations();
|
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);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
10
index.js
10
index.js
|
|
@ -20,6 +20,16 @@ client.on("ready", () => {
|
||||||
console.log("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
|
client.registry
|
||||||
.registerGroups([
|
.registerGroups([
|
||||||
["ssps", "Příkazy pro SSPŠ"],
|
["ssps", "Příkazy pro SSPŠ"],
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,7 @@ class API {
|
||||||
request = request;
|
request = request;
|
||||||
|
|
||||||
async getSupplementations(date = new Date) {
|
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);
|
return new Supplementations(res);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue