From 3105c95ea301a9beb10379f92d7e7c826f5eed34 Mon Sep 17 00:00:00 2001 From: Chloe Date: Thu, 18 Apr 2024 16:12:44 +1000 Subject: [PATCH 1/4] completed csesocLinks command --- commands/csesocLinks.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 commands/csesocLinks.js diff --git a/commands/csesocLinks.js b/commands/csesocLinks.js new file mode 100644 index 00000000..01179276 --- /dev/null +++ b/commands/csesocLinks.js @@ -0,0 +1,34 @@ +const { SlashCommandBuilder } = require("@discordjs/builders"); +const cheerio = require("cheerio"); +module.exports = { + data: new SlashCommandBuilder() + .setName("csesoclinks") + .setDescription("Provides all CSESoc related links."), + async execute(interaction) { + fetch("https://linktr.ee/csesoc") + .then(function (response) { + return response.text(); + }) + .then(function (html) { + const $ = cheerio.load(html); + const links = $("a"); + let output = ""; + links.each((index, value) => { + const title = $(value).text().trim(); + const href = $(value).attr("href"); + if (href && href !== "#" && !title.includes("Linktree")) { + output += `${title}: ${href}\n`; + } + }); + console.log(output); + + interaction.reply({ + content: output, + // ephemeral: true, + }); + }) + .catch(function (err) { + console.log("Failed to fetch page: ", err); + }); + }, +}; From 645479cb82438adde544e65955c76170657b4c5d Mon Sep 17 00:00:00 2001 From: Chloe Date: Thu, 18 Apr 2024 18:16:44 +1000 Subject: [PATCH 2/4] linting --- commands/csesocLinks.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/commands/csesocLinks.js b/commands/csesocLinks.js index 01179276..6ca48122 100644 --- a/commands/csesocLinks.js +++ b/commands/csesocLinks.js @@ -3,7 +3,7 @@ const cheerio = require("cheerio"); module.exports = { data: new SlashCommandBuilder() .setName("csesoclinks") - .setDescription("Provides all CSESoc related links."), + .setDescription("Provides CSESoc Linktree links."), async execute(interaction) { fetch("https://linktr.ee/csesoc") .then(function (response) { @@ -20,11 +20,8 @@ module.exports = { output += `${title}: ${href}\n`; } }); - console.log(output); - interaction.reply({ content: output, - // ephemeral: true, }); }) .catch(function (err) { From 1ff7e24b3e6680e44fde710a8987fed16cebc4f5 Mon Sep 17 00:00:00 2001 From: Chloe Date: Sun, 21 Apr 2024 20:50:47 +1000 Subject: [PATCH 3/4] Refactor execute function to use arrow functions --- commands/csesocLinks.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/commands/csesocLinks.js b/commands/csesocLinks.js index 6ca48122..0d2108f3 100644 --- a/commands/csesocLinks.js +++ b/commands/csesocLinks.js @@ -6,10 +6,10 @@ module.exports = { .setDescription("Provides CSESoc Linktree links."), async execute(interaction) { fetch("https://linktr.ee/csesoc") - .then(function (response) { - return response.text(); + .then((res) => { + return res.text(); }) - .then(function (html) { + .then((html) => { const $ = cheerio.load(html); const links = $("a"); let output = ""; @@ -21,10 +21,10 @@ module.exports = { } }); interaction.reply({ - content: output, + content: output, }); }) - .catch(function (err) { + .catch((err) => { console.log("Failed to fetch page: ", err); }); }, From d2568b0bcf1d735269c153e1181b4928a7b4aeff Mon Sep 17 00:00:00 2001 From: Chloe Date: Sun, 21 Apr 2024 20:57:49 +1000 Subject: [PATCH 4/4] linting --- commands/csesocLinks.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/csesocLinks.js b/commands/csesocLinks.js index 0d2108f3..f8c5d4d6 100644 --- a/commands/csesocLinks.js +++ b/commands/csesocLinks.js @@ -21,7 +21,7 @@ module.exports = { } }); interaction.reply({ - content: output, + content: output, }); }) .catch((err) => {