cinch-twitter 0.3.13 → 1.0.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.
- checksums.yaml +7 -0
- data/.document +5 -5
- data/.gitignore +18 -0
- data/CHANGELOG.md +34 -28
- data/Gemfile +4 -18
- data/LICENSE.txt +22 -20
- data/README.md +61 -61
- data/Rakefile +1 -47
- data/cinch-twitter.gemspec +30 -71
- data/lib/cinch/plugins/twitter/version.rb +5 -0
- data/lib/cinch/plugins/twitter.rb +101 -83
- metadata +30 -81
- data/Gemfile.lock +0 -37
- data/VERSION +0 -1
- data/lib/cinch/plugins/twitter/error_handler.rb +0 -36
- data/lib/cinch/plugins/twitter/formatter.rb +0 -78
- data/lib/cinch/plugins/twitter/tweet_handler.rb +0 -77
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: e56ca49c5393538538557bc9f7431a5f003e22ca
|
|
4
|
+
data.tar.gz: bdf4f72769e54bc9525ee27e51bf2b4dc55c86e9
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 04b57feaad9ddaa6adde77350c0e96d956067fdc4587413c61ba14e950e4248fbb835a653e35a47e77e0a15d6c3f12a5586183a48131a8abbc8865d8064f7771
|
|
7
|
+
data.tar.gz: 5ad0914a81075e66e470b1901c03038c8ec0d85dc8450a1c8adc7bc78aa0cf87b852363b552aaec6117cb3d0b2c30d069141259730c8520691cb8a88908de58b
|
data/.document
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
lib/**/*.rb
|
|
2
|
-
bin/*
|
|
3
|
-
-
|
|
4
|
-
features/**/*.feature
|
|
5
|
-
LICENSE.txt
|
|
1
|
+
lib/**/*.rb
|
|
2
|
+
bin/*
|
|
3
|
+
-
|
|
4
|
+
features/**/*.feature
|
|
5
|
+
LICENSE.txt
|
data/.gitignore
ADDED
data/CHANGELOG.md
CHANGED
|
@@ -1,28 +1,34 @@
|
|
|
1
|
-
# Version 0.
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*
|
|
10
|
-
|
|
11
|
-
# Version 0.3.
|
|
12
|
-
*
|
|
13
|
-
|
|
14
|
-
# Version 0.3.
|
|
15
|
-
*
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
*
|
|
23
|
-
|
|
24
|
-
# Version 0.
|
|
25
|
-
*
|
|
26
|
-
|
|
27
|
-
# Version 0.
|
|
28
|
-
*
|
|
1
|
+
# Version 1.0.0
|
|
2
|
+
* Major rewrite from the ground up
|
|
3
|
+
* Uses Twitter gem 4.8 (API v.1.1)
|
|
4
|
+
* Removes ?ts and ?tw commands (twitter search and twitter user info respectively)
|
|
5
|
+
* Your OAuth and access keys can still be entered the same way as before in config
|
|
6
|
+
|
|
7
|
+
# Version 0.3.12 + 0.3.13
|
|
8
|
+
* Various fixes
|
|
9
|
+
* Fixing Gemfile's dependencies
|
|
10
|
+
|
|
11
|
+
# Version 0.3.8 .. Version 0.3.11
|
|
12
|
+
* ?tw <nick> no longer raises an exception when status does not exist.
|
|
13
|
+
|
|
14
|
+
# Version 0.3.7
|
|
15
|
+
* Another minor fix. Made https the standard for all links.
|
|
16
|
+
|
|
17
|
+
# Version 0.3.6
|
|
18
|
+
* Query commands (?tw, ?ts) now only fire if the command is at the start of the line.
|
|
19
|
+
|
|
20
|
+
# Version 0.3.4 + 0.3.5
|
|
21
|
+
* Removed useless addition of the bots nick for ENHANCE_YOUR_CALM and reworded message.
|
|
22
|
+
* Removed formatting for error messages since Cinch's Format() cannot seem to be accessible in the ErrorHandler module.
|
|
23
|
+
|
|
24
|
+
# Version 0.3.3
|
|
25
|
+
* Various updates and fixes
|
|
26
|
+
|
|
27
|
+
# Version 0.3.0
|
|
28
|
+
* The plugin now requires Twitter 3.0.0 and above.
|
|
29
|
+
|
|
30
|
+
# Version 0.2.0
|
|
31
|
+
* The plugin can now be included via `Cinch::Plugins::Twitter`.
|
|
32
|
+
|
|
33
|
+
# Version 0.1.0
|
|
34
|
+
* Initial release
|
data/Gemfile
CHANGED
|
@@ -1,18 +1,4 @@
|
|
|
1
|
-
source
|
|
2
|
-
|
|
3
|
-
#
|
|
4
|
-
|
|
5
|
-
gem 'activesupport', '>= 3.0.0'
|
|
6
|
-
gem 'twitter', '~> 3.0'
|
|
7
|
-
gem 'cinch', '~> 2.0.3'
|
|
8
|
-
|
|
9
|
-
# Add dependencies to develop your gem here.
|
|
10
|
-
# Include everything needed to run rake, tests, features, etc.
|
|
11
|
-
group :development do
|
|
12
|
-
#gem "shoulda", ">= 0"
|
|
13
|
-
gem "yard", "~> 0.7"
|
|
14
|
-
gem "rdoc", "~> 3.12"
|
|
15
|
-
gem "bundler", ">= 1.0.0"
|
|
16
|
-
gem "jeweler", "~> 1.8.4"
|
|
17
|
-
#gem "simplecov", ">= 0"
|
|
18
|
-
end
|
|
1
|
+
source 'https://rubygems.org'
|
|
2
|
+
|
|
3
|
+
# Specify your gem's dependencies in cinch-twitter.gemspec
|
|
4
|
+
gemspec
|
data/LICENSE.txt
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
Copyright (c)
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
the
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
Copyright (c) 2013 Mark Seymour
|
|
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
CHANGED
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
1
|
+
# Cinch::Twitter
|
|
2
|
+
|
|
3
|
+
A Cinch plugin for accessing Twitter, using [Erik Michaels-Ober's](https://github.com/sferik/) wonderful [Twitter gem](https://github.com/sferik/twitter).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
gem 'cinch-twitter'
|
|
10
|
+
|
|
11
|
+
And then execute:
|
|
12
|
+
|
|
13
|
+
$ bundle
|
|
14
|
+
|
|
15
|
+
Or install it yourself as:
|
|
16
|
+
|
|
17
|
+
$ gem install cinch-twitter
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
### Bot commands
|
|
22
|
+
|
|
23
|
+
* `!tw <username><+D>` - Gets the latest tweet of the specified user, or the tweet 'D' tweets back, between 1 and 20.
|
|
24
|
+
* `!tw #[id]` - Gets the tweet at the specified ID
|
|
25
|
+
|
|
26
|
+
Shorthand commands are also available:
|
|
27
|
+
* `@[username]<+D>`, `@#[id]`
|
|
28
|
+
|
|
29
|
+
If for instance, an error occurs (such as a timeout, an account is protected, or can't be found), the plugin will send a message to the channel with an informative message.
|
|
30
|
+
|
|
31
|
+
### Requiring and including the plugin
|
|
32
|
+
require 'cinch/plugins/twitter'
|
|
33
|
+
# ...
|
|
34
|
+
Bot.config {|c|
|
|
35
|
+
# ...
|
|
36
|
+
c.plugins.plugins << Cinch::Plugins::Twitter
|
|
37
|
+
|
|
38
|
+
### Plugin Configuration
|
|
39
|
+
|
|
40
|
+
To configure the plugin, you must insert your access keys for the client.
|
|
41
|
+
|
|
42
|
+
To retrieve your access keys and `oauth` tokens, if you already have an application set up, please visit https://dev.twitter.com/apps, otherwise visit https://dev.twitter.com/apps/new and follow the instructions.
|
|
43
|
+
|
|
44
|
+
Example:
|
|
45
|
+
|
|
46
|
+
c.plugins.options[Cinch::Plugins::Twitter::Client] = {
|
|
47
|
+
access_keys: {
|
|
48
|
+
consumer_key: "XXXXXXX",
|
|
49
|
+
consumer_secret: "XXXXXXX",
|
|
50
|
+
oauth_token: "XXXXXXX",
|
|
51
|
+
oauth_token_secret: "XXXXXXX"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
## Contributing
|
|
56
|
+
|
|
57
|
+
1. Fork it
|
|
58
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
59
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
60
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
61
|
+
5. Create new Pull Request
|
data/Rakefile
CHANGED
|
@@ -1,47 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
require 'rubygems'
|
|
4
|
-
require 'bundler'
|
|
5
|
-
begin
|
|
6
|
-
Bundler.setup(:default, :development)
|
|
7
|
-
rescue Bundler::BundlerError => e
|
|
8
|
-
$stderr.puts e.message
|
|
9
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
|
10
|
-
exit e.status_code
|
|
11
|
-
end
|
|
12
|
-
require 'rake'
|
|
13
|
-
|
|
14
|
-
require 'jeweler'
|
|
15
|
-
Jeweler::Tasks.new do |gem|
|
|
16
|
-
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
|
17
|
-
gem.name = "cinch-twitter"
|
|
18
|
-
gem.homepage = "http://github.com/mseymour/cinch-twitter"
|
|
19
|
-
gem.license = "MIT"
|
|
20
|
-
gem.summary = %Q{A Cinch plugin for accessing Twitter.}
|
|
21
|
-
gem.description = %Q{A Twitter plugin for Cinch.}
|
|
22
|
-
gem.email = "mark.seymour.ns@gmail.com"
|
|
23
|
-
gem.authors = ["Mark Seymour"]
|
|
24
|
-
# dependencies defined in Gemfile
|
|
25
|
-
end
|
|
26
|
-
Jeweler::RubygemsDotOrgTasks.new
|
|
27
|
-
|
|
28
|
-
=begin require 'rake/testtask'
|
|
29
|
-
Rake::TestTask.new(:test) do |test|
|
|
30
|
-
test.libs << 'lib' << 'test'
|
|
31
|
-
test.pattern = 'test/**/test_*.rb'
|
|
32
|
-
test.verbose = true
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
require 'rcov/rcovtask'
|
|
36
|
-
Rcov::RcovTask.new do |test|
|
|
37
|
-
test.libs << 'test'
|
|
38
|
-
test.pattern = 'test/**/test_*.rb'
|
|
39
|
-
test.verbose = true
|
|
40
|
-
test.rcov_opts << '--exclude "gems/*"'
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
task :default => :test
|
|
44
|
-
=end
|
|
45
|
-
|
|
46
|
-
require 'yard'
|
|
47
|
-
YARD::Rake::YardocTask.new
|
|
1
|
+
require "bundler/gem_tasks"
|
data/cinch-twitter.gemspec
CHANGED
|
@@ -1,71 +1,30 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
Gem::Specification.new do |
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"lib/cinch/plugins/twitter/error_handler.rb",
|
|
32
|
-
"lib/cinch/plugins/twitter/formatter.rb",
|
|
33
|
-
"lib/cinch/plugins/twitter/tweet_handler.rb"
|
|
34
|
-
]
|
|
35
|
-
s.homepage = "http://github.com/mseymour/cinch-twitter"
|
|
36
|
-
s.licenses = ["MIT"]
|
|
37
|
-
s.require_paths = ["lib"]
|
|
38
|
-
s.rubygems_version = "1.8.24"
|
|
39
|
-
s.summary = "A Cinch plugin for accessing Twitter."
|
|
40
|
-
|
|
41
|
-
if s.respond_to? :specification_version then
|
|
42
|
-
s.specification_version = 3
|
|
43
|
-
|
|
44
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
|
45
|
-
s.add_runtime_dependency(%q<activesupport>, [">= 3.0.0"])
|
|
46
|
-
s.add_runtime_dependency(%q<twitter>, ["~> 3.0"])
|
|
47
|
-
s.add_runtime_dependency(%q<cinch>, ["~> 2.0.3"])
|
|
48
|
-
s.add_development_dependency(%q<yard>, ["~> 0.7"])
|
|
49
|
-
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
|
50
|
-
s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
|
|
51
|
-
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
|
52
|
-
else
|
|
53
|
-
s.add_dependency(%q<activesupport>, [">= 3.0.0"])
|
|
54
|
-
s.add_dependency(%q<twitter>, ["~> 3.0"])
|
|
55
|
-
s.add_dependency(%q<cinch>, ["~> 2.0.3"])
|
|
56
|
-
s.add_dependency(%q<yard>, ["~> 0.7"])
|
|
57
|
-
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
|
58
|
-
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
|
59
|
-
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
|
60
|
-
end
|
|
61
|
-
else
|
|
62
|
-
s.add_dependency(%q<activesupport>, [">= 3.0.0"])
|
|
63
|
-
s.add_dependency(%q<twitter>, ["~> 3.0"])
|
|
64
|
-
s.add_dependency(%q<cinch>, ["~> 2.0.3"])
|
|
65
|
-
s.add_dependency(%q<yard>, ["~> 0.7"])
|
|
66
|
-
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
|
67
|
-
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
|
68
|
-
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
|
|
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/twitter/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
|
|
8
|
+
spec.name = "cinch-twitter"
|
|
9
|
+
spec.version = Cinch::Twitter::VERSION
|
|
10
|
+
spec.authors = ["Mark Seymour"]
|
|
11
|
+
spec.email = ["mark.seymour.ns@gmail.com"]
|
|
12
|
+
spec.description = %q{A Twitter plugin for Cinch.}
|
|
13
|
+
spec.summary = %q{A Cinch plugin for accessing Twitter.}
|
|
14
|
+
spec.homepage = "https://github.com/mseymour/cinch-twitter"
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
|
|
17
|
+
spec.files = `git ls-files`.split($/)
|
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
20
|
+
spec.require_paths = ["lib"]
|
|
21
|
+
|
|
22
|
+
# Gem dependencies
|
|
23
|
+
spec.add_dependency 'twitter', '~> 4.8'
|
|
24
|
+
spec.add_dependency 'cinch', '~> 2.0'
|
|
25
|
+
spec.add_dependency "oj", "~> 2.0.14"
|
|
26
|
+
|
|
27
|
+
# Development dependencies
|
|
28
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
|
29
|
+
spec.add_development_dependency "rake"
|
|
30
|
+
end
|
|
@@ -1,83 +1,101 @@
|
|
|
1
|
-
# coding: utf-8
|
|
2
|
-
|
|
3
|
-
require
|
|
4
|
-
require
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
set(
|
|
15
|
-
plugin_name: "Twitter",
|
|
16
|
-
help: "Access Twitter from the comfort of your IRC client! Usage:\n* `!tw <username
|
|
17
|
-
required_options: [:access_keys])
|
|
18
|
-
|
|
19
|
-
def initialize
|
|
20
|
-
super
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
c.
|
|
24
|
-
c.
|
|
25
|
-
c.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
else
|
|
46
|
-
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
def
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
require "oj"
|
|
4
|
+
require "twitter"
|
|
5
|
+
|
|
6
|
+
module Cinch
|
|
7
|
+
module Plugins
|
|
8
|
+
class Twitter
|
|
9
|
+
include Cinch::Plugin
|
|
10
|
+
|
|
11
|
+
TWITTER_URL_BASE = 'https://twitter.com/'
|
|
12
|
+
ERROR_TPL = Cinch::Formatting.format(:bold, 'Uhoh! »') + ' %s'
|
|
13
|
+
|
|
14
|
+
set(
|
|
15
|
+
plugin_name: "Twitter",
|
|
16
|
+
help: "Access Twitter from the comfort of your IRC client! Usage:\n* `!tw <username><-D>` - Gets the latest tweet of the specified user, or the tweet 'D' tweets back, between 1 and 20.\n* `!tw #[id]` - Gets the tweet at the specified ID\n* `?tw [username]` - Gets the specified user's Twitter profile\n* `?ts [term]` - Searches for three of the most recent tweets regarding the specified query\n\nShorthand: `@[username]<+D>`, @#[id]",
|
|
17
|
+
required_options: [:access_keys])
|
|
18
|
+
|
|
19
|
+
def initialize *args
|
|
20
|
+
super
|
|
21
|
+
::Twitter.configure do |c|
|
|
22
|
+
c.consumer_key = config[:access_keys][:consumer_key]
|
|
23
|
+
c.consumer_secret = config[:access_keys][:consumer_secret]
|
|
24
|
+
c.oauth_token = config[:access_keys][:oauth_token]
|
|
25
|
+
c.oauth_token_secret = config[:access_keys][:oauth_token_secret]
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
match /tw (\w+)(?:-(\d+))?$/, method: :execute_tweet
|
|
30
|
+
match /(\w+)(?:-(\d+))?$/, method: :execute_tweet, prefix: /^@/
|
|
31
|
+
def execute_tweet m, username, offset
|
|
32
|
+
offset ||= 0
|
|
33
|
+
|
|
34
|
+
user = ::Twitter.user(username)
|
|
35
|
+
|
|
36
|
+
return m.reply ERROR_TPL % "#{user.screen_name}'s tweets are protected." if user.protected?
|
|
37
|
+
return m.reply "#{user.screen_name} is lame because they haven't tweeted yet!" if user.status.nil?
|
|
38
|
+
|
|
39
|
+
# Getting the user's 20 latest tweets if our offset is greater than 0:
|
|
40
|
+
if offset.to_i > 0
|
|
41
|
+
tweets = ::Twitter.user_timeline(user)
|
|
42
|
+
return m.reply ERROR_TPL % "You cannot backtrack more than #{tweets.count.pred} tweets before the current tweet." if offset.to_i > tweets.count.pred
|
|
43
|
+
tweet = tweets[offset.to_i]
|
|
44
|
+
# Otherwise, just get the latest tweet from the user object.
|
|
45
|
+
else
|
|
46
|
+
tweet = user.status
|
|
47
|
+
end
|
|
48
|
+
m.reply format_tweet(tweet)
|
|
49
|
+
rescue ::Twitter::Error::NotFound => e
|
|
50
|
+
m.reply ERROR_TPL % "#{username} doesn't exist."
|
|
51
|
+
rescue ::Twitter::Error => e
|
|
52
|
+
m.reply ERROR_TPL % "#{e.message.gsub(/user/i, username)}. (#{e.class})"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
match /tw #(\d+)$/, method: :execute_id
|
|
57
|
+
match /#(\d+)$/, method: :execute_id, prefix: /^@/
|
|
58
|
+
def execute_id m, id
|
|
59
|
+
tweet = ::Twitter.status(id)
|
|
60
|
+
|
|
61
|
+
#return m.reply ERROR_TPL % "#{user.screen_name}'s tweets are protected." if user.protected?
|
|
62
|
+
|
|
63
|
+
m.reply format_tweet(tweet)
|
|
64
|
+
rescue ::Twitter::Error::NotFound => e
|
|
65
|
+
m.reply ERROR_TPL % "#{id} doesn't exist."
|
|
66
|
+
rescue ::Twitter::Error => e
|
|
67
|
+
m.reply ERROR_TPL % "#{e.message.gsub(/user/i, id)}. (#{e.class})"
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
private
|
|
71
|
+
|
|
72
|
+
def format_tweet tweet
|
|
73
|
+
# Username (and retweeted username if applicable)
|
|
74
|
+
head = []
|
|
75
|
+
head << tweet.user.screen_name
|
|
76
|
+
head << "(RT from %s)" % tweet.retweeted_status.user.screen_name if tweet.retweet?
|
|
77
|
+
|
|
78
|
+
# Tweet tweet
|
|
79
|
+
body = !!tweet.retweet? ? tweet.retweeted_status.full_text : tweet.full_text
|
|
80
|
+
|
|
81
|
+
# Metadata
|
|
82
|
+
tail = []
|
|
83
|
+
tail << tweet.created_at.strftime("at %b %-d %Y, %-l:%M %p %Z")
|
|
84
|
+
tail << "from #{tweet.place.full_name}" if !!tweet.place
|
|
85
|
+
tail << "via #{tweet.source.gsub( %r{</?[^>]+?>}, '' )}"
|
|
86
|
+
|
|
87
|
+
# URLs for tweet and replied to:
|
|
88
|
+
urls = []
|
|
89
|
+
urls << "#{TWITTER_URL_BASE}#{tweet.user.screen_name}/status/#{tweet.id}"
|
|
90
|
+
urls << "in reply to #{format_reply_url(tweet.in_reply_to_screen_name, tweet.in_reply_to_status_id)}" if tweet.reply?
|
|
91
|
+
|
|
92
|
+
[Format(:bold, [*head, '»'] * ' '), body, ['(', tail * ' · ', ')'].join, urls * ' '].join(' ')
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def format_reply_url(username, id)
|
|
96
|
+
"#{TWITTER_URL_BASE}#{username}#{"/status/#{id}" if !!id}"
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
metadata
CHANGED
|
@@ -1,176 +1,125 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cinch-twitter
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
5
|
-
prerelease:
|
|
4
|
+
version: 1.0.0
|
|
6
5
|
platform: ruby
|
|
7
6
|
authors:
|
|
8
7
|
- Mark Seymour
|
|
9
8
|
autorequire:
|
|
10
9
|
bindir: bin
|
|
11
10
|
cert_chain: []
|
|
12
|
-
date:
|
|
11
|
+
date: 2013-06-18 00:00:00.000000000 Z
|
|
13
12
|
dependencies:
|
|
14
|
-
- !ruby/object:Gem::Dependency
|
|
15
|
-
name: activesupport
|
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
|
17
|
-
none: false
|
|
18
|
-
requirements:
|
|
19
|
-
- - ! '>='
|
|
20
|
-
- !ruby/object:Gem::Version
|
|
21
|
-
version: 3.0.0
|
|
22
|
-
type: :runtime
|
|
23
|
-
prerelease: false
|
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
-
none: false
|
|
26
|
-
requirements:
|
|
27
|
-
- - ! '>='
|
|
28
|
-
- !ruby/object:Gem::Version
|
|
29
|
-
version: 3.0.0
|
|
30
13
|
- !ruby/object:Gem::Dependency
|
|
31
14
|
name: twitter
|
|
32
15
|
requirement: !ruby/object:Gem::Requirement
|
|
33
|
-
none: false
|
|
34
16
|
requirements:
|
|
35
17
|
- - ~>
|
|
36
18
|
- !ruby/object:Gem::Version
|
|
37
|
-
version: '
|
|
19
|
+
version: '4.8'
|
|
38
20
|
type: :runtime
|
|
39
21
|
prerelease: false
|
|
40
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
41
|
-
none: false
|
|
42
23
|
requirements:
|
|
43
24
|
- - ~>
|
|
44
25
|
- !ruby/object:Gem::Version
|
|
45
|
-
version: '
|
|
26
|
+
version: '4.8'
|
|
46
27
|
- !ruby/object:Gem::Dependency
|
|
47
28
|
name: cinch
|
|
48
29
|
requirement: !ruby/object:Gem::Requirement
|
|
49
|
-
none: false
|
|
50
30
|
requirements:
|
|
51
31
|
- - ~>
|
|
52
32
|
- !ruby/object:Gem::Version
|
|
53
|
-
version: 2.0
|
|
33
|
+
version: '2.0'
|
|
54
34
|
type: :runtime
|
|
55
35
|
prerelease: false
|
|
56
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
57
|
-
none: false
|
|
58
37
|
requirements:
|
|
59
38
|
- - ~>
|
|
60
39
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: 2.0
|
|
40
|
+
version: '2.0'
|
|
62
41
|
- !ruby/object:Gem::Dependency
|
|
63
|
-
name:
|
|
42
|
+
name: oj
|
|
64
43
|
requirement: !ruby/object:Gem::Requirement
|
|
65
|
-
none: false
|
|
66
44
|
requirements:
|
|
67
45
|
- - ~>
|
|
68
46
|
- !ruby/object:Gem::Version
|
|
69
|
-
version:
|
|
70
|
-
type: :
|
|
47
|
+
version: 2.0.14
|
|
48
|
+
type: :runtime
|
|
71
49
|
prerelease: false
|
|
72
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
73
|
-
none: false
|
|
74
51
|
requirements:
|
|
75
52
|
- - ~>
|
|
76
53
|
- !ruby/object:Gem::Version
|
|
77
|
-
version:
|
|
54
|
+
version: 2.0.14
|
|
78
55
|
- !ruby/object:Gem::Dependency
|
|
79
|
-
name:
|
|
56
|
+
name: bundler
|
|
80
57
|
requirement: !ruby/object:Gem::Requirement
|
|
81
|
-
none: false
|
|
82
58
|
requirements:
|
|
83
59
|
- - ~>
|
|
84
60
|
- !ruby/object:Gem::Version
|
|
85
|
-
version: '3
|
|
61
|
+
version: '1.3'
|
|
86
62
|
type: :development
|
|
87
63
|
prerelease: false
|
|
88
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
89
|
-
none: false
|
|
90
65
|
requirements:
|
|
91
66
|
- - ~>
|
|
92
67
|
- !ruby/object:Gem::Version
|
|
93
|
-
version: '3
|
|
68
|
+
version: '1.3'
|
|
94
69
|
- !ruby/object:Gem::Dependency
|
|
95
|
-
name:
|
|
70
|
+
name: rake
|
|
96
71
|
requirement: !ruby/object:Gem::Requirement
|
|
97
|
-
none: false
|
|
98
72
|
requirements:
|
|
99
|
-
- -
|
|
73
|
+
- - '>='
|
|
100
74
|
- !ruby/object:Gem::Version
|
|
101
|
-
version:
|
|
75
|
+
version: '0'
|
|
102
76
|
type: :development
|
|
103
77
|
prerelease: false
|
|
104
78
|
version_requirements: !ruby/object:Gem::Requirement
|
|
105
|
-
none: false
|
|
106
79
|
requirements:
|
|
107
|
-
- -
|
|
80
|
+
- - '>='
|
|
108
81
|
- !ruby/object:Gem::Version
|
|
109
|
-
version:
|
|
110
|
-
- !ruby/object:Gem::Dependency
|
|
111
|
-
name: jeweler
|
|
112
|
-
requirement: !ruby/object:Gem::Requirement
|
|
113
|
-
none: false
|
|
114
|
-
requirements:
|
|
115
|
-
- - ~>
|
|
116
|
-
- !ruby/object:Gem::Version
|
|
117
|
-
version: 1.8.4
|
|
118
|
-
type: :development
|
|
119
|
-
prerelease: false
|
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
-
none: false
|
|
122
|
-
requirements:
|
|
123
|
-
- - ~>
|
|
124
|
-
- !ruby/object:Gem::Version
|
|
125
|
-
version: 1.8.4
|
|
82
|
+
version: '0'
|
|
126
83
|
description: A Twitter plugin for Cinch.
|
|
127
|
-
email:
|
|
84
|
+
email:
|
|
85
|
+
- mark.seymour.ns@gmail.com
|
|
128
86
|
executables: []
|
|
129
87
|
extensions: []
|
|
130
|
-
extra_rdoc_files:
|
|
131
|
-
- CHANGELOG.md
|
|
132
|
-
- LICENSE.txt
|
|
133
|
-
- README.md
|
|
88
|
+
extra_rdoc_files: []
|
|
134
89
|
files:
|
|
135
90
|
- .document
|
|
91
|
+
- .gitignore
|
|
136
92
|
- CHANGELOG.md
|
|
137
93
|
- Gemfile
|
|
138
|
-
- Gemfile.lock
|
|
139
94
|
- LICENSE.txt
|
|
140
95
|
- README.md
|
|
141
96
|
- Rakefile
|
|
142
|
-
- VERSION
|
|
143
97
|
- cinch-twitter.gemspec
|
|
144
98
|
- lib/cinch/plugins/twitter.rb
|
|
145
|
-
- lib/cinch/plugins/twitter/
|
|
146
|
-
|
|
147
|
-
- lib/cinch/plugins/twitter/tweet_handler.rb
|
|
148
|
-
homepage: http://github.com/mseymour/cinch-twitter
|
|
99
|
+
- lib/cinch/plugins/twitter/version.rb
|
|
100
|
+
homepage: https://github.com/mseymour/cinch-twitter
|
|
149
101
|
licenses:
|
|
150
102
|
- MIT
|
|
103
|
+
metadata: {}
|
|
151
104
|
post_install_message:
|
|
152
105
|
rdoc_options: []
|
|
153
106
|
require_paths:
|
|
154
107
|
- lib
|
|
155
108
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
156
|
-
none: false
|
|
157
109
|
requirements:
|
|
158
|
-
- -
|
|
110
|
+
- - '>='
|
|
159
111
|
- !ruby/object:Gem::Version
|
|
160
112
|
version: '0'
|
|
161
|
-
segments:
|
|
162
|
-
- 0
|
|
163
|
-
hash: 595335937
|
|
164
113
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
|
-
none: false
|
|
166
114
|
requirements:
|
|
167
|
-
- -
|
|
115
|
+
- - '>='
|
|
168
116
|
- !ruby/object:Gem::Version
|
|
169
117
|
version: '0'
|
|
170
118
|
requirements: []
|
|
171
119
|
rubyforge_project:
|
|
172
|
-
rubygems_version:
|
|
120
|
+
rubygems_version: 2.0.3
|
|
173
121
|
signing_key:
|
|
174
|
-
specification_version:
|
|
122
|
+
specification_version: 4
|
|
175
123
|
summary: A Cinch plugin for accessing Twitter.
|
|
176
124
|
test_files: []
|
|
125
|
+
has_rdoc:
|
data/Gemfile.lock
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
GEM
|
|
2
|
-
remote: http://rubygems.org/
|
|
3
|
-
specs:
|
|
4
|
-
activesupport (3.0.0)
|
|
5
|
-
cinch (2.0.3)
|
|
6
|
-
faraday (0.8.1)
|
|
7
|
-
multipart-post (~> 1.1)
|
|
8
|
-
git (1.2.5)
|
|
9
|
-
jeweler (1.8.4)
|
|
10
|
-
bundler (~> 1.0)
|
|
11
|
-
git (>= 1.2.5)
|
|
12
|
-
rake
|
|
13
|
-
rdoc
|
|
14
|
-
json (1.7.3)
|
|
15
|
-
multi_json (1.3.6)
|
|
16
|
-
multipart-post (1.1.5)
|
|
17
|
-
rake (0.9.2.2)
|
|
18
|
-
rdoc (3.12)
|
|
19
|
-
json (~> 1.4)
|
|
20
|
-
simple_oauth (0.1.8)
|
|
21
|
-
twitter (3.1.1)
|
|
22
|
-
faraday (~> 0.8)
|
|
23
|
-
multi_json (~> 1.3)
|
|
24
|
-
simple_oauth (~> 0.1.6)
|
|
25
|
-
yard (0.8.2.1)
|
|
26
|
-
|
|
27
|
-
PLATFORMS
|
|
28
|
-
x86-mingw32
|
|
29
|
-
|
|
30
|
-
DEPENDENCIES
|
|
31
|
-
activesupport (>= 3.0.0)
|
|
32
|
-
bundler (>= 1.0.0)
|
|
33
|
-
cinch (~> 2.0.3)
|
|
34
|
-
jeweler (~> 1.8.4)
|
|
35
|
-
rdoc (~> 3.12)
|
|
36
|
-
twitter (~> 3.0)
|
|
37
|
-
yard (~> 0.7)
|
data/VERSION
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
0.3.13
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
# coding: utf-8
|
|
2
|
-
|
|
3
|
-
module Cinch
|
|
4
|
-
module Plugins
|
|
5
|
-
class Twitter
|
|
6
|
-
module ErrorHandler
|
|
7
|
-
|
|
8
|
-
class Warnings < StandardError
|
|
9
|
-
class TooManyTweets < Warnings; end;
|
|
10
|
-
class NoTweets < Warnings; end;
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def handle_error(ex, username)
|
|
14
|
-
params = {
|
|
15
|
-
username: username
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
exceptions = {
|
|
19
|
-
::Twitter::Error::BadRequest => "Bad request!",
|
|
20
|
-
::Twitter::Error::Unauthorized => "%<username>s's account seems to be protected.",
|
|
21
|
-
::Twitter::Error::Forbidden => "Suspended!",
|
|
22
|
-
::Twitter::Error::NotFound => "The account \"%<username>s\" seems to be not found!",
|
|
23
|
-
::Twitter::Error::NotAcceptable => "An invalid format is specified in the search request.",
|
|
24
|
-
::Twitter::Error::EnhanceYourCalm => "Enhance your calm. I am being rate limited.",
|
|
25
|
-
::Twitter::Error::InternalServerError => "Something seems to be broken! Please try again in a minute.",
|
|
26
|
-
::Twitter::Error::BadGateway => "Twitter seems to be down, or is being upgraded. Please try again in a minute.",
|
|
27
|
-
::Twitter::Error::ServiceUnavailable => "Twitter is currently under heavy load. Please try again in a few minutes, and hopefully it'll clear up.",
|
|
28
|
-
Warnings::TooManyTweets => "You cannot backtrack past 20 tweets.",
|
|
29
|
-
Warnings::NoTweets => "%<username>s is lame for creating an account and not tweeting yet!"}
|
|
30
|
-
|
|
31
|
-
"Uhoh! · #{exceptions[ex.class]} (#{ex.message})" % params;
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
# coding: utf-8
|
|
2
|
-
require 'cgi'
|
|
3
|
-
require 'cinch/formatting'
|
|
4
|
-
|
|
5
|
-
module Cinch
|
|
6
|
-
module Plugins
|
|
7
|
-
class Twitter
|
|
8
|
-
module Formatter
|
|
9
|
-
|
|
10
|
-
def format_tweet(tweet)
|
|
11
|
-
tweet_text = expand_uris(tweet.full_text, tweet.urls)
|
|
12
|
-
parts, head, body, tail, urls = [], [], [], [], []
|
|
13
|
-
head = Cinch::Formatting.format(:bold,"#{tweet.user.screen_name} »")
|
|
14
|
-
body << CGI::unescapeHTML(tweet_text.gsub("\n", " ").squeeze(" "))
|
|
15
|
-
body << Cinch::Formatting.format(:aqua,"*twoosh*") if tweet.full_text.length == 140
|
|
16
|
-
tail << "From #{tweet.place.full_name}" if !tweet.place.blank?
|
|
17
|
-
tail << "at #{tweet.created_at.strftime("%B %-d, %Y, %-I:%M%P")}"
|
|
18
|
-
tail << "via #{tweet.source.gsub( %r{</?[^>]+?>}, '' )}"
|
|
19
|
-
urls << "https://twitter.com/#{tweet.user.screen_name}"
|
|
20
|
-
urls << Cinch::Formatting.format(:grey,"in reply to") if !tweet.in_reply_to_screen_name.blank?
|
|
21
|
-
urls << "https://twitter.com/#{tweet.in_reply_to_screen_name}#{"/statuses/#{tweet.in_reply_to_status_id.to_s}" if !tweet.in_reply_to_status_id.blank?}" if !tweet.in_reply_to_screen_name.blank?
|
|
22
|
-
parts = [head, body, ["(", tail.join(" "), ")"].join, urls].flatten
|
|
23
|
-
parts.join(" ")
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def format_search(tweet)
|
|
27
|
-
tweet_text = expand_uris(tweet.full_text, tweet.urls)
|
|
28
|
-
parts, head, body, tail, urls = [], [], [], [], []
|
|
29
|
-
head = Cinch::Formatting.format(:bold,"#{tweet.from_user} »")
|
|
30
|
-
body << CGI::unescapeHTML(tweet_text.gsub("\n", " ").squeeze(" "))
|
|
31
|
-
body << Cinch::Formatting.format(:aqua,"*twoosh*") if tweet.full_text.length == 140
|
|
32
|
-
tail << "at #{tweet.created_at.strftime("%B %-d, %Y, %-I:%M%P")}"
|
|
33
|
-
urls << "https://twitter.com/#{tweet.from_user}"
|
|
34
|
-
parts = [head, body, ["(", tail.join(" "), ")"].join, urls].flatten
|
|
35
|
-
parts.join(" ")
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def format_tweep_info(tweep)
|
|
39
|
-
head = "#{Cinch::Formatting.format(:aqua,tweep.name)}" + Cinch::Formatting.format(:silver," (#{tweep.screen_name})") + Cinch::Formatting.format(:grey," - #{tweep.url ? "#{tweep.url} " : ''}https://twitter.com/#{tweep.screen_name}")
|
|
40
|
-
bio = ""
|
|
41
|
-
bio = Cinch::Formatting.format(:aqua,"\"#{tweep.description.strip}\"") if !tweep.description.blank?
|
|
42
|
-
location = ""
|
|
43
|
-
location = "They are from #{Cinch::Formatting.format(:aqua,tweep.location.strip)}" if !tweep.location.blank?
|
|
44
|
-
desc = [] << "has made #{tweep.statuses_count} tweets since #{tweep.created_at.strftime("%B %-d, %Y")}"
|
|
45
|
-
desc << "follows #{tweep.friends_count} tweeps" if tweep.friends_count > 0
|
|
46
|
-
desc << "has #{tweep.followers_count} followers" if tweep.followers_count > 0
|
|
47
|
-
desc << "has favourited #{tweep.favourites_count} tweets" if tweep.favourites_count > 0
|
|
48
|
-
desc << "is also in #{tweep.listed_count} lists" if tweep.listed_count > 0
|
|
49
|
-
flags = []
|
|
50
|
-
flags << "is actually a group-run account" if tweep.contributors_enabled?
|
|
51
|
-
flags << "is a translator for Twitter" if tweep.is_translator?
|
|
52
|
-
flags << "is verified" if tweep.verified?
|
|
53
|
-
flags << "would rather keep their life secret" if tweep.protected?
|
|
54
|
-
tweet = []
|
|
55
|
-
tweet_tail = []
|
|
56
|
-
if tweep.status
|
|
57
|
-
tweep_status_text = expand_uris(tweep.status.full_text, tweep.status.urls)
|
|
58
|
-
tweet << Cinch::Formatting.format(:aqua,"Their latest tweet:")
|
|
59
|
-
tweet << CGI::unescapeHTML(tweep_status_text.gsub("\n", " ").squeeze(" "))
|
|
60
|
-
tweet_tail << "from #{tweep.status.place.full_name}" if !tweep.status.place.blank?
|
|
61
|
-
tweet_tail << "at #{tweep.status.created_at.strftime("%B %-d, %Y, %-I:%M%P")}"
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
parts = [head, bio, location, desc, flags].reject(&:blank?).map {|e| e.is_a?(Array) ? "#{tweep.name} " + e.to_sentence + "." : e }
|
|
65
|
-
parts << [tweet, Cinch::Formatting.format(:silver,["(", tweet_tail.join(" "), ")"].join)].join(" ") if tweep.status
|
|
66
|
-
parts.join("\n")
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
private
|
|
70
|
-
|
|
71
|
-
def expand_uris t, uris
|
|
72
|
-
uris.each_with_object(t) {|entity,tweet| tweet.gsub!(entity.url, entity.expanded_url) }
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
end
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
# coding: utf-8
|
|
2
|
-
require 'cinch/plugins/twitter/formatter'
|
|
3
|
-
require 'cinch/plugins/twitter/error_handler'
|
|
4
|
-
|
|
5
|
-
module Cinch
|
|
6
|
-
module Plugins
|
|
7
|
-
class Twitter
|
|
8
|
-
module TweetHandler
|
|
9
|
-
# Handler methods
|
|
10
|
-
class << self
|
|
11
|
-
include Formatter
|
|
12
|
-
include ErrorHandler
|
|
13
|
-
|
|
14
|
-
EXCEPTIONS = [::Twitter::Error, ErrorHandler::Warnings]
|
|
15
|
-
AMessage = Struct.new(:message,:type)
|
|
16
|
-
|
|
17
|
-
def tweet_by_username(params={})
|
|
18
|
-
params = { username: "Twitter", nth_tweet: 0 }.merge(params)
|
|
19
|
-
begin
|
|
20
|
-
raise Warnings::TooManyTweets if params[:nth_tweet].to_i > 20
|
|
21
|
-
timeline = ::Twitter.user_timeline params[:username], include_entities: true, include_rts: true, count: params[:nth_tweet].to_i.succ
|
|
22
|
-
raise Warnings::NoTweets if timeline.blank?
|
|
23
|
-
tweet = timeline.last
|
|
24
|
-
params[:username] = tweet.user.screen_name if !tweet.user.nil? # For proper case.
|
|
25
|
-
|
|
26
|
-
return "No tweets!" if timeline.blank?
|
|
27
|
-
return "Protected!" if tweet.user.protected?
|
|
28
|
-
|
|
29
|
-
AMessage.new format_tweet(tweet) # The fun starts here. If there is ever a problem, it'll bubble up here and be caught.
|
|
30
|
-
|
|
31
|
-
rescue *EXCEPTIONS => ex
|
|
32
|
-
AMessage.new handle_error(ex, params[:username]), :notice
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def tweet_by_id(params={})
|
|
37
|
-
params = {id: 0 }.merge(params)
|
|
38
|
-
begin
|
|
39
|
-
tweet = ::Twitter.status params[:id], include_entities: true
|
|
40
|
-
params[:username] = tweet.user.screen_name if !tweet.user.nil? # For easy access.
|
|
41
|
-
AMessage.new format_tweet(tweet) # If there is ever a problem, it'll bubble up here and be caught.
|
|
42
|
-
rescue *EXCEPTIONS => ex
|
|
43
|
-
AMessage.new handle_error(ex, params[:username]), :notice
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def tweep_info(params={})
|
|
48
|
-
params = {username: "Twitter"}.merge(params)
|
|
49
|
-
begin
|
|
50
|
-
tweep = ::Twitter.user params[:username], include_entities: true
|
|
51
|
-
AMessage.new format_tweep_info(tweep)
|
|
52
|
-
rescue *EXCEPTIONS => ex
|
|
53
|
-
AMessage.new handle_error(ex, params[:username]), :notice
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def search_by_term(params={})
|
|
58
|
-
params = {term: "cat"}.merge(params)
|
|
59
|
-
begin
|
|
60
|
-
results = []
|
|
61
|
-
::Twitter.search(params[:term], include_entities: true, rpp: 3, result_type: "recent").results.each {|status|
|
|
62
|
-
params[:username] = status.from_user
|
|
63
|
-
results << format_search(status)
|
|
64
|
-
}
|
|
65
|
-
results << "There are no results for \"#{params[:term]}\"." if results.empty?
|
|
66
|
-
AMessage.new results.join("\n")
|
|
67
|
-
rescue *EXCEPTIONS => ex
|
|
68
|
-
AMessage.new handle_error(ex, params[:username]), :notice
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
end
|