Skip to content
This repository was archived by the owner on Nov 6, 2024. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"fastify": "^4.0.0",
"fastify-cli": "^4.1.1",
"fastify-plugin": "^3.0.0",
"mongodb": "^4.7.0"
"mongodb": "^6.2.0"
},
"devDependencies": {
"@types/node": "^18.0.0",
Expand Down
1 change: 0 additions & 1 deletion src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export async function connect(): Promise<
const config = getConfig();
const client = new mongo.MongoClient(config.mongoUrl, {
serverApi: "1",
keepAlive: true,
retryWrites: true,
});
console.log("connecting to database...");
Expand Down
30 changes: 30 additions & 0 deletions src/states/render-messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ export const renderAmizoneMenu = () => ({
title: "Exam Schedule",
description: "(includes location/room no.)",
},
{
id: "7",
title: "Help" ,
description: "(List of short commands)",
},
{
id: "6",
title: "Logout",
Expand Down Expand Up @@ -286,6 +291,31 @@ export const renderExamSchedule = (schedule: V1ExaminationSchedule) => {
${exams}`;
};

export const renderHelpMessage = () =>
`Help Commands

/a - To get attendance

/c - To know your courses

/f - To give feedback

/l - To Logout

/e - Exam Schedule

For class schedule

/cs

Some more easy ways

/cs +x (for x days into the future)

/cs -x (for x days in the past)

For example:- /cs+0 will render todays Class Schedule).`;

export const renderFacultyFeedbackInstructions =
() => `This method will submit feedback for *all* your faculty in a single step.

Expand Down
39 changes: 37 additions & 2 deletions src/states/state-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
renderFacultyFeedbackInstructions,
renderFacultyFeedbackConfirmation,
renderExamSchedule,
renderHelpMessage,
} from "./render-messages.js";
import { firstNonEmpty, newAmizoneClient } from "../utils.js";

Expand Down Expand Up @@ -112,8 +113,10 @@ const AmizoneMenuOptions = {
GET_COURSES: "courses",
FILL_FACULTY_FEEDBACK: "fill faculty feedback",
GET_EXAM_SCHEDULE: "exam schedule",
GET_HELP: "help",
};


type StateHandlerFunctionOut = Promise<{
success: boolean;
message: string | object | null;
Expand Down Expand Up @@ -173,6 +176,18 @@ const amizoneMenuHandlersMap: Map<string, StateHandlerFunction> = new Map([
newState: states.EXPECT_FACULTY_FEEDBACK_SPEC,
}),
],
[
AmizoneMenuOptions.GET_HELP,
async (): StateHandlerFunctionOut => {
try {

return { success: true, message: renderHelpMessage() };
}
catch (err) {
return { success: false, message: "" };
}
}
],
[
AmizoneMenuOptions.GET_EXAM_SCHEDULE,
async (ctx): StateHandlerFunctionOut => {
Expand All @@ -187,7 +202,7 @@ const amizoneMenuHandlersMap: Map<string, StateHandlerFunction> = new Map([
} catch (err) {
return { success: false, message: "" };
}
},
}
],
]);

Expand Down Expand Up @@ -217,7 +232,27 @@ export const handleLoggedIn = async (ctx: BotHandlerContext): Promise<User> => {
return updatedUser;
}

const messageHandler = amizoneMenuHandlersMap.get(inputMessage);
type InputType = {
[key: string]: string;
};

const mappings: InputType = {
"/a": AmizoneMenuOptions.GET_ATTENDANCE,
"/c":AmizoneMenuOptions.GET_COURSES,
"/cs": AmizoneMenuOptions.GET_SCHEDULE,
"/f": AmizoneMenuOptions.FILL_FACULTY_FEEDBACK,
"/e" : AmizoneMenuOptions.GET_EXAM_SCHEDULE,
"/h" : AmizoneMenuOptions.GET_HELP,
};

let inputMessageSlash: string = inputMessage;

if (inputMessage in mappings) {
inputMessageSlash = mappings[inputMessage];
}


const messageHandler = amizoneMenuHandlersMap.get(inputMessageSlash);

