termtter 1.7.2 → 1.8.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.
- data/.gitignore +1 -1
- data/README.rdoc +1 -0
- data/Rakefile +2 -1
- data/VERSION +1 -1
- data/bin/termtter +1 -0
- data/bin/termtter_frame +134 -0
- data/lib/plugins/aa.rb +44 -0
- data/lib/plugins/another_prompt.rb +42 -41
- data/lib/plugins/appendtitle.rb +82 -0
- data/lib/plugins/ar.rb +11 -8
- data/lib/plugins/async.rb +3 -2
- data/lib/plugins/capital_update.rb +12 -0
- data/lib/plugins/channel.rb +149 -0
- data/lib/plugins/clock.rb +10 -0
- data/lib/plugins/defaults/command_line.rb +8 -0
- data/lib/plugins/defaults/confirm.rb +1 -1
- data/lib/plugins/defaults/hashtag.rb +1 -1
- data/lib/plugins/defaults/keyword.rb +11 -0
- data/lib/plugins/defaults/list.rb +32 -6
- data/lib/plugins/defaults/standard_commands.rb +135 -52
- data/lib/plugins/defaults/standard_completion.rb +14 -0
- data/lib/plugins/defaults/stdout.rb +59 -27
- data/lib/plugins/defaults/user.rb +32 -0
- data/lib/plugins/draft.rb +9 -12
- data/lib/plugins/easy_post.rb +5 -0
- data/lib/plugins/event_invoked_at.rb +23 -0
- data/lib/plugins/expand-tinyurl.rb +13 -20
- data/lib/plugins/favotter.rb +9 -9
- data/lib/plugins/footer.rb +9 -12
- data/lib/plugins/friends.rb +0 -26
- data/lib/plugins/grass.rb +2 -4
- data/lib/plugins/growl.rb +47 -0
- data/lib/plugins/gyazo.rb +16 -18
- data/lib/plugins/hi.rb +31 -10
- data/lib/plugins/http_server.rb +3 -2
- data/lib/plugins/irc_gw.rb +71 -17
- data/lib/plugins/line.rb +10 -0
- data/lib/plugins/linefeed.rb +6 -1
- data/lib/plugins/list_switch.rb +76 -0
- data/lib/plugins/nop.rb +9 -0
- data/lib/plugins/notify-send.rb +1 -1
- data/lib/plugins/notify-send2.rb +25 -16
- data/lib/plugins/notify-send3.rb +16 -13
- data/lib/plugins/nuance.rb +29 -0
- data/lib/plugins/open_url.rb +1 -5
- data/lib/plugins/random.rb +2 -6
- data/lib/plugins/reply_sound.rb +33 -0
- data/lib/plugins/say.rb +2 -2
- data/lib/plugins/storage/sqlite3.rb +1 -1
- data/lib/plugins/story.rb +44 -0
- data/lib/plugins/tinyurl.rb +50 -29
- data/lib/plugins/translate_tweet.rb +38 -0
- data/lib/plugins/web.rb +27 -0
- data/lib/termtter.rb +8 -4
- data/lib/termtter/client.rb +17 -21
- data/lib/termtter/command.rb +35 -13
- data/lib/termtter/config.rb +13 -0
- data/lib/termtter/config_template.erb +3 -2
- data/lib/termtter/default_config.rb +2 -2
- data/lib/termtter/event.rb +69 -0
- data/lib/termtter/hook.rb +6 -1
- data/lib/termtter/hookable.rb +9 -1
- data/lib/termtter/httppool.rb +17 -9
- data/lib/termtter/optparse.rb +11 -1
- data/lib/termtter/rubytter_proxy.rb +21 -5
- data/spec/plugins/capital_update_spec.rb +9 -0
- data/spec/plugins/fib_spec.rb +2 -4
- data/spec/plugins/hi_spec.rb +9 -0
- data/spec/plugins/tinyurl_spec.rb +78 -0
- data/spec/termtter/client_spec.rb +5 -12
- data/spec/termtter/command_spec.rb +22 -10
- data/spec/termtter/config_spec.rb +23 -0
- data/spec/termtter/event_spec.rb +129 -0
- data/spec/termtter/optparse_spec.rb +2 -2
- data/spec/termtter/rubytter_proxy_spec.rb +1 -1
- metadata +39 -8
- data/bin/kill_termtter +0 -22
- data/lib/plugins/defaults/users.rb +0 -63
- data/lib/plugins/pause.rb +0 -3
- data/test/friends_timeline.json +0 -5
- data/test/search.json +0 -8
data/lib/plugins/nop.rb
ADDED
data/lib/plugins/notify-send.rb
CHANGED
@@ -15,7 +15,7 @@ Termtter::Client.register_hook(
|
|
15
15
|
|
16
16
|
text << %Q|\n<a href="http://twitter.com/">more...</a>| if statuses.size > max
|
17
17
|
|
18
|
-
|
18
|
+
Termtter::Client.notify 'timeline', text unless text.empty?
|
19
19
|
end
|
20
20
|
}
|
21
21
|
)
|
data/lib/plugins/notify-send2.rb
CHANGED
@@ -1,33 +1,41 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
-
|
3
2
|
require 'fileutils'
|
3
|
+
config.plugins.notify_send.set_default(
|
4
|
+
:icon_cache_dir, "#{Termtter::CONF_DIR}/tmp/user_profile_images")
|
4
5
|
|
5
|
-
config.plugins.notify_send.
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
FileUtils.mkdir_p(config.plugins.notify_send.icon_cache_dir) unless
|
7
|
+
File.exist?(config.plugins.notify_send.icon_cache_dir)
|
8
|
+
Dir.glob("#{config.plugins.notify_send.icon_cache_dir}/*") {|f|
|
9
|
+
File.delete(f) unless File.size?(f) }
|
9
10
|
unless File.exist?("#{config.plugins.notify_send.icon_cache_dir}/default.png")
|
10
|
-
File.open(
|
11
|
-
|
11
|
+
File.open(
|
12
|
+
"#{config.plugins.notify_send.icon_cache_dir}/default.png", "wb") do |f|
|
13
|
+
f << open(
|
14
|
+
"http://static.twitter.com/images/default_profile_normal.png").read
|
12
15
|
end
|
13
16
|
end
|
14
17
|
|
15
18
|
def get_icon_path(s)
|
16
19
|
/https?:\/\/.+\/(\d+)\/.*?$/ =~ s.user.profile_image_url
|
17
|
-
cache_file = "%s/%s-%s%s" % [
|
18
|
-
|
19
|
-
|
20
|
-
|
20
|
+
cache_file = "%s/%s-%s%s" % [
|
21
|
+
config.plugins.notify_send.icon_cache_dir,
|
22
|
+
s.user.screen_name,
|
23
|
+
$+,
|
24
|
+
File.extname(s.user.profile_image_url)]
|
21
25
|
unless File.exist?(cache_file)
|
22
26
|
Thread.new(s,cache_file) do |s,cache_file|
|
23
|
-
Dir.glob(
|
27
|
+
Dir.glob(
|
28
|
+
"#{config.plugins.notify_send.icon_cache_dir}/#{s.user.screen_name}-*") {|f|
|
29
|
+
File.delete(f)
|
30
|
+
}
|
24
31
|
begin
|
25
32
|
s.user.profile_image_url.sub!(/^https/,'http')
|
26
33
|
File.open(cache_file, 'wb') do |f|
|
27
34
|
f << open(URI.escape(s.user.profile_image_url)).read
|
28
35
|
end
|
29
36
|
rescue OpenURI::HTTPError
|
30
|
-
cache_file =
|
37
|
+
cache_file =
|
38
|
+
"#{config.plugins.notify_send.icon_cache_dir}/default.png"
|
31
39
|
end
|
32
40
|
end
|
33
41
|
end
|
@@ -42,11 +50,12 @@ Termtter::Client.register_hook(
|
|
42
50
|
Thread.start do
|
43
51
|
statuses.each do |s|
|
44
52
|
text = CGI.escapeHTML(s.text)
|
45
|
-
text.gsub!(
|
46
|
-
|
53
|
+
text.gsub!(
|
54
|
+
%r{https?://[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+},
|
55
|
+
'<a href="\0">\0</a>')
|
56
|
+
Termtter::Client.notify(s.user.screen_name, text)
|
47
57
|
sleep 0.1
|
48
58
|
end
|
49
59
|
end
|
50
60
|
}
|
51
61
|
)
|
52
|
-
|
data/lib/plugins/notify-send3.rb
CHANGED
@@ -1,25 +1,29 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
-
|
3
2
|
require 'fileutils'
|
4
3
|
require 'RMagick'
|
5
4
|
require 'uri'
|
6
5
|
|
7
6
|
# Copy from notify-send2.rb
|
8
|
-
config.plugins.notify_send.set_default(
|
7
|
+
config.plugins.notify_send.set_default(
|
8
|
+
:icon_cache_dir, "#{Termtter::CONF_DIR}/tmp/user_profile_images")
|
9
9
|
def get_icon_path(s)
|
10
|
-
FileUtils.mkdir_p(config.plugins.notify_send.icon_cache_dir) unless
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
FileUtils.mkdir_p(config.plugins.notify_send.icon_cache_dir) unless
|
11
|
+
File.exist?(config.plugins.notify_send.icon_cache_dir)
|
12
|
+
cache_file = "%s/%s%s" % [
|
13
|
+
config.plugins.notify_send.icon_cache_dir,
|
14
|
+
s.user.screen_name,
|
15
|
+
File.extname(s.user.profile_image_url)]
|
16
|
+
if !File.exist?(cache_file) ||
|
17
|
+
(File.atime(cache_file) + 24*60*60) < Time.now
|
15
18
|
File.open(cache_file, "wb") do |f|
|
16
19
|
begin
|
17
20
|
http_class = Net::HTTP
|
18
21
|
unless config.proxy.host.nil? or config.proxy.host.empty?
|
19
|
-
http_class = Net::HTTP::Proxy(
|
20
|
-
|
21
|
-
|
22
|
-
|
22
|
+
http_class = Net::HTTP::Proxy(
|
23
|
+
config.proxy.host,
|
24
|
+
config.proxy.port,
|
25
|
+
config.proxy.user_name,
|
26
|
+
config.proxy.password)
|
23
27
|
end
|
24
28
|
uri = URI.parse(URI.escape(s.user.profile_image_url))
|
25
29
|
image = http_class.get(uri.host, uri.path, uri.port)
|
@@ -45,7 +49,7 @@ Termtter::Client.register_hook(
|
|
45
49
|
text = %Q{"#{text}"} if text =~ /^-/
|
46
50
|
text.gsub!(URI.regexp,'<a href="\0">\0</a>')
|
47
51
|
begin
|
48
|
-
system 'notify-send', '-i', get_icon_path(s)
|
52
|
+
system 'notify-send', s.user.screen_name, text, '-i', get_icon_path(s)
|
49
53
|
sleep 0.05
|
50
54
|
rescue
|
51
55
|
end
|
@@ -53,6 +57,5 @@ Termtter::Client.register_hook(
|
|
53
57
|
end
|
54
58
|
}
|
55
59
|
)
|
56
|
-
|
57
60
|
# notify-send3.rb
|
58
61
|
# caching resized profile image.
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#-*- coding: utf-8 -*-
|
2
|
+
def say_cmd(s)
|
3
|
+
return unless /darwin/i =~ RUBY_PLATFORM
|
4
|
+
system 'say "'+s+'" >/dev/null 2> /dev/null'
|
5
|
+
end
|
6
|
+
Termtter::Client.register_command(
|
7
|
+
:name => :nuance,
|
8
|
+
:author => 'Sora Harakami',
|
9
|
+
:help => ['nuance', 'how to say "termtter" in Japanese'],
|
10
|
+
:exec => lambda do |arg|
|
11
|
+
puts <<-EOM
|
12
|
+
== どのようにして'termtter'と発音するか ==
|
13
|
+
日本語発音されると「たーむったー」とします。
|
14
|
+
英語発音すると「たーむたー」とです。
|
15
|
+
EOM
|
16
|
+
if /darwin/i =~ RUBY_PLATFORM
|
17
|
+
puts "こんなに発音されます。"
|
18
|
+
say_cmd 'termtter'
|
19
|
+
sleep 2
|
20
|
+
end
|
21
|
+
puts "補足情報:"
|
22
|
+
puts <<-EOM
|
23
|
+
[2010/3/28 6:54:22 PM] &ujihisa25: たーみったーとよんだひとは
|
24
|
+
[2010/3/28 6:54:29 PM] &ujihisa25: あとで大変舐めに会うとか
|
25
|
+
EOM
|
26
|
+
Thread.new{say_cmd 'peropero'}
|
27
|
+
puts "ぺろぺろ"
|
28
|
+
end
|
29
|
+
)
|
data/lib/plugins/open_url.rb
CHANGED
@@ -9,11 +9,7 @@ module Termtter::Client
|
|
9
9
|
else
|
10
10
|
case RUBY_PLATFORM
|
11
11
|
when /linux/
|
12
|
-
|
13
|
-
system 'firefox', uri
|
14
|
-
else
|
15
|
-
system '$BROWSER', uri
|
16
|
-
end
|
12
|
+
system 'xdg-open', uri
|
17
13
|
when /mswin(?!ce)|mingw|bccwin/
|
18
14
|
system 'explorer', uri
|
19
15
|
else
|
data/lib/plugins/random.rb
CHANGED
@@ -3,9 +3,8 @@ module Termtter::Client
|
|
3
3
|
register_command(
|
4
4
|
:name => :random, :aliases => [:rand],
|
5
5
|
:exec_proc => lambda {|_|
|
6
|
-
|
7
6
|
unless public_storage[:log]
|
8
|
-
puts 'Error: You
|
7
|
+
puts 'Error: You need to load "log" plugin!'
|
9
8
|
return
|
10
9
|
end
|
11
10
|
|
@@ -14,10 +13,7 @@ module Termtter::Client
|
|
14
13
|
puts 'No status.'
|
15
14
|
return
|
16
15
|
end
|
17
|
-
|
18
16
|
execute("update #{status.text}")
|
19
|
-
|
20
17
|
},
|
21
|
-
:help => ['random', '
|
22
|
-
)
|
18
|
+
:help => ['random', 'post randomly'])
|
23
19
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#-*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
# FIXME: Currently this plugin is available only on Mac OS X.
|
4
|
+
|
5
|
+
if RUBY_PLATFORM =~ /darwin/i
|
6
|
+
config.plugins.reply_sound.set_default(:interval, 600)
|
7
|
+
config.plugins.reply_sound.set_default(
|
8
|
+
:sound_file, '/System/Library/Sounds/Hero.aiff')
|
9
|
+
|
10
|
+
reply_sound_cache = nil
|
11
|
+
reply_sound_cache_ids = []
|
12
|
+
|
13
|
+
Termtter::Client.add_task(
|
14
|
+
:name => :reply_sound,
|
15
|
+
:interval => config.plugins.reply_sound.interval) do
|
16
|
+
replies = Termtter::API.twitter.replies
|
17
|
+
new_replies = replies.delete_if {|x| reply_sound_cache_ids.index(x[:id]) }
|
18
|
+
if !reply_sound_cache.nil? && new_replies.size > 0
|
19
|
+
if respond_to? :spawn, true
|
20
|
+
system 'afplay "'+config.plugins.reply_sound.sound_file+'" 2>/dev/null &'
|
21
|
+
else
|
22
|
+
spawn 'afplay', config.plugins.reply_sound.sound_file, :out => '/dev/null'
|
23
|
+
end
|
24
|
+
Termtter::Client.output(
|
25
|
+
new_replies, Termtter::Event.new(:new_replies,:type => :reply))
|
26
|
+
end
|
27
|
+
reply_sound_cache = replies
|
28
|
+
reply_sound_cache_ids += replies.map {|x| x[:id]}
|
29
|
+
end
|
30
|
+
else
|
31
|
+
puts TermColor.parse(
|
32
|
+
"<red>WARNING: Currently reply_sound plugin is available only on Mac OS X.</red>")
|
33
|
+
end
|
data/lib/plugins/say.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
|
-
raise 'say.rb runs only in OSX Leopard' if /
|
3
|
+
raise 'say.rb runs only in OSX Leopard or Snow Leopard' if /darwin(9|10)/ !~ RUBY_PLATFORM
|
4
4
|
|
5
5
|
# say :: String -> String -> IO ()
|
6
6
|
def say(who, what)
|
@@ -23,4 +23,4 @@ module Termtter::Client
|
|
23
23
|
end
|
24
24
|
|
25
25
|
# KNOWN BUG:
|
26
|
-
# * exit or <C-c>
|
26
|
+
# * exit or <C-c> doesn't work quickly.
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
def generate_story
|
4
|
+
you = config.user_name
|
5
|
+
friends = config.plugins.stdout.sweets.dup
|
6
|
+
the_man = friends.delete(friends.sample)
|
7
|
+
a = friends.delete(friends.sample)
|
8
|
+
b = friends.delete(friends.sample)
|
9
|
+
c = friends.delete(friends.sample)
|
10
|
+
|
11
|
+
story = <<-"EOS"
|
12
|
+
|
13
|
+
--- アタシの名前は#{you}。心に傷を負った女子高生。
|
14
|
+
モテカワスリムで恋愛体質の愛されガール♪
|
15
|
+
アタシがつるんでる友達は援助交際をやってる#{a}、
|
16
|
+
学校にナイショでキャバクラで働いてる#{b}。
|
17
|
+
訳あって不良グループの一員になってる#{c}。
|
18
|
+
友達がいてもやっぱり学校はタイクツ。
|
19
|
+
今日もミキとちょっとしたことで口喧嘩になった。
|
20
|
+
女のコ同士だとこんなこともあるからストレスが溜まるよね☆
|
21
|
+
そんな時アタシは一人でTwitterを使うことにしている。
|
22
|
+
がんばった自分へのご褒美ってやつ?自分らしさの演出とも言うかな!
|
23
|
+
「あームカツク」・・。そんなことをつぶやきながらしつこいrepliesを軽くあしらう。
|
24
|
+
「カノジョー、ちょっと話聞いてくれない?」
|
25
|
+
どいつもこいつも同じようなツイートしか投稿しない。
|
26
|
+
Twitterの男はカッコイイけどなんか薄っぺらくてキライだ。
|
27
|
+
もっと等身大のアタシを見て欲しい。
|
28
|
+
「すいません・・。」・・・またか、とセレブなアタシは思った。
|
29
|
+
シカトするつもりだったけど、チラっとTwitterの男の顔を見た。
|
30
|
+
「・・!!」
|
31
|
+
・・・チガウ・・・今までの男とはなにかが決定的に違う。スピリチュアルな感覚がアタシのカラダを
|
32
|
+
駆け巡った・・。「・・(カッコイイ・・!!・・これってtermtter・・?)」
|
33
|
+
男は#{the_man}だった。連れていかれてfibでやすらぎされた。
|
34
|
+
「キャーやめて!」gをキメた。
|
35
|
+
「ガッシ!ボカッ!」アタシはコミッタになった。コミット(笑)
|
36
|
+
EOS
|
37
|
+
end
|
38
|
+
|
39
|
+
Termtter::Client.register_command(
|
40
|
+
:name => 'story',
|
41
|
+
:help => 'Show a dramatic story in Japanese.',
|
42
|
+
:exec => lambda {|arg|
|
43
|
+
puts generate_story
|
44
|
+
})
|
data/lib/plugins/tinyurl.rb
CHANGED
@@ -1,39 +1,60 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
]
|
9
|
-
|
10
|
-
|
3
|
+
config.plugins.tinyurl.set_default(:shorturl_makers, [
|
4
|
+
{ :host => "api.bit.ly",
|
5
|
+
:format => '/shorten?version=2.0.1&longUrl=%s&login=termtter&apiKey=R_e7f22d523a803dbff7f67de18c109856' },
|
6
|
+
{ :host => "is.gd", :format => '/api.php?longurl=%s' },
|
7
|
+
{ :host => "tinyurl.com", :format => '/api-create.php?url=%s' },
|
8
|
+
])
|
9
|
+
config.plugins.tinyurl.set_default(:ignore_regexp, %r{
|
10
|
+
\Ahttp://bit\.ly/ | \Ahttp://tinyurl\.com/ | \Ahttp://is\.gd/
|
11
|
+
| \Ahttp://ff\.im/ | \Ahttp://j\.mp/ | \Ahttp://goo\.gl/
|
12
|
+
| \Ahttp://tr\.im/ | \Ahttp://short\.to/ | \Ahttp://ow\.ly/
|
13
|
+
| \Ahttp://u\.nu/ | \Ahttp://twurl\.nl/
|
14
|
+
}x )
|
15
|
+
config.plugins.tinyurl.set_default(:tinyurl_hook_commands, [:update, :reply, :retweet])
|
16
|
+
config.plugins.tinyurl.set_default(:uri_regexp,
|
17
|
+
/#{URI.regexp(%w(http https ftp))}\S*/ )
|
11
18
|
|
12
|
-
Termtter::Client
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
25
|
-
if res.code == '200'
|
26
|
-
result = res.body
|
27
|
-
if result =~ /"shortUrl": "(http.*)"/
|
28
|
-
result = $1
|
29
|
-
end
|
30
|
-
break
|
19
|
+
module Termtter::Client
|
20
|
+
register_hook(
|
21
|
+
:name => :tinyurl,
|
22
|
+
:points => config.plugins.tinyurl.tinyurl_hook_commands.map {|cmd|
|
23
|
+
"modify_arg_for_#{cmd.to_s}".to_sym
|
24
|
+
},
|
25
|
+
:exec_proc => lambda {|cmd, arg|
|
26
|
+
arg.gsub(config.plugins.tinyurl.uri_regexp) do |url|
|
27
|
+
result = nil
|
28
|
+
config.plugins.tinyurl.shorturl_makers.each do |site|
|
29
|
+
result = shorten_url(url, site[:host], site[:format])
|
30
|
+
break if result
|
31
31
|
end
|
32
|
+
result or url
|
33
|
+
end
|
34
|
+
}
|
35
|
+
)
|
36
|
+
|
37
|
+
# returns nil if not shorten
|
38
|
+
def self.shorten_url(url, host, format)
|
39
|
+
return url if config.plugins.tinyurl.ignore_regexp =~ url # already shorten
|
40
|
+
url_enc = URI.escape(url, /[^a-zA-Z0-9.:]/)
|
41
|
+
res = Termtter::HTTPpool.start(host) do |h|
|
42
|
+
h.get(format % url_enc)
|
43
|
+
end
|
44
|
+
if res.code == '200'
|
45
|
+
result = res.body
|
46
|
+
if /"shortUrl": "(http.*)"/ =~ result
|
47
|
+
result = $1
|
48
|
+
elsif /"statusCode": "ERROR"/ =~ result
|
49
|
+
return nil
|
32
50
|
end
|
33
51
|
result
|
52
|
+
else
|
53
|
+
nil
|
34
54
|
end
|
35
|
-
|
36
|
-
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
37
58
|
|
38
59
|
# tinyuri.rb
|
39
60
|
# make URLs in your update to convert tinyurl.com/XXXXXXX.
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# Description: Update translated tweet to (other|same) account when you're update
|
2
|
+
# Author: Sora Harakami
|
3
|
+
|
4
|
+
require 'open-uri'
|
5
|
+
require 'json'
|
6
|
+
require 'cgi'
|
7
|
+
|
8
|
+
def translate_by_google(text,o={})
|
9
|
+
opt = {:from => "",:to => "en"}.merge(o)
|
10
|
+
j = JSON.parse(open(
|
11
|
+
"http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=" \
|
12
|
+
+"#{CGI.escape(text)}&langpair=#{CGI.escape("#{opt[:from]}|#{opt[:to]}")}").read)
|
13
|
+
j["responseData"]["translatedText"] rescue nil
|
14
|
+
end
|
15
|
+
|
16
|
+
config.plugins.translate_tweet.set_default(:to,"en")
|
17
|
+
config.plugins.translate_tweet.set_default(:user_name,nil)
|
18
|
+
config.plugins.translate_tweet.set_default(:password,nil)
|
19
|
+
config.plugins.translate_tweet.set_default(:header,"")
|
20
|
+
config.plugins.translate_tweet.set_default(:footer,"")
|
21
|
+
|
22
|
+
Termtter::Client.register_hook(
|
23
|
+
:name => :translate_tweet,
|
24
|
+
:point => :post_exec_update,
|
25
|
+
:exec => lambda do |cmd,t,result|
|
26
|
+
tw = (config.plugins.translate_tweet.user_name.nil? || \
|
27
|
+
config.plugins.translate_tweet.password.nil?) ? \
|
28
|
+
Termtter::API.twitter : \
|
29
|
+
Rubytter.new(config.plugins.translate_tweet.user_name, \
|
30
|
+
config.plugins.translate_tweet.password)
|
31
|
+
tt = config.plugins.translate_tweet.header + \
|
32
|
+
translate_by_google( \
|
33
|
+
t,:to => config.plugins.translate_tweet.to) + \
|
34
|
+
config.plugins.translate_tweet.footer
|
35
|
+
tw.update(tt)
|
36
|
+
puts "translated => #{tt}"
|
37
|
+
end
|
38
|
+
)
|