cinch-twitterstatus 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,23 +5,23 @@ rvm:
5
5
  - 1.9.3
6
6
  env:
7
7
  global:
8
- - secure: ! 'RYlcShCnPWh5tG/gHK2BSqxtBz/GWe66kTv9LBj0dhJAj+/aYxMCO4bnSXQ5
8
+ - secure: ! 'Yz/VAtfbXwk6JD/2/z6c2SGygNGELrF0dlZ/M5nOrDiKNm8lxpC6w19esGbB
9
9
 
10
- XFAaRb4OIZ94uaKck1G4sY/crUmcvphNsKSpt8EemY1JL1JLPuoXFblJYPUZ
10
+ CYt8UtqylceJ2UxYngHLVH48oPb+A5fv21/jDJMqHeO/N4WjwQUOzBZXfZG6
11
11
 
12
- XWAmMLvYBRmMxvjJgZ3NO0k5RRnTP35i2Fowsj4b3jIul7eJ6ys='
13
- - secure: ! 'GKCjuQvI131Rbk5Dd5t4wrN1jP1K7A1wm0abIvWmoTgxOHUIcRwcQTzwrACX
12
+ lpugXIsT9Q10q0AsXry65YuzZtpY7VkVQUNSBYte7jTcWbLmIWQ='
13
+ - secure: ! 'CbdMyExVnyHfPQ+scSky8JIlqK0dU7idBrtvipQIA2dGfIIj0lzuUDEqvtAv
14
14
 
15
- SOf3K7ep185d/q8h7EQ+BZ9DuGLA48c3dLhd1Nf1CplK8QfjZy4UbpZ6AAd1
15
+ +9A7Mw01ddxQ/tXdixHDBNOhp9Ddz+4/0OSMyIb/5uFy+l7b2B2K4A4R5crI
16
16
 
17
- 8JnB+si7lTYHNRW1YjMg239iOdGUyaK1bSrFk0iYXWUkS80LPnE='
18
- - secure: ! 'T7gEZtRyUKS2mcrHpIUmBTMsPGJ5EWcYUQmiIHFch+cSR9hFBc1HvITa4W8M
17
+ RBc5W5rgzRLnDD7HL4BZMRDpx3sJRLcIH9S4bclXyjkzQ7yzVDc='
18
+ - secure: ! 'Pl14JkhwMe+HHi1Ht0znd0+TnSzdSGvtG4pX8+oSWuIyfTd3xfoj7Pf1S4P/
19
19
 
20
- VJfA9qHWI7ybI/q5zJtxh7sXw9YSNntRveEFSWZSoOiRtxZa7Y+ZHoyS56bL
20
+ 7SVnixq2gQh13OaL4Tj2sR6+AHz6n+onareFoKkZPSJuDRh6yXFfvKIdx4MV
21
21
 
22
- 6ttPIfaAPwqhc1IPJBWnoIJF83VNn6hUoVni5M72wGi+wptqAWo='
23
- - secure: ! 'SzPZg486jGoOYKQoH9PAdtL91R6DxVKpu4wvBm5K4zMIKnUd7jOtfYs7Ukm5
22
+ l5lIJbSI4icPWOMk6ObMCzIb/m3m4Z/BG3O5E/6AcJDQa7rspL0='
23
+ - secure: ! 'Xrh52mNuRCf1kJHpZctrz3gfBZQ/rlC+qz/MlvZ9L7sm1CFSIoJdizrOYawt
24
24
 
25
- FngWZo5MX5shTp32DCmgpKR9HBX4rxRxTzeriWRztQ22k59w6ftKlnmmEyLw
25
+ cKOyLfsLrcnJqGbq0s++cSQ2QDggEGxtVkMXxIw7dBFn2icZsKsTN5rh28UR
26
26
 
