stalkerr 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3489d438829ecb853ae319bbf7142e55b81c990a
4
- data.tar.gz: cd49cbf27ad03f133d475bfe051671856b43105a
3
+ metadata.gz: 8fa6ca412a98e0f1e06e9ebcecef0cc0d94614d2
4
+ data.tar.gz: 173b729e7245b4d2359062acdef617941058aed6
5
5
  SHA512:
6
- metadata.gz: 4dee29abedc5b57d391131491662ea8f8e9232fc64b5da5962ce45c2cba50d7d2d218de80c47080cb19ed3760b6156984aa85a03fdd786615b209746472191f3
7
- data.tar.gz: 678024dc0c53d52ee7b9a928efc4a6d86f4d15b67b3224241912328cc99972599d456091b71e53cfd6d851e41dfa866ee130b05e6a2587962e98703183f007c0
6
+ metadata.gz: b76e30f8582c38eb6f39327a2dc8cbd70709874d3dad047638a20e22fdafde1fde8d1dc024eabe1c078200a23ed8c5a6e839d97b84e84e1de233396eb1cf695f
7
+ data.tar.gz: 5d1e9e5a0640036e8d08075e135a4318aa9d40a4fe196d7a9a766b2c705777951c2cb9ee010fdc11fa2e15cc50486b1e31af5a6a3c11ea486cee21a3062a93a5
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --order random
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.2
5
+ before_install:
6
+ - gem update bundler
7
+ script:
8
+ - bundle exec rspec
9
+ notifications:
10
+ irc:
11
+ on_success: change
12
+ on_failure: always
13
+ channels:
14
+ - "irc.freenode.org#linyows"
data/Gemfile CHANGED
@@ -1,7 +1,16 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'net-irc'
4
- gem 'json'
5
- gem 'octokit'
6
- gem 'qiita'
7
- gem 'string-irc'
3
+ gemspec
4
+
5
+ group :development do
6
+ gem 'pry'
7
+ gem 'awesome_print', require: 'ap'
8
+ end
9
+
10
+ group :test do
11
+ gem 'coveralls', require: false
12
+ gem 'simplecov', require: false
13
+ gem 'rspec', '~> 3.1.0'
14
+ gem 'vcr', '~> 2.9.3'
15
+ gem 'webmock', '~> 1.19.0'
16
+ end
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 by linyows <linyows@gmail.com>
1
+ Copyright (c) 2013 linyows <linyows@gmail.com>
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,23 +1,67 @@
1
1
  Stalkerr
2
2
  ========
3
3
 
