21 lines
689 B
JavaScript
21 lines
689 B
JavaScript
const command = {
|
|
name: "hn",
|
|
desc: "fetch hacker news",
|
|
run: async (client, msg, splitted) => {
|
|
const data = await fetch(
|
|
`https://hn.algolia.com/api/v1/search?tags=front_page`
|
|
)
|
|
.then((res) => res.json())
|
|
.then((data) => data.hits[Math.floor(Math.random() * data.hits.length)])
|
|
.catch((err) => console.log(err));
|
|
|
|
client
|
|
.say(
|
|
msg.channelName,
|
|
`${msg.displayName}, Hacker News: ${data.title} (Points: ${data.points}, Comments: ${data.num_comments}) Article: ${data.url} Comments: https://news.ycombinator.com/item?id=${data.objectID}`
|
|
)
|
|
.catch((err) => console.log(err));
|
|
},
|
|
};
|
|
|
|
module.exports = { command };
|