jugyo-termtter 0.8.14 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. data/README.rdoc +8 -8
  2. data/Rakefile +3 -5
  3. data/lib/{plugin → plugins}/april_fool.rb +0 -0
  4. data/lib/plugins/bomb.rb +42 -0
  5. data/lib/{plugin → plugins}/clear.rb +0 -0
  6. data/lib/{plugin → plugins}/confirm.rb +0 -0
  7. data/lib/{plugin → plugins}/cool.rb +0 -0
  8. data/lib/{plugin → plugins}/devel.rb +0 -0
  9. data/lib/{filter → plugins}/en2ja.rb +1 -1
  10. data/lib/plugins/english.rb +25 -0
  11. data/lib/{plugin → plugins}/erb.rb +0 -0
  12. data/lib/{filter → plugins}/expand-tinyurl.rb +6 -6
  13. data/lib/plugins/favorite.rb +63 -0
  14. data/lib/plugins/fib.rb +28 -0
  15. data/lib/{filter/fib.rb → plugins/fib_filter.rb} +1 -2
  16. data/lib/{plugin → plugins}/filter.rb +0 -0
  17. data/lib/{plugin → plugins}/graduatter.rb +1 -2
  18. data/lib/{plugin → plugins}/grass.rb +2 -2
  19. data/lib/{plugin → plugins}/group.rb +9 -9
  20. data/lib/{plugin → plugins}/growl.rb +11 -12
  21. data/lib/{plugin → plugins}/hatebu.rb +5 -5
  22. data/lib/{plugin → plugins}/history.rb +13 -13
  23. data/lib/plugins/ignore.rb +19 -0
  24. data/lib/plugins/keyword.rb +18 -0
  25. data/lib/{plugin → plugins}/log.rb +18 -12
  26. data/lib/{plugin → plugins}/me.rb +1 -2
  27. data/lib/{plugin → plugins}/modify_arg_hook_sample.rb +0 -0
  28. data/lib/{plugin → plugins}/msagent.rb +1 -1
  29. data/lib/plugins/multi_reply.rb +27 -0
  30. data/lib/{plugin → plugins}/notify-send.rb +1 -1
  31. data/lib/{plugin → plugins}/otsune.rb +0 -0
  32. data/lib/plugins/outputz.rb +33 -0
  33. data/lib/{plugin → plugins}/pause.rb +0 -0
  34. data/lib/{plugin → plugins}/plugin.rb +0 -0
  35. data/lib/{plugin → plugins}/post_exec_hook_sample.rb +0 -0
  36. data/lib/{plugin → plugins}/pre_exec_hook_sample.rb +0 -0
  37. data/lib/{plugin → plugins}/primes.rb +9 -2
  38. data/lib/plugins/quicklook.rb +41 -0
  39. data/lib/{plugin → plugins}/random.rb +0 -0
  40. data/lib/{plugin → plugins}/reblog.rb +3 -3
  41. data/lib/{plugin → plugins}/reload.rb +0 -0
  42. data/lib/{filter → plugins}/reply.rb +0 -0
  43. data/lib/{filter → plugins}/reverse.rb +1 -1
  44. data/lib/{plugin → plugins}/say.rb +1 -1
  45. data/lib/{plugin → plugins}/scrape.rb +4 -4
  46. data/lib/plugins/screen-notify.rb +13 -0
  47. data/lib/plugins/screen.rb +24 -0
  48. data/lib/{plugin → plugins}/shell.rb +0 -0
  49. data/lib/{plugin → plugins}/sl.rb +4 -4
  50. data/lib/plugins/spam.rb +13 -0
  51. data/lib/{plugin → plugins}/standard_plugins.rb +72 -18
  52. data/lib/plugins/stdout.rb +80 -0
  53. data/lib/plugins/storage/DB.rb +37 -0
  54. data/lib/plugins/storage/status.rb +48 -0
  55. data/lib/plugins/storage/status_mook.rb +30 -0
  56. data/lib/plugins/storage.rb +47 -0
  57. data/lib/plugins/system_status.rb +33 -0
  58. data/lib/{plugin → plugins}/translation.rb +15 -5
  59. data/lib/{plugin → plugins}/update_editor.rb +6 -6
  60. data/lib/plugins/uri-open.rb +64 -0
  61. data/lib/{filter → plugins}/url_addspace.rb +0 -0
  62. data/lib/{plugin → plugins}/wassr_post.rb +1 -1
  63. data/lib/{plugin → plugins}/yhara.rb +1 -1
  64. data/lib/plugins/yhara_filter.rb +8 -0
  65. data/lib/plugins/yonda.rb +21 -0
  66. data/lib/termtter/api.rb +28 -2
  67. data/lib/termtter/client.rb +90 -102
  68. data/lib/termtter/command.rb +32 -31
  69. data/lib/termtter/config.rb +64 -0
  70. data/lib/termtter/connection.rb +9 -7
  71. data/lib/termtter/hook.rb +11 -2
  72. data/lib/termtter/optparse.rb +14 -0
  73. data/lib/termtter/version.rb +1 -1
  74. data/lib/termtter.rb +19 -22
  75. data/spec/plugin/english_spec.rb +19 -0
  76. data/spec/plugin/favorite_spec.rb +10 -0
  77. data/spec/plugin/fib_spec.rb +1 -2
  78. data/spec/plugin/pause_spec.rb +8 -0
  79. data/spec/plugin/plugin_spec.rb +1 -1
  80. data/spec/plugin/primes_spec.rb +15 -0
  81. data/spec/plugin/sl_spec.rb +8 -0
  82. data/spec/plugin/spam_spec.rb +0 -13
  83. data/spec/plugin/standard_plugins_spec.rb +0 -7
  84. data/spec/plugin/storage/DB_spec.rb +12 -0
  85. data/spec/plugin/storage/status_spec.rb +24 -0
  86. data/spec/spec_helper.rb +3 -0
  87. data/spec/termtter/client_spec.rb +63 -1
  88. data/spec/termtter/command_spec.rb +6 -68
  89. data/spec/termtter/config_spec.rb +111 -0
  90. data/spec/termtter/hook_spec.rb +69 -0
  91. data/spec/termtter_spec.rb +22 -34
  92. metadata +81 -72
  93. data/lib/filter/english.rb +0 -8
  94. data/lib/filter/ignore.rb +0 -19
  95. data/lib/filter/yhara.rb +0 -20
  96. data/lib/plugin/bomb.rb +0 -29
  97. data/lib/plugin/english.rb +0 -59
  98. data/lib/plugin/favorite.rb +0 -75
  99. data/lib/plugin/fib.rb +0 -8
  100. data/lib/plugin/follow.rb +0 -60
  101. data/lib/plugin/keyword.rb +0 -18
  102. data/lib/plugin/multi_reply.rb +0 -36
  103. data/lib/plugin/outputz.rb +0 -35
  104. data/lib/plugin/quicklook.rb +0 -38
  105. data/lib/plugin/screen.rb +0 -24
  106. data/lib/plugin/spam.rb +0 -9
  107. data/lib/plugin/stdout.rb +0 -63
  108. data/lib/plugin/system_status.rb +0 -33
  109. data/lib/plugin/uri-open.rb +0 -69
  110. data/lib/plugin/yonda.rb +0 -20
  111. data/lib/termtter/status.rb +0 -26
  112. data/lib/termtter/twitter.rb +0 -188
  113. data/lib/termtter/user.rb +0 -13
  114. data/spec/termtter/user_spec.rb +0 -27
  115. data/test/test_termtter.rb +0 -86