27
- lHDU487H20FD7KqwTdHfufD8U1hLmQP8+xjLkEDyiIiJOnLAFfE='
27
+ W2TakLhFB8f+LQ+/P9PvV1wlSOJQRFItLjjOtcEoQVLi51Pwuzw='
data/README.md CHANGED
@@ -6,7 +6,8 @@
6
6
  [![Coverage Status](https://coveralls.io/repos/bhaberer/cinch-twitterstatus/badge.png?branch=master)](https://coveralls.io/r/bhaberer/cinch-twitterstatus?branch=master)
7
7
  [![Code Climate](https://codeclimate.com/github/bhaberer/cinch-twitterstatus.png)](https://codeclimate.com/github/bhaberer/cinch-twitterstatus)
8
8
 
9
- Posts the content of a linked Tweet to the channel, can also follow users and post their tweets.
9
+ Posts the content of a linked Tweet to the channel, can also follow users and
10
+ post their tweets.
10
11
 
11
12
  ## Installation
12
13
 
@@ -32,28 +33,18 @@ For the gem to work alll you will need to is add the gem to your plugins:
32
33
  end
33
34
  end
34
35
 
35
- And, acquire Twitter credentials. They are simple to acquire, see https://dev.twitter.com/apps/new
36
+ And, acquire Twitter credentials. They are simple to acquire,
37
+ see https://dev.twitter.com/apps/new
36
38
 
37
- Once you have said credentials you will need to pass them to the Plugin's config like so:
39
+ Once you have said credentials you will need to pass them to the Plugin's
40
+ config like so:
38
41
 
39
- c.plugins.options[Cinch::Plugins::TwitterStatus] = { :consumer_key => 'consumer_key',
40
- :consumer_secret => 'consumer_secret',
41
- :oauth_token => 'oauth_token',
42
- :oauth_secret => 'oauth_secret' }
43
-
44
- Then post a link to a specific tweet and the bot should post the content of said tweet to the channel.
45
-
46
- ### Watching Twitter Users ###
47
-
48
- If you have a twitter account that the bot should watch for new tweets, you can
49
- define it in the config as well:
50
-
51
42
  c.plugins.options[Cinch::Plugins::TwitterStatus] = { consumer_key: 'consumer_key',
52
43
  consumer_secret: 'consumer_secret',
53
- oauth_token: 'oauth_token',
54
- oauth_secret: 'oauth_secret',
55
- watchers: { '#channel': ['twitteruser'] } }
44
+ access_token: 'access_token',
45
+ access_secret: 'access_secret' }
56
46
 
47
+ Then post a link to a specific tweet and the bot should post the content of said tweet to the channel.
57
48
 
58
49
  ## Contributing
59
50
 
@@ -4,13 +4,13 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'cinch/plugins/twitterstatus/version'
5
5
 
6
6
  Gem::Specification.new do |gem|
7
- gem.name = "cinch-twitterstatus"
8
- gem.version = Cinch::Twitterstatus::VERSION
9
- gem.authors = ["Brian Haberer"]
10
- gem.email = ["bhaberer@gmail.com"]
7
+ gem.name = 'cinch-twitterstatus'
8
+ gem.version = Cinch::Plugins::TwitterStatus::VERSION
9
+ gem.authors = ['Brian Haberer']
10
+ gem.email = ['bhaberer@gmail.com']
11
11
  gem.description = %q{Cinch IRC bot Plugin that access the Twitter API to post the content of linked twitter statuses to the channel.}
12
12
  gem.summary = %q{Cinch Plugin to post tweets to channel.}
13
- gem.homepage = "https://github.com/bhaberer/cinch-twitterstatus"
13
+ gem.homepage = 'https://github.com/bhaberer/cinch-twitterstatus'
14
14
  gem.license = 'MIT'
15
15
 
16
16
  gem.files = `git ls-files`.split($/)
@@ -18,11 +18,12 @@ Gem::Specification.new do |gem|
18
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
19
  gem.require_paths = ["lib"]
20
20
 
21
- gem.add_development_dependency 'rake'
22
- gem.add_development_dependency 'rspec'
23
- gem.add_development_dependency 'coveralls'
24
- gem.add_development_dependency 'cinch-test'
21
+ gem.add_development_dependency 'rake'
22
+ gem.add_development_dependency 'rspec'
23
+ gem.add_development_dependency 'coveralls'
24
+ gem.add_development_dependency 'cinch-test'
25
25
 
26
- gem.add_dependency 'twitter', '~> 4.8.1'
27
- gem.add_dependency 'cinch', '~> 2.0.0'
26
+ gem.add_dependency 'twitter', '~> 5.7.1'
27
+ gem.add_dependency 'cinch', '~> 2.0.12'
28
+ gem.add_dependency 'cinch-toolbox', '~> 1.1.0'
28
29
  end
@@ -1,2 +1,3 @@
1
+ # -*- encoding: utf-8 -*-
1
2
  require 'cinch/plugins/twitterstatus/version'
2
- require 'cinch/plugins/twitterstatus/twitterstatus'
3
+ require 'cinch/plugins/twitterstatus'
@@ -0,0 +1,65 @@
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 TwitterStatus
9
+ include Cinch::Plugin
10
+
11
+ self.help = 'Just link to a specific twitter status and I will post the ' +
12
+ ' content of that tweet.'
13
+
14
+ listen_to :channel
15
+
16
+ def initialize(*args)
17
+ super
18
+ @client = twitter_client
19
+ end
20
+
21
+ def listen(m)
22
+ Cinch::Toolbox.extract_urls(m.message).each do |url|
23
+ if url.match(%r(^https?://mobile|w{3}?\.?twitter\.com/))
24
+ msg = format_tweet(url)
25
+ m.reply msg unless msg.nil?
26
+ end
27
+ end
28
+ rescue Twitter::Error::NotFound, Twitter::Error::Forbidden
29
+ debug 'User posted an invalid twitter status'
30
+ end
31
+
32
+ def format_tweet(url)
33
+ # Parse the url and get the relevant data
34
+ user, status = parse_twitter_url(url)
35
+
36
+ # Return blank if we didn't get a good user and status
37
+ return if user.nil? || status.nil?
38
+
39
+ tweet_text(user, status)
40
+ end
41
+
42
+ def tweet_text(user, status)
43
+ # Scrub the tweet for returns so we don't have multilined responses.
44
+ status.gsub!(/[\n]+/, ' ') if status.match(/\n/)
45
+ "@#{user} tweeted \"#{status}\""
46
+ end
47
+
48
+ private
49
+
50
+ def parse_twitter_url(url)
51
+ tweet_id = url[%r(statuse?s?/(\d+)/?), 1]
52
+ user = url[%r(/?#?!?/([^\/]+)/statuse?s?), 1]
53
+ [user, @client.status(tweet_id).text]
54
+ end
55
+
56
+ def twitter_client
57
+ Twitter::REST::Client.new do |c|
58
+ c.consumer_key = config[:consumer_key]
59
+ c.consumer_secret = config[:consumer_secret]
60
+ c.access_token = config[:access_token]
61
+ c.access_token_secret = config[:access_secret]
62
+ end
63
+ end
64
+ end
65
+ end
@@ -1,5 +1,9 @@
1
+ # -*- encoding: utf-8 -*-
1
2
  module Cinch
2
- module Twitterstatus
3
- VERSION = "1.0.1"
3
+ module Plugins
4
+ # Versioning info
5
+ class TwitterStatus
6
+ VERSION = '1.1.0'
7
+ end
4
8
  end
5
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cinch-twitterstatus
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-27 00:00:00.000000000 Z
12
+ date: 2014-02-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -82,7 +82,7 @@ dependencies:
82
82
  requirements:
83
83
  - - ~>
84
84
  - !ruby/object:Gem::Version
85
- version: 4.8.1
85
+ version: 5.7.1
86
86
  type: :runtime
87
87
  prerelease: false
88
88
  version_requirements: !ruby/object:Gem::Requirement
@@ -90,7 +90,7 @@ dependencies:
90
90
  requirements:
91
91
  - - ~>
92
92
  - !ruby/object:Gem::Version
93
- version: 4.8.1
93
+ version: 5.7.1
94
94
  - !ruby/object:Gem::Dependency
95
95
  name: cinch
96
96
  requirement: !ruby/object:Gem::Requirement
@@ -98,7 +98,7 @@ dependencies:
98
98
  requirements:
99
99
  - - ~>
100
100
  - !ruby/object:Gem::Version
101
- version: 2.0.0
101
+ version: 2.0.12
102
102
  type: :runtime
103
103
  prerelease: false
104
104
  version_requirements: !ruby/object:Gem::Requirement
@@ -106,7 +106,23 @@ dependencies:
106
106
  requirements:
107
107
  - - ~>
108
108
  - !ruby/object:Gem::Version
109
- version: 2.0.0
109
+ version: 2.0.12
110
+ - !ruby/object:Gem::Dependency
111
+ name: cinch-toolbox
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: 1.1.0
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: 1.1.0
110
126
  description: Cinch IRC bot Plugin that access the Twitter API to post the content
111
127
  of linked twitter statuses to the channel.
112
128
  email:
@@ -123,7 +139,7 @@ files:
123
139
  - Rakefile
124
140
  - cinch-twitterstatus.gemspec
125
141
  - lib/cinch-twitterstatus.rb
126
- - lib/cinch/plugins/twitterstatus/twitterstatus.rb
142
+ - lib/cinch/plugins/twitterstatus.rb
127
143
  - lib/cinch/plugins/twitterstatus/version.rb
128
144
  - spec/cinch-twitterstatus_spec.rb
129
145
  - spec/spec_helper.rb
@@ -1,94 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'cinch'
3
- require 'twitter'
4
-
5
- module Cinch::Plugins
6
- class TwitterStatus
7
- include Cinch::Plugin
8
-
9
- self.help = 'Just link to a specific twitter status and I will post the content of that tweet.'
10
-
11
- listen_to :channel
12
- timer 15, method: :check_watched
13
-
14
- def initialize(*args)
15
- super
16
- if config
17
- Twitter.configure do |c|
18
- c.consumer_key = config[:consumer_key]
19
- c.consumer_secret = config[:consumer_secret]
20
- c.oauth_token = config[:oauth_token]
21
- c.oauth_token_secret = config[:oauth_secret]
22
- end
23
-
24
- if config[:watchers]
25
- @watched = Hash.new
26
- config[:watchers].each_pair do |chan, users|
27
- @watched[chan] = Hash.new
28
- users.each { |user| refresh_cache(chan, user) }
29
- end
30
- end
31
- end
32
- end
33
-
34
- def check_watched
35
- return unless @watched
36
-
37
- @watched.keys.each do |chan|
38
- @watched[chan].keys.each do |user|
39
- begin
40
- # Just check the last tweet, if they are posting more than once
41
- # every timer tick I don't want to spam the channel.
42
- tweet = Twitter::Client.new.user_timeline(user).first
43
- unless @watched[chan][user].include?(tweet.id)
44
- @watched[chan][user] << tweet.id
45
-
46
- msg = format_tweet(user, Twitter.status(tweet.id).text)
47
- Channel(chan).send msg unless msg.nil?
48
- end
49
- refresh_cache(chan, user)
50
- rescue Twitter::Error::NotFound
51
- debug "You have set an invalid or protected user (#{user}) to watch, please correct this error"
52
- end
53
- end
54
- end
55
- end
56
-
57
- def listen(m)
58
- urls = URI.extract(m.message, ["http", "https"])
59
- urls.each do |url|
60
- if url.match(/^https?:\/\/mobile|w{3}?\.?twitter\.com/)
61
- if tweet = url.match(/https?:\/\/mobile|w{3}?\.?twitter\.com\/?#?!?\/([^\/]+)\/statuse?s?\/(\d+)\/?/)
62
- msg = format_tweet(tweet[1], Twitter.status(tweet[2]).text)
63
- m.reply msg unless msg.nil?
64
- end
65
- end
66
- end
67
- rescue Twitter::Error::NotFound
68
- debug "User posted an invalid twitter status"
69
- rescue Twitter::Error::Forbidden
70
- debug "User attempted to post a Protected Tweet or you have not set valid Twitter credentials."
71
- end
72
-
73
- private
74
-
75
- def format_tweet(user, status)
76
- # Return blank if we didn't get a good user and status
77
- return if user.nil? || status.nil?
78
-
79
- # Scrub the tweet for returns so we don't have multilined responses.
80
- status.gsub!(/[\n]+/, " ") if status.match(/\n/)
81
-
82
- return "@#{user} tweeted \"#{status}\""
83
- end
84
-
85
- def refresh_cache(chan, user)
86
- @watched[chan][user] = []
87
- Twitter::Client.new.user_timeline(user).each do |tweet|
88
- @watched[chan][user] << tweet.id
89
- end
90
- rescue Twitter::Error::NotFound
91
- debug "You have set an invalid or protected user (#{user}) to watch, please correct this error"
92
- end
93
- end
94
- end