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 +4 -4
- data/.rspec +2 -0
- data/.travis.yml +14 -0
- data/Gemfile +14 -5
- data/LICENSE +1 -1
- data/README.md +52 -8
- data/Rakefile +4 -2
- data/lib/stalkerr/const.rb +1 -1
- data/lib/stalkerr/extensions/string.rb +14 -0
- data/lib/stalkerr/session.rb +88 -79
- data/lib/stalkerr/target/github.rb +91 -54
- data/lib/stalkerr/target/github_enterprise.rb +34 -0
- data/lib/stalkerr/target/qiita.rb +21 -1
- data/lib/stalkerr/version.rb +1 -1
- data/spec/fixtures/vcr_cassettes/gitio/response.yml +48 -0
- data/spec/fixtures/vcr_cassettes/octokit_client/commit.yml +112 -0
- data/spec/fixtures/vcr_cassettes/octokit_client/received_events.yml +346 -0
- data/spec/fixtures/vcr_cassettes/qiita_client/login.yml +64 -0
- data/spec/helper.rb +54 -0
- data/spec/stalkerr/extensions/string_spec.rb +50 -0
- data/spec/stalkerr/target/github_spec.rb +127 -0
- data/spec/stalkerr/target/qiita_spec.rb +33 -0
- data/stalkerr.gemspec +23 -22
- metadata +41 -49
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8fa6ca412a98e0f1e06e9ebcecef0cc0d94614d2
|
4
|
+
data.tar.gz: 173b729e7245b4d2359062acdef617941058aed6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b76e30f8582c38eb6f39327a2dc8cbd70709874d3dad047638a20e22fdafde1fde8d1dc024eabe1c078200a23ed8c5a6e839d97b84e84e1de233396eb1cf695f
|
7
|
+
data.tar.gz: 5d1e9e5a0640036e8d08075e135a4318aa9d40a4fe196d7a9a766b2c705777951c2cb9ee010fdc11fa2e15cc50486b1e31af5a6a3c11ea486cee21a3062a93a5
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
CHANGED
@@ -1,7 +1,16 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
gem '
|
7
|
-
gem '
|
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
data/README.md
CHANGED
@@ -1,23 +1,67 @@
|
|
1
1
|
Stalkerr
|
2
2
|
========
|
3
3
|
|
4
|
+
[][gem]
|
5
|
+
[][travis]
|
6
|
+
[][gemnasium]
|
7
|
+
[][codeclimate]
|
8
|
+
[][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
|

|
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
|
-
|
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
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
58
|
+
Support Service
|
18
59
|
|
19
|
-
|
20
|
-
|
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
data/lib/stalkerr/const.rb
CHANGED
@@ -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
|
|
data/lib/stalkerr/session.rb
CHANGED
@@ -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
|
-
|
7
|
+
module Stalkerr
|
8
|
+
class TargetingError < StandardError; end
|
8
9
|
|
9
|
-
|
10
|
-
'Stalkerr'
|
11
|
-
end
|
12
|
-
|
13
|
-
def server_version
|
14
|
-
Stalkerr::VERSION
|
15
|
-
end
|
10
|
+
class Session < Net::IRC::Server::Session
|
16
11
|
|
17
|
-
|
18
|
-
|
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
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
44
|
+
def on_join(m)
|
45
|
+
super
|
46
|
+
create_worker(m.params)
|
47
|
+
end
|
55
48
|
|
56
|
-
|
49
|
+
def on_part(m)
|
50
|
+
super
|
51
|
+
kill @threads[m.params.first]
|
52
|
+
end
|
57
53
|
|
58
|
-
|
59
|
-
|
60
|
-
|
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
|
-
|
67
|
-
id, pw = key.match(/(.*?):(.*)/).to_a.pop(2)
|
68
|
-
{ username: id, password: pw }
|
69
|
-
end
|
59
|
+
private
|
70
60
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
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
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
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
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
@targets[ch]
|
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
|
-
|
102
|
-
|
103
|
-
|
109
|
+
def kill(thread)
|
110
|
+
thread.kill if thread && thread.alive?
|
111
|
+
end
|
104
112
|
|
105
|
-
|
106
|
-
|
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
|
-
|
13
|
-
|
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.
|
23
|
-
@client = Octokit.new(
|
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
|
-
|
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
|
-
|
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
|
-
|
50
|
+
repository = event.repo.name
|
51
|
+
|
52
|
+
status = title = link = ''
|
44
53
|
body = []
|
45
|
-
|
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
|
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
|
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
|
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
|
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
|
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
|
-
|
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 = "#{
|
93
|
-
line = "#{
|
94
|
-
line << " - #{
|
95
|
-
body =
|
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 = "#{
|
105
|
+
link = "#{client.web_endpoint}#{event.repo.name}"
|
98
106
|
when 'CreateEvent'
|
99
107
|
if obj.ref_type.eql? 'repository'
|
100
|
-
|
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 = "#{
|
116
|
+
link = "#{client.web_endpoint}#{event.repo.name}"
|
109
117
|
when 'DeleteEvent'
|
110
118
|
status = "deleted #{obj.ref_type}:#{obj.ref}"
|
111
|
-
link = "#{
|
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
|
-
|
132
|
+
repository = nil
|
125
133
|
status = "#{obj.action} repository"
|
126
134
|
title = event.repo.name
|
127
|
-
link = "#{
|
135
|
+
link = "#{client.web_endpoint}#{event.repo.name}"
|
128
136
|
when 'FollowEvent'
|
129
|
-
|
130
|
-
|
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 = ["#{
|
136
|
-
profile << "#{
|
137
|
-
profile << "#{
|
138
|
-
profile << "#{
|
139
|
-
profile << "#{
|
140
|
-
profile << "#{
|
141
|
-
profile << "#{
|
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 = "#{
|
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 = "#{
|
156
|
+
link = "#{client.web_endpoint}#{user.login}"
|
149
157
|
when 'GistEvent'
|
150
|
-
|
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
|
-
|
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
|
-
|
175
|
-
|
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
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
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
|
187
|
-
|
188
|
-
|
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[
|
235
|
+
response.key?('Location') ? response['Location'] : url
|
199
236
|
end
|
200
237
|
end
|
201
238
|
end
|