Commit b00e9d4d authored by Sigfried Seldeslachts's avatar Sigfried Seldeslachts
Browse files

Added exam command and other small changes

parent d0b398a5
Pipeline #10655 passed with stage
in 25 seconds
......@@ -7,7 +7,8 @@
"axios": "^0.18.0",
"cheerio": "^1.0.0-rc.2",
"discord.js": "^12.0.2",
"dotenv": "^6.2.0"
"dotenv": "^6.2.0",
"moment": "^2.29.1"
},
"repository": {
"type": "git",
......
const axios = require('axios');
const moment = require('moment');
const { MessageEmbed } = require("discord.js");
/**
* Shows the excuse
* @param msg
*/
const command = async (msg, args) => {
msg.channel.startTyping(2);
if (args === null || args.length <= 0) {
return;
}
try {
let count = 0; // Max count for Discord emb
let fields = [];
const { data: { data } } = await axios.get(`https://api.examenrooster.diana.be/api/rooster/${args[0]}`);
data.forEach((item) => {
if (count >= 19) {
fields.push({
name: "Zie Diana's Examenrooster voor alle vakken.",
value: "",
});
return;
}
let title = moment(item.timestamp).format("dddd D MMM [om] HH:mm");
if (item.lokaal !== null && item.lokaal.trim() !== "") {
title += ` - ${item.lokaal} @ ${item.campus}`;
} else if (item.examenvorm !== null && item.examenvorm === "M Online") {
title += " - ONLINE";
}
fields.push({
name: item.olanaam,
value: title.charAt(0).toUpperCase() + title.slice(1),
});
count++;
});
if (fields.length <= 0) {
fields.push({
name: "Geen examens",
value: "Er zijn geen verdere examens gepland voor jouw studentennummer."
})
}
const embed = new MessageEmbed()
.setTitle(`Examenrooster voor ${args[0]}`)
.setFooter("Bron: Diana Examenrooster")
.setURL(`https://examenrooster.diana.be/rooster/${args[0]}`)
.setTimestamp((new Date()))
.addFields(fields);
msg.reply(embed);
} catch (e) {
if (e && e.response && e.response.data && e.response.data.message) {
msg.reply(`Er ging iets mis! Ik kreeg de volgende melding van Diana's Examenrooster: ${e.response.data.message}`);
} else {
msg.reply("Ik kon geen examenrooster ophalen.");
console.error(e);
}
}
msg.channel.stopTyping(true);
}
module.exports = {
aliases: ['examens'],
description: "toont jouw examens",
author: "Sigfried",
onMessage: command,
};
require('dotenv').config();
const { MessageEmbed } = require("discord.js");
const index = require('../../index.js');
const commands = index.commands;
require('dotenv').config();
module.exports = async (msg) => {
if (msg.author.bot) return;
let content = msg.content;
let prefix = false;
if (msg.author.bot) return;
let content = msg.content;
let prefix = false;
// Removes ! if present
if (content.startsWith(process.env.PREFIX)) {
content = content.slice(process.env.PREFIX.length);
prefix = true;
}
// Removes ! if present
if (content.startsWith(process.env.PREFIX)) {
content = content.slice(process.env.PREFIX.length);
prefix = true;
}
// Removes ! and splits by space and gets first item
const args = content.split(/ +/);
const commandRequest = args.shift().toLowerCase();
// Removes ! and splits by space and gets first item
const args = content.split(/ +/);
const commandRequest = args.shift().toLowerCase();
Object.keys(commands).forEach((key) => {
const command = commands[key];
Object.keys(commands).forEach((key) => {
const command = commands[key];
// Execute the custom activation function if present
if (command.activation) command.activation(msg, args);
try {
// Execute the custom activation function if present
if (command.activation) command.activation(msg, args);
// If an alias matches then execute the onMessage
if (prefix && command.aliases && command.aliases.some(alias => alias === commandRequest)) command.onMessage(msg, args);
});
// If an alias matches then execute the onMessage
if (prefix && command.aliases && command.aliases.some(alias => alias === commandRequest)) command.onMessage(msg, args);
} catch (e) {
const botChannel = msg.guild.channels.resolve(process.env.BOT_CHANNEL_ID);
const embed = new MessageEmbed()
.setTitle("Exception occured while executing a command.")
.setDescription(e)
.setColor("#FF0000");
botChannel.send(embed);
}
});
}
......@@ -2,7 +2,7 @@ const { MessageEmbed } = require("discord.js");
module.exports = async (msg) => {
if (msg.author.bot || msg.content.startsWith(process.env.PREFIX)) return;
if (msg.author == null || msg.author.bot || msg.content.startsWith(process.env.PREFIX)) return;
try {
const botChannel = msg.guild.channels.resolve(process.env.BOT_CHANNEL_ID);
......
......@@ -13,23 +13,19 @@ module.exports = async (reaction, user) => {
switch (reaction.emoji.name) {
case "1️⃣":
await member.roles.add(process.env.ROLE_TI);
await member.roles.add(process.env.ROLE_TI_1);
member.roles.add(process.env.ROLE_TI);
member.roles.add(process.env.ROLE_TI_1);
break;
case "2️⃣":
await member.roles.add(process.env.ROLE_TI);
await member.roles.add(process.env.ROLE_TI_2);
member.roles.add(process.env.ROLE_TI);
member.roles.add(process.env.ROLE_TI_2);
break;
case "3️⃣":
await member.roles.add(process.env.ROLE_TI);
await member.roles.add(process.env.ROLE_TI_3);
break;
case "4️⃣":
await member.roles.add(process.env.ROLE_TI);
await member.roles.add(process.env.ROLE_TI_4);
member.roles.add(process.env.ROLE_TI);
member.roles.add(process.env.ROLE_TI_3);
break;
case "🇬":
await member.roles.add(process.env.ROLE_GRADUAAT);
member.roles.add(process.env.ROLE_GRADUAAT);
break;
default:
break;
......
......@@ -13,21 +13,14 @@ module.exports = async (reaction, user) => {
switch (reaction.emoji.name) {
case "1️⃣":
await member.roles.remove(process.env.ROLE_TI);
await member.roles.remove(process.env.ROLE_TI_1);
break;
case "2️⃣":
await member.roles.remove(process.env.ROLE_TI);
await member.roles.remove(process.env.ROLE_TI_2);
break;
case "3️⃣":
await member.roles.remove(process.env.ROLE_TI);
await member.roles.remove(process.env.ROLE_TI_3);
break;
case "4️⃣":
await member.roles.remove(process.env.ROLE_TI);
await member.roles.remove(process.env.ROLE_TI_4);
break;
case "🇬":
await member.roles.remove(process.env.ROLE_GRADUAAT);
break;
......
const moment = require('moment');
require('dotenv').config();
moment.locale("nl");
/**
* Discord Init
......
......@@ -198,6 +198,11 @@ mime-types@^2.1.12:
dependencies:
mime-db "1.45.0"
moment@^2.29.1:
version "2.29.1"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.29.1.tgz#b2be769fa31940be9eeea6469c075e35006fa3d3"
integrity sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ==
ms@2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment