draftcode-termtter 1.0.8

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.
Files changed (118) hide show
  1. data/History.txt +4 -0
  2. data/README.rdoc +100 -0
  3. data/Rakefile +55 -0
  4. data/bin/kill_termtter +22 -0
  5. data/bin/termtter +6 -0
  6. data/lib/plugins/addspace.rb +27 -0
  7. data/lib/plugins/april_fool.rb +15 -0
  8. data/lib/plugins/bomb.rb +39 -0
  9. data/lib/plugins/clear.rb +14 -0
  10. data/lib/plugins/command_plus.rb +47 -0
  11. data/lib/plugins/confirm.rb +33 -0
  12. data/lib/plugins/cool.rb +10 -0
  13. data/lib/plugins/countter.rb +23 -0
  14. data/lib/plugins/devel.rb +18 -0
  15. data/lib/plugins/direct_messages.rb +36 -0
  16. data/lib/plugins/en2ja.rb +11 -0
  17. data/lib/plugins/english.rb +25 -0
  18. data/lib/plugins/erb.rb +17 -0
  19. data/lib/plugins/exec.rb +17 -0
  20. data/lib/plugins/exec_and_update.rb +14 -0
  21. data/lib/plugins/expand-tinyurl.rb +34 -0
  22. data/lib/plugins/fib.rb +28 -0
  23. data/lib/plugins/fib_filter.rb +14 -0
  24. data/lib/plugins/filter.rb +69 -0
  25. data/lib/plugins/graduatter.rb +8 -0
  26. data/lib/plugins/grass.rb +27 -0
  27. data/lib/plugins/group.rb +64 -0
  28. data/lib/plugins/growl.rb +52 -0
  29. data/lib/plugins/growl2.rb +143 -0
  30. data/lib/plugins/hatebu.rb +59 -0
  31. data/lib/plugins/hatebu_and_update.rb +58 -0
  32. data/lib/plugins/history.rb +93 -0
  33. data/lib/plugins/ignore.rb +19 -0
  34. data/lib/plugins/keyword.rb +18 -0
  35. data/lib/plugins/l2.rb +25 -0
  36. data/lib/plugins/log.rb +73 -0
  37. data/lib/plugins/me.rb +10 -0
  38. data/lib/plugins/modify_arg_hook_sample.rb +7 -0
  39. data/lib/plugins/msagent.rb +38 -0
  40. data/lib/plugins/multi_reply.rb +27 -0
  41. data/lib/plugins/notify-send.rb +22 -0
  42. data/lib/plugins/notify-send2.rb +52 -0
  43. data/lib/plugins/notify-send3.rb +45 -0
  44. data/lib/plugins/open_url.rb +59 -0
  45. data/lib/plugins/otsune.rb +21 -0
  46. data/lib/plugins/outputz.rb +33 -0
  47. data/lib/plugins/pause.rb +3 -0
  48. data/lib/plugins/post_exec_hook_sample.rb +9 -0
  49. data/lib/plugins/pre_exec_hook_sample.rb +9 -0
  50. data/lib/plugins/primes.rb +30 -0
  51. data/lib/plugins/quicklook.rb +41 -0
  52. data/lib/plugins/random.rb +23 -0
  53. data/lib/plugins/reblog.rb +40 -0
  54. data/lib/plugins/reload.rb +3 -0
  55. data/lib/plugins/reply.rb +8 -0
  56. data/lib/plugins/retweet.rb +46 -0
  57. data/lib/plugins/reverse.rb +13 -0
  58. data/lib/plugins/say.rb +26 -0
  59. data/lib/plugins/scrape.rb +41 -0
  60. data/lib/plugins/screen-notify.rb +20 -0
  61. data/lib/plugins/screen.rb +24 -0
  62. data/lib/plugins/shell.rb +14 -0
  63. data/lib/plugins/sl.rb +48 -0
  64. data/lib/plugins/spam.rb +16 -0
  65. data/lib/plugins/standard_plugins.rb +525 -0
  66. data/lib/plugins/stdout.rb +220 -0
  67. data/lib/plugins/storage.rb +55 -0
  68. data/lib/plugins/storage/DB.rb +37 -0
  69. data/lib/plugins/storage/status.rb +83 -0
  70. data/lib/plugins/storage/status_mook.rb +30 -0
  71. data/lib/plugins/switch_user.rb +22 -0
  72. data/lib/plugins/system_status.rb +33 -0
  73. data/lib/plugins/timer.rb +18 -0
  74. data/lib/plugins/tinyurl.rb +20 -0
  75. data/lib/plugins/translation.rb +38 -0
  76. data/lib/plugins/typable_id.rb +94 -0
  77. data/lib/plugins/update_editor.rb +53 -0
  78. data/lib/plugins/uri-open.rb +66 -0
  79. data/lib/plugins/wassr_post.rb +22 -0
  80. data/lib/plugins/yhara.rb +148 -0
  81. data/lib/plugins/yhara_filter.rb +8 -0
  82. data/lib/plugins/yonda.rb +21 -0
  83. data/lib/termtter.rb +38 -0
  84. data/lib/termtter/api.rb +57 -0
  85. data/lib/termtter/client.rb +324 -0
  86. data/lib/termtter/command.rb +80 -0
  87. data/lib/termtter/config.rb +68 -0
  88. data/lib/termtter/config_setup.rb +38 -0
  89. data/lib/termtter/connection.rb +41 -0
  90. data/lib/termtter/hook.rb +31 -0
  91. data/lib/termtter/optparse.rb +14 -0
  92. data/lib/termtter/system_extensions.rb +115 -0
  93. data/lib/termtter/task.rb +17 -0
  94. data/lib/termtter/task_manager.rb +116 -0
  95. data/lib/termtter/version.rb +4 -0
  96. data/spec/plugins/cool_spec.rb +10 -0
  97. data/spec/plugins/english_spec.rb +19 -0
  98. data/spec/plugins/fib_spec.rb +15 -0
  99. data/spec/plugins/filter_spec.rb +18 -0
  100. data/spec/plugins/pause_spec.rb +8 -0
  101. data/spec/plugins/primes_spec.rb +15 -0
  102. data/spec/plugins/shell_spec.rb +10 -0
  103. data/spec/plugins/sl_spec.rb +8 -0
  104. data/spec/plugins/spam_spec.rb +4 -0
  105. data/spec/plugins/standard_plugins_spec.rb +23 -0
  106. data/spec/plugins/storage/DB_spec.rb +12 -0
  107. data/spec/plugins/storage/status_spec.rb +24 -0
  108. data/spec/spec_helper.rb +7 -0
  109. data/spec/termtter/client_spec.rb +255 -0
  110. data/spec/termtter/command_spec.rb +107 -0
  111. data/spec/termtter/config_spec.rb +111 -0
  112. data/spec/termtter/hook_spec.rb +78 -0
  113. data/spec/termtter/task_manager_spec.rb +78 -0
  114. data/spec/termtter/task_spec.rb +22 -0
  115. data/spec/termtter_spec.rb +29 -0
  116. data/test/friends_timeline.json +5 -0
  117. data/test/search.json +8 -0
  118. metadata +211 -0
