twitch_bot/commands/hn.js

24 lines
730 B
JavaScript
Raw Normal View History

const command = {
name: "hn",
desc: "fetch hacker news",
2023-02-02 23:37:42 +01:00
restricted: false,
2023-02-02 23:58:58 +01:00
mod: false,
run: async (client, msg) => {
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)])
2023-02-11 13:48:05 +01:00
.catch((err) =>
console.error("Error when fetching hacker news: " + err.message)
);
2023-02-11 13:48:05 +01:00
await 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}`
);
},
};
2023-02-01 22:11:48 +01:00
module.exports = { command };