lib/agig/session.rb in agig-0.0.4 vs lib/agig/session.rb in agig-0.0.5

- old
+ new

@@ -15,16 +15,18 @@ 'CreateEvent' => '13', 'ForkEvent' => '3', 'PushEvent' => '14', } - ACTIVITIES = %w( - GistEvent - ForkEvent - FollowEvent - WatchEvent - ) + CHANNEL_SELECTOR = { + 'GistEvent' => '#activity', + 'ForkEvent' => '#activity', + 'FollowEvent' => '#activity', + 'WatchEvent' => '#activity', + 'PullRequestEvent' => '#pull_requests', + 'PullRequestReviewCommentEvent' => '#pull_requests', + } def server_name "github" end @@ -34,10 +36,18 @@ def main_channel @opts.main_channel || "#github" end + def channels + CHANNEL_SELECTOR.values.uniq << main_channel + end + + def channel(type) + CHANNEL_SELECTOR[type] || main_channel + end + def initialize(*args) super @last_retrieved = Time.now end @@ -56,11 +66,11 @@ when /\A\d+\z/ then value.to_i when /\A(?:\d+\.\d*|\.\d+)\z/ then value.to_f else value end } - [main_channel, '#activity'].each {|c| post @nick, JOIN, c } + channels.each {|c| post @nick, JOIN, c } @retrieve_thread = Thread.start do loop do begin @log.info 'retrieveing feed...' @@ -77,11 +87,10 @@ end entries.reverse_each do |entry| next if entry[:datetime] <= @last_retrieved type = entry[:id][%r|tag:github.com,2008:(.+?)/\d+|, 1] - channel = ACTIVITIES.include?(type) ? '#activity' : main_channel - post entry[:author], PRIVMSG, channel, "\003#{EVENTS[type] || '5'}#{entry[:title]}\017 \00314#{entry[:link]}\017" + post entry[:author], PRIVMSG, channel(type), "\003#{EVENTS[type] || '5'}#{entry[:title]}\017 \00314#{entry[:link]}\017" end @last_retrieved = entries.first[:datetime] @log.info 'sleep' sleep 30