Skip to content

Commit

Permalink
Release 2.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
elijaholmos committed Jan 5, 2023
1 parent 9efba54 commit d56cf31
Show file tree
Hide file tree
Showing 44 changed files with 478 additions and 260 deletions.
10 changes: 9 additions & 1 deletion api/controllers/GatewayController.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Elijah Olmos
* Copyright (C) 2023 Elijah Olmos
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand All @@ -20,6 +20,8 @@ import AssessmentFeedback from '../data/AssessmentFeedback';
import HeaderFields from '../data/HeaderFields';
import GetInboxLeftPanelNotification from '../data/GetInboxLeftPanelNotification';
import getPostsByInboxForumId from '../data/getPostsByInboxForumId';
import AddStudentGradeSeenDateTime from '../data/AddStudentGradeSeenDateTime';
import markPostsAsRead from '../data/markPostsAsRead';

export class GatewayController {
static GetAnnouncementsStudent({ courseClassId }) {
Expand All @@ -40,4 +42,10 @@ export class GatewayController {
static getPostsByInboxForumId({}) {
return getPostsByInboxForumId;
}
static AddStudentGradeSeenDateTime({}) {
return AddStudentGradeSeenDateTime;
}
static markPostsAsRead({}) {
return markPostsAsRead;
}
}
2 changes: 1 addition & 1 deletion api/controllers/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Elijah Olmos
* Copyright (C) 2023 Elijah Olmos
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand Down
2 changes: 1 addition & 1 deletion api/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Elijah Olmos
* Copyright (C) 2023 Elijah Olmos
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand Down
3 changes: 2 additions & 1 deletion api/routes/gateway.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Elijah Olmos
* Copyright (C) 2023 Elijah Olmos
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand Down Expand Up @@ -43,6 +43,7 @@ const unauth = {
router.post('/', async (req, res) => {
//return res.status(200).send(unauth);
const { operationName, variables = {} } = req.body;
console.log(`operationName: ${operationName}`);
res.send(await GatewayController[operationName](variables));
});

Expand Down
2 changes: 1 addition & 1 deletion api/routes/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Elijah Olmos
* Copyright (C) 2023 Elijah Olmos
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand Down
2 changes: 1 addition & 1 deletion api/routes/refresh-token.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Elijah Olmos
* Copyright (C) 2023 Elijah Olmos
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand Down
2 changes: 1 addition & 1 deletion api/routes/token-validate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Elijah Olmos
* Copyright (C) 2023 Elijah Olmos
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand Down
9 changes: 6 additions & 3 deletions bot.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Elijah Olmos
* Copyright (C) 2023 Elijah Olmos
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand Down Expand Up @@ -186,16 +186,19 @@ class DiscordHaloBot extends Client {
* @param {Object} args Destructured arguments
* @param {Interaction} args.intr Discord.js `Interaction`
* @param {EmbedBase | EmbedBase[]} [args.embed] Singular embed object to be included in reply. If unspecified, existing embeds are removed
* @param {boolean} [args.followUp] Whether or not to send another reply instead of replacing the existing one
* @returns {Promise<Message>} The reply that was sent (or the last one, if multiple were sent)
*/
async intrReply({ intr, embed = null, ...options }) {
async intrReply({ intr, embed = null, followUp = false, ...options }) {
const payload = {
embeds: !!embed ? [embed] : [],
fetchReply: true,
...options,
};
if (!Array.isArray(embed))
return intr.deferred || intr.replied ? await intr.editReply(payload) : await intr.reply(payload);
return intr.deferred || intr.replied
? await intr[followUp ? 'followUp' : 'editReply'](payload)
: await intr.reply(payload);
let msg;
for (const e of embed) {
payload.embeds = [e];
Expand Down
2 changes: 1 addition & 1 deletion caches.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Elijah Olmos
* Copyright (C) 2023 Elijah Olmos
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand Down
2 changes: 1 addition & 1 deletion classes/Command.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Elijah Olmos
* Copyright (C) 2023 Elijah Olmos
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand Down
2 changes: 1 addition & 1 deletion classes/CookieManager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Elijah Olmos
* Copyright (C) 2023 Elijah Olmos
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand Down
2 changes: 1 addition & 1 deletion classes/FirebaseStore.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Elijah Olmos
* Copyright (C) 2023 Elijah Olmos
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand Down
11 changes: 7 additions & 4 deletions classes/HaloWatcher.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Elijah Olmos
* Copyright (C) 2023 Elijah Olmos
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand Down Expand Up @@ -96,8 +96,10 @@ export class HaloWatcher extends EventEmitter {
class_id,
active_users,
//inject the readable course code into the response objects
//this metadata is being stored in the cache unnecessarily
metadata: {
courseCode: course.courseCode,
slugId: course.slugId,
},
})) ?? old_announcements;
// Logger.debug(old_announcements?.length);
Expand All @@ -120,9 +122,9 @@ export class HaloWatcher extends EventEmitter {
//write local cache to file, since changes were detected
await writeCacheFile({ filepath: class_id, data: new_announcements });

// to prevent announcement spam upon bot restart, only emit announcements that were published in past 1 hour
// to prevent announcement spam upon bot restart, only emit announcements that were published in past 6 hours
for (const announcement of this.#locateDifferenceInArrays(new_announcements, old_announcements))
new Date(announcement.publishDate).getTime() > new Date().getTime() - 1000 * 60 * 60 * 1 &&
new Date(announcement.publishDate).getTime() > new Date().getTime() - 1000 * 60 * 60 * 6 &&
this.emit('announcement', announcement);
} catch (e) {
if (e.code === 401)
Expand All @@ -145,7 +147,7 @@ export class HaloWatcher extends EventEmitter {
for (const [course_id, course] of Object.entries(COURSES)) {
for (const uid of Firebase.getActiveUsersInClass(course_id)) {
try {
//Logger.debug(`Getting ${uid} grades for ${course.courseCode}...`);
// Logger.debug(`Getting ${uid} grades for ${course.courseCode}...`);
const cookie = await Firebase.getUserCookie(uid); //store user cookie for multiple uses
if (!cookie) continue;
const old_grades = get([course_id, uid], null);
Expand Down Expand Up @@ -195,6 +197,7 @@ export class HaloWatcher extends EventEmitter {
courseCode: course.courseCode,
finalGrade,
uid,
slugId: course.slugId,
},
})
);
Expand Down
2 changes: 1 addition & 1 deletion classes/LocalCache.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Elijah Olmos
* Copyright (C) 2023 Elijah Olmos
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand Down
2 changes: 1 addition & 1 deletion classes/Logger.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Elijah Olmos
* Copyright (C) 2023 Elijah Olmos
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand Down
2 changes: 1 addition & 1 deletion classes/components/ConfirmInteraction.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Elijah Olmos
* Copyright (C) 2023 Elijah Olmos
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand Down
2 changes: 1 addition & 1 deletion classes/components/EmbedBase.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Elijah Olmos
* Copyright (C) 2023 Elijah Olmos
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand Down
2 changes: 1 addition & 1 deletion classes/events/CronEvent.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Elijah Olmos
* Copyright (C) 2023 Elijah Olmos
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand Down
2 changes: 1 addition & 1 deletion classes/events/DiscordEvent.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Elijah Olmos
* Copyright (C) 2023 Elijah Olmos
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand Down
2 changes: 1 addition & 1 deletion classes/events/FirebaseEvent.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Elijah Olmos
* Copyright (C) 2023 Elijah Olmos
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand Down
2 changes: 1 addition & 1 deletion classes/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Elijah Olmos
* Copyright (C) 2023 Elijah Olmos
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand Down
4 changes: 2 additions & 2 deletions classes/services/401Service.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Elijah Olmos
* Copyright (C) 2023 Elijah Olmos
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand Down Expand Up @@ -38,7 +38,7 @@ export const handle401 = async function ({ uid, msg }) {
user,
embed: new EmbedBase({
title: 'Service Disconnected',
description: `Halo Notification Service has temporarily lost connection to your Halo account. The connection will automatically be restored after some time; no action is required from you.
description: `Halo Notification Service has temporarily lost connection to your Halo account. This occurs when Halo automatically logs you out; unfortunately, nothing can be done by HNS to fix this.
To help prevent disconnections, periodically navigate to [halo.gcu.edu](https://halo.gcu.edu) using your web browser that has the HNS extension installed.`,
}).Error(),
components: [
Expand Down
29 changes: 28 additions & 1 deletion classes/services/AnnouncementService.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Elijah Olmos
* Copyright (C) 2023 Elijah Olmos
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand Down Expand Up @@ -82,6 +82,10 @@ export class AnnouncementService {
*/
static #parseAnnouncementData({ announcement }) {
//Logger.debug(announcement);
const {
metadata: { slugId },
} = announcement;

return {
content: `New announcement posted for **${announcement.metadata.courseCode}**:`,
embeds: [
Expand Down Expand Up @@ -114,6 +118,29 @@ export class AnnouncementService {
timestamp: announcement.publishDate,
}),
],
components: [
{
components: [
{
type: 2,
style: 1,
custom_id: `$post_${announcement.id}`,
disabled: false,
label: 'Mark as Read',
emoji: {
name: '✉',
},
},
{
type: 2,
style: 5,
label: 'View Announcements',
url: `https://halo.gcu.edu/courses/${slugId}/announcements`,
},
],
type: 1,
},
],
};
}
}
2 changes: 1 addition & 1 deletion classes/services/EncryptionService.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Elijah Olmos
* Copyright (C) 2023 Elijah Olmos
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand Down
4 changes: 2 additions & 2 deletions classes/services/FirebaseService.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Elijah Olmos
* Copyright (C) 2023 Elijah Olmos
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand All @@ -19,7 +19,7 @@ import { decryptCookieObject, encryptCookieObject, isValidCookieObject, Logger }
import { COOKIES } from '../../caches';
import { db } from '../../firebase';
import { CLASS_USERS_MAP, DEFAULT_SETTINGS_STORE, DISCORD_USER_MAP, USER_SETTINGS_STORE } from '../../stores';
const ACTIVE_STAGES = ['PRE_START', 'CURRENT'];
const ACTIVE_STAGES = ['PRE_START', 'CURRENT', 'POST'];

export const getActiveClasses = async function () {
return (
Expand Down
34 changes: 32 additions & 2 deletions classes/services/GradeService.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Elijah Olmos
* Copyright (C) 2023 Elijah Olmos
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand Down Expand Up @@ -84,12 +84,15 @@ export class GradeService {
const {
finalPoints,
finalComment,
assessment: { points, title },
assessment: { points, title, id: assessmentId },
metadata: {
courseCode,
finalGrade: { finalPoints: totalFinalPoints, maxPoints, gradeValue },
slugId,
},
} = grade;
const feedbackUrl = `https://halo.gcu.edu/courses/${slugId}/student/gradebook#grading-feedback/${assessmentId}`;

return {
content: `New grade published for **${courseCode}**:`,
embeds: [
Expand Down Expand Up @@ -125,6 +128,33 @@ export class GradeService {
timestamp: Date.now(),
}),
],
components: [
{
components: [
{
type: 2,
style: 1,
custom_id: `$grade_${assessmentId}`,
disabled: false,
label: 'Mark as Read',
emoji: {
name: '✉',
},
},
...(feedbackUrl?.startsWith('https://')
? [
{
type: 2,
style: 5,
label: 'View Feedback',
url: feedbackUrl,
},
]
: []),
],
type: 1,
},
],
};
}
}
Loading

0 comments on commit d56cf31

Please sign in to comment.