Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalized feed reader #31

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
**/*.log
config/environment.rb
.rvmrc
*.swp
6 changes: 5 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ gem 'rest-client'
gem 'daemons'

gem 'capistrano'
gem 'hunspell-ffi'
gem 'hunspell-ffi'

group :development, :test do
gem "pry"
end
13 changes: 13 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ GEM
net-ssh (>= 2.0.14)
net-ssh-gateway (>= 1.1.0)
cinch (1.1.1)
coderay (0.9.8)
daemons (1.1.0)
ffi (1.0.11)
highline (1.6.9)
hunspell-ffi (0.1.2)
ffi (>= 0.6.3)
method_source (0.6.7)
ruby_parser (>= 2.3.1)
mime-types (1.16)
net-scp (1.0.4)
net-ssh (>= 1.99.1)
Expand All @@ -21,8 +24,17 @@ GEM
net-ssh (2.2.1)
net-ssh-gateway (1.1.0)
net-ssh (>= 1.99.1)
pry (0.9.7.4)
coderay (~> 0.9.8)
method_source (~> 0.6.7)
ruby_parser (>= 2.3.1)
slop (~> 2.1.0)
rest-client (1.6.1)
mime-types (>= 1.16)
ruby_parser (2.3.1)
sexp_processor (~> 3.0)
sexp_processor (3.0.10)
slop (2.1.0)

PLATFORMS
ruby
Expand All @@ -32,4 +44,5 @@ DEPENDENCIES
cinch
daemons
hunspell-ffi
pry
rest-client
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ Running your own Mendibot
=========================
0. Clone the repository and run `bundle install`
1. Create a channel where you can test and not bother anyone
2. Copy `config/default_environment.rb` to `config/environment.rb`
2. Copy `config/environment.rb.example` to `config/environment.rb`
3. Set CHANNELS in `config/environment.rb` to the test channel you created
4. From your local command line, run `ruby bin/mendibot.rb`
4. From your local command line, run `ruby bin/mendibot.rb`
7 changes: 1 addition & 6 deletions bin/mendibot.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
#!/usr/bin/env ruby

begin
require_relative '../config/environment'
rescue LoadError
require_relative '../config/default_environment'
end

require_relative '../config/environment'
require_relative '../lib/mendibot'

Mendibot.run
14 changes: 11 additions & 3 deletions config/default_environment.rb → config/environment.rb.example
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,17 @@ module Config

OPERATORS = %w{ USERNAME_1 USERNAME_2 USERNAME_3 }

# Community RSS feed location and polling interval in seconds
RSS_URL = 'http://community.mendicantuniversity.org/articles.rss'
RSS_INTERVAL = 900
# RSS Feed Configuration
RSS_SETTINGS = {
interval: 900,
feeds: [
{
name: "example feed",
url: "http://www.example.com/feed.rss",
channels: ["#channel-1", "#channel-2"]
}
]
}

# Set to print the log URL when ending discussions
# Example: "http://mylogz.com/messages?"
Expand Down
2 changes: 1 addition & 1 deletion lib/mendibot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
require_relative '../plugins/ip2geo'
require_relative '../plugins/new_room'
require_relative '../plugins/spell'
require_relative '../plugins/community_rss'
require_relative '../plugins/rss_relay'

require_relative 'mendibot/mendibot'
2 changes: 1 addition & 1 deletion lib/mendibot/mendibot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def parse_options(options = {})
Mendibot::Plugins::IP2Geo,
Mendibot::Plugins::NewRoom,
Mendibot::Plugins::Spell,
Mendibot::Plugins::CommunityRSS
Mendibot::Plugins::RSSRelay
],
password: Mendibot::Config::PASSWORD
}.merge(options)
Expand Down
37 changes: 0 additions & 37 deletions plugins/community_rss.rb

This file was deleted.

36 changes: 36 additions & 0 deletions plugins/rss_relay.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require 'cinch'
require 'open-uri'
require 'rss'

module Mendibot
module Plugins
class RSSRelay
include Cinch::Plugin

timer Mendibot::Config::RSS_SETTINGS[:interval], method: :pull

def pull
Mendibot::Config::RSS_SETTINGS[:feeds].each do |feed|
open(feed[:url]) do |rss|
data = ::RSS::Parser.parse(rss)
min_time = Time.now - Mendibot::Config::RSS_SETTINGS[:interval]

data.items.each do |item|
next unless item.respond_to?(:pubDate) && !item.pubDate.nil?

if item.pubDate >= min_time
feed[:channels].each do |chan|
Channel(chan).send <<-MESSAGE
via #{feed[:name]} comes the epic saga "#{item.title}" (#{item.link})!
MESSAGE
end
end
end
end
end
rescue Exception => e
bot.logger.debug e.message
end
end
end
end