Skip to content

Commit 6da7e8e

Browse files
authored
[DISC-107] Adding csesocLinks to get CSESoc related links (#170)
* completed csesocLinks command * linting * Refactor execute function to use arrow functions * linting
1 parent 34e2f53 commit 6da7e8e

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

commands/csesocLinks.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const { SlashCommandBuilder } = require("@discordjs/builders");
2+
const cheerio = require("cheerio");
3+
module.exports = {
4+
data: new SlashCommandBuilder()
5+
.setName("csesoclinks")
6+
.setDescription("Provides CSESoc Linktree links."),
7+
async execute(interaction) {
8+
fetch("https://linktr.ee/csesoc")
9+
.then((res) => {
10+
return res.text();
11+
})
12+
.then((html) => {
13+
const $ = cheerio.load(html);
14+
const links = $("a");
15+
let output = "";
16+
links.each((index, value) => {
17+
const title = $(value).text().trim();
18+
const href = $(value).attr("href");
19+
if (href && href !== "#" && !title.includes("Linktree")) {
20+
output += `${title}: ${href}\n`;
21+
}
22+
});
23+
interaction.reply({
24+
content: output,
25+
});
26+
})
27+
.catch((err) => {
28+
console.log("Failed to fetch page: ", err);
29+
});
30+
},
31+
};

0 commit comments

Comments
 (0)