@@ -1,59 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- require 'erb'
4
-
5
- module Termtter
6
- Client.clear_hooks # FIXME: not to clear all but to clear just stdout.rb
7
-
8
- configatron.set_default(
9
- :timeline_format,
10
- '<%= color(time, 90) %> <%= color(status, status_color) %> <%= color(id, 90) %>')
11
-
12
- def color(str, num)
13
- "\e[#{num}m#{str}\e[0m"
14
- end
15
-
16
- # FIXME: The code below is a copy from stdout.rb so it's not DRY. DRY it.
17
-
18
- Client.add_hook do |statuses, event|
19
- colors = %w(0 31 32 33 34 35 36 91 92 93 94 95 96)
20
-
21
- case event
22
- when :update_friends_timeline, :list_friends_timeline, :list_user_timeline, :show, :replies
23
- unless statuses.empty?
24
- statuses.reverse! if event == :update_friends_timeline
25
- statuses.each do |s|
26
- text = s.text.gsub("\n", '')
27
- next unless Status.english?(text) # if you substitute "if" for "unless", this script will be "japanese.rb"
28
- status_color = colors[s.user_screen_name.hash % colors.size]
29
- status = "#{s.user_screen_name}: #{text}"
30
- if s.in_reply_to_status_id
31
- status += " (reply to #{s.in_reply_to_status_id})"
32
- end
33
-
34
- time_format = case event
35
- when :update_friends_timeline, :list_friends_timeline
36
- '%H:%M:%S'
37
- else
38
- '%m-%d %H:%M'
39
- end
40
- time = "(#{s.created_at.strftime(time_format)})"
41
-
42
- id = s.id
43
-
44
- puts ERB.new(configatron.timeline_format).result(binding)
45
- end
46
- end
47
- when :search
48
- statuses.each do |s|
49
- text = s.text.gsub("\n", '')
50
- status_color = colors[s.user_screen_name.hash % colors.size]
51
-
52
- status = "#{s.user_screen_name}: #{text}"
53
- time = "(#{s.created_at.strftime('%m-%d %H:%M')})"
54
- id = s.id
55
- puts ERB.new(configatron.timeline_format).result(binding)
56
- end
57
- end
58
- end
59
- end
@@ -1,75 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- module Termtter::Client
4
- add_help 'favorite,fav ID', 'Favorite a status'
5
-
6
- add_command %r'^(?:favorite|fav)\s+(\d+)\s*$' do |m, t|
7
- id = m[1]
8
- res = t.favorite(id)
9
- if res.code == '200'
10
- puts "Favorited status ##{id}"
11
- else
12
- puts "Failed: #{res}"
13
- end
14
- end
15
-
16
- add_help 'favorite,fav USER', 'Favorite last status on the user'
17
-
18
- add_command %r'^(?:favorite|fav)\s+@(.+)\s*$' do |m, t|
19
- user = m[1].strip
20
- statuses = t.get_user_timeline(user)
21
- unless statuses.empty?
22
- id = statuses[0].id
23
- text = statuses[0].text
24
- res = t.favorite(id)
25
- if res.code == '200'
26
- puts %Q(Favorited last status ##{id} on user @#{user}: "#{text}")
27
- else
28
- puts "Failed: #{res}"
29
- end
30
- end
31
- end
32
-
33
- if public_storage[:log]
34
- add_help 'favorite,fav /WORD', 'Favorite a status by searching'
35
-
36
- add_command %r'^(?:favorite|fav)\s+/(.+)$' do |m, t|
37
- pat = Regexp.new(m[1])
38
- statuses = public_storage[:log].select {|s| pat =~ s.text }
39
- if statuses.size == 1
40
- status = statuses.first
41
- res = t.favorite(status.id)
42
- if res.code == '200'
43
- puts %Q(Favorited "#{status.user_screen_name}: #{status.text}")
44
- else
45
- puts "Failed: #{res}"
46
- end
47
- else
48
- puts "#{pat} does not match single status"
49
- end
50
- end
51
- end
52
-
53
- add_completion do |input|
54
- case input
55
- when /^(favorite|fav)\s+@(.*)/
56
- find_user_candidates $2, "#{$1} @%s"
57
- when /^(favorite|fav)\s+(\d*)/
58
- find_status_id_candidates $2, "#{$1} %s"
59
- else
60
- %w(favorite).grep(/^#{Regexp.quote input}/)
61
- end
62
- end
63
- end
64
-
65
- module Termtter
66
- class Twitter
67
- def favorite(id)
68
- uri = "#{@connection.protocol}://twitter.com/favourings/create/#{id}.json"
69
-
70
- @connection.start('twitter.com', @connection.port) do |http|
71
- http.request(post_request(uri))
72
- end
73
- end
74
- end
75
- end
data/lib/plugin/fib.rb DELETED
@@ -1,8 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- def fib(n)i=0;j=1;n.times{j=i+i=j};i end
4
- module Termtter::Client
5
- add_command /^fib\s+(\d+)/ do|m,t|t.update_status x="fib(#{n=m[1].to_i}) = #{fib n}"
6
- puts"=> #{x}"end
7
- add_command /^fibyou\s(\w+)\s(\d+)/ do|m,t|puts"=> #{t.update_status("@#{m[1]} fib(#{n=m[2].to_i}) = #{fib n}")}"end end
8
- # TODO: use add_macro
data/lib/plugin/follow.rb DELETED
@@ -1,60 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- module Termtter::Client
4
- register_command(
5
- :name => :follow, :aliases => [],
6
- :exec_proc => lambda {|args|
7
- args.split(' ').each do |arg|
8
- if arg =~ /^(\w+)/
9
- res = Termtter::API::twitter.social($1.strip, :follow)
10
- if res.code == '200'
11
- puts "Followed user @#{$1}"
12
- else
13
- puts "Failed: #{res}"
14
- end
15
- end
16
- end
17
- },
18
- :completion_proc => lambda {|cmd, args|
19
- find_user_candidates args, "#{cmd} %s"
20
- },
21
- :help => ['follow USER', 'Follow user']
22
- )
23
-
24
- register_command(
25
- :name => :leave, :aliases => [],
26
- :exec_proc => lambda {|args|
27
- args.split(' ').each do |arg|
28
- if arg =~ /^(\w+)/
29
- res = Termtter::API::twitter.social($1.strip, :leave)
30
- if res.code == '200'
31
- puts "Leaved user @#{$1}"
32
- else
33
- puts "Failed: #{res}"
34
- end
35
- end
36
- end
37
- },
38
- :completion_proc => lambda {|cmd, args|
39
- find_user_candidates args, "#{cmd} %s"
40
- },
41
- :help => ['leave USER', 'Leave user']
42
- )
43
- end
44
-
45
- module Termtter
46
- class Twitter
47
- def social(user, type)
48
- type =
49
- case type.to_sym
50
- when :follow then 'create'
51
- when :leave then 'destroy'
52
- end
53
- uri = "#{@connection.protocol}://twitter.com/friendships/#{type}/#{user}.json"
54
-
55
- @connection.start('twitter.com', @connection.port) do |http|
56
- http.request(post_request(uri))
57
- end
58
- end
59
- end
60
- end
@@ -1,18 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- configatron.set_default('plugins.keyword.keywords', [])
4
-
5
- module Termtter
6
- class Status
7
- def has_keyword?
8
- configatron.plugins.keyword.keywords.find { |k| k === self.text }
9
- end
10
- alias :has_keyword :has_keyword?
11
- end
12
- end
13
-
14
- # keyword.rb
15
- # provides a keyword watching method
16
- # example config
17
- # configatron.plugins.stdout.timeline_format = '<%= color(time, 90) %> <%= color(status, s.has_keyword ? 4 : status_color) %> <%= color(id, 90) %>'
18
- # configatron.plugins.keyword.keywords = [ /motemen/ ]
@@ -1,36 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- module Termtter::Client
4
- add_help 'multi_reply, mp TEXT', 'reply to multi user'
5
- add_command /^(multi_reply|mr)\s+(.*)/ do |m, t|
6
- text = ERB.new(m[2]).result(binding).gsub(/\n/, ' ')
7
- unless text.empty?
8
- #targets, _, msg = text.match /(@(.+))*\s+(.+)/
9
- #targets.split(/\s+/).
10
- # map {|u| "#{u} #{msg}" }.
11
- # each do |post|
12
- # t.update_status(post)
13
- # puts "=> #{post}"
14
- # end
15
- /(@(.+))*\s+(.+)/ =~ text
16
- if $1
17
- msg = $3
18
- text = $1.split(/\s+/).map {|u| "#{u} #{msg}" }
19
- end
20
- Array(text).each do |post|
21
- t.update_status(post)
22
- puts "=> #{post}"
23
- end
24
- #
25
- end
26
- end
27
-
28
- add_completion do |input|
29
- case input
30
- when /^(multi_reply|mr)\s+(.*)@([^\s]*)$/
31
- find_user_candidates $3, "#{$1} #{$2}@%s"
32
- else
33
- %w[ mreply mp ].grep(/^#{Regexp.quote input}/)
34
- end
35
- end
36
- end
@@ -1,35 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
-
4
- module Termtter::Client
5
- configatron.plugins.outputz.set_default(:uri, 'termtter://twitter.com/status/update')
6
-
7
- key = configatron.plugins.outputz.secret_key
8
- if key.instance_of? Configatron::Store
9
- puts 'Need your secret key'
10
- puts 'please set configatron.plugins.outputz.secret_key'
11
- else
12
- add_command /^(update|u)\s+(.*)/ do |m, t|
13
- text = ERB.new(m[2]).result(binding).gsub(/\n/, ' ')
14
- unless text.empty?
15
- t.update_status(text)
16
- puts "=> #{text}"
17
- end
18
- t.instance_variable_get('@connection').
19
- start('outputz.com', 80) do |http|
20
- key = CGI.escape key
21
- uri = CGI.escape configatron.plugins.outputz.uri
22
- size = text.split(//).size
23
- http.post('/api/post', "key=#{key}&uri=#{uri}&size=#{size}")
24
- end
25
- end
26
- end
27
- end
28
-
29
- # outputz.rb
30
- # a plugin that report to outputz your post
31
- #
32
- # settings (note: must this order)
33
- # configatron.plugins.outputz.secret_key = 'your secret key'
34
- # plugin 'outputz'
35
-
@@ -1,38 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- require 'uri'
4
- require 'open-uri'
5
- require 'pathname'
6
- require 'tmpdir'
7
-
8
- configatron.plugins.quicklook.set_default(:quicklook_tmpdir, "#{Dir.tmpdir}/termtter-quicklook-tmpdir")
9
- tmpdir = Pathname.new(configatron.plugins.quicklook.quicklook_tmpdir)
10
- tmpdir.mkdir unless tmpdir.exist?
11
-
12
- def quicklook(url)
13
- tmpdir = Pathname.new(configatron.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
- add_command %r'^(?:quicklook|ql)\s+(\w+)$' do |m,t|
26
- id = m[1]
27
- status = t.show(id).first
28
-
29
- if (status)
30
- uris = URI.regexp.match(status.text).to_a
31
- quicklook(uris.first) unless uris.empty?
32
- end
33
- end
34
- end
35
-
36
- # quicklook.rb
37
- # TODO:
38
- # Close quicklook window automatically.
data/lib/plugin/screen.rb DELETED
@@ -1,24 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- module Termtter
4
- module Plugin
5
- module Screen
6
- def self.set_title(title)
7
- print "\033k#{title}\033\\"
8
- end
9
- end
10
- end
11
- end
12
-
13
- # Add below to your ~/.termtter
14
- #
15
- # require 'plugin/yonda'
16
- # require 'plugin/screen'
17
- # module Termtter::Client
18
- # add_hook do |statuses, event|
19
- # case event
20
- # when :update_friends_timeline, :plugin_yonda_yonda
21
- # Termtter::Plugin::Screen::set_title("termtter(#{public_storage[:unread_count]})")
22
- # end
23
- # end
24
- # end
data/lib/plugin/spam.rb DELETED
@@ -1,9 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- Termtter::Twitter.new(configatron.user_name, configatron.password).update_status('*super spam time*')
4
- module Termtter::Client
5
- clear_commands
6
- add_command /.+/ do |m, t|
7
- Thread.new { t.update_status(m[0]) }
8
- end
9
- end
data/lib/plugin/stdout.rb DELETED
@@ -1,63 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- require 'termcolor'
4
- require 'erb'
5
-
6
- configatron.plugins.stdout.set_default(
7
- :colors,
8
- [:none, :red, :green, :yellow, :blue, :magenta, :cyan])
9
- configatron.plugins.stdout.set_default(
10
- :timeline_format,
11
- '<90><%=time%></90> <<%=status_color%>><%=status%></<%=status_color%>> <90><%=id%></90>')
12
-
13
- $highline = HighLine.new
14
-
15
- def color(str, value)
16
- return str if value == :none
17
- case value
18
- when String, Symbol
19
- $highline.color(str, value)
20
- else
21
- "\e[#{value}m#{str}\e[0m"
22
- end
23
- end
24
-
25
- module Termtter::Client
26
-
27
- def self.print_statuses(statuses, sort = true, time_format = '%H:%M:%S')
28
- (sort ? statuses.sort_by{ |s| s.id} : statuses).each do |s|
29
- text = s.text
30
- status_color = configatron.plugins.stdout.colors[s.user_screen_name.hash % configatron.plugins.stdout.colors.size]
31
- status = "#{s.user_screen_name}: #{text}"
32
- if s.in_reply_to_status_id
33
- status += " (reply to #{s.in_reply_to_status_id})"
34
- end
35
-
36
- time = "(#{s.created_at.strftime(time_format)})"
37
- id = s.id
38
- erbed_text = ERB.new(configatron.plugins.stdout.timeline_format).result(binding)
39
- puts TermColor.parse(erbed_text)
40
- end
41
- end
42
-
43
- def self.print_statuses_with_date(statuses, sort = true)
44
- print_statuses(statuses, sort, '%m-%d %H:%M')
45
- end
46
-
47
- add_hook do |statuses, event|
48
- next if statuses.empty?
49
-
50
- case event
51
- when :update_friends_timeline, :list_friends_timeline
52
- print_statuses(statuses)
53
- when :search, :list_user_timeline, :show, :replies
54
- print_statuses_with_date(statuses)
55
- end
56
- end
57
-
58
- end
59
- # stdout.rb
60
- # output statuses to stdout
61
- # example config
62
- # configatron.plugins.stdout.colors = [:none, :red, :green, :yellow, :blue, :magenta, :cyan]
63
- # configatron.plugins.stdout.timeline_format = '<90><%=time%></90> <<%=status_color%>><%=status%></<%=status_color%>> <90><%=id%></90>'
@@ -1,33 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- require 'erb'
4
-
5
- configatron.plugins.system_status.set_default(:default_status_proc, lambda { Time.now.strftime("%x %X") })
6
- configatron.plugins.system_status.set_default(:interval, 1)
7
- configatron.plugins.system_status.set_default(:default_color, :on_blue)
8
- configatron.plugins.system_status.set_default(:format, '<%= status %>')
9
-
10
- def out_put_status(status, color)
11
- formatted_status = ERB.new(configatron.plugins.system_status.format).result(binding)
12
- colored_status = color(formatted_status, color)
13
- print "\e[s\e[1000G\e[#{status.size - 1}D#{colored_status}\e[u"
14
- $stdout.flush
15
- end
16
-
17
- module Termtter::Client
18
- add_task(:name => :system_status, :interval => configatron.plugins.system_status.interval) do
19
- status = (@@task_manager.get_task(:update_timeline).exec_at - Time.now).to_i.to_s
20
- color = public_storage[:system_status_color] ||
21
- configatron.plugins.system_status.default_color
22
- out_put_status(status, color)
23
- end
24
- end
25
-
26
- # system_status.rb
27
- # show system status on left side.
28
- # output public_storage[:system_status] or Time.now.strftime("%x %X") if nil
29
- # example config
30
- # configatron.plugins.system_status.default_status_proc = lambda { Time.now.strftime("%x %X") }
31
- # configatron.plugins.system_status.interval = 1
32
- # configatron.plugins.system_status.default_color = :on_blue
33
- # configatron.plugins.system_status.format = '<%= status %>'
@@ -1,69 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- module Termtter::Client
4
- public_storage[:uris] = []
5
-
6
- add_hook do |statuses, event, t|
7
- if !statuses.empty? && event == :update_friends_timeline
8
- statuses.each do |s|
9
- public_storage[:uris] += s.text.scan(%r|https?://[^\s]+|)
10
- end
11
- end
12
- end
13
-
14
- def self.open_uri(uri)
15
- unless configatron.plugins.uri_open.browser.nil?
16
- system configatron.plugins.uri_open.browser, uri
17
- else
18
- case RUBY_PLATFORM
19
- when /linux/
20
- system 'firefox', uri
21
- when /mswin(?!ce)|mingw|bccwin/
22
- system 'explorer', uri
23
- else
24
- system 'open', uri
25
- end
26
- end
27
- end
28
-
29
- add_command /^uri-open\s*$/ do |m, t|
30
- public_storage[:uris].each do |uri|
31
- open_uri(uri)
32
- end
33
- public_storage[:uris].clear
34
- end
35
-
36
- add_command /^uri-open\s+(\d+)$/ do |m, t|
37
- if m[1]
38
- index = m[1].to_i
39
- open_uri(public_storage[:uris][index])
40
- public_storage[:uris].delete_at(index)
41
- end
42
- end
43
-
44
- add_command /^uri-open\s+list\s*$/ do |m, t|
45
- public_storage[:uris].each_with_index do |uri, index|
46
- puts "#{index}: #{uri}"
47
- end
48
- end
49
-
50
- add_command /^uri-open\s+delete\s+(\d+)$/ do |m, t|
51
- public_storage[:uris].delete_at(m[1].to_i) if m[1]
52
- end
53
-
54
- add_command /^uri-open\s+clear\s*$/ do |m, t|
55
- public_storage[:uris].clear
56
- puts "clear uris"
57
- end
58
-
59
- add_completion do |input|
60
- ['uri-open ', 'uri-open list', 'uri-open delete', 'uri-open clear'].grep(/^#{Regexp.quote input}/)
61
- end
62
- end
63
- # ~/.termtter
64
- # plugin 'uri-open'
65
- #
66
- # see also: http://ujihisa.nowa.jp/entry/c3dd00c4e0
67
- #
68
- # KNOWN BUG
69
- # * In Debian, exit or C-c in the termtter kills your firefox.
data/lib/plugin/yonda.rb DELETED
@@ -1,20 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- module Termtter::Client
4
- register_command(
5
- :name => :yonda, :aliases => [:y],
6
- :exec_proc => proc{|arg|
7
- public_storage[:unread_count] = 0
8
- print "\033[2J\033[H" # FIXME
9
- call_hooks [], :plugin_yonda_yonda
10
- },
11
- :help => ['yonda,y', 'Mark as read']
12
- )
13
-
14
- add_hook do |statuses, event|
15
- case event
16
- when :update_friends_timeline
17
- public_storage[:unread_count] += statuses.size
18
- end
19
- end
20
- end
@@ -1,26 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- module Termtter
4
- class Status
5
- %w(
6
- id text created_at truncated
7
- in_reply_to_status_id in_reply_to_user_id in_reply_to_screen_name
8
- user_id user_name user_screen_name user_url user_profile_image_url
9
- ).each do |attr|
10
- attr_accessor attr.to_sym
11
- end
12
-
13
- def eql?(other); self.id == other.id end
14
- def hash; self.id end
15
-
16
- def english?
17
- self.class.english?(self.text)
18
- end
19
-
20
- # english? :: String -> Boolean
21
- def self.english?(message)
22
- /[一-龠]+|[ぁ-ん]+|[ァ-ヴー]+|[a-zA-Z0-9]+/ !~ message
23
- end
24
- end
25
- end
26
-