if (messageHandler === undefined) {
// TODO: send a more helpful message...
Expand Down
90 changes: 22 additions & 68 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,13 @@
"@jridgewell/resolve-uri" "^3.0.3"
"@jridgewell/sourcemap-codec" "^1.4.10"

"@mongodb-js/saslprep@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@mongodb-js/saslprep/-/saslprep-1.1.0.tgz#022fa36620a7287d17acd05c4aae1e5f390d250d"
integrity sha512-Xfijy7HvfzzqiOAhAepF4SGN5e9leLkMvg/OPOF97XemjfVCYN/oWa75wnkc6mltMSTwY+XlbhWgUOJmkFspSw==
dependencies:
sparse-bitfield "^3.0.3"

"@nodelib/[email protected]":
version "2.1.5"
resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz#7619c2eb21b25483f6d167548b4cfd5a7488c3d5"
Expand Down Expand Up @@ -791,11 +798,6 @@ balanced-match@^1.0.0:
resolved "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz"
integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==

base64-js@^1.3.1:
version "1.5.1"
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a"
integrity sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==

binary-extensions@^2.0.0:
version "2.2.0"
resolved "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz"
Expand Down Expand Up @@ -832,26 +834,16 @@ browserslist@^4.20.2:
node-releases "^2.0.5"
picocolors "^1.0.0"

bson@^4.6.3:
version "4.6.4"
resolved "https://registry.yarnpkg.com/bson/-/bson-4.6.4.tgz#e66d4a334f1ab230dfcfb9ec4ea9091476dd372e"
integrity sha512-TdQ3FzguAu5HKPPlr0kYQCyrYUYh8tFM+CMTpxjNzVzxeiJY00Rtuj3LXLHSgiGvmaWlZ8PE+4KyM2thqE38pQ==
dependencies:
buffer "^5.6.0"
bson@^6.2.0:
version "6.2.0"
resolved "https://registry.yarnpkg.com/bson/-/bson-6.2.0.tgz#4b6acafc266ba18eeee111373c2699304a9ba0a3"
integrity sha512-ID1cI+7bazPDyL9wYy9GaQ8gEEohWvcUl/Yf0dIdutJxnmInEEyCsb4awy/OiBfall7zBA179Pahi3vCdFze3Q==

buffer-from@^1.0.0:
version "1.1.2"
resolved "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz"
integrity sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==

buffer@^5.6.0:
version "5.7.1"
resolved "https://registry.yarnpkg.com/buffer/-/buffer-5.7.1.tgz#ba62e7c13133053582197160851a8f648e99eed0"
integrity sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==
dependencies:
base64-js "^1.3.1"
ieee754 "^1.1.13"

caching-transform@^4.0.0:
version "4.0.0"
resolved "https://registry.npmjs.org/caching-transform/-/caching-transform-4.0.0.tgz"
Expand Down Expand Up @@ -1197,11 +1189,6 @@ delayed-stream@~1.0.0:
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
integrity sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==

denque@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/denque/-/denque-2.0.1.tgz#bcef4c1b80dc32efe97515744f21a4229ab8934a"
integrity sha512-tfiWc6BQLXNLpNiR5iGd0Ocu3P3VpxfzFiqubLgMfhfOw9WyvgJBd46CClNn9k3qfbjvT//0cf7AlYRX/OslMQ==

[email protected]:
version "2.0.0"
resolved "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz"
Expand Down Expand Up @@ -2022,11 +2009,6 @@ http-errors@^2.0.0:
statuses "2.0.1"
toidentifier "1.0.1"

ieee754@^1.1.13:
version "1.2.1"
resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.2.1.tgz#8eb7a10a63fff25d15a57b001586d177d1b0d352"
integrity sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==

ignore@^5.2.0:
version "5.2.0"
resolved "https://registry.npmjs.org/ignore/-/ignore-5.2.0.tgz"
Expand Down Expand Up @@ -2101,11 +2083,6 @@ internal-slot@^1.0.3:
has "^1.0.3"
side-channel "^1.0.4"

ip@^1.1.5:
version "1.1.8"
resolved "https://registry.yarnpkg.com/ip/-/ip-1.1.8.tgz#ae05948f6b075435ed3307acce04629da8cdbf48"
integrity sha512-PuExPYUiu6qMBQb4l06ecm6T6ujzhmh+MeJcW9wa89PoAz5pvd4zPgN5WJV104mb6S2T1AwNIAaB70JNrLQWhg==

[email protected]:
version "1.9.1"
resolved "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz"
Expand Down Expand Up @@ -2596,25 +2573,22 @@ mkdirp@^1.0.4:
resolved "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz"
integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==

mongodb-connection-string-url@^2.5.2:
version "2.5.2"
resolved "https://registry.yarnpkg.com/mongodb-connection-string-url/-/mongodb-connection-string-url-2.5.2.tgz#f075c8d529e8d3916386018b8a396aed4f16e5ed"
integrity sha512-tWDyIG8cQlI5k3skB6ywaEA5F9f5OntrKKsT/Lteub2zgwSUlhqEN2inGgBTm8bpYJf8QYBdA/5naz65XDpczA==
mongodb-connection-string-url@^2.6.0:
version "2.6.0"
resolved "https://registry.yarnpkg.com/mongodb-connection-string-url/-/mongodb-connection-string-url-2.6.0.tgz#57901bf352372abdde812c81be47b75c6b2ec5cf"
integrity sha512-WvTZlI9ab0QYtTYnuMLgobULWhokRjtC7db9LtcVfJ+Hsnyr5eo6ZtNAt3Ly24XZScGMelOcGtm7lSn0332tPQ==
dependencies:
"@types/whatwg-url" "^8.2.1"
whatwg-url "^11.0.0"

mongodb@^4.7.0:
version "4.7.0"
resolved "https://registry.yarnpkg.com/mongodb/-/mongodb-4.7.0.tgz#99f7323271d93659067695b60e7b4efee2de9bf0"
integrity sha512-HhVar6hsUeMAVlIbwQwWtV36iyjKd9qdhY+s4wcU8K6TOj4Q331iiMy+FoPuxEntDIijTYWivwFJkLv8q/ZgvA==
mongodb@^6.2.0:
version "6.2.0"
resolved "https://registry.yarnpkg.com/mongodb/-/mongodb-6.2.0.tgz#2c9dcb3eeaf528ed850e94b3df392de6c6b0d7ab"
integrity sha512-d7OSuGjGWDZ5usZPqfvb36laQ9CPhnWkAGHT61x5P95p/8nMVeH8asloMwW6GcYFeB0Vj4CB/1wOTDG2RA9BFA==
dependencies:
bson "^4.6.3"
denque "^2.0.1"
mongodb-connection-string-url "^2.5.2"
socks "^2.6.2"
optionalDependencies:
saslprep "^1.0.3"
"@mongodb-js/saslprep" "^1.1.0"
bson "^6.2.0"
mongodb-connection-string-url "^2.6.0"

[email protected]:
version "1.1.4"
Expand Down Expand Up @@ -3222,13 +3196,6 @@ safe-stable-stringify@^2.1.0:
resolved "https://registry.npmjs.org/safe-stable-stringify/-/safe-stable-stringify-2.3.1.tgz"
integrity sha512-kYBSfT+troD9cDA85VDnHZ1rpHC50O0g1e6WlGHVCz/g+JS+9WKLj+XwFYyR8UbrZN8ll9HUpDAAddY58MGisg==

saslprep@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/saslprep/-/saslprep-1.0.3.tgz#4c02f946b56cf54297e347ba1093e7acac4cf226"
integrity sha512-/MY/PEMbk2SuY5sScONwhUDsV2p77Znkb/q3nSVstq/yQzYJOH/Azh29p9oJLsl3LnQwSvZDKagDGBsBwSooag==
dependencies:
sparse-bitfield "^3.0.3"

scheduler@^0.20.2:
version "0.20.2"
resolved "https://registry.npmjs.org/scheduler/-/scheduler-0.20.2.tgz"
Expand Down Expand Up @@ -3324,19 +3291,6 @@ slice-ansi@^3.0.0:
astral-regex "^2.0.0"
is-fullwidth-code-point "^3.0.0"

smart-buffer@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/smart-buffer/-/smart-buffer-4.2.0.tgz#6e1d71fa4f18c05f7d0ff216dd16a481d0e8d9ae"
integrity sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg==

socks@^2.6.2:
version "2.6.2"
resolved "https://registry.yarnpkg.com/socks/-/socks-2.6.2.tgz#ec042d7960073d40d94268ff3bb727dc685f111a"
integrity sha512-zDZhHhZRY9PxRruRMR7kMhnf3I8hDs4S3f9RecfnGxvcBHQcKcIH/oUcEWffsfl1XxdYlA7nnlGbbTvPz9D8gA==
dependencies:
ip "^1.1.5"
smart-buffer "^4.2.0"

sonic-boom@^2.2.0:
version "2.8.0"
resolved "https://registry.npmjs.org/sonic-boom/-/sonic-boom-2.8.0.tgz"
Expand Down