summaryrefslogtreecommitdiffstats
path: root/news
diff options
context:
space:
mode:
authortv <tv@nomic.retiolum>2014-03-17 03:54:49 +0100
committertv <tv@nomic.retiolum>2014-03-17 03:54:49 +0100
commitac8e7d1197d6c6466980fdf82ed8536c81cb612e (patch)
treec9b5e085bab31714b7f099c0206a545bad462e5d /news
parente8292ba803596a2605d0ff8a94f51eb8707c115a (diff)
newsbot.js: remember last feed to not doublepost
Diffstat (limited to 'news')
-rw-r--r--news/newsbot.js42
1 files changed, 16 insertions, 26 deletions
diff --git a/news/newsbot.js b/news/newsbot.js
index 55564f0f..a598f118 100644
--- a/news/newsbot.js
+++ b/news/newsbot.js
@@ -85,6 +85,12 @@ function create_feedbot (nick, uri, channels) {
client.say(channel, text)
})
}
+
+ function broadcast_new_item (item) {
+ return getShortLink(item.link, function (error, shortlink) {
+ return broadcast(item.title + ' ' + shortlink)
+ })
+ }
client.once('registered', loop_feedparser)
client.once('registered', deaf_myself)
@@ -134,35 +140,19 @@ function create_feedbot (nick, uri, channels) {
}
})
feedparser.on('end', function () {
- items = items.sort(function (a, b) {
- return a.date - b.date
- })
-
- var indexOfLastGuid = items
- .map(function (x) { return x.guid })
- .indexOf(client.lastGuid)
-
- var newitems = items
- var olditems = []
- // if items contain lastGuid, then only items after that are news
- if (!!~indexOfLastGuid) {
- olditems = newitems.splice(0, indexOfLastGuid + 1)
+ if (client.lastItems) {
+ items.forEach(function (item)) {
+ if (!client.lastItems.hasOwnProperty(item.title)) {
+ broadcast_new_item(item)
+ }
+ })
}
- if (newitems.length > 0) {
- // only broadcast news if we're not starting up
- // (i.e. we already have a lastGuid)
- if (client.lastGuid) {
- newitems.forEach(function (item) {
- return getShortLink(item.link, function (error, shortlink) {
- return broadcast(item.title + ' ' + shortlink)
- })
- })
- }
-
- client.lastGuid = newitems[newitems.length - 1].guid
- }
+ client.lastItems = {}
+ items.forEach(function (item) {
+ client.lastItems[item.title] = true
+ })
return setTimeout(loop_feedparser, feedbot_loop_delay)
})