Class: Artaius::Plugins::NewsFetcher

Inherits:
Object
  • Object
show all
Includes:
Cinch::Plugin
Defined in:
lib/artaius/plugins/news_fetcher.rb

Constant Summary collapse

KAGDEV_RSS =

Internal: RSS address of KAG development blog.

'http://devlog.kag2d.com/rss'
CHECK_TIME_LAPSE =

Internal: Time lapse between checking RSS feed for new posts.

1800

Instance Method Summary collapse

Instance Method Details

#latest_news(m) ⇒ Object

Internal: Send on the channel information about the latest post at KAG development blog and give a link to it.

Returns nothing.



63
64
65
66
67
68
69
70
71
# File 'lib/artaius/plugins/news_fetcher.rb', line 63

def latest_news(m)
  news = News.order(:date).last

  author = reveal_author(news.author)
  date   = I18n.localize(news.date, :full)

  m.reply I18n.news_fetcher.latest_news(date, author, news.title)
  m.reply I18n.news_fetcher.read_post(news.link)
end

#send_newsObject

Internal: Send latest news on channels.

Returns nothing.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/artaius/plugins/news_fetcher.rb', line 23

def send_news
  feed = RSS::Parser.parse open(KAGDEV_RSS).read
  last_post_title = feed.channel.item.title

  # Check, whether the latest title of the post at KAG development
  # blog is still the same, as it was, when the fetcher checked it last
  # time.
  return if unchanged?(last_post_title)

  item = feed.channel.item

     = item.pubDate
   = item.dc_creator
  last_post_link   = item.link

  News.create(
    :title  => last_post_title,
    :date   => ,
    :author => ,
    :link   => last_post_link
  )

  real_author = reveal_author()
  short_link = open("http://clck.ru/--?url=#{last_post_link}").read

  Bot::CHANNELS.each do |chan|
    Channel(chan).send I18n.news_fetcher.news(real_author, last_post_title, short_link)
  end
rescue SocketError
  nil
end