Skip to content

migrate from insou api to circles for the handbook commands #128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 22, 2023
Merged
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
52 changes: 27 additions & 25 deletions commands/handbook.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,76 +27,78 @@ 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;
// console.log(data);
} catch (e) {
return await interaction.reply({
content: "Invalid course code.",
ephemeral: true,
});
}

const {
title, code, UOC, level, description, study_level, school, campus,
equivalents, raw_requirements, exclusions, handbook_note, terms
} = 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",
inline: true,
},
{
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"]
.map((course) => `[${course}](${handbookURL}${course})`)
.join(", ") || "None",
value:
Object.keys(equivalents)
.map((course) => `[${course}](${course})`)
.join(", ") || "None",
inline: true,
},
{
name: "Exclusion Courses",
value:
data["exclusion_courses"]
Object.keys(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] });
}
},
Expand Down
2 changes: 1 addition & 1 deletion config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ user: user
dbname: bot
password: pass
host: 0.0.0.0
port: 40041
port: 40041
2 changes: 1 addition & 1 deletion config/handbook.json
Original file line number Diff line number Diff line change
@@ -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/"
}