Class: Cinch::Plugins::RssMonitor

Inherits:
Object
  • Object
show all
Includes:
Cinch::Plugin
Defined in:
lib/cinch/rssmonitor.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ RssMonitor

Returns a new instance of RssMonitor.



15
16
17
18
19
# File 'lib/cinch/rssmonitor.rb', line 15

def initialize(*args)
	super

	@rss_file = config[:rss_file]
end

Instance Method Details

#add_rss(m, rss, link) ⇒ Object



21
22
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
54
55
56
57
58
# File 'lib/cinch/rssmonitor.rb', line 21

def add_rss(m, rss, link)

	rss_name = get_rss
	rss_name = rss_name.find{|q| q["rss"] == rss }

	if rss_name.nil?
	  feed_base = "nothing"
	else
	  feed_base = rss_name["rss"]
	end

	if feed_base == rss
	  m.reply "#{rss} has already been added"  
	else      

	  #get title
	  get_title = SimpleRSS.parse open("#{link}")
	  title = get_title.items.first.title
	  m.reply title

	  # add rss link and last/first title
	  new_rss = { "rss" => rss, "link" => link, "deleted" => false, "title" => title}

	  # add it to the list
	  existing_rss = get_rss  || []
	  existing_rss << new_rss

	  new_rss_index = existing_rss.index(new_rss)
	  existing_rss[new_rss_index]["id"] = new_rss_index + 1

	  # write it to the file
	  output = File.new(@rss_file, 'w')
	  output.puts YAML.dump(existing_rss)
	  output.close

	  m.reply "Added rss #{rss}"
	end
end

#read_rss(m, rss) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/cinch/rssmonitor.rb', line 60

def read_rss(m, rss)
	rss_name = get_rss
	rss_name = rss_name.detect{|q| q["rss"] == rss } 

	if rss_name.nil?
	  m.reply "RSS not found"
	else
	  link = rss_name["link"]
	  rss = SimpleRSS.parse open("#{rss_name["link"]}")
	  m.reply "#{rss.items.first.title} - #{rss.items.first.link}"
	end
end