cinch-twitterwatch 1.0.2 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +10 -11
- data/cinch-twitterwatch.gemspec +1 -1
- data/lib/cinch/plugins/twitterwatch.rb +63 -61
- data/lib/cinch/plugins/twitterwatch/cache.rb +29 -26
- data/lib/cinch/plugins/twitterwatch/version.rb +1 -1
- metadata +33 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5cb6bb0efb75b1458d01bc6a920c4060a7cfb812
|
4
|
+
data.tar.gz: 8b0e79db3d6037f7a13c612c2a06aad71e3ef9ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 073e1c70ca6bdcaf58d29f23ebf414fa3d563bc4265da57082f2e1b154632aaa63a944cc224f46ce9791ef2ebfa146df4343987fd3f245bfd07d174cb1e6e43b
|
7
|
+
data.tar.gz: 11f29d9222efac7efd3b1a3a90c56c1712797ddb865637d79c7dcd3b63231035000ab0ea6f24e448d4dc9794bb76c6dc0b82b5cbebd31442eaf05164108b743c
|
data/.travis.yml
CHANGED
@@ -1,17 +1,16 @@
|
|
1
1
|
---
|
2
2
|
language: ruby
|
3
3
|
rvm:
|
4
|
-
- 2.1.0
|
5
|
-
- 2.0.0
|
6
|
-
- 1.9.3
|
7
|
-
- 1.9.2
|
8
|
-
- 1.8.7
|
9
|
-
- jruby-18mode
|
10
|
-
- jruby-19mode
|
11
|
-
-
|
12
|
-
-
|
13
|
-
-
|
14
|
-
- ree
|
4
|
+
- 2.1.0
|
5
|
+
- 2.0.0
|
6
|
+
- 1.9.3
|
7
|
+
- 1.9.2
|
8
|
+
- 1.8.7
|
9
|
+
- jruby-18mode
|
10
|
+
- jruby-19mode
|
11
|
+
- ruby-head
|
12
|
+
- jruby-head
|
13
|
+
- ree
|
15
14
|
matrix:
|
16
15
|
allow_failures:
|
17
16
|
- rvm: 1.8.7
|
data/cinch-twitterwatch.gemspec
CHANGED
@@ -25,6 +25,6 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_development_dependency 'cinch-test', '~> 0.0', '>= 0.0.4'
|
26
26
|
|
27
27
|
spec.add_dependency 'twitter', '~> 5.7', '>= 5.7.1'
|
28
|
-
spec.add_dependency 'cinch', '~> 2
|
28
|
+
spec.add_dependency 'cinch', '~> 2', '>= 2.0.12'
|
29
29
|
spec.add_dependency 'cinch-toolbox', '~> 1.1', '>= 1.1.2'
|
30
30
|
end
|
@@ -3,81 +3,83 @@ require 'cinch'
|
|
3
3
|
require 'cinch/toolbox'
|
4
4
|
require 'twitter'
|
5
5
|
|
6
|
-
module Cinch
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
module Cinch
|
7
|
+
module Plugins
|
8
|
+
# Cinch Plugin to post twitter statuses
|
9
|
+
class TwitterWatch
|
10
|
+
include Cinch::Plugin
|
10
11
|
|
11
|
-
|
12
|
+
timer 15, method: :check_watched
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
def initialize(*args)
|
15
|
+
super
|
16
|
+
@client = twitter_client
|
17
|
+
@watched = build_watchers
|
18
|
+
end
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
20
|
+
def check_watched
|
21
|
+
return unless @watched
|
22
|
+
@watched.each { |w| check_for_tweet(w) }
|
23
|
+
rescue Twitter::Error::NotFound
|
24
|
+
debug 'You have set an invalid or protected user ' \
|
25
|
+
'to watch, please correct this error'
|
26
|
+
rescue Twitter::Error::TooManyRequests
|
27
|
+
debug 'Trottled checking user; sleeping 60 seconds.'
|
28
|
+
sleep 60
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
31
|
+
def check_for_tweet(w)
|
32
|
+
# Just check the last tweet, if they are posting more than once
|
33
|
+
# every timer tick we don't want to spam the channel.
|
34
|
+
debug "Checking Tweets for #{w.nick} (#{w.tweet_cache.count} cached)"
|
35
|
+
tweet = @client.user(w.nick).status
|
36
|
+
status = w.tweet_unless_cached(tweet.id)
|
37
|
+
Channel(w.channel).msg(tweet_text(w.nick, status)) unless status.nil?
|
38
|
+
end
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
40
|
+
def format_tweet(url)
|
41
|
+
# Parse the url and get the relevant data
|
42
|
+
user, status = parse_twitter_url(url)
|
42
43
|
|
43
|
-
|
44
|
-
|
44
|
+
# Return blank if we didn't get a good user and status
|
45
|
+
return if user.nil? || status.nil?
|
45
46
|
|
46
|
-
|
47
|
-
|
47
|
+
tweet(user, status)
|
48
|
+
end
|
48
49
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
def tweet_text(user, status)
|
51
|
+
# Scrub the tweet for returns so we don't have multilined responses.
|
52
|
+
flat_status = status.gsub(/[\n]+/, ' ')
|
53
|
+
"@#{user} tweeted \"#{flat_status}\""
|
54
|
+
end
|
54
55
|
|
55
|
-
|
56
|
+
private
|
56
57
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
58
|
+
def parse_twitter_url(url)
|
59
|
+
tweet_id = url[%r{statuse?s?/(\d+)/?}, 1]
|
60
|
+
user = url[%r{/?#?!?/([^\/]+)/statuse?s?}, 1]
|
61
|
+
[user, Twitter.status(tweet_id).text]
|
62
|
+
end
|
62
63
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
64
|
+
def build_watchers
|
65
|
+
watched = []
|
66
|
+
config[:watchers].each_pair do |chan, users|
|
67
|
+
users.each do |user|
|
68
|
+
watcher = Cache.new(user, chan, @client)
|
69
|
+
debug "#{watcher.init_cache}"
|
70
|
+
watched << watcher
|
71
|
+
end
|
70
72
|
end
|
73
|
+
watched
|
71
74
|
end
|
72
|
-
watched
|
73
|
-
end
|
74
75
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
76
|
+
def twitter_client
|
77
|
+
Twitter::REST::Client.new do |c|
|
78
|
+
c.consumer_key = config[:consumer_key]
|
79
|
+
c.consumer_secret = config[:consumer_secret]
|
80
|
+
c.access_token = config[:access_token]
|
81
|
+
c.access_token_secret = config[:access_secret]
|
82
|
+
end
|
81
83
|
end
|
82
84
|
end
|
83
85
|
end
|
@@ -1,34 +1,37 @@
|
|
1
|
-
module Cinch
|
2
|
-
|
3
|
-
class
|
4
|
-
|
1
|
+
module Cinch
|
2
|
+
module Plugins
|
3
|
+
class TwitterWatch
|
4
|
+
# Class for tracking the already retrieved tweets so that we don't repost
|
5
|
+
class Cache
|
6
|
+
attr_accessor :nick, :channel, :tweet_cache, :client
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
def initialize(nick, channel, client)
|
9
|
+
@nick = nick
|
10
|
+
@client = client
|
11
|
+
@channel = channel
|
12
|
+
@tweet_cache = {}
|
13
|
+
end
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
|
15
|
+
def init_cache
|
16
|
+
@client.user_timeline(@nick).each do |tweet|
|
17
|
+
cache_tweet(tweet.id)
|
18
|
+
end
|
19
|
+
"Cache: [#{@nick}]: #{@tweet_cache.count} tweets cached."
|
20
|
+
rescue Twitter::Error::NotFound
|
21
|
+
debug "You have set an invalid or protected user (#{@nick}) to " \
|
22
|
+
' watch, please correct this error'
|
16
23
|
end
|
17
|
-
"Cache: [#{@nick}]: #{@tweet_cache.count} tweets cached."
|
18
|
-
rescue Twitter::Error::NotFound
|
19
|
-
debug "You have set an invalid or protected user (#{@nick}) to " +
|
20
|
-
' watch, please correct this error'
|
21
|
-
end
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
def tweet_unless_cached(tweet_id)
|
26
|
+
return if @tweet_cache.key?(tweet_id)
|
27
|
+
cache_tweet(tweet_id)
|
28
|
+
@client.status(tweet_id).text
|
29
|
+
end
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
-
|
31
|
+
def cache_tweet(tweet_id)
|
32
|
+
@tweet_cache[tweet_id.to_i] = true
|
33
|
+
true
|
34
|
+
end
|
32
35
|
end
|
33
36
|
end
|
34
37
|
end
|
metadata
CHANGED
@@ -1,149 +1,149 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cinch-twitterwatch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Haberer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.3'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '10.1'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.1'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '2.14'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '2.14'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: coveralls
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - ~>
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0.7'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - ~>
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0.7'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: cinch-test
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - ~>
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0.0'
|
76
|
-
- -
|
76
|
+
- - ">="
|
77
77
|
- !ruby/object:Gem::Version
|
78
78
|
version: 0.0.4
|
79
79
|
type: :development
|
80
80
|
prerelease: false
|
81
81
|
version_requirements: !ruby/object:Gem::Requirement
|
82
82
|
requirements:
|
83
|
-
- - ~>
|
83
|
+
- - "~>"
|
84
84
|
- !ruby/object:Gem::Version
|
85
85
|
version: '0.0'
|
86
|
-
- -
|
86
|
+
- - ">="
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: 0.0.4
|
89
89
|
- !ruby/object:Gem::Dependency
|
90
90
|
name: twitter
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
92
92
|
requirements:
|
93
|
-
- - ~>
|
93
|
+
- - "~>"
|
94
94
|
- !ruby/object:Gem::Version
|
95
95
|
version: '5.7'
|
96
|
-
- -
|
96
|
+
- - ">="
|
97
97
|
- !ruby/object:Gem::Version
|
98
98
|
version: 5.7.1
|
99
99
|
type: :runtime
|
100
100
|
prerelease: false
|
101
101
|
version_requirements: !ruby/object:Gem::Requirement
|
102
102
|
requirements:
|
103
|
-
- - ~>
|
103
|
+
- - "~>"
|
104
104
|
- !ruby/object:Gem::Version
|
105
105
|
version: '5.7'
|
106
|
-
- -
|
106
|
+
- - ">="
|
107
107
|
- !ruby/object:Gem::Version
|
108
108
|
version: 5.7.1
|
109
109
|
- !ruby/object:Gem::Dependency
|
110
110
|
name: cinch
|
111
111
|
requirement: !ruby/object:Gem::Requirement
|
112
112
|
requirements:
|
113
|
-
- - ~>
|
113
|
+
- - "~>"
|
114
114
|
- !ruby/object:Gem::Version
|
115
|
-
version: '2
|
116
|
-
- -
|
115
|
+
version: '2'
|
116
|
+
- - ">="
|
117
117
|
- !ruby/object:Gem::Version
|
118
118
|
version: 2.0.12
|
119
119
|
type: :runtime
|
120
120
|
prerelease: false
|
121
121
|
version_requirements: !ruby/object:Gem::Requirement
|
122
122
|
requirements:
|
123
|
-
- - ~>
|
123
|
+
- - "~>"
|
124
124
|
- !ruby/object:Gem::Version
|
125
|
-
version: '2
|
126
|
-
- -
|
125
|
+
version: '2'
|
126
|
+
- - ">="
|
127
127
|
- !ruby/object:Gem::Version
|
128
128
|
version: 2.0.12
|
129
129
|
- !ruby/object:Gem::Dependency
|
130
130
|
name: cinch-toolbox
|
131
131
|
requirement: !ruby/object:Gem::Requirement
|
132
132
|
requirements:
|
133
|
-
- - ~>
|
133
|
+
- - "~>"
|
134
134
|
- !ruby/object:Gem::Version
|
135
135
|
version: '1.1'
|
136
|
-
- -
|
136
|
+
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: 1.1.2
|
139
139
|
type: :runtime
|
140
140
|
prerelease: false
|
141
141
|
version_requirements: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
|
-
- - ~>
|
143
|
+
- - "~>"
|
144
144
|
- !ruby/object:Gem::Version
|
145
145
|
version: '1.1'
|
146
|
-
- -
|
146
|
+
- - ">="
|
147
147
|
- !ruby/object:Gem::Version
|
148
148
|
version: 1.1.2
|
149
149
|
description: Cinch plugin that watches for new tweets from users.
|
@@ -153,8 +153,8 @@ executables: []
|
|
153
153
|
extensions: []
|
154
154
|
extra_rdoc_files: []
|
155
155
|
files:
|
156
|
-
- .gitignore
|
157
|
-
- .travis.yml
|
156
|
+
- ".gitignore"
|
157
|
+
- ".travis.yml"
|
158
158
|
- Gemfile
|
159
159
|
- LICENSE.txt
|
160
160
|
- README.md
|
@@ -176,17 +176,17 @@ require_paths:
|
|
176
176
|
- lib
|
177
177
|
required_ruby_version: !ruby/object:Gem::Requirement
|
178
178
|
requirements:
|
179
|
-
- -
|
179
|
+
- - ">="
|
180
180
|
- !ruby/object:Gem::Version
|
181
181
|
version: '0'
|
182
182
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
183
183
|
requirements:
|
184
|
-
- -
|
184
|
+
- - ">="
|
185
185
|
- !ruby/object:Gem::Version
|
186
186
|
version: '0'
|
187
187
|
requirements: []
|
188
188
|
rubyforge_project:
|
189
|
-
rubygems_version: 2.
|
189
|
+
rubygems_version: 2.4.8
|
190
190
|
signing_key:
|
191
191
|
specification_version: 4
|
192
192
|
summary: Cinch Plugin to follow twitter.
|