mirror of
https://github.com/danbulant/ssps-bot
synced 2026-07-06 19:40:53 +00:00
rozpoznání třídy podle role
This commit is contained in:
parent
09be34aa9b
commit
44b5821ad3
2 changed files with 58 additions and 7 deletions
|
|
@ -2,8 +2,12 @@ const commando = require("@iceprod/discord.js-commando");
|
||||||
const { MessageEmbed } = require("discord.js");
|
const { MessageEmbed } = require("discord.js");
|
||||||
const { DateTime } = require("luxon");
|
const { DateTime } = require("luxon");
|
||||||
const api = require("../../utils/api");
|
const api = require("../../utils/api");
|
||||||
|
const ssps = require("../../utils/ssps-server");
|
||||||
|
|
||||||
module.exports = class rozvrh extends commando.Command {
|
module.exports = class rozvrh extends commando.Command {
|
||||||
|
/**
|
||||||
|
* @arg {import("@iceprod/discord.js-commando").CommandoClient} client
|
||||||
|
* */
|
||||||
constructor(client) {
|
constructor(client) {
|
||||||
super(client, {
|
super(client, {
|
||||||
name: "rozvrh",
|
name: "rozvrh",
|
||||||
|
|
@ -12,10 +16,27 @@ module.exports = class rozvrh extends commando.Command {
|
||||||
description: "Zobrazí rozvrh hodin pro danou třídu",
|
description: "Zobrazí rozvrh hodin pro danou třídu",
|
||||||
args: [{
|
args: [{
|
||||||
key: "className",
|
key: "className",
|
||||||
type: "string",
|
|
||||||
prompt: "Jakou třídu chcete zvolit?",
|
prompt: "Jakou třídu chcete zvolit?",
|
||||||
validate(val) {
|
isEmpty(val, msg) {
|
||||||
return /^[1-4]\.?[ABCKGL]$/i.test(val);
|
if(val) return false;
|
||||||
|
if(!client.guilds.resolve(ssps.server)) return true;
|
||||||
|
console.log("Finding roles");
|
||||||
|
return !Object.entries(ssps.roles).find(([id, name]) =>
|
||||||
|
client.guilds.resolve(ssps.server).roles.valueOf().has(id)
|
||||||
|
);
|
||||||
|
},
|
||||||
|
validate(val, msg) {
|
||||||
|
if(/^[1-4]\.?[ABCKGL]$/i.test(val)) return true;
|
||||||
|
if(!client.guilds.resolve(ssps.server)) return false;
|
||||||
|
return Object.entries(ssps.roles).find(([id, name]) =>
|
||||||
|
client.guilds.resolve(ssps.server).roles.valueOf().has(id)
|
||||||
|
);
|
||||||
|
},
|
||||||
|
parse(val, msg) {
|
||||||
|
if(val) return val;
|
||||||
|
return Object.entries(ssps.roles).find(([id, name]) =>
|
||||||
|
client.guilds.resolve(ssps.server).roles.valueOf().has(id)
|
||||||
|
)[1];
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
});
|
});
|
||||||
|
|
@ -27,10 +48,12 @@ module.exports = class rozvrh extends commando.Command {
|
||||||
if(!className) return msg.reply("Třída není podporovaná.");
|
if(!className) return msg.reply("Třída není podporovaná.");
|
||||||
const sc = await api.getSchedule(className);
|
const sc = await api.getSchedule(className);
|
||||||
|
|
||||||
const date = DateTime.now();
|
let date = DateTime.now();
|
||||||
if(date.hour > 16) date.plus({ days: 1 }); // show tomorrow supplementations after 4PM
|
if(date.hour > 16) date = date.plus({ days: 1 }); // show tomorrow supplementations after 4PM
|
||||||
const dayOfWeek = (date.weekday > 1 && date.weekday < 6 ? date.weekday : 1) - 1;
|
if(date.weekday === 0 || date.weekday === 7) {
|
||||||
const schedule = sc.schedule[dayOfWeek];
|
date = date.plus({ days: date.weekday === 0 ? 2 : 1 });
|
||||||
|
}
|
||||||
|
const schedule = sc.schedule[date.weekday - 1];
|
||||||
|
|
||||||
const embed = new MessageEmbed();
|
const embed = new MessageEmbed();
|
||||||
embed.setTitle("Rozvrh");
|
embed.setTitle("Rozvrh");
|
||||||
|
|
|
||||||
28
utils/ssps-server.js
Normal file
28
utils/ssps-server.js
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
|
||||||
|
const roles = {
|
||||||
|
"882938478525050911": "1K",
|
||||||
|
"882938577632247829": "1A",
|
||||||
|
"882938625581527111": "1B",
|
||||||
|
"882938838480207892": "1C",
|
||||||
|
"882938589002989568": "1G",
|
||||||
|
"887339014020038717": "2K",
|
||||||
|
"886966083897155665": "2A",
|
||||||
|
"887339001084796928": "2B",
|
||||||
|
"887339009783779379": "2C",
|
||||||
|
"887339017480335390": "2L",
|
||||||
|
"887339028859486208": "3K",
|
||||||
|
"887339020030443561": "3A",
|
||||||
|
"887339023180398663": "3B",
|
||||||
|
"887339025910878268": "3C",
|
||||||
|
"887339031388631050": "3L",
|
||||||
|
"887339042260279326": "4K",
|
||||||
|
"887339033817153567": "4A",
|
||||||
|
"887339036891566100": "4B",
|
||||||
|
"887339039533957151": "4C",
|
||||||
|
"887339044961406996": "4L"
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
roles,
|
||||||
|
server: "882560404167995443"
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue