cinch-twitterwatch 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: 4b745d127c6fe8c403ac4f105f995a116acb04b7
4
+ data.tar.gz: 63a71efaf6719ac11311116ee6ab2cdac89ade80
5
+ SHA512:
6
+ metadata.gz: 0496c061f9c544579d5d809e2886006dd8175f0346501d73c272192a6c521b04d6f24f169371c666c3f0a5ec65d3b3aabb1779505d384dd8928cf7f44b6401a3
7
+ data.tar.gz: 688ad1a73518af042410df7251947c97e6dca431c114d3874cd83102eea33121c0081058cac4c8ee419dced156339accabcefed2e42fcafbc9ddeaa21465e6bf
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ spec/secret.rb
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,45 @@
1
+ ---
2
+ language: ruby
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
+ - rbx
12
+ - ruby-head
13
+ - jruby-head
14
+ - ree
15
+ matrix:
16
+ allow_failures:
17
+ - rvm: 1.8.7
18
+ - rvm: ree
19
+ - rvm: jruby-18mode
20
+ - rvm: jruby-19mode
21
+ - rvm: jruby-head
22
+ fast_finish: true
23
+ env:
24
+ global:
25
+ - JRUBY_OPTS=-Xcext.enabled=true
26
+ - secure: ! 'AuTqK4GVSvHxsUdgDXivtFuCQjB7EX19zM5C2b2omp1BLAQsnAyDse/6x2Oe
27
+
28
+ kB7SzCwH/PIeSJ8xNzcKF/c32lJZBdQAU7Cz210XoXCevefpWa4Y/4u/nNi2
29
+
30
+ eltSdGuJWwAiFMjBGz4IHa2Q7UnS9FcyB4FZXfaPCVZdkmffSzg='
31
+ - secure: ! 'Ajl+5EjsPtpEh25qfyk0RF2i/oM6g29AWqRHmC+I/TuWhMaFawdTESiqbvJk
32
+
33
+ Pir0ogqE+GufgueOYHKmIoYUHfs+dwS82/zBt3bmd8hpSsIGYGMcKVT8Zswe
34
+
35
+ QKT3JOOv7Igf96sgHhDk9T/n8ZlyUhtAJmau2MGdYw6Un0gTnZQ='
36
+ - secure: ! '1GFCEhzcB7bPhWQA2BJTerMvTa0tZjyrnozP5jgz5ejX5pKp8Q6OQogrrPk9
37
+
38
+ HZ1KuobWBKF2mnT8S0Kmjia5oR7XQGwanV12Xpe2e+NnqrbWsf7ZZ9OcUK6D
39
+
40
+ MjxAZ2zKo0l6zGyor8Alf5ejcAzTJky+/I855tn8zA8jNPG9fD4='
41
+ - secure: ! 'xUpzXMelLHrVpjT64uuWi8TbDAElda+gBPXLctHwrL+IgxHekAz6cDIgyukT
42
+
43
+ bGlWHFpl0lpedv9/eZbv7OchQOcWg45TccbxMcMjHfxYSDNr73RI1L0epn6j
44
+
45
+ UsvChSvlzCmUoYeXqygr/1t1ujABLqoaT+YThn957hlVIoUMOUA='
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cinch-twitterwatch.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Brian Haberer
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # Cinch::Plugins::TwitterWatch
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/cinch-twitterwatch.png)](http://badge.fury.io/rb/cinch-twitterwatch)
4
+ [![Dependency Status](https://gemnasium.com/bhaberer/cinch-twitterwatch.png)](https://gemnasium.com/bhaberer/cinch-twitterwatch)
5
+ [![Build Status](https://travis-ci.org/bhaberer/cinch-twitterwatch.png?branch=master)](https://travis-ci.org/bhaberer/cinch-twitterwatch)
6
+ [![Coverage Status](https://coveralls.io/repos/bhaberer/cinch-twitterwatch/badge.png?branch=master)](https://coveralls.io/r/bhaberer/cinch-twitterwatch?branch=master)
7
+ [![Code Climate](https://codeclimate.com/github/bhaberer/cinch-twitterwatch.png)](https://codeclimate.com/github/bhaberer/cinch-twitterwatch)
8
+
9
+ Posts the content of a linked Tweet to the channel, can also follow users and
10
+ post their tweets.
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ gem 'cinch-twitterwatch'
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install cinch-twitterwatch
25
+
26
+ ## Usage
27
+
28
+ For the gem to work all you will need to is require the gem and add
29
+ it to your plugins:
30
+
31
+ require 'cinch-twitterwatch'
32
+
33
+ @bot = Cinch::Bot.new do
34
+ configure do |c|
35
+ c.plugins.plugins = [ Cinch::Plugins::TwitterWatch]
36
+ end
37
+ end
38
+
39
+ And, acquire Twitter credentials. They are simple to acquire,
40
+ see https://dev.twitter.com/apps/new
41
+
42
+ Once you have said credentials you will need to pass them to the Plugin's
43
+ config like so:
44
+
45
+ c.plugins.options[Cinch::Plugins::TwitterWatch] = { consumer_key: 'consumer_key',
46
+ consumer_secret: 'consumer_secret',
47
+ access_token: 'access_token',
48
+ access_secret: 'access_secret',
49
+ watchers: {
50
+ '#CHANNEL' => ['TWITTER_USERNAME']
51
+ }
52
+ }
53
+
54
+ Then post a link to a specific tweet and the bot should post the content of said tweet to the channel.
55
+
56
+ ## Contributing
57
+
58
+ 1. Fork it
59
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
60
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
61
+ 4. Push to the branch (`git push origin my-new-feature`)
62
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cinch/plugins/twitterwatch/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'cinch-twitterwatch'
8
+ spec.version = Cinch::Plugins::TwitterWatch::VERSION
9
+ spec.authors = ['Brian Haberer']
10
+ spec.email = ['bhaberer@gmail.com']
11
+ spec.description = %q{Cinch plugin that watches for new tweets from users.}
12
+ spec.summary = %q{Cinch Plugin to follow twitter.}
13
+ spec.homepage = 'https://github.com/bhaberer/cinch-twitterwatch'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.3'
22
+ spec.add_development_dependency 'rake', '~> 10.1'
23
+ spec.add_development_dependency 'rspec', '~> 2.14'
24
+ spec.add_development_dependency 'coveralls', '~> 0.7'
25
+ spec.add_development_dependency 'cinch-test', '~> 0.0', '>= 0.0.4'
26
+
27
+ spec.add_dependency 'twitter', '~> 5.7', '>= 5.7.1'
28
+ spec.add_dependency 'cinch', '~> 2.0', '>= 2.0.12'
29
+ spec.add_dependency 'cinch-toolbox', '~> 1.1', '>= 1.1.2'
30
+ end
@@ -0,0 +1,35 @@
1
+ module Cinch::Plugins
2
+ class TwitterWatch
3
+ class Cache
4
+ attr_accessor :nick, :channel, :tweet_cache, :client
5
+
6
+ def initialize(nick, channel, client)
7
+ @nick = nick
8
+ @client = client
9
+ @channel = channel
10
+ @tweet_cache = {}
11
+ end
12
+
13
+ def init_cache
14
+ @client.user_timeline(@nick).each do |tweet|
15
+ cache_tweet(tweet.id)
16
+ 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
+
23
+ def tweet_unless_cached(tweet_id)
24
+ return if @tweet_cache.key?(tweet_id)
25
+ cache_tweet(tweet_id)
26
+ @client.status(tweet_id).text
27
+ end
28
+
29
+ def cache_tweet(tweet_id)
30
+ @tweet_cache[tweet_id.to_i] = true
31
+ true
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,9 @@
1
+ # -*- encoding: utf-8 -*-
2
+ module Cinch
3
+ module Plugins
4
+ # Versioning info
5
+ class TwitterWatch
6
+ VERSION = '1.0.2'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,84 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'cinch'
3
+ require 'cinch/toolbox'
4
+ require 'twitter'
5
+
6
+ module Cinch::Plugins
7
+ # Cinch Plugin to post twitter statuses
8
+ class TwitterWatch
9
+ include Cinch::Plugin
10
+
11
+ timer 15, method: :check_watched
12
+
13
+ def initialize(*args)
14
+ super
15
+ @client = twitter_client
16
+ @watched = build_watchers
17
+ end
18
+
19
+ def check_watched
20
+ return unless @watched
21
+ @watched.each { |w| check_for_tweet(w) }
22
+ rescue Twitter::Error::NotFound
23
+ debug 'You have set an invalid or protected user ' +
24
+ 'to watch, please correct this error'
25
+ rescue Twitter::Error::TooManyRequests
26
+ debug 'Trottled checking user; sleeping 60 seconds.'
27
+ sleep 60
28
+ end
29
+
30
+ def check_for_tweet(w)
31
+ # Just check the last tweet, if they are posting more than once
32
+ # every timer tick we don't want to spam the channel.
33
+ debug "Checking Tweets for #{w.nick} (#{w.tweet_cache.count} cached)"
34
+ tweet = @client.user(w.nick).status
35
+ status = w.tweet_unless_cached(tweet.id)
36
+ Channel(w.channel).msg(tweet_text(w.nick, status)) unless status.nil?
37
+ end
38
+
39
+ def format_tweet(url)
40
+ # Parse the url and get the relevant data
41
+ user, status = parse_twitter_url(url)
42
+
43
+ # Return blank if we didn't get a good user and status
44
+ return if user.nil? || status.nil?
45
+
46
+ tweet(user, status)
47
+ end
48
+
49
+ def tweet_text(user, status)
50
+ # Scrub the tweet for returns so we don't have multilined responses.
51
+ status.gsub!(/[\n]+/, ' ') if status.match(/\n/)
52
+ "@#{user} tweeted \"#{status}\""
53
+ end
54
+
55
+ private
56
+
57
+ def parse_twitter_url(url)
58
+ tweet_id = url[%r(statuse?s?/(\d+)/?), 1]
59
+ user = url[%r(/?#?!?/([^\/]+)/statuse?s?), 1]
60
+ [user, Twitter.status(tweet_id).text]
61
+ end
62
+
63
+ def build_watchers
64
+ watched = []
65
+ config[:watchers].each_pair do |chan, users|
66
+ users.each do |user|
67
+ watcher = Cache.new(user, chan, @client)
68
+ debug "#{watcher.init_cache}"
69
+ watched << watcher
70
+ end
71
+ end
72
+ watched
73
+ end
74
+
75
+ def twitter_client
76
+ Twitter::REST::Client.new do |c|
77
+ c.consumer_key = config[:consumer_key]
78
+ c.consumer_secret = config[:consumer_secret]
79
+ c.access_token = config[:access_token]
80
+ c.access_token_secret = config[:access_secret]
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,4 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'cinch/plugins/twitterwatch/version'
3
+ require 'cinch/plugins/twitterwatch'
4
+ require 'cinch/plugins/twitterwatch/cache'
@@ -0,0 +1,26 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'cinch'
3
+ require 'spec_helper'
4
+ describe Cinch::Plugins::TwitterWatch do
5
+ include Cinch::Test
6
+
7
+ before(:all) do
8
+ @bot = make_bot(Cinch::Plugins::TwitterWatch,
9
+ { filename: '/dev/null',
10
+ watchers: { '#foo' => ['weirdo513'] },
11
+ consumer_key: ENV['CONSUMER_KEY'],
12
+ consumer_secret: ENV['CONSUMER_SECRET'],
13
+ oauth_token: ENV['OAUTH_TOKEN'],
14
+ oauth_secret: ENV['OAUTH_SECRET'] })
15
+ end
16
+
17
+ describe "Watchers" do
18
+ # FIXME: cinch-test does not allow timers to function
19
+ it 'should not post tweets that already existed when the bot was started' do
20
+ sleep 20
21
+ get_replies(make_message(@bot, 'https://twitter.com/weirdo513/status/344186643609174016',
22
+ { channel: '#foo', nick: 'bar' }))
23
+ end
24
+ end
25
+ end
26
+
@@ -0,0 +1,16 @@
1
+ require 'coveralls'
2
+ require 'simplecov'
3
+
4
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
5
+ SimpleCov::Formatter::HTMLFormatter,
6
+ Coveralls::SimpleCov::Formatter
7
+ ]
8
+ SimpleCov.start
9
+
10
+ if File::exist? File.join(File.dirname(__FILE__), "secret.rb")
11
+ require 'secret'
12
+ end
13
+
14
+ require 'json'
15
+ require 'cinch-twitterwatch'
16
+ require 'cinch/test'
metadata ADDED
@@ -0,0 +1,195 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cinch-twitterwatch
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Brian Haberer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.1'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '2.14'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.14'
55
+ - !ruby/object:Gem::Dependency
56
+ name: coveralls
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '0.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: cinch-test
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '0.0'
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: 0.0.4
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: '0.0'
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: 0.0.4
89
+ - !ruby/object:Gem::Dependency
90
+ name: twitter
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ~>
94
+ - !ruby/object:Gem::Version
95
+ version: '5.7'
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: 5.7.1
99
+ type: :runtime
100
+ prerelease: false
101
+ version_requirements: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ~>
104
+ - !ruby/object:Gem::Version
105
+ version: '5.7'
106
+ - - ! '>='
107
+ - !ruby/object:Gem::Version
108
+ version: 5.7.1
109
+ - !ruby/object:Gem::Dependency
110
+ name: cinch
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ~>
114
+ - !ruby/object:Gem::Version
115
+ version: '2.0'
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: 2.0.12
119
+ type: :runtime
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: '2.0'
126
+ - - ! '>='
127
+ - !ruby/object:Gem::Version
128
+ version: 2.0.12
129
+ - !ruby/object:Gem::Dependency
130
+ name: cinch-toolbox
131
+ requirement: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ~>
134
+ - !ruby/object:Gem::Version
135
+ version: '1.1'
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: 1.1.2
139
+ type: :runtime
140
+ prerelease: false
141
+ version_requirements: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ~>
144
+ - !ruby/object:Gem::Version
145
+ version: '1.1'
146
+ - - ! '>='
147
+ - !ruby/object:Gem::Version
148
+ version: 1.1.2
149
+ description: Cinch plugin that watches for new tweets from users.
150
+ email:
151
+ - bhaberer@gmail.com
152
+ executables: []
153
+ extensions: []
154
+ extra_rdoc_files: []
155
+ files:
156
+ - .gitignore
157
+ - .travis.yml
158
+ - Gemfile
159
+ - LICENSE.txt
160
+ - README.md
161
+ - Rakefile
162
+ - cinch-twitterwatch.gemspec
163
+ - lib/cinch-twitterwatch.rb
164
+ - lib/cinch/plugins/twitterwatch.rb
165
+ - lib/cinch/plugins/twitterwatch/cache.rb
166
+ - lib/cinch/plugins/twitterwatch/version.rb
167
+ - spec/cinch-twitterwatch_spec.rb
168
+ - spec/spec_helper.rb
169
+ homepage: https://github.com/bhaberer/cinch-twitterwatch
170
+ licenses:
171
+ - MIT
172
+ metadata: {}
173
+ post_install_message:
174
+ rdoc_options: []
175
+ require_paths:
176
+ - lib
177
+ required_ruby_version: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ! '>='
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ required_rubygems_version: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ! '>='
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ requirements: []
188
+ rubyforge_project:
189
+ rubygems_version: 2.2.2
190
+ signing_key:
191
+ specification_version: 4
192
+ summary: Cinch Plugin to follow twitter.
193
+ test_files:
194
+ - spec/cinch-twitterwatch_spec.rb
195
+ - spec/spec_helper.rb