Skip to content

Commit

Permalink
Actually fixed the issue of a 15:00-16:00 period showing up in a free…
Browse files Browse the repository at this point in the history
… check from 14:00-15:00.
  • Loading branch information
nightmarishblue committed Oct 16, 2023
1 parent 87d218c commit 1017e6a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 34 deletions.
4 changes: 2 additions & 2 deletions calendarbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ client.on('interactionCreate', async interaction => {
// offset the date as is appropriate.
// offset is the diff between the current day and the day we want.
dateObject.setDate(dateObject.getDate() - offset)
dateObject.setHours(8)
dateObject.setHours(8, 0, 0, 0)
let startDate = dateObject.toISOString()
dateObject.setHours(22)
dateObject.setHours(22, 0, 0, 0)
let endDate = dateObject.toISOString()

Timetable.fetchRawTimetableData(courseID, startDate, endDate, 'programme')
Expand Down
1 change: 1 addition & 0 deletions room-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function findRoomIdentities(codesToQuery) {
// This function does that, adding errors to an embed.
function generateTimeRange(errorEmbed, timeRange) {
let date = new Date();
date.setHours(date.getHours(), 0, 0, 0); // make sure the hour's on the dot.
const currentTime = date.getHours();
const defaultTimes = [currentTime, (currentTime + 1) % 24]
try {
Expand Down
63 changes: 31 additions & 32 deletions timetable.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,22 @@ async function fetchCourseData(query, data) {
async function fetchRawTimetableData(identitiesToQuery, startDate, endDate, mode) {
/* two modes, 'programme' and 'location'. programme is the default.
programme expects one string or a list with one string, location can take a list of any size.
times are set to 8:00 - 22:00 if startTime is not defined. */
*/
if (typeof (mode) != 'string') {
mode = 'programme';
};

// have to make sure an event beginning at the exact end time doesn't show up
endDate.setMinutes(endDate.getMinutes() - 1);
endDate = await new Date(endDate);
endDate.setMinutes(-1)
endDate = await endDate.toISOString()

const categoryIdentity = (mode == 'programme') ? programmeIdentity : locationIdentity;

let output = new Promise(function (resolve, reject) {
let output = await new Promise(function (resolve, reject) {
const reqPayload = {
method: 'POST',
uri: `https://scientia-eu-v4-api-d1-03.azurewebsites.net/api/Public/CategoryTypes/Categories/Events/Filter/a1fdee6b-68eb-47b8-b2ac-a4c60c8e6177?startRange=${startDate}&endRange=${endDate}`,
//uri: `https://opentimetable.dcu.ie/broker/api/categoryTypes/${categoryIdentity}/categories/events/filter`,
//headers: reqHeaders,
body: constructRequestBody(identitiesToQuery, mode),
json: true
};
Expand All @@ -139,7 +139,6 @@ async function fetchRawTimetableData(identitiesToQuery, startDate, endDate, mode
resolve(res_body)
})
.catch(function (err) { // Catch any errors
//console.error(err)
reject(err)
});
})
Expand All @@ -148,33 +147,33 @@ async function fetchRawTimetableData(identitiesToQuery, startDate, endDate, mode

// Starts a search from a module code, and returns the title of the first result
// unnecessary, since now the result does everything.
async function fetchModuleNameFromCode(query) {
var reqPayload = {
method: 'POST',
uri: `https://opentimetable.dcu.ie/broker/api/CategoryTypes/${moduleIdentity}/Categories/Filter?pageNumber=1&query=${query}`,
headers: reqHeaders,
json: true
};

return new Promise(function (resolve, reject) {
Request(reqPayload) // Send the HTTP Request
.then(function (res_body) {
let results = res_body['Results'];

if (results.length == 0) {
reject(`Module identity not found with supplied module code '${query}'.`);
} else {
resolve(res_body['Results'][0]['Name']);
}
})
.catch(function (err) { // Catch any errors
reject(err);
});
});
}
// async function fetchModuleNameFromCode(query) {
// var reqPayload = {
// method: 'POST',
// uri: `https://opentimetable.dcu.ie/broker/api/CategoryTypes/${moduleIdentity}/Categories/Filter?pageNumber=1&query=${query}`,
// headers: reqHeaders,
// json: true
// };

// return new Promise(function (resolve, reject) {
// Request(reqPayload) // Send the HTTP Request
// .then(function (res_body) {
// let results = res_body['Results'];

// if (results.length == 0) {
// reject(`Module identity not found with supplied module code '${query}'.`);
// } else {
// resolve(res_body['Results'][0]['Name']);
// }
// })
// .catch(function (err) { // Catch any errors
// reject(err);
// });
// });
// }

exported = {
weekdays, fetchDay, extractTimeFromDate, timeToString,reqHeaders, startOfWeek, constructRequestBody, fetchCourseData, fetchRawTimetableData, fetchModuleNameFromCode
weekdays, fetchDay, extractTimeFromDate, timeToString,reqHeaders, startOfWeek, constructRequestBody, fetchCourseData, fetchRawTimetableData
}

module.exports = exported

0 comments on commit 1017e6a

Please sign in to comment.