retrobot 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog.md +4 -0
- data/Gemfile.lock +1 -1
- data/lib/retrobot.rb +1 -0
- data/lib/retrobot/config.rb +3 -1
- data/lib/retrobot/tweet_filters.rb +1 -0
- data/lib/retrobot/tweet_filters/suppress_pattern.rb +30 -0
- data/lib/retrobot/version.rb +1 -1
- data/retrobot.example.yml +1 -0
- data/spec/lib/retrobot/tweet_filters_spec.rb +62 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 237d796585e44c76de0301958af7802d5e85d7de
|
4
|
+
data.tar.gz: 2607e0dd0b57a3089a79c20e450a04235c91746b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bef0efecc73f63232c9ae1863bde8b06285ac23c2e290a3d8bc0096cd5780b9b1de6429fc411802260922b2d5d0256c80bccbb357e461c1c5fc6377559f986d1
|
7
|
+
data.tar.gz: 862bcafae52911b466c828dbca9f684fe839b8c747556e6f2c9bc86c55cf2616af5714bd8fff32c26a412084d990c60b2c93ba2e3e9ea34f332dcdfe19b994cd
|
data/ChangeLog.md
CHANGED
data/Gemfile.lock
CHANGED
data/lib/retrobot.rb
CHANGED
@@ -97,6 +97,7 @@ class Retrobot
|
|
97
97
|
return @tweet_filters if @tweet_filters
|
98
98
|
@tweet_filters = []
|
99
99
|
@tweet_filters << TweetFilters::RetroDays.new(self)
|
100
|
+
@tweet_filters << TweetFilters::SuppressPattern.new(self) if @config.suppress_pattern
|
100
101
|
@tweet_filters << TweetFilters::AddInReplyToUrl.new(self) if @config.add_in_reply_to_url
|
101
102
|
@tweet_filters << TweetFilters::Retweet.new(self)
|
102
103
|
@tweet_filters << TweetFilters::RemoveAtmark.new(self)
|
data/lib/retrobot/config.rb
CHANGED
@@ -18,6 +18,7 @@ class Retrobot
|
|
18
18
|
retry_interval
|
19
19
|
retry_count
|
20
20
|
add_in_reply_to_url
|
21
|
+
suppress_pattern
|
21
22
|
)
|
22
23
|
|
23
24
|
DEFAULTS = {
|
@@ -29,7 +30,8 @@ class Retrobot
|
|
29
30
|
loop_interval: 3,
|
30
31
|
retry_interval: 3,
|
31
32
|
retry_count: 5,
|
32
|
-
add_in_reply_to_url: false
|
33
|
+
add_in_reply_to_url: false,
|
34
|
+
suppress_pattern: nil,
|
33
35
|
}
|
34
36
|
|
35
37
|
def initialize(options={})
|
@@ -5,6 +5,7 @@ require 'retrobot/tweet_filters/retweet'
|
|
5
5
|
require 'retrobot/tweet_filters/tweet'
|
6
6
|
require 'retrobot/tweet_filters/unescape'
|
7
7
|
require 'retrobot/tweet_filters/add_in_reply_to_url'
|
8
|
+
require 'retrobot/tweet_filters/suppress_pattern'
|
8
9
|
|
9
10
|
class Retrobot
|
10
11
|
module TweetFilters
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'retrobot/tweet_filters/base'
|
2
|
+
|
3
|
+
class Retrobot
|
4
|
+
module TweetFilters
|
5
|
+
class SuppressPattern < Base
|
6
|
+
def initialize(retrobot)
|
7
|
+
super
|
8
|
+
end
|
9
|
+
|
10
|
+
def filter(tweet)
|
11
|
+
text = text tweet
|
12
|
+
if pattern && text =~ pattern
|
13
|
+
logger.info "Skipped by suppress_pattern: #{tweet.text}"
|
14
|
+
nil
|
15
|
+
else
|
16
|
+
tweet
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def pattern
|
22
|
+
config.suppress_pattern ? Regexp.new(config.suppress_pattern) : nil
|
23
|
+
end
|
24
|
+
|
25
|
+
def text(tweet)
|
26
|
+
tweet.retweeted_status_id ? tweet.text.sub(/^RT @.+: /, '') : tweet.text
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/retrobot/version.rb
CHANGED
data/retrobot.example.yml
CHANGED
@@ -8,3 +8,4 @@ access_secret: your_access_secret
|
|
8
8
|
# debug: false (default)
|
9
9
|
# dryrun: false (default)
|
10
10
|
# add_in_reply_to_url: false (default=false / add url of in_reply_to into the tweet)
|
11
|
+
# suppress_pattern: '@\w+' (default=nil / regular expression for tweet text which you don't need to tweet)
|
@@ -142,4 +142,66 @@ describe Retrobot::TweetFilters do
|
|
142
142
|
expect(retrobot.client).to have_received(:update).with('hello')
|
143
143
|
end
|
144
144
|
end
|
145
|
+
|
146
|
+
describe 'SuppressPattern' do
|
147
|
+
let(:filter_class) { Retrobot::TweetFilters::SuppressPattern }
|
148
|
+
|
149
|
+
context 'suppress_pattern == nil' do
|
150
|
+
it 'does nothing' do
|
151
|
+
tweet_before = Retrobot::Tweet.new.tap do |t|
|
152
|
+
t.text = 'hello'
|
153
|
+
end
|
154
|
+
tweet_after = filter.filter(tweet_before)
|
155
|
+
expect(tweet_after).to be(tweet_after)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
context 'suppress_pattern is a regexp' do
|
160
|
+
let(:config) { Retrobot::Config.new suppress_pattern: '^@mirakui' }
|
161
|
+
|
162
|
+
describe 'does not match text' do
|
163
|
+
it 'does nothing' do
|
164
|
+
tweet_before = Retrobot::Tweet.new.tap do |t|
|
165
|
+
t.text = 'hello'
|
166
|
+
end
|
167
|
+
tweet_after = filter.filter(tweet_before)
|
168
|
+
expect(tweet_after).to be(tweet_after)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
describe 'matches text' do
|
173
|
+
it 'skips' do
|
174
|
+
tweet_before = Retrobot::Tweet.new.tap do |t|
|
175
|
+
t.text = '@mirakui hello'
|
176
|
+
end
|
177
|
+
tweet_after = filter.filter(tweet_before)
|
178
|
+
expect(tweet_after).to be(nil)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
context 'RT text' do
|
183
|
+
describe 'does not match text' do
|
184
|
+
it 'skips' do
|
185
|
+
tweet_before = Retrobot::Tweet.new.tap do |t|
|
186
|
+
t.retweeted_status_id = 12345
|
187
|
+
t.text = 'RT @mirakui: hello'
|
188
|
+
end
|
189
|
+
tweet_after = filter.filter(tweet_before)
|
190
|
+
expect(tweet_after).to be(tweet_after)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
describe 'matches text' do
|
195
|
+
it 'skips' do
|
196
|
+
tweet_before = Retrobot::Tweet.new.tap do |t|
|
197
|
+
t.retweeted_status_id = 12345
|
198
|
+
t.text = 'RT @mirakui: @mirakui hello'
|
199
|
+
end
|
200
|
+
tweet_after = filter.filter(tweet_before)
|
201
|
+
expect(tweet_after).to be(nil)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
145
207
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: retrobot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Issei Naruta
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: twitter
|
@@ -138,6 +138,7 @@ files:
|
|
138
138
|
- lib/retrobot/tweet_filters/remove_atmark.rb
|
139
139
|
- lib/retrobot/tweet_filters/retro_days.rb
|
140
140
|
- lib/retrobot/tweet_filters/retweet.rb
|
141
|
+
- lib/retrobot/tweet_filters/suppress_pattern.rb
|
141
142
|
- lib/retrobot/tweet_filters/tweet.rb
|
142
143
|
- lib/retrobot/tweet_filters/unescape.rb
|
143
144
|
- lib/retrobot/version.rb
|