Skip to content
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
6 changes: 1 addition & 5 deletions bot/bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
require File.expand_path('../command_patterns', __FILE__)
require File.expand_path('../finish_notifier', __FILE__)
require File.expand_path('../pipeline_notifier', __FILE__)
require File.expand_path('../../lib/couchdb', __FILE__)

opts = Trollop.options do
opt :server, 'IRC server, expressed as a URI (irc://SERVER:PORT or ircs://SERVER:PORT for SSL)', :type => String
Expand All @@ -17,8 +16,6 @@
opt :schemes, 'Comma-separated list of acceptable URI schemes', :default => 'http,https,ftp'
opt :redis, 'URL of Redis server', :default => ENV['REDIS_URL'] || 'redis://localhost:6379/0'
opt :password, 'IRC server password', :default => nil, :type => String
opt :db, 'URL of CouchDB database', :default => ENV['COUCHDB_URL'] || 'http://localhost:5984/archivebot'
opt :db_credentials, 'Credentials for CouchDB database (USERNAME:PASSWORD)', :type => String, :default => nil
end

redis = Redis.new(:url => opts[:redis])
Expand Down Expand Up @@ -54,8 +51,7 @@
c.messages_per_second = 1.0
end

couchdb = Couchdb.new(URI(opts[:db]), opts[:db_credentials])
brain = Brain.new(schemes, redis, couchdb)
brain = Brain.new(schemes, redis)

on :message, CommandPatterns::ARCHIVE do |m, target, params|
brain.request_archive(m, target, params)
Expand Down
40 changes: 33 additions & 7 deletions bot/brain.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'addressable/uri'
require 'json'

require File.expand_path('../../lib/job', __FILE__)
require File.expand_path('../../lib/pipeline_info', __FILE__)
Expand All @@ -17,13 +18,11 @@ class Brain
include AddIgnoreSets
include PipelineOptions

attr_reader :couchdb
attr_reader :redis
attr_reader :schemes
attr_reader :url_pattern

def initialize(schemes, redis, couchdb)
@couchdb = couchdb
def initialize(schemes, redis)
@redis = redis
@schemes = schemes
@url_pattern ||= %r{(?:#{schemes.join('|')})://.+}
Expand Down Expand Up @@ -125,7 +124,20 @@ def request_archive(m, target, params, depth=:inf, url_file=false)

if h[:user_agent_alias]
ua_alias = h[:user_agent_alias]
user_agent = couchdb.user_agent_for_alias(ua_alias)

user_agents = {}

Dir.glob(File.join(File.expand_path('../../db/user_agents', __FILE__), "*.json")).each do |file|
data = JSON.parse(File.read(file))

data["agents"].each do |agent|
agent["aliases"].each do |alias_name|
user_agents[alias_name] = agent["name"]
end
end
end

user_agent = user_agents[ua_alias]

if !user_agent
reply m, %Q{Sorry, I don't know what the user agent "#{ua_alias}" is.}
Expand Down Expand Up @@ -260,7 +272,23 @@ def add_ignore_sets(m, job, names, need_authorization=true)

return unless names && !names.empty?

ignore_pairs = couchdb.resolve_ignore_sets(names)
unknown = []
ignore_pairs = []

names.each do |name|
file = File.join(File.expand_path('../../db/ignore_patterns', __FILE__), "#{name}.json")

if File.file?(file)
data = JSON.parse(File.read(file))

data.fetch('patterns', []).map do |pattern|
ignore_pairs << [name, pattern]
end
else
unknown << name
[]
end
end

resolved = ignore_pairs.map(&:first).uniq
patterns = ignore_pairs.map(&:last)
Expand All @@ -273,8 +301,6 @@ def add_ignore_sets(m, job, names, need_authorization=true)
reply m, %Q{Added #{patterns.length} patterns from ignore set #{resolved.first} to job #{job.ident}.}
end

unknown = names - resolved

if !unknown.empty?
reply m, "The following sets are unknown: #{unknown.join(', ')}"
end
Expand Down
8 changes: 0 additions & 8 deletions cogs/ignore_pattern_updater.rb

This file was deleted.

14 changes: 0 additions & 14 deletions cogs/start.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
require 'trollop'
require 'uri'

require File.expand_path('../ignore_pattern_updater', __FILE__)
require File.expand_path('../user_agent_updater', __FILE__)
require File.expand_path('../../lib/job', __FILE__)
require File.expand_path('../../lib/redis_subscriber', __FILE__)
require File.expand_path('../../lib/shared_config', __FILE__)
Expand Down Expand Up @@ -35,16 +33,6 @@ def on_receive(ident)
Reaper.supervise_as :reaper, opts[:redis]
TwitterTweeter.supervise_as :twitter_tweeter, opts[:redis], opts[:twitter_config]

ignore_patterns_path = File.expand_path('../../db/ignore_patterns', __FILE__)

IgnorePatternUpdater.supervise_as :ignore_pattern_updater,
ignore_patterns_path, db_uri, opts[:db_credentials]

user_agents_path = File.expand_path('../../db/user_agents', __FILE__)

UserAgentUpdater.supervise_as :user_agent_updater,
user_agents_path, db_uri, opts[:db_credentials]

# This should be started after all actors it references have started, which is
# why it's the last actor to start up.
if opts[:twitter_config]
Expand All @@ -55,8 +43,6 @@ def on_receive(ident)
if opts[:twitter_config]
Celluloid::Actor[:broadcaster].stop
end
Celluloid::Actor[:ignore_pattern_updater].stop
Celluloid::Actor[:user_agent_updater].stop
end

trap('INT') do
Expand Down
12 changes: 0 additions & 12 deletions cogs/user_agent_updater.rb

This file was deleted.