tweetbot 0.1.5 → 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.
- data/lib/tweetbot/bot.rb +18 -2
- data/lib/tweetbot/talk.rb +1 -0
- data/lib/tweetbot/version.rb +1 -1
- data/spec/tweetbot_config_spec.rb +31 -0
- metadata +10 -10
data/lib/tweetbot/bot.rb
CHANGED
@@ -4,14 +4,25 @@ module TweetBot
|
|
4
4
|
attr_accessor :response_frequency, :twitter_auth
|
5
5
|
|
6
6
|
DefaultFrequency = 20
|
7
|
+
Noop = lambda {|status|}
|
8
|
+
|
7
9
|
|
8
10
|
def initialize()
|
9
11
|
self.response_frequency = DefaultFrequency
|
10
12
|
@responses_for_phrases = Hash.new { |hash, key| hash[key] = [] }
|
13
|
+
@blocks_for_phrases = {}
|
14
|
+
end
|
15
|
+
|
16
|
+
def on_status_captured(key, &block)
|
17
|
+
@blocks_for_phrases[key] = block
|
18
|
+
end
|
19
|
+
|
20
|
+
def alert_status_captured(status)
|
21
|
+
find_phrase_value(@blocks_for_phrases, status.text, Noop).call(status)
|
11
22
|
end
|
12
23
|
|
13
24
|
def phrases_to_search
|
14
|
-
@responses_for_phrases.keys
|
25
|
+
@responses_for_phrases.keys + @blocks_for_phrases.keys
|
15
26
|
end
|
16
27
|
|
17
28
|
def responses_for(phrase)
|
@@ -57,7 +68,12 @@ module TweetBot
|
|
57
68
|
end
|
58
69
|
|
59
70
|
def responses_for_tweet(tweet)
|
60
|
-
@responses_for_phrases
|
71
|
+
find_phrase_value(@responses_for_phrases, tweet.text, [])
|
72
|
+
end
|
73
|
+
|
74
|
+
def find_phrase_value(hash, text, default)
|
75
|
+
hash.select { |phrase, _| text =~ /#{phrase.downcase}/i }.values[0] || default
|
61
76
|
end
|
77
|
+
|
62
78
|
end
|
63
79
|
end
|
data/lib/tweetbot/talk.rb
CHANGED
data/lib/tweetbot/version.rb
CHANGED
@@ -93,6 +93,37 @@ describe "configuring tweetbot with a config block" do
|
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
+
context "configuring a status captured block" do
|
97
|
+
let(:statuses) { [] }
|
98
|
+
let(:bot) do
|
99
|
+
TweetBot.configure do |bot|
|
100
|
+
bot.on_status_captured "positivember" do |status|
|
101
|
+
statuses << status.text
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
it "adds the phrase to the phrases to search" do
|
107
|
+
bot.phrases_to_search.should include("positivember")
|
108
|
+
end
|
109
|
+
|
110
|
+
context "status text contains the phrase" do
|
111
|
+
it "calls the block" do
|
112
|
+
status = stub(text: "Yeah #positivember")
|
113
|
+
bot.alert_status_captured(status)
|
114
|
+
statuses.should include("Yeah #positivember")
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context "status text does not contain the phrase" do
|
119
|
+
it "does not call the block" do
|
120
|
+
status = stub(text: "negativity")
|
121
|
+
bot.alert_status_captured(status)
|
122
|
+
statuses.should be_empty
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
96
127
|
context "without a configure block" do
|
97
128
|
it "returns a bot that I can use" do
|
98
129
|
bot = TweetBot.configure
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tweetbot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-11-01 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &2152637360 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2152637360
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: timecop
|
27
|
-
requirement: &
|
27
|
+
requirement: &2152636500 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2152636500
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: twitter
|
38
|
-
requirement: &
|
38
|
+
requirement: &2152635460 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2152635460
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: tweetstream
|
49
|
-
requirement: &
|
49
|
+
requirement: &2152634360 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2152634360
|
58
58
|
description: Using tweetbot, you can easily create twitter bots that respond to key
|
59
59
|
phrases that people say on the twitters
|
60
60
|
email:
|