From db3cfdd67cd1269b0eb8441ed99416880d1467b4 Mon Sep 17 00:00:00 2001 From: imagine-hussain Date: Tue, 24 Jan 2023 04:28:24 +1100 Subject: [PATCH 1/4] migrate from insou api to circles for the handbook commands --- commands/handbook.js | 44 +++++++++++++++++++++++--------------------- config/handbook.json | 2 +- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/commands/handbook.js b/commands/handbook.js index 6be75e35..7be9b54e 100644 --- a/commands/handbook.js +++ b/commands/handbook.js @@ -27,7 +27,9 @@ module.exports = { let data; try { - const response = await axios.get(`${apiURL}${courseCode}`); + // Documented at: + // https://circlesapi.csesoc.app/docs#/courses/get_course_courses_getCourse__courseCode__get + const response = await axios.get(`${apiURL}/courses/getCourse/${courseCode}`); data = response.data; } catch (e) { return await interaction.reply({ @@ -36,27 +38,32 @@ module.exports = { }); } + const { + title, code, uoc, level, description, study_level, school, + faculty, equivalents, exclusions, terms, raw_requirements + } = data; + const courseInfo = new MessageEmbed() - .setTitle(data["title"]) - .setURL(`${handbookURL}${courseCode}`) + .setTitle(title) + .setURL(`${handbookURL}/${code}`) .setColor(0x3a76f8) .setAuthor( - `Course Info: ${courseCode} (${data["credit_points"]} UOC)`, + `Course Info: ${code} (${uoc} UOC)`, "https://i.imgur.com/EE3Q40V.png", ) .addFields( { name: "Overview", - value: textVersion(data["description"]).substring( + value: textVersion(description).substring( 0, - Math.min(textVersion(data["description"]).indexOf("\n"), 1024), + Math.min(textVersion(description).indexOf("\n"), 1024), ), inline: false, }, { name: "Enrolment Requirements", value: - data["enrolment_requirements"].replace( + raw_requirements.replace( /[A-Z]{4}[0-9]{4}/g, `[$&](${handbookURL}$&)`, ) || "None", @@ -64,18 +71,13 @@ module.exports = { }, { name: "Offering Terms", - value: data["offering_terms"], - inline: true, - }, - { - name: "Delivery Mode", - value: data["delivery_mode"], + value: terms.join(", "), inline: true, }, { name: "Equivalent Courses", value: - data["equivalent_courses"] + equivalents .map((course) => `[${course}](${handbookURL}${course})`) .join(", ") || "None", inline: true, @@ -83,19 +85,19 @@ module.exports = { { name: "Exclusion Courses", value: - data["exclusion_courses"] + exclusions .map((course) => `[${course}](${handbookURL}${course})`) .join(", ") || "None", inline: true, }, - { - name: "Course Outline", - value: `[${courseCode} Course Outline](${data["course_outline_url"]})`, - inline: true, - }, + /* { */ + /* name: "Course Outline", */ + /* value: `[${courseCode} Course Outline](${data["course_outline_url"]})`, */ + /* inline: true, */ + /* }, */ ) .setTimestamp() - .setFooter("Data fetched from Zac's Handbook API"); + .setFooter("Data fetched from Circles' Api"); await interaction.reply({ embeds: [courseInfo] }); } diff --git a/config/handbook.json b/config/handbook.json index 3fe12ea2..d67bd252 100644 --- a/config/handbook.json +++ b/config/handbook.json @@ -1,4 +1,4 @@ { - "apiURL": "https://handbook.insou.dev/api/v1/course/", + "apiURL": "https://circlesapi.csesoc.app/", "handbookURL": "https://www.handbook.unsw.edu.au/undergraduate/courses/2022/" } From f7f653cb4ffc48852876e95d11eda23ba95ba894 Mon Sep 17 00:00:00 2001 From: imagine-hussain Date: Tue, 24 Jan 2023 04:33:51 +1100 Subject: [PATCH 2/4] remove trailing forward slash in handbook.json --- config/handbook.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/handbook.json b/config/handbook.json index d67bd252..9a8d7097 100644 --- a/config/handbook.json +++ b/config/handbook.json @@ -1,4 +1,4 @@ { - "apiURL": "https://circlesapi.csesoc.app/", + "apiURL": "https://circlesapi.csesoc.app", "handbookURL": "https://www.handbook.unsw.edu.au/undergraduate/courses/2022/" } From 79659f9e69390909011afd63614b94290746c23b Mon Sep 17 00:00:00 2001 From: tunein Date: Sat, 18 Feb 2023 18:53:11 +1100 Subject: [PATCH 3/4] handbook: the handbook is fixed --- commands/handbook.js | 18 +++++++++--------- config/database.yml | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/commands/handbook.js b/commands/handbook.js index 7be9b54e..5fe9b037 100644 --- a/commands/handbook.js +++ b/commands/handbook.js @@ -31,6 +31,7 @@ module.exports = { // https://circlesapi.csesoc.app/docs#/courses/get_course_courses_getCourse__courseCode__get const response = await axios.get(`${apiURL}/courses/getCourse/${courseCode}`); data = response.data; + console.log(data); } catch (e) { return await interaction.reply({ content: "Invalid course code.", @@ -39,8 +40,8 @@ module.exports = { } const { - title, code, uoc, level, description, study_level, school, - faculty, equivalents, exclusions, terms, raw_requirements + title, code, UOC, level, description, study_level, school, campus, + equivalents, raw_requirements, exclusions, handbook_note, terms } = data; const courseInfo = new MessageEmbed() @@ -48,7 +49,7 @@ module.exports = { .setURL(`${handbookURL}/${code}`) .setColor(0x3a76f8) .setAuthor( - `Course Info: ${code} (${uoc} UOC)`, + `Course Info: ${code} (${UOC} UOC)`, "https://i.imgur.com/EE3Q40V.png", ) .addFields( @@ -76,16 +77,16 @@ module.exports = { }, { name: "Equivalent Courses", - value: - equivalents - .map((course) => `[${course}](${handbookURL}${course})`) - .join(", ") || "None", + value: + Object.keys(equivalents) + .map((course) => `[${course}](${course})`) + .join(", ") || "None", inline: true, }, { name: "Exclusion Courses", value: - exclusions + Object.keys(exclusions) .map((course) => `[${course}](${handbookURL}${course})`) .join(", ") || "None", inline: true, @@ -98,7 +99,6 @@ module.exports = { ) .setTimestamp() .setFooter("Data fetched from Circles' Api"); - await interaction.reply({ embeds: [courseInfo] }); } }, diff --git a/config/database.yml b/config/database.yml index 1fa06e4f..eac5e48b 100644 --- a/config/database.yml +++ b/config/database.yml @@ -6,4 +6,4 @@ user: user dbname: bot password: pass host: 0.0.0.0 -port: 40041 +port: 40041 \ No newline at end of file From 9c9ac9f29b03916362113a5eae9c4e1a8cc276cb Mon Sep 17 00:00:00 2001 From: zcDay1 <113964162+zcDay1@users.noreply.github.com> Date: Wed, 22 Feb 2023 12:13:16 +1100 Subject: [PATCH 4/4] Update handbook.js commented out a console.log --- commands/handbook.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/handbook.js b/commands/handbook.js index 5fe9b037..339fd563 100644 --- a/commands/handbook.js +++ b/commands/handbook.js @@ -31,7 +31,7 @@ module.exports = { // https://circlesapi.csesoc.app/docs#/courses/get_course_courses_getCourse__courseCode__get const response = await axios.get(`${apiURL}/courses/getCourse/${courseCode}`); data = response.data; - console.log(data); + // console.log(data); } catch (e) { return await interaction.reply({ content: "Invalid course code.",