4
+ [![Gem Version](https://badge.fury.io/rb/stalkerr.png)][gem]
5
+ [![Build Status](https://secure.travis-ci.org/linyows/stalkerr.png?branch=master)][travis]
6
+ [![Dependency Status](https://gemnasium.com/linyows/stalkerr.png?travis)][gemnasium]
7
+ [![Code Climate](https://codeclimate.com/github/linyows/stalkerr.png)][codeclimate]
8
+ [![Coverage Status](https://coveralls.io/repos/linyows/stalkerr/badge.png?branch=master)][coveralls]
9
+
10
+ [gem]: https://rubygems.org/gems/stalkerr
11
+ [travis]: http://travis-ci.org/linyows/stalkerr
12
+ [gemnasium]: https://gemnasium.com/linyows/stalkerr
13
+ [codeclimate]: https://codeclimate.com/github/linyows/stalkerr
14
+ [coveralls]: https://coveralls.io/r/linyows/stalkerr
15
+
4
16
  Stalkerr is IRC Gateway, inspired by [agig](https://github.com/hsbt/agig) and [atig](https://github.com/mzp/atig).
5
17
 
6
18
  ![The Shining](http://goo.gl/7JPKQ)
7
19
 
20
+ Installation
21
+ ------------
22
+
23
+ And then execute:
24
+
25
+ ```sh
26
+ $ bundle
27
+ ```
28
+
29
+ Or install it yourself as:
30
+
31
+ ```sh
32
+ $ gem install octospy
33
+ ```
34
+
8
35
  Usage
9
36
  -----
10
37
 
11
- ### Start Stalkerr
38
+ Start Stalkerr
39
+
40
+ ```sh
41
+ $ stalkerr -D
42
+ ```
43
+
44
+ Join channel with username and access_token
45
+
46
+ ```irc
47
+ /join #github <username>:<access_token>
48
+ ```
49
+
50
+ If use GitHub:Enterprise
12
51
 
13
- $ gem install stalkerr
14
- $ stalkerr --help
15
- $ stalkerr -D
52
+ ```sh
53
+ $ env GITHUB_ENTERPRISE_API_ENDPOINT="http://your.enterprise.domain/api/v3/" \
54
+ > env GITHUB_ENTERPRISE_WEB_ENDPOINT="http://your.enterprise.domain/" \
55
+ > stalkerr -D
56
+ ```
16
57
 
17
- ### Connecting to Stalkerr
58
+ Support Service
18
59
 
19
- /join #github <username>:<password>
20
- /join #qiita <username>:<password>
60
+ - GitHub
61
+ - GitHub:Enterprise
62
+ - Qiita
63
+ - ~~twitter~~
64
+ - ~~facebook~~
21
65
 
22
66
  Contributing
23
67
  ------------
@@ -36,4 +80,4 @@ Author
36
80
  License
37
81
  -------
38
82
 
39
- MIT
83
+ The MIT License (MIT)
data/Rakefile CHANGED
@@ -1,2 +1,4 @@
1
- #!/usr/bin/env rake
2
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
@@ -6,5 +6,5 @@ module Stalkerr::Const
6
6
 
7
7
  ROLLBACK_SEC = 60 * 60
8
8
 
9
- FETCH_INTERVAL = 30
9
+ FETCH_INTERVAL = 60 * 3
10
10
  end
@@ -1,3 +1,5 @@
1
+ require 'string-irc'
2
+
1
3
  module Stalkerr::Extensions
2
4
  module String
3
5
  def constantize
@@ -10,6 +12,18 @@ module Stalkerr::Extensions
10
12
  end
11
13
  constant
12
14
  end
15
+
16
+ def camerize
17
+ self.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
18
+ end
19
+
20
+ def split_by_crlf
21
+ self.split(/\r\n|\n/).map { |v| v unless v.eql? '' }.compact
22
+ end
23
+
24
+ def to_irc_color
25
+ StringIrc.new(self)
26
+ end
13
27
  end
14
28
  end
15
29
 
@@ -4,105 +4,114 @@ require 'net/irc'
4
4
  require 'stalkerr'
5
5
  Dir["#{File.dirname(__FILE__)}/target/*.rb"].each { |p| require p }
6
6
 
7
- class Stalkerr::Session < Net::IRC::Server::Session
7
+ module Stalkerr
8
+ class TargetingError < StandardError; end
8
9
 
9
- def server_name
10
- 'Stalkerr'
11
- end
12
-
13
- def server_version
14
- Stalkerr::VERSION
15
- end
10
+ class Session < Net::IRC::Server::Session
16
11
 
17
- def initialize(*args)
18
- super
19
- @debug = args.last.debug
20
- @channels = @threads = @targets = {}
21
- Dir["#{File.dirname(__FILE__)}/target/*.rb"].each do |path|
22
- name = File.basename(path, '.rb')
23
- @channels.merge!(name.to_sym => "##{name}")
12
+ def server_name
13
+ 'Stalkerr'
24
14
  end
25
- end
26
15
 
27
- def on_user(m)
28
- super
29
- @real, *@opts = @real.split(/\s+/)
30
- @opts = OpenStruct.new @opts.inject({}) { |r, i|
31
- key, value = i.split("=", 2)
32
- r.update key => case value
33
- when nil then true
34
- when /\A\d+\z/ then value.to_i
35
- when /\A(?:\d+\.\d*|\.\d+)\z/ then value.to_f
36
- else value
37
- end
38
- }
39
- end
16
+ def server_version
17
+ Stalkerr::VERSION
18
+ end
40
19
 
41
- def on_join(m)
42
- super
43
- create_worker(m.params)
44
- end
20
+ def initialize(*args)
21
+ super
22
+ @debug = args.last.debug
23
+ @channels = @threads = @targets = {}
24
+ Dir["#{File.dirname(__FILE__)}/target/*.rb"].each do |path|
25
+ name = File.basename(path, '.rb')
26
+ @channels.merge!(name.to_sym => "##{name}")
27
+ end
28
+ end
45
29
 
46
- def on_part(m)
47
- super
48
- kill @threads[m.params.first]
49
- end
30
+ def on_user(m)
31
+ super
32
+ @real, *@opts = @real.split(/\s+/)
33
+ @opts = OpenStruct.new @opts.inject({}) { |r, i|
34
+ key, value = i.split("=", 2)
35
+ r.update key => case value
36
+ when nil then true
37
+ when /\A\d+\z/ then value.to_i
38
+ when /\A(?:\d+\.\d*|\.\d+)\z/ then value.to_f
39
+ else value
40
+ end
41
+ }
42
+ end
50
43
 
51
- def on_disconnected
52
- super
53
- kill_all
54
- end
44
+ def on_join(m)
45
+ super
46
+ create_worker(m.params)
47
+ end
55
48
 
56
- private
49
+ def on_part(m)
50
+ super
51
+ kill @threads[m.params.first]
52
+ end
57
53
 
58
- def create_worker(params)
59
- channels = params[0].split(',')
60
- keys = params[1].split(',')
61
- channels.each_with_index.map { |v, i| [v, keys[i]] }.each do |channel, key|
62
- guard auth_data(key).merge(channel: channel)
54
+ def on_disconnected
55
+ super
56
+ kill_all
63
57
  end
64
- end
65
58
 
66
- def auth_data(key)
67
- id, pw = key.match(/(.*?):(.*)/).to_a.pop(2)
68
- { username: id, password: pw }
69
- end
59
+ private
70
60
 
71
- def guard(params)
72
- ch = params[:channel]
73
- return if @threads[ch].is_a?(Thread) && @threads[ch].alive?
74
- post @nick, JOIN, ch
61
+ def create_worker(params)
62
+ channels = params[0].split(',')
63
+ keys = params[1].split(',')
64
+ channels.each_with_index.map { |v, i| [v, keys[i]] }.each do |channel, key|
65
+ guard auth_data(key).merge(channel: channel)
66
+ end
67
+ end
75
68
 
76
- @threads[ch] = Thread.start(target params) do |service|
77
- loop do
78
- begin
79
- service.stalking do |prefix, command, *params|
80
- post(prefix, command, *params)
69
+ def auth_data(key)
70
+ id, pw = key.match(/(.*?):(.*)/).to_a.pop(2)
71
+ raise ArgumentError, 'username is missing' if id.nil?
72
+ raise ArgumentError, 'password or token is missing' if pw.nil?
73
+ { username: id, password: pw }
74
+ end
75
+
76
+ def guard(params)
77
+ ch = params[:channel]
78
+ return if @threads[ch].is_a?(Thread) && @threads[ch].alive?
79
+ post @nick, JOIN, ch
80
+
81
+ @threads[ch] = Thread.start(target params) do |service|
82
+ loop do
83
+ begin
84
+ service.stalking do |prefix, command, *p|
85
+ post(prefix, command, *p)
86
+ end
87
+ sleep Stalkerr::Const::FETCH_INTERVAL
88
+ rescue Exception => e
89
+ @log.error e.inspect
90
+ e.backtrace.each { |l| @log.error "\t#{l}" }
91
+ sleep Stalkerr::Const::FETCH_INTERVAL
81
92
  end
82
- sleep Stalkerr::Const::FETCH_INTERVAL
83
- rescue Exception => e
84
- @log.error e.inspect
85
- e.backtrace.each { |l| @log.error "\t#{l}" }
86
- sleep Stalkerr::Const::FETCH_INTERVAL
87
93
  end
88
94
  end
95
+ rescue => e
96
+ @log.error e
89
97
  end
90
- end
91
98
 
92
- def target(params)
93
- ch = params[:channel]
94
- class_name = "Stalkerr::Target::#{@channels.invert[ch].capitalize}"
95
- unless @targets[ch].is_a?(class_name.constantize)
96
- @targets[ch] = class_name.constantize.new(params[:username], params[:password])
99
+ def target(params)
100
+ ch = params[:channel]
101
+ class_name = "Stalkerr::Target::#{@channels.invert[ch].to_s.camerize}"
102
+
103
+ unless @targets[ch].is_a?(class_name.constantize)
104
+ @targets[ch] = class_name.constantize.new(params[:username], params[:password])
105
+ end
106
+ @targets[ch]
97
107
  end
98
- @targets[ch]
99
- end
100
108
 
101
- def kill(thread)
102
- thread.kill if thread && thread.alive?
103
- end
109
+ def kill(thread)
110
+ thread.kill if thread && thread.alive?
111
+ end
104
112
 
105
- def kill_all
106
- @threads.each { |channel, thread| thread.kill if thread.alive? } rescue nil
113
+ def kill_all
114
+ @threads.each { |channel, thread| thread.kill if thread.alive? } rescue nil
115
+ end
107
116
  end
108
117
  end
@@ -2,25 +2,30 @@ require 'time'
2
2
  require 'net/irc'
3
3
  require 'octokit'
4
4
  require 'net/http'
5
- require 'string-irc'
6
5
  require 'stalkerr'
7
6
 
8
7
  module Stalkerr::Target
8
+ class GithubError < StandardError; end
9
+
9
10
  class Github
10
11
  include Net::IRC::Constants
11
12
 
12
- HOST = 'https://github.com'
13
- CHANNEL = '#github'
13
+ def channel
14
+ ENV['GITHUB_CHANNEL'] || '#github'
15
+ end
14
16
 
15
17
  def initialize(username, password)
18
+ raise GithubError, 'username is nil' if username.nil?
19
+ raise GithubError, 'password is nil' if password.nil?
20
+
16
21
  @username = username
17
22
  @password = password
18
23
  @last_event_id = nil
19
24
  end
20
25
 
21
26
  def client
22
- if !@client || @client && !@client.authenticated?
23
- @client = Octokit.new(login: @username, password: @password)
27
+ if !@client || @client && !@client.token_authenticated?
28
+ @client = Octokit::Client.new(access_token: @password)
24
29
  end
25
30
  @client
26
31
  end
@@ -29,27 +34,30 @@ module Stalkerr::Target
29
34
  @post = post
30
35
  client.received_events(@username).sort_by(&:id).reverse_each { |event|
31
36
  if @last_event_id.nil?
32
- next if Time.now.utc - Stalkerr::Const::ROLLBACK_SEC >= Time.parse(event.created_at).utc
37
+ time = Time.now - Stalkerr::Const::ROLLBACK_SEC
38
+ next if time >= event.created_at.localtime
33
39
  else
34
- next if @last_event_id >= event.id
40
+ next if @last_event_id.to_i >= event.id.to_i
35
41
  end
36
- result = parse(event)
37
- @last_event_id = result if result != false
42
+ next unless result = parse(event)
43
+ posts(result)
44
+ @last_event_id = result[:event_id]
38
45
  }
39
46
  end
40
47
 
41
48
  def parse(event)
42
49
  obj = event.payload
43
- header = status = title = link = ''
50
+ repository = event.repo.name
51
+
52
+ status = title = link = ''
44
53
  body = []
45
- none_repository = false
46
- notice_body = false
54
+ notice = false
47
55
 
48
56
  case event.type
49
57
  when 'CommitCommentEvent'
50
58
  status = "commented on commit"
51
59
  title = "#{obj.comment.path}"
52
- body = body + split_for_comment(obj.comment.body)
60
+ body = obj.comment.body.split_by_crlf if obj.comment.body
53
61
  link = obj.comment.html_url
54
62
  when 'PullRequestReviewCommentEvent'
55
63
  status = "commented on pull request"
@@ -60,7 +68,7 @@ module Stalkerr::Target
60
68
  else
61
69
  title = obj.comment.path
62
70
  end
63
- body = body + split_for_comment(obj.comment.body)
71
+ body = obj.comment.body.split_by_crlf if obj.comment.body
64
72
  link = obj.comment.html_url
65
73
  when 'IssueCommentEvent'
66
74
  if obj.action == 'created'
@@ -69,35 +77,35 @@ module Stalkerr::Target
69
77
  else
70
78
  status = "#{obj.action} issue comment"
71
79
  end
72
- body = body + split_for_comment(obj.comment.body)
80
+ body = obj.comment.body.split_by_crlf if obj.comment.body
73
81
  link = obj.comment.html_url
74
82
  when 'IssuesEvent'
75
83
  status = "#{obj.action} issue ##{obj.issue.number}"
76
84
  title = obj.issue.title
77
- body = body + split_for_comment(obj.issue.body)
85
+ body = obj.issue.body.split_by_crlf if obj.issue.body
78
86
  body << "assignee: #{obj.issue.assignee.login}" if obj.issue.assignee
79
87
  body << "milestone: #{obj.issue.milestone.title}[#{obj.issue.milestone.state}]" if obj.issue.milestone
80
88
  link = obj.issue.html_url
81
89
  when 'PullRequestEvent'
82
90
  status = "#{obj.action} pull request ##{obj.number}"
83
91
  title = obj.pull_request.title
84
- body = body + split_for_comment(obj.pull_request.body)
92
+ body = obj.pull_request.body.split_by_crlf if obj.pull_request.body
85
93
  link = obj.pull_request.html_url
86
94
  when 'PushEvent'
87
- notice_body = true
95
+ notice = true
88
96
  status = "pushed to #{obj.ref.gsub('refs/heads/', '')}"
89
97
  obj.commits.each do |commit|
90
98
  verbose_commit = client.commit(event.repo.name, commit.sha)
91
99
  name = verbose_commit.author ? verbose_commit.author.login : commit.author.name
92
- url = "#{HOST}/#{event.repo.name}/commit/#{commit.sha}"
93
- line = "#{StringIrc.new(name).silver}: #{commit.message}"
94
- line << " - #{StringIrc.new(shorten url).blue}"
95
- body = body + split_for_comment(line)
100
+ url = "#{client.web_endpoint}#{event.repo.name}/commit/#{commit.sha}"
101
+ line = "#{name.to_irc_color.silver}: #{commit.message}"
102
+ line << " - #{shorten(url).to_irc_color.blue}"
103
+ body = line.split_by_crlf
96
104
  end
97
- link = "#{HOST}/#{event.repo.name}"
105
+ link = "#{client.web_endpoint}#{event.repo.name}"
98
106
  when 'CreateEvent'
99
107
  if obj.ref_type.eql? 'repository'
100
- none_repository = true
108
+ repository = nil
101
109
  status = "created repository"
102
110
  title = event.repo.name
103
111
  title = "#{title}: #{obj.description}" if obj.description
@@ -105,10 +113,10 @@ module Stalkerr::Target
105
113
  status = "created #{obj.ref_type}:#{obj.ref}"
106
114
  title = obj.description
107
115
  end
108
- link = "#{HOST}/#{event.repo.name}"
116
+ link = "#{client.web_endpoint}#{event.repo.name}"
109
117
  when 'DeleteEvent'
110
118
  status = "deleted #{obj.ref_type}:#{obj.ref}"
111
- link = "#{HOST}/#{event.repo.name}"
119
+ link = "#{client.web_endpoint}#{event.repo.name}"
112
120
  when 'DownloadEvent'
113
121
  status = "download #{obj.name}"
114
122
  title = obj.description
@@ -121,33 +129,33 @@ module Stalkerr::Target
121
129
  status = "add team"
122
130
  title = obj.team.name
123
131
  when 'WatchEvent'
124
- none_repository = true
132
+ repository = nil
125
133
  status = "#{obj.action} repository"
126
134
  title = event.repo.name
127
- link = "#{HOST}/#{event.repo.name}"
135
+ link = "#{client.web_endpoint}#{event.repo.name}"
128
136
  when 'FollowEvent'
129
- none_repository = true
130
- notice_body = true
137
+ repository = nil
138
+ notice = true
131
139
  user = obj.target
132
140
  status = "followed"
133
141
  title = user.login
134
142
  title = "#{title} (#{user.name})" if user.name && user.name != ''
135
- profile = ["#{StringIrc.new('repos').silver}: #{user.public_repos}"]
136
- profile << "#{StringIrc.new('followers').silver}: #{user.followers}"
137
- profile << "#{StringIrc.new('following').silver}: #{user.following}"
138
- profile << "#{StringIrc.new('location').silver}: #{user.location && user.location != '' ? user.location : '-'}"
139
- profile << "#{StringIrc.new('company').silver}: #{user.company && user.company != '' ? user.company : '-'}"
140
- profile << "#{StringIrc.new('bio').silver}: #{user.bio && user.bio != '' ? user.bio : '-'}"
141
- profile << "#{StringIrc.new('blog').silver}: #{user.blog && user.blog != '' ? user.blog : '-'}"
143
+ profile = ["#{'repos'.to_irc_color.silver}: #{user.public_repos}"]
144
+ profile << "#{'followers'.to_irc_color.silver}: #{user.followers}"
145
+ profile << "#{'following'.to_irc_color.silver}: #{user.following}"
146
+ profile << "#{'location'.to_irc_color.silver}: #{user.location && user.location != '' ? user.location : '-'}"
147
+ profile << "#{'company'.to_irc_color.silver}: #{user.company && user.company != '' ? user.company : '-'}"
148
+ profile << "#{'bio'.to_irc_color.silver}: #{user.bio && user.bio != '' ? user.bio : '-'}"
149
+ profile << "#{'blog'.to_irc_color.silver}: #{user.blog && user.blog != '' ? user.blog : '-'}"
142
150
  body << profile.join(', ')
143
- link = "#{HOST}/#{user.login}"
151
+ link = "#{client.web_endpoint}#{user.login}"
144
152
  when 'MemberEvent'
145
153
  user = obj.member
146
154
  status = "#{obj.action} member"
147
155
  title = user.login
148
- link = "#{HOST}/#{user.login}"
156
+ link = "#{client.web_endpoint}#{user.login}"
149
157
  when 'GistEvent'
150
- none_repository = true
158
+ repository = nil
151
159
  status = "#{obj.action}d gist"
152
160
  title = obj.gist.description unless obj.gist.description.eql? ''
153
161
  link = obj.gist.html_url
@@ -158,8 +166,7 @@ module Stalkerr::Target
158
166
  return false
159
167
  end
160
168
 
161
- nick = event.actor.login
162
- unless status.eql? ''
169
+ unless status.empty?
163
170
  color = case
164
171
  when status.include?('created') then :pink
165
172
  when status.include?('commented') then :yellow
@@ -171,21 +178,51 @@ module Stalkerr::Target
171
178
  when status.include?('followed') then :seven_eleven
172
179
  else :aqua
173
180
  end
174
- header = StringIrc.new(status).send(color)
175
- header = "(#{event.repo.name}) #{header}" unless none_repository
181
+ status = status.to_irc_color.send(color)
182
+ end
183
+
184
+ unless body.eql? ''
185
+ if body.length > 20
186
+ body_footer = body[-3..-1]
187
+ body = body[0...15]
188
+ body << '-----8<----- c u t -----8<-----'
189
+ body = body + body_footer
190
+ end
176
191
  end
177
- header = "#{header} #{title}" unless title.eql? ''
178
- header = "#{header} - #{StringIrc.new(shorten link).blue}" unless link.eql? ''
179
192
 
180
- @post.call nick, NOTICE, CHANNEL, header unless header.eql? ''
181
- mode = notice_body ? NOTICE : PRIVMSG
182
- body.each { |b| @post.call nick, mode, CHANNEL, b } unless body.eql? ''
183
- event.id
193
+ {
194
+ event_id: event.id,
195
+ nick: event.actor.login,
196
+ status: status,
197
+ repository: repository,
198
+ link: link,
199
+ title: title,
200
+ body: body,
201
+ notice: notice
202
+ }
184
203
  end
185
204
 
186
- def split_for_comment(string)
187
- return [] unless string.is_a? String
188
- string.split(/\r\n|\n/).map { |v| v unless v.eql? '' }.compact
205
+ def posts(p)
206
+ header = ''
207
+ header = "(#{p[:repository]}) #{p[:status]}" unless p[:repository].eql? ''
208
+ header = "#{header} #{p[:title]}" unless p[:title].eql? ''
209
+ header = "#{header} - #{shorten(p[:link]).to_irc_color.blue}" unless p[:link].eql? ''
210
+
211
+ unless header.empty?
212
+ @post.call p[:nick], NOTICE, channel, header
213
+ end
214
+
215
+ if !p[:body].nil? && !p[:body].empty?
216
+ p[:body].each do |line|
217
+ mode = p[:notice] ? NOTICE : PRIVMSG
218
+ # maximum line length 512
219
+ # http://www.mirc.com/rfc2812.html
220
+ line.each_char.each_slice(512) do |string|
221
+ @post.call p[:nick], mode, channel, string.join
222
+ sleep 1
223
+ end
224
+ end
225
+ end
189
226
  end
190
227
 
191
228
  def shorten(url)
@@ -195,7 +232,7 @@ module Stalkerr::Target
195
232
  query = Hash.new.tap { |h| h[:url] = url }
196
233
  request.body = URI.encode_www_form(query)
197
234
  response = http.request(request)
198
- response.key?('Location') ? response["Location"] : url
235
+ response.key?('Location') ? response['Location'] : url
199
236
  end
200
237
  end
201
238
  end