adding max posts
This commit is contained in:
parent
8608fc661d
commit
776c026a19
22
bot.js
22
bot.js
@ -4,8 +4,17 @@ if (process.env.NODE_ENV !== "production") {
|
||||
let Mastodon = require("mastodon-api");
|
||||
let Parser = require("rss-parser");
|
||||
let parser = new Parser();
|
||||
let maxPostPerScan = process.env.MAX_POST_PER_SCAN;
|
||||
|
||||
(async () => {
|
||||
await postFeed();
|
||||
|
||||
setInterval(async () => {
|
||||
await postFeed();
|
||||
}, 20 * 60 * 1000);
|
||||
})();
|
||||
|
||||
async function postFeed() {
|
||||
const M = new Mastodon({
|
||||
access_token: `${process.env.MASTODON_ACCESS_KEY}`,
|
||||
timeout_ms: 60 * 1000, // optional HTTP request timeout to apply to all requests.
|
||||
@ -20,13 +29,20 @@ let parser = new Parser();
|
||||
);
|
||||
var postDate = new Date(timeline.data[0].created_at);
|
||||
|
||||
feed.items.forEach(async (item) => {
|
||||
let count = 0;
|
||||
feed.items.every(async (item) => {
|
||||
if (count > maxPostPerScan) return false;
|
||||
|
||||
let pubDate = new Date(item.pubDate);
|
||||
|
||||
if (pubDate > postDate) {
|
||||
M.post("statuses", {
|
||||
count++;
|
||||
await M.post("statuses", {
|
||||
status: `${item.title}\n\n#NeoVibe #${process.env.POST_HASHTAG}\n\n${item.link}`,
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
})();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user