@@ -0,0 +1,52 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'fileutils'
4
+
5
+ config.plugins.notify_send.set_default(:icon_cache_dir, "#{Termtter::CONF_DIR}/tmp/user_profile_images")
6
+
7
+ FileUtils.mkdir_p(config.plugins.notify_send.icon_cache_dir) unless File.exist?(config.plugins.notify_send.icon_cache_dir)
8
+ Dir.glob("#{config.plugins.notify_send.icon_cache_dir}/*") {|f| File.delete(f) unless File.size?(f) }
9
+ unless File.exist?("#{config.plugins.notify_send.icon_cache_dir}/default.png")
10
+ File.open("#{config.plugins.notify_send.icon_cache_dir}/default.png", "wb") do |f|
11
+ f << open("http://static.twitter.com/images/default_profile_normal.png").read
12
+ end
13
+ end
14
+
15
+ def get_icon_path(s)
16
+ /https?:\/\/.+\/(\d+)\/.*?$/ =~ s.user.profile_image_url
17
+ cache_file = "%s/%s-%s%s" % [ config.plugins.notify_send.icon_cache_dir,
18
+ s.user.screen_name,
19
+ $+,
20
+ File.extname(s.user.profile_image_url) ]
21
+ unless File.exist?(cache_file)
22
+ Thread.new(s,cache_file) do |s,cache_file|
23
+ Dir.glob("#{config.plugins.notify_send.icon_cache_dir}/#{s.user.screen_name}-*") {|f| File.delete(f) }
24
+ begin
25
+ s.user.profile_image_url.sub!(/^https/,'http')
26
+ File.open(cache_file, 'wb') do |f|
27
+ f << open(URI.escape(s.user.profile_image_url)).read
28
+ end
29
+ rescue OpenURI::HTTPError
30
+ cache_file = "#{config.plugins.notify_send.icon_cache_dir}/default.png"
31
+ end
32
+ end
33
+ end
34
+ return cache_file
35
+ end
36
+
37
+ Termtter::Client.register_hook(
38
+ :name => :notify_send2,
39
+ :points => [:output],
40
+ :exec_proc => lambda {|statuses, event|
41
+ return unless event == :update_friends_timeline
42
+ Thread.start do
43
+ statuses.each do |s|
44
+ text = CGI.escapeHTML(s.text)
45
+ text.gsub!(%r{https?://[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+},'<a href="\0">\0</a>')
46
+ system 'notify-send', s.user.screen_name, text, '-i', get_icon_path(s)
47
+ sleep 0.1
48
+ end
49
+ end
50
+ }
51
+ )
52
+
@@ -0,0 +1,45 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'fileutils'
4
+ require 'RMagick'
5
+
6
+ # Copy from notify-send2.rb
7
+ config.plugins.notify_send.set_default(:icon_cache_dir, "#{Termtter::CONF_DIR}/tmp/user_profile_images")
8
+ def get_icon_path(s)
9
+ FileUtils.mkdir_p(config.plugins.notify_send.icon_cache_dir) unless File.exist?(config.plugins.notify_send.icon_cache_dir)
10
+ cache_file = "%s/%s%s" % [ config.plugins.notify_send.icon_cache_dir,
11
+ s.user.screen_name,
12
+ File.extname(s.user.profile_image_url) ]
13
+ if !File.exist?(cache_file) || (File.atime(cache_file) + 24*60*60) < Time.now
14
+ File.open(cache_file, "wb") do |f|
15
+ begin
16
+ image = open(URI.escape(s.user.profile_image_url)).read
17
+ rimage = Magick::Image.from_blob(image).first
18
+ rimage = rimage.resize_to_fill(48, 48)
19
+ f << rimage.to_blob
20
+ rescue OpenURI::HTTPError
21
+ return nil
22
+ end
23
+ end
24
+ end
25
+ cache_file
26
+ end
27
+
28
+ Termtter::Client.register_hook(
29
+ :name => :notify_send3,
30
+ :points => [:output],
31
+ :exec_proc => lambda {|statuses, event|
32
+ return unless event == :update_friends_timeline
33
+ Thread.start do
34
+ statuses.each do |s|
35
+ text = CGI.escapeHTML(s.text)
36
+ text.gsub!(%r{https?://[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+},'<a href="\0">\0</a>')
37
+ system 'notify-send', s.user.screen_name, text, '-i', get_icon_path(s)
38
+ sleep 0.1
39
+ end
40
+ end
41
+ }
42
+ )
43
+
44
+ # notify-send3.rb
45
+ # caching resized profile image.
@@ -0,0 +1,59 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'uri'
4
+
5
+ module Termtter::Client
6
+ def self.open_uri(uri)
7
+ unless config.plugins.open_url.browser.empty?
8
+ system config.plugins.open_url.browser, uri
9
+ else
10
+ case RUBY_PLATFORM
11
+ when /linux/
12
+ system 'firefox', uri
13
+ when /mswin(?!ce)|mingw|bccwin/
14
+ system 'explorer', uri
15
+ else
16
+ system 'open', uri
17
+ end
18
+ end
19
+ end
20
+
21
+ register_command(
22
+ :name => :open_url,
23
+ :help => ['open_url (TYPABLE|ID|@USER)', 'Open url'],
24
+ :exec_proc => lambda {|arg|
25
+ Thread.new(arg) do |arg|
26
+ if public_storage[:typable_id] && status = typable_id_status(arg)
27
+ status.text.gsub(URI.regexp) {|uri|
28
+ open_uri(uri)
29
+ }
30
+ else
31
+ case arg
32
+ when /^@([A-Za-z0-9_]+)/
33
+ user = $1
34
+ statuses = Termtter::API.twitter.user_timeline(user)
35
+ return if statuses.empty?
36
+ statuses[0].text.gsub(URI.regexp) {|uri| open_uri(uri) }
37
+ when /^\d+/
38
+ Termtter::API.twitter.show(arg).text.gsub(URI.regexp) {|uri| open_uri(uri) }
39
+ end
40
+ end
41
+ end
42
+ },
43
+ :completion_proc => lambda {|cmd, arg|
44
+ if public_storage[:typable_id] && typable_id?(arg)
45
+ "#{cmd} #{typable_id_convert(arg)}"
46
+ else
47
+ case arg
48
+ when /@(.*)/
49
+ find_user_candidates $1, "#{cmd} @%s"
50
+ when /(\d+)/
51
+ find_status_ids(arg).map{|id| "#{cmd} #{$1}"}
52
+ end
53
+ end
54
+ }
55
+ )
56
+ end
57
+
58
+ #Optional Setting
59
+ # config.plugins.open_url.browser = firefox
@@ -0,0 +1,21 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module Termtter::Client
4
+ register_macro(:otsune, "update @%s 頭蓋骨の中身がお気の毒です.",
5
+ :help => ['otsune {SCREENNAME}', 'update "@{SCREENNAME} 頭蓋骨の中身がお気の毒です"'],
6
+ :completion_proc => lambda {|cmd, args|
7
+ find_user_candidates args, "#{cmd} %s"
8
+ }
9
+ )
10
+ end
11
+
12
+ module Termtter::Client
13
+ register_macro(:otsnue, "update @%s 頭蓋骨の中身がお気の毒です.",
14
+ :help => ['otsnue {SCREENNAME}', 'update @%s 頭が気の毒です.'],
15
+ :completion_proc => lambda {|cmd, args|
16
+ find_user_candidates args, "#{cmd} %s"
17
+ }
18
+ )
19
+ end
20
+
21
+ # vim: fenc=utf8
@@ -0,0 +1,33 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module Termtter::Client
4
+ config.plugins.outputz.set_default(:uri, 'termtter://twitter.com/status/update')
5
+
6
+ key = config.plugins.outputz.secret_key
7
+ if key.empty?
8
+ puts 'Need your secret key'
9
+ puts 'please set config.plugins.outputz.secret_key'
10
+ else
11
+ register_hook(
12
+ :name => :outputz,
13
+ :points => [:pre_exec_update],
14
+ :exec_proc => lambda {|cmd, arg|
15
+ Thread.new do
16
+ Termtter::API.connection.start('outputz.com', 80) do |http|
17
+ key = CGI.escape key
18
+ uri = CGI.escape config.plugins.outputz.uri
19
+ size = arg.split(//).size
20
+ http.post('/api/post', "key=#{key}&uri=#{uri}&size=#{size}")
21
+ end
22
+ end
23
+ }
24
+ )
25
+ end
26
+ end
27
+
28
+ # outputz.rb
29
+ # a plugin that report to outputz your post
30
+ #
31
+ # settings (note: must this order)
32
+ # config.plugins.outputz.secret_key = 'your secret key'
33
+ # plugin 'outputz'
@@ -0,0 +1,3 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ Termtter::Client.pause
@@ -0,0 +1,9 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ Termtter::Client.register_hook(
4
+ :name => :post_exec_hook_sample,
5
+ :points => [:post_exec_list],
6
+ :exec_proc => lambda {|cmd, arg, result|
7
+ p result
8
+ }
9
+ )
@@ -0,0 +1,9 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ Termtter::Client.register_hook(
4
+ :name => :pre_exec_hook_sample,
5
+ :points => [:pre_exec_update],
6
+ :exec_proc => lambda {|cmd, arg|
7
+ false if /^y?$/i !~ Readline.readline("update? #{arg} [Y/n] ", false)
8
+ }
9
+ )
@@ -0,0 +1,30 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ def primes(n)
4
+ return "" if n < 3
5
+ table = []
6
+ (2 .. n).each do |i|
7
+ table << i
8
+ end
9
+
10
+ prime = []
11
+ loop do
12
+ prime << table[0]
13
+ table = table.delete_if {|x| x % prime.max == 0 }
14
+ break if table.max < (prime.max ** 2)
15
+ end
16
+
17
+ r = (table+prime).sort {|a, b| a<=>b }
18
+ r.join(', ')
19
+ end
20
+
21
+ module Termtter::Client
22
+ register_command(
23
+ :name => :primes,
24
+ :exec_proc => lambda {|arg|
25
+ n = arg.to_i
26
+ text = "primes(#{n}) = {#{primes n}}}"
27
+ puts "=> " << text
28
+ }
29
+ )
30
+ end
@@ -0,0 +1,41 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'uri'
4
+ require 'open-uri'
5
+ require 'pathname'
6
+ require 'tmpdir'
7
+
8
+ config.plugins.quicklook.set_default(:quicklook_tmpdir, "#{Dir.tmpdir}/termtter-quicklook-tmpdir")
9
+ tmpdir = Pathname.new(config.plugins.quicklook.quicklook_tmpdir)
10
+ tmpdir.mkdir unless tmpdir.exist?
11
+
12
+ def quicklook(url)
13
+ tmpdir = Pathname.new(config.plugins.quicklook.quicklook_tmpdir)
14
+ path = tmpdir + Pathname.new(url).basename
15
+
16
+ Thread.new do
17
+ open(path, 'w') do |f|
18
+ f.write(open(url).read)
19
+ end
20
+ system("qlmanage -p #{path} > /dev/null 2>&1")
21
+ end
22
+ end
23
+
24
+ module Termtter::Client
25
+ register_command(
26
+ :name => :quicklook, :aliases => [:ql],
27
+ :exec_proc => proc{|arg|
28
+ status = Termtter::API.twitter.show(arg)
29
+ if (status)
30
+ uris = URI.regexp.match(status.text).to_a
31
+ quicklook(uris.first) unless uris.empty?
32
+ end
33
+ }
34
+ )
35
+ end
36
+
37
+ # quicklook.rb
38
+ # REQUIREMENTS:
39
+ # plugin 'expand-tinyurl'
40
+ # TODO:
41
+ # Close quicklook window automatically.
@@ -0,0 +1,23 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Termtter::Client
3
+ register_command(
4
+ :name => :random, :aliases => [:rand],
5
+ :exec_proc => lambda {|_|
6
+
7
+ unless public_storage[:log]
8
+ puts 'Error: You should load "log" plugin!'
9
+ return
10
+ end
11
+
12
+ status = public_storage[:log][rand(public_storage[:log].size)]
13
+ unless status
14
+ puts 'No status.'
15
+ return
16
+ end
17
+
18
+ call_commands("update #{status.text}")
19
+
20
+ },
21
+ :help => ['random', 'random post']
22
+ )
23
+ end
@@ -0,0 +1,40 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'rubygems'
4
+ require 'tumblr'
5
+
6
+ module Termtter::Client
7
+ register_command(
8
+ :name => :reblog, :aliases => [],
9
+ :exec_proc => lambda {|arg|
10
+ if arg =~ /^reblog\s+(\d+)(.*)$/
11
+ id = $1.strip
12
+ comment = $2.strip
13
+ statuses = public_storage[:log].select { |s| s.id == id }
14
+ unless statuses.empty?
15
+ status = statuses.first
16
+ else
17
+ status = t.show(id).first
18
+ end
19
+
20
+ Tumblr::API.write(config.plugins.reblog.email, config.plugins.reblog.password) do
21
+ quote("#{status.text}", "<a href=\"http://twitter.com/#{status.user_screen_name}/status/#{status.id}\">Twitter / #{status.user_name}</a>")
22
+ end
23
+ end
24
+ },
25
+ :completion_proc => lambda {|cmd, args|
26
+ if args =~ /^(\d*)$/
27
+ find_status_ids($1){|id| "#{cmd} #{id}"}
28
+ end
29
+ },
30
+ :help => ['reblog ID', 'Tumblr Reblog a status']
31
+ )
32
+ end
33
+
34
+ # reblog.rb
35
+ # tumblr reblog it!
36
+ #
37
+ # config.plugins.reblog.email = 'your-email-on-tumblr'
38
+ # config.plugins.reblog.password = 'your-password-on-tumblr'
39
+ #
40
+ # reblog 1114860346
@@ -0,0 +1,3 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ Termtter::Client.register_macro :reload, "eval exec $0"
@@ -0,0 +1,8 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ Termtter::Client.add_filter do |statuses|
4
+ statuses.select{|s| s.text =~ /@/ }
5
+ end
6
+
7
+ # filter-reply.rb
8
+ # select @ reply post only
@@ -0,0 +1,46 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ config.plugins.retweet.set_default(:format, 'RT @<%=s.user.screen_name%>: <%=s.text%>')
4
+
5
+ module Termtter::Client
6
+ def self.post_retweet(s)
7
+ text = ERB.new(config.plugins.retweet.format).result(binding)
8
+ Termtter::API.twitter.update(text)
9
+ puts "=> #{text}"
10
+ end
11
+
12
+ register_command(
13
+ :name => :retweet,
14
+ :aliases => [:rt],
15
+ :help => ['retweet,rt (TYPABLE|ID|@USER)', 'Post a retweet message'],
16
+ :exec_proc => lambda {|arg|
17
+ if public_storage[:typable_id] && s = typable_id_status(arg)
18
+ post_retweet(s)
19
+ else
20
+ case arg
21
+ when /(\d+)/
22
+ post_retweet(Termtter::API.twitter.show(arg))
23
+ #s = Twitter::API.twitter.show(arg)
24
+ #post_retweet(s)
25
+ when /@([A-Za-z0-9_]+)/
26
+ user = $1
27
+ statuses = Termtter::API.twitter.user_timeline(user)
28
+ return if statuses.empty?
29
+ post_retweet(statuses[0])
30
+ end
31
+ end
32
+ },
33
+ :completion_proc => lambda {|cmd, arg|
34
+ if public_storage[:typable_id] && s = typable_id_status(arg)
35
+ "u #{ERB.new(config.plugins.retweet.format).result(binding)}"
36
+ else
37
+ case arg
38
+ when /@(.*)/
39
+ find_user_candidates $1, "#{cmd} @%s"
40
+ when /(\d+)/
41
+ find_status_ids(arg).map{|id| "#{cmd} #{$1}"}
42
+ end
43
+ end
44
+ }
45
+ )
46
+ end