Skip to content

Commit

Permalink
more work on #38
Browse files Browse the repository at this point in the history
  • Loading branch information
seiyria committed Jun 4, 2014
1 parent 04c1f6b commit f13bd08
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/modules/util/RSSModule.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ module.exports = (Module) ->

feeds: {}

MAX_CACHED_URLS: 100

constructor: (moduleManager) ->
super moduleManager

@db = @newDatabase 'feed-cache'

generateKey = (origin, key) =>
origin.bot.config.server + origin.channel + key

Expand All @@ -26,18 +30,24 @@ module.exports = (Module) ->
@reply origin, "You need to specify a valid URL."
return

#check for title existence

newFeed = new FeedSub url,
interval: interval

newFeed.on "item", (item) =>
shorturl item.link, (shorturl) =>
@reply origin, "[#{color.bold title}] (#{shorturl}) #{item.title}"
history: 10

@feeds[generateKey origin,title] = newFeed

#load _cache from the database

newFeed.start()

@reply origin, "I am now watching #{title} (#{url}) for posts."
newFeed.on "item", (item) =>
#check if URL cached (up to 100 items), ignore if so - otherwise cache (both in DB and on feed._cache)
shorturl item.link, (shorturl) =>
@reply origin, "[#{color.bold title}] (#{shorturl}) #{item.title}"

@reply origin, "I am now watching #{color.bold title} (#{url}) for posts."

@addRoute "rss :title :interval *", (origin, route) =>
interval = parseInt route.params.interval
Expand All @@ -50,4 +60,6 @@ module.exports = (Module) ->
@addRoute "rss :title *", (origin, route) =>
rss origin, route.splats[0], route.params.title

#remove RSS by title

RSSModule

0 comments on commit f13bd08

Please sign in to comment.