cinch-twitter 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +18 -0
- data/Gemfile.lock +40 -0
- data/LICENSE.txt +20 -0
- data/README.md +60 -0
- data/Rakefile +47 -0
- data/VERSION +1 -0
- data/cinch-twitter.gemspec +69 -0
- data/lib/cinch/plugins/twitter.rb +86 -0
- data/lib/cinch/plugins/twitter/error_handler.rb +37 -0
- data/lib/cinch/plugins/twitter/formatter.rb +79 -0
- data/lib/cinch/plugins/twitter/tweet_handler.rb +75 -0
- metadata +174 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
gem 'activesupport', '>= 3.0.0'
|
6
|
+
gem 'twitter', '>= 2.5.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
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (3.2.6)
|
5
|
+
i18n (~> 0.6)
|
6
|
+
multi_json (~> 1.0)
|
7
|
+
cinch (2.0.3)
|
8
|
+
faraday (0.8.1)
|
9
|
+
multipart-post (~> 1.1)
|
10
|
+
git (1.2.5)
|
11
|
+
i18n (0.6.0)
|
12
|
+
jeweler (1.8.4)
|
13
|
+
bundler (~> 1.0)
|
14
|
+
git (>= 1.2.5)
|
15
|
+
rake
|
16
|
+
rdoc
|
17
|
+
json (1.7.3)
|
18
|
+
multi_json (1.3.6)
|
19
|
+
multipart-post (1.1.5)
|
20
|
+
rake (0.9.2.2)
|
21
|
+
rdoc (3.12)
|
22
|
+
json (~> 1.4)
|
23
|
+
simple_oauth (0.1.8)
|
24
|
+
twitter (2.5.0)
|
25
|
+
faraday (~> 0.8)
|
26
|
+
multi_json (~> 1.3)
|
27
|
+
simple_oauth (~> 0.1.6)
|
28
|
+
yard (0.8.2.1)
|
29
|
+
|
30
|
+
PLATFORMS
|
31
|
+
x86-mingw32
|
32
|
+
|
33
|
+
DEPENDENCIES
|
34
|
+
activesupport (>= 3.0.0)
|
35
|
+
bundler (>= 1.0.0)
|
36
|
+
cinch (>= 2.0.3)
|
37
|
+
jeweler (~> 1.8.4)
|
38
|
+
rdoc (~> 3.12)
|
39
|
+
twitter (>= 2.5.0)
|
40
|
+
yard (~> 0.7)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Mark Seymour
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
cinch-twitter
|
2
|
+
=============
|
3
|
+
|
4
|
+
A Cinch plugin for accessing Twitter, using [John Nunemaker's](https://github.com/jnunemaker) wonderful [Twitter gem](https://github.com/jnunemaker/twitter).
|
5
|
+
|
6
|
+
Requiring the gem: `require 'cinch/plugins/twitter'`
|
7
|
+
|
8
|
+
Usage
|
9
|
+
-----
|
10
|
+
|
11
|
+
* `!tw <username><+D>` - Gets the latest tweet of the specified user, or the tweet 'D' tweets back, between 1 and 20.
|
12
|
+
* `!tw #[id]` - Gets the tweet at the specified ID
|
13
|
+
* `?tw [username]` - Gets the specified user's Twitter profile
|
14
|
+
* `?ts [term]` - Searches for three of the most recent tweets regarding the specified query
|
15
|
+
|
16
|
+
Shorthand commands are also available:
|
17
|
+
* `@[username]<+D>`, @#[id]
|
18
|
+
|
19
|
+
Loading
|
20
|
+
-------
|
21
|
+
|
22
|
+
This should be obvious, right? Not so.
|
23
|
+
|
24
|
+
`c.plugins.plugins << Cinch::Plugins::Twitter::Client`
|
25
|
+
|
26
|
+
Configuration
|
27
|
+
-------------
|
28
|
+
|
29
|
+
To configure the plugin, you must insert your access keys for the client. If you wish, you may use `JSON` or `YAML` to store and deserialize them.
|
30
|
+
|
31
|
+
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.
|
32
|
+
|
33
|
+
Example:
|
34
|
+
|
35
|
+
c.plugins.options[Cinch::Plugins::Twitter::Client] = {
|
36
|
+
access_keys: {
|
37
|
+
consumer_key: "XXXXXXX",
|
38
|
+
consumer_secret: "XXXXXXX",
|
39
|
+
oauth_token: "XXXXXXX",
|
40
|
+
oauth_token_secret: "XXXXXXX"
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
Contributing to cinch-twitter
|
45
|
+
-----------------------------
|
46
|
+
|
47
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
48
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
49
|
+
* Fork the project.
|
50
|
+
* Start a feature/bugfix branch.
|
51
|
+
* Commit and push until you are happy with your contribution.
|
52
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
53
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
54
|
+
|
55
|
+
Copyright
|
56
|
+
---------
|
57
|
+
|
58
|
+
Copyright (c) 2012 Mark Seymour. See LICENSE.txt for
|
59
|
+
further details.
|
60
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# encoding: utf-8
|
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
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "cinch-twitter"
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Mark Seymour"]
|
12
|
+
s.date = "2012-06-27"
|
13
|
+
s.description = "A Twitter plugin for Cinch."
|
14
|
+
s.email = "mark.seymour.ns@gmail.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
23
|
+
"LICENSE.txt",
|
24
|
+
"README.md",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"cinch-twitter.gemspec",
|
28
|
+
"lib/cinch/plugins/twitter.rb",
|
29
|
+
"lib/cinch/plugins/twitter/error_handler.rb",
|
30
|
+
"lib/cinch/plugins/twitter/formatter.rb",
|
31
|
+
"lib/cinch/plugins/twitter/tweet_handler.rb"
|
32
|
+
]
|
33
|
+
s.homepage = "http://github.com/mseymour/cinch-twitter"
|
34
|
+
s.licenses = ["MIT"]
|
35
|
+
s.require_paths = ["lib"]
|
36
|
+
s.rubygems_version = "1.8.24"
|
37
|
+
s.summary = "A Cinch plugin for accessing Twitter."
|
38
|
+
|
39
|
+
if s.respond_to? :specification_version then
|
40
|
+
s.specification_version = 3
|
41
|
+
|
42
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
43
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 3.0.0"])
|
44
|
+
s.add_runtime_dependency(%q<twitter>, [">= 2.5.0"])
|
45
|
+
s.add_runtime_dependency(%q<cinch>, [">= 2.0.3"])
|
46
|
+
s.add_development_dependency(%q<yard>, ["~> 0.7"])
|
47
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
48
|
+
s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
|
49
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
50
|
+
else
|
51
|
+
s.add_dependency(%q<activesupport>, [">= 3.0.0"])
|
52
|
+
s.add_dependency(%q<twitter>, [">= 2.5.0"])
|
53
|
+
s.add_dependency(%q<cinch>, [">= 2.0.3"])
|
54
|
+
s.add_dependency(%q<yard>, ["~> 0.7"])
|
55
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
56
|
+
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
57
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
58
|
+
end
|
59
|
+
else
|
60
|
+
s.add_dependency(%q<activesupport>, [">= 3.0.0"])
|
61
|
+
s.add_dependency(%q<twitter>, [">= 2.5.0"])
|
62
|
+
s.add_dependency(%q<cinch>, [">= 2.0.3"])
|
63
|
+
s.add_dependency(%q<yard>, ["~> 0.7"])
|
64
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
65
|
+
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
66
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'twitter'
|
4
|
+
require 'active_support/core_ext/object/blank'
|
5
|
+
require 'active_support/core_ext/array/conversions'
|
6
|
+
require 'cinch/plugins/twitter/tweet_handler'
|
7
|
+
|
8
|
+
module Cinch
|
9
|
+
module Plugins
|
10
|
+
module Twitter
|
11
|
+
|
12
|
+
class Client
|
13
|
+
include Cinch::Plugin
|
14
|
+
include Twitter::TweetHandler
|
15
|
+
|
16
|
+
set(
|
17
|
+
plugin_name: "Twitter",
|
18
|
+
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]",
|
19
|
+
required_options: [:access_keys])
|
20
|
+
|
21
|
+
def initialize(*args)
|
22
|
+
super
|
23
|
+
keys = config[:access_keys]
|
24
|
+
::Twitter.configure do |c|
|
25
|
+
c.consumer_key = keys["consumer_key"]
|
26
|
+
c.consumer_secret = keys["consumer_secret"]
|
27
|
+
c.oauth_token = keys["oauth_token"]
|
28
|
+
c.oauth_token_secret = keys["oauth_token_secret"]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def is_notice?(m)
|
33
|
+
m.type == :notice ? true : false
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
match /tw$/, method: :execute_tweet
|
38
|
+
match /tw (\w+)(?:-(\d+))?$/, method: :execute_tweet
|
39
|
+
match /^@(\w+)(?:-(\d+))?$/, method: :execute_tweet, use_prefix: false
|
40
|
+
def execute_tweet(m, username = nil, nth_tweet = nil)
|
41
|
+
options = {}
|
42
|
+
options[:username] = username unless username.nil?
|
43
|
+
options[:nth_tweet] = nth_tweet unless nth_tweet.nil?
|
44
|
+
result = tweet_by_username(options)
|
45
|
+
if is_notice?(result)
|
46
|
+
m.user.notice result.message
|
47
|
+
else
|
48
|
+
m.reply result.message
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
match /tw #(\d+)$/, method: :execute_id
|
53
|
+
match /^@#(\d+)$/, method: :execute_id, use_prefix: false
|
54
|
+
def execute_id(m, id)
|
55
|
+
result = tweet_by_id(id: id)
|
56
|
+
if is_notice?(result)
|
57
|
+
m.user.notice result.message
|
58
|
+
else
|
59
|
+
m.reply result.message
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
match /\?tw (\w+)$/, method: :execute_info, use_prefix: false
|
64
|
+
def execute_info(m, username)
|
65
|
+
result = tweep_info(username: username)
|
66
|
+
if is_notice?(result)
|
67
|
+
m.user.notice result.message
|
68
|
+
else
|
69
|
+
m.reply result.message
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
match /\?ts (.+)$/, method: :execute_search, use_prefix: false
|
74
|
+
def execute_search(m, term)
|
75
|
+
result = search_by_term(term: term)
|
76
|
+
if is_notice?(result)
|
77
|
+
m.user.notice result.message
|
78
|
+
else
|
79
|
+
m.reply result.message
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Cinch
|
4
|
+
module Plugins
|
5
|
+
module 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, bot_nick)
|
14
|
+
params = {
|
15
|
+
username: username,
|
16
|
+
bot_nick: bot_nick
|
17
|
+
}
|
18
|
+
|
19
|
+
exceptions = {
|
20
|
+
::Twitter::Error::BadRequest => "Bad request!",
|
21
|
+
::Twitter::Error::Unauthorized => "%<username>s's account seems to be protected.",
|
22
|
+
::Twitter::Error::Forbidden => "Suspended!",
|
23
|
+
::Twitter::Error::NotFound => "The account \"%<username>s\" seems to be not found!",
|
24
|
+
::Twitter::Error::NotAcceptable => "An invalid format is specified in the search request.",
|
25
|
+
::Twitter::Error::EnhanceYourCalm => "Enhance your calm. %<bot_nick>s is being rate limited.",
|
26
|
+
::Twitter::Error::InternalServerError => "Something seems to be broken! Please try again in a minute.",
|
27
|
+
::Twitter::Error::BadGateway => "Twitter seems to be down, or is being upgraded. Please try again in a minute.",
|
28
|
+
::Twitter::Error::ServiceUnavailable => "Twitter is currently under heavy load. Please try again in a few minutes, and hopefully it'll clear up.",
|
29
|
+
Warnings::TooManyTweets => "You cannot backtrack past 20 tweets.",
|
30
|
+
Warnings::NoTweets => "%<username>s is lame for creating an account and not tweeting yet!"}
|
31
|
+
|
32
|
+
"#{Format(:red,:bold,"Uhoh!")} · #{exceptions[ex.class]}" % params;
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'cgi'
|
3
|
+
|
4
|
+
module Cinch
|
5
|
+
module Plugins
|
6
|
+
module Twitter
|
7
|
+
module Formatter
|
8
|
+
|
9
|
+
def format_tweet(tweet)
|
10
|
+
tweet_text = expand_uris(tweet.text, tweet.attrs["entities"]["urls"])
|
11
|
+
parts, head, body, tail, urls = [], [], [], [], []
|
12
|
+
head = Format(:bold,"#{tweet.user.screen_name} »")
|
13
|
+
body << CGI::unescapeHTML(tweet_text.gsub("\n", " ").squeeze(" "))
|
14
|
+
body << Format(:aqua,"*twoosh*") if tweet.text.length == 140
|
15
|
+
tail << "From #{tweet.place.full_name}" if !tweet.place.blank?
|
16
|
+
tail << "at #{tweet.created_at.strftime("%B %-d, %Y, %-I:%m%P")}"
|
17
|
+
tail << "via #{tweet.source.gsub( %r{</?[^>]+?>}, '' )}"
|
18
|
+
urls << "https://twitter.com/#{tweet.user.screen_name}"
|
19
|
+
urls << Format(:grey,"in reply to") if !tweet.in_reply_to_screen_name.blank?
|
20
|
+
urls << "http://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?
|
21
|
+
parts = [head, body, ["(", tail.join(" "), ")"].join, urls].flatten
|
22
|
+
parts.join(" ")
|
23
|
+
end
|
24
|
+
|
25
|
+
def format_search(tweet)
|
26
|
+
tweet_text = expand_uris(tweet.text, tweet.attrs["entities"]["urls"])
|
27
|
+
parts, head, body, tail, urls = [], [], [], [], []
|
28
|
+
head = Format(:bold,"#{tweet.from_user} »")
|
29
|
+
body << CGI::unescapeHTML(tweet_text.gsub("\n", " ").squeeze(" "))
|
30
|
+
body << Format(:aqua,"*twoosh*") if tweet.text.length == 140
|
31
|
+
tail << "at #{tweet.created_at.strftime("%B %-d, %Y, %-I:%m%P")}"
|
32
|
+
urls << "https://twitter.com/#{tweet.from_user}"
|
33
|
+
parts = [head, body, ["(", tail.join(" "), ")"].join, urls].flatten
|
34
|
+
parts.join(" ")
|
35
|
+
end
|
36
|
+
|
37
|
+
def format_tweep_info(tweep)
|
38
|
+
tweep_status_text = expand_uris(tweep.status.text, tweep.status.attrs["entities"]["urls"])
|
39
|
+
head = "#{Format(:aqua,tweep.name)}" + Format(:silver," (#{tweep.screen_name})") + Format(:grey," - #{tweep.url} https://twitter.com/#{tweep.screen_name}")
|
40
|
+
bio = ""
|
41
|
+
bio = Format(:aqua,"\"#{tweep.description.strip}\"") if !tweep.description.blank?
|
42
|
+
location = ""
|
43
|
+
location = "They are from #{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 = [] << Format(:aqua,"Their latest tweet:")
|
55
|
+
tweet << CGI::unescapeHTML(tweep_status_text.gsub("\n", " ").squeeze(" "))
|
56
|
+
tweet_tail = []
|
57
|
+
tweet_tail << "from #{tweep.status.place.full_name}" if !tweep.status.place.blank?
|
58
|
+
tweet_tail << "at #{tweep.status.created_at.strftime("%B %-d, %Y, %-I:%m%P")}"
|
59
|
+
|
60
|
+
parts = [head, bio, location, desc, flags].reject(&:blank?).map {|e| e.is_a?(Array) ? "#{tweep.name} " + e.to_sentence + "." : e }
|
61
|
+
parts << [tweet, Format(:silver,["(", tweet_tail.join(" "), ")"].join)].join(" ")
|
62
|
+
parts.join("\n")
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def expand_uris t, uris
|
68
|
+
tweet = t.dup
|
69
|
+
uris.each {|u|
|
70
|
+
expanded_url, url = u["expanded_url"], u["url"]
|
71
|
+
tweet.gsub! url, expanded_url
|
72
|
+
}
|
73
|
+
return tweet
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,75 @@
|
|
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
|
+
module Twitter
|
8
|
+
module TweetHandler
|
9
|
+
include Formatter
|
10
|
+
include ErrorHandler
|
11
|
+
|
12
|
+
EXCEPTIONS = [::Twitter::Error, ErrorHandler::Warnings]
|
13
|
+
AMessage = Struct.new(:message,:type)
|
14
|
+
|
15
|
+
# Handler methods
|
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], @bot.nick), :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], @bot.nick), :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], @bot.nick), :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").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], @bot.nick), :notice
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
metadata
ADDED
@@ -0,0 +1,174 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cinch-twitter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Mark Seymour
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-27 00:00:00.000000000 Z
|
13
|
+
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
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: twitter
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.5.0
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.5.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: cinch
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.0.3
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.0.3
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: yard
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0.7'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0.7'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rdoc
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '3.12'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '3.12'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: bundler
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 1.0.0
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 1.0.0
|
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
|
126
|
+
description: A Twitter plugin for Cinch.
|
127
|
+
email: mark.seymour.ns@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files:
|
131
|
+
- LICENSE.txt
|
132
|
+
- README.md
|
133
|
+
files:
|
134
|
+
- .document
|
135
|
+
- Gemfile
|
136
|
+
- Gemfile.lock
|
137
|
+
- LICENSE.txt
|
138
|
+
- README.md
|
139
|
+
- Rakefile
|
140
|
+
- VERSION
|
141
|
+
- cinch-twitter.gemspec
|
142
|
+
- lib/cinch/plugins/twitter.rb
|
143
|
+
- lib/cinch/plugins/twitter/error_handler.rb
|
144
|
+
- lib/cinch/plugins/twitter/formatter.rb
|
145
|
+
- lib/cinch/plugins/twitter/tweet_handler.rb
|
146
|
+
homepage: http://github.com/mseymour/cinch-twitter
|
147
|
+
licenses:
|
148
|
+
- MIT
|
149
|
+
post_install_message:
|
150
|
+
rdoc_options: []
|
151
|
+
require_paths:
|
152
|
+
- lib
|
153
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
154
|
+
none: false
|
155
|
+
requirements:
|
156
|
+
- - ! '>='
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
159
|
+
segments:
|
160
|
+
- 0
|
161
|
+
hash: -858696623
|
162
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
163
|
+
none: false
|
164
|
+
requirements:
|
165
|
+
- - ! '>='
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: '0'
|
168
|
+
requirements: []
|
169
|
+
rubyforge_project:
|
170
|
+
rubygems_version: 1.8.24
|
171
|
+
signing_key:
|
172
|
+
specification_version: 3
|
173
|
+
summary: A Cinch plugin for accessing Twitter.
|
174
|
+
test_files: []
|