README
@abbot hn
(defaults to point threshold of 100)
@abbot hn 200
(only show posts above 200 points)
@abbot hn 200 5
(only show top 5 posts above 200 points)
Usage
@abbot hn
(defaults to point threshold of 100)
@abbot hn 200
(only show posts above 200 points)
@abbot hn 200 5
(only show top 5 posts above 200 points)
Code
const axios = require(‘axios’);
const [first, second] = bot.arguments.split(‘ ‘);
const threshold = Number(first) || 100;
const limit = Number(second) || 10;
await axios.get(“https://node-hnapi.herokuapp.com/news?page=1”)
.then(res => {
return res.data
.map(({id, title, points}) => ({id, title, points}))
.filter(({points}) => points > threshold)
.sort((a, b) => b.points – a.points)
.map(({id, title, points}) => {
return`- [${points} points] <https://news.ycombinator.com/item?id=${id}|${title}>`
})
.slice(0, limit)
.join(‘\n’);
})
.then(text => bot.reply(text))
.catch(err => bot.reply(`Something went wrong! ${String(err)}`))
})();