jugyo-termtter 0.7.7 → 0.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.
Files changed (68) hide show
  1. data/Manifest.txt +10 -0
  2. data/Rakefile +25 -0
  3. data/bin/kill_termtter +22 -0
  4. data/lib/filter/en2ja.rb +2 -0
  5. data/lib/filter/expand-tinyurl.rb +2 -0
  6. data/lib/filter/fib.rb +2 -0
  7. data/lib/filter/ignore.rb +2 -0
  8. data/lib/filter/reverse.rb +2 -0
  9. data/lib/plugin/april_fool.rb +15 -0
  10. data/lib/plugin/bomb.rb +11 -8
  11. data/lib/plugin/confirm.rb +9 -24
  12. data/lib/plugin/cool.rb +8 -10
  13. data/lib/plugin/english.rb +2 -0
  14. data/lib/plugin/erb.rb +9 -9
  15. data/lib/plugin/favorite.rb +2 -0
  16. data/lib/plugin/fib.rb +2 -0
  17. data/lib/plugin/filter.rb +41 -36
  18. data/lib/plugin/follow.rb +36 -20
  19. data/lib/plugin/graduatter.rb +2 -0
  20. data/lib/plugin/group.rb +32 -34
  21. data/lib/plugin/growl.rb +3 -1
  22. data/lib/plugin/hatebu.rb +46 -44
  23. data/lib/plugin/history.rb +16 -4
  24. data/lib/plugin/keyword.rb +2 -0
  25. data/lib/plugin/log.rb +32 -32
  26. data/lib/plugin/modify_arg_hook_sample.rb +7 -0
  27. data/lib/plugin/msagent.rb +2 -0
  28. data/lib/plugin/multi_reply.rb +2 -0
  29. data/lib/plugin/notify-send.rb +2 -0
  30. data/lib/plugin/otsune.rb +17 -13
  31. data/lib/plugin/outputz.rb +2 -0
  32. data/lib/plugin/pause.rb +3 -0
  33. data/lib/plugin/plugin.rb +29 -24
  34. data/lib/plugin/post_exec_hook_sample.rb +9 -0
  35. data/lib/plugin/pre_exec_hook_sample.rb +9 -0
  36. data/lib/plugin/primes.rb +2 -0
  37. data/lib/plugin/quicklook.rb +2 -0
  38. data/lib/plugin/reblog.rb +27 -25
  39. data/lib/plugin/reload.rb +3 -3
  40. data/lib/plugin/say.rb +2 -0
  41. data/lib/plugin/scrape.rb +35 -37
  42. data/lib/plugin/screen.rb +2 -0
  43. data/lib/plugin/shell.rb +12 -2
  44. data/lib/plugin/sl.rb +42 -25
  45. data/lib/plugin/spam.rb +2 -0
  46. data/lib/plugin/standard_plugins.rb +99 -49
  47. data/lib/plugin/stdout.rb +2 -0
  48. data/lib/plugin/system_status.rb +7 -15
  49. data/lib/plugin/translation.rb +2 -0
  50. data/lib/plugin/update_editor.rb +21 -21
  51. data/lib/plugin/uri-open.rb +2 -0
  52. data/lib/plugin/wassr_post.rb +10 -9
  53. data/lib/plugin/yhara.rb +16 -25
  54. data/lib/plugin/yonda.rb +2 -0
  55. data/lib/termtter.rb +44 -24
  56. data/lib/termtter/api.rb +2 -0
  57. data/lib/termtter/client.rb +140 -56
  58. data/lib/termtter/command.rb +15 -5
  59. data/lib/termtter/connection.rb +3 -1
  60. data/lib/termtter/hook.rb +18 -0
  61. data/lib/termtter/status.rb +2 -0
  62. data/lib/termtter/task.rb +16 -0
  63. data/lib/termtter/task_manager.rb +116 -0
  64. data/lib/termtter/twitter.rb +15 -4
  65. data/lib/termtter/user.rb +13 -0
  66. data/run_termtter.rb +1 -0
  67. data/test/test_termtter.rb +2 -0
  68. metadata +14 -3
@@ -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 => proc {|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 => proc {|cmd, arg|
7
+ false if /^y?$/i !~ Readline.readline("update? #{arg} [Y/n] ", false)
8
+ }
9
+ )
data/lib/plugin/primes.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  def primes(n)
2
4
  table = []
3
5
  (2 .. n).each do |i|
@@ -1,3 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  require 'uri'
2
4
  require 'open-uri'
3
5
  require 'pathname'
data/lib/plugin/reblog.rb CHANGED
@@ -1,32 +1,34 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  require 'rubygems'
2
4
  require 'tumblr'
3
5
 
4
6
  module Termtter::Client
5
- add_help 'reblog ID', 'Tumblr Reblog a status'
6
-
7
- add_command %r'^reblog\s+(\d+)(.*)$' do |m, t|
8
- id = m[1]
9
- comment = m[2].strip
10
- statuses = public_storage[:log].select { |s| s.id == id }
11
- unless statuses.empty?
12
- status = statuses.first
13
- else
14
- status = t.show(id).first
15
- end
16
-
17
- Tumblr::API.write(configatron.plugins.reblog.email, configatron.plugins.reblog.password) do
18
- quote("#{status.text}", "<a href=\"http://twitter.com/#{status.user_screen_name}/status/#{status.id}\">Twitter / #{status.user_name}</a>")
19
- end
20
- end
21
-
22
- add_completion do |input|
23
- case input
24
- when /^(reblog)\s+(\d*)$/
25
- find_status_id_candidates $2, "#{$1} %s"
26
- else
27
- %w(reblog).grep(/^#{Regexp.quote input}/)
28
- end
29
- end
7
+ register_command(
8
+ :name => :reblog, :aliases => [],
9
+ :exec_proc => proc {|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(configatron.plugins.reblog.email, configatron.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 => proc {|cmd, args|
26
+ if args =~ /^(\d*)$/
27
+ find_status_id_candidates $1, "#{cmd} %s"
28
+ end
29
+ },
30
+ :help => ['reblog ID', 'Tumblr Reblog a status']
31
+ )
30
32
  end
31
33
 
32
34
  # reblog.rb
data/lib/plugin/reload.rb CHANGED
@@ -1,3 +1,3 @@
1
- module Termtter::Client
2
- add_macro /^reload$/, 'eval exec $0'
3
- end
1
+ # -*- coding: utf-8 -*-
2
+
3
+ Termtter::Client.register_macro :reload, "eval exec $0"
data/lib/plugin/say.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  raise 'say.rb runs only in OSX Leopard' if /darwin9/ !~ RUBY_PLATFORM
2
4
 
3
5
  # say :: String -> String -> IO ()
data/lib/plugin/scrape.rb CHANGED
@@ -1,43 +1,41 @@
1
- module Termtter::Client
2
- def self.scrape_group(group, t)
3
- members = configatron.plugins.group.groups[group] || []
4
- members.map {|member|
5
- t.get_user_timeline(member)
6
- }.flatten
7
- end
8
-
9
- def self.scrape_groups(t)
10
- groups = configatron.plugins.group.groups
11
- groups.map {|group|
12
- scrape_group(group, t)
13
- }.flatten
14
- end
15
-
16
- add_help 'scrape_group GROUPNAME', 'Get the group timeline'
17
- add_help 'scrape_groups', 'Get all groups timeline'
1
+ # -*- coding: utf-8 -*-
18
2
 
19
- add_command /^(?:scrape_group)\s+(.+)/ do |m, t|
20
- group_name = m[1].to_sym
21
- statuses = scrape_group(group_name, t)
22
- call_hooks(statuses, :pre_filter, t)
23
- puts "done"
24
- end
25
-
26
- add_command /^(?:scrape_groups)\s*$/ do |m, t|
27
- statuses = scrape_groups(t)
28
- call_hooks(statuses, :pre_filter, t)
29
- puts "done"
30
- end
3
+ module Termtter::Client
31
4
 
32
- add_completion do |input|
33
- case input
34
- when /^(scrape_group)?\s+(.+)/
35
- find_group_candidates($2, "#{$1} %s") if defined? find_group_candidates
36
- when /^(scrape_group)\s+$/
37
- configatron.plugins.group.groups.keys
38
- else
39
- %w(scrape_group scrape_groups).grep(/^#{Regexp.quote input}/)
5
+ def self.scrape_members(members)
6
+ statuses = []
7
+ members.each_with_index do |member, index|
8
+ puts "member #{index+1}/#{members.size} #{member}"
9
+ statuses += Termtter::API.twitter.get_user_timeline(member)
40
10
  end
11
+ statuses
12
+ end
13
+
14
+ def self.scrape_group(group)
15
+ members = configatron.plugins.group.groups[group] || []
16
+ scrape_members(members)
41
17
  end
42
18
 
19
+ register_command(
20
+ :name => :scrape_group,
21
+ :exec_proc => proc{ |args|
22
+ groups = args.split(' ').map{|g| g.to_sym}
23
+ if groups.include? :all
24
+ groups = configatron.plugins.group.groups.keys
25
+ puts "get all groups..."
26
+ end
27
+ members = []
28
+ groups.each do |group|
29
+ members += configatron.plugins.group.groups[group]
30
+ end
31
+ statuses = scrape_members(members.uniq.compact.sort)
32
+ call_hooks(statuses, :pre_filter)
33
+ },
34
+ :completion_proc => proc {|cmd, args|
35
+ arg = args.split(' ').last
36
+ prefix = args.split(' ')[0..-2].join(' ')
37
+ find_group_candidates arg, "#{cmd} #{prefix} %s"
38
+ },
39
+ :help => ['scrape_group GROUPNAME(S)', 'Get the group timeline']
40
+ )
43
41
  end
data/lib/plugin/screen.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  module Termtter
2
4
  module Plugin
3
5
  module Screen
data/lib/plugin/shell.rb CHANGED
@@ -1,4 +1,14 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  module Termtter::Client
2
- add_help 'shell,sh', 'Start your shell'
3
- add_macro /^(?:shell|sh)\s*$/, "eval system ENV['SHELL'] || ENV['COMSPEC']"
4
+ register_command :name => :shell, :aliases => [:sh],
5
+ :help => ['shell,sh', 'Start your shell'],
6
+ :exec_proc => proc {|args|
7
+ begin
8
+ pause
9
+ system ENV['SHELL'] || ENV['COMSPEC']
10
+ ensure
11
+ resume
12
+ end
13
+ }
4
14
  end
data/lib/plugin/sl.rb CHANGED
@@ -1,31 +1,48 @@
1
- module Termtter::Client
2
- public_storage[:current] = ''
1
+ # -*- coding: utf-8 -*-
3
2
 
4
- add_macro /^sl\s*$/, 'eval system "sl"'
3
+ module Termtter
5
4
 
6
- add_help 'pwd', 'Show current direcroty'
7
- add_macro /^pwd\s*$/, 'eval public_storage[:current]'
5
+ module Client
8
6
 
9
- add_help 'ls', 'Show list in current directory'
10
- add_command /^ls\s*$/ do |m, t|
11
- call_commands "list #{public_storage[:current]}", t
12
- end
7
+ public_storage[:current] = ''
8
+ public_storage[:orig_prompt] = configatron.prompt
9
+ configatron.prompt = "~/ #{public_storage[:orig_prompt]}"
13
10
 
14
- add_help 'cd USER', 'Change current directory'
15
- add_command /^(?:cd\s+|\.\/)(.*)/ do |m, t|
16
- directory = m[1].strip
17
- directory = '' if /\~/ =~ directory
18
- public_storage[:current] = directory
19
- puts "=> #{directory}"
20
- end
21
- add_macro /^cd$/, 'eval public_storage[:current] = ""'
22
-
23
- add_completion do |input|
24
- case input
25
- when /^(cd\s+|\.\/)(.*)/
26
- find_user_candidates $2, "#{$1.gsub(/\s+/, ' ')}%s"
27
- else
28
- %w[ sl ls cd pwd ./ ].grep(/^#{Regexp.quote input}/)
29
- end
11
+ register_command(
12
+ :name => :sl, :aliases => [],
13
+ :exec_proc => proc {|arg| system("sl") },
14
+ :help => ['sl', 'The train pass in front of your screen']
15
+ )
16
+
17
+ register_command(
18
+ :name => :pwd, :aliases => [],
19
+ :exec_proc => proc {|arg| public_storage[:current] },
20
+ :help => ['pwd', 'Show current direcroty']
21
+ )
22
+
23
+ register_command(
24
+ :name => :ls, :aliases => [],
25
+ :exec_proc => proc {|arg|
26
+ call_commands("list #{arg.empty? ? public_storage[:current] : arg}", API.twitter)
27
+ },
28
+ :completion_proc => proc {|cmd, args|
29
+ find_user_candidates args, "#{cmd} %s"
30
+ },
31
+ :help => ['ls', 'Show list in current directory']
32
+ )
33
+
34
+ register_command(
35
+ :name => :cd, :aliases => [],
36
+ :exec_proc => proc {|arg|
37
+ public_storage[:current] =
38
+ (arg.nil? || /\~/ =~ arg) ? '' : arg
39
+ configatron.prompt = "~/#{public_storage[:current]} #{public_storage[:orig_prompt]}"
40
+ },
41
+ :completion_proc => proc {|cmd, args|
42
+ find_user_candidates args, "#{cmd} %s"
43
+ },
44
+ :help => ['cd USER', 'Change current directory']
45
+ )
30
46
  end
31
47
  end
48
+
data/lib/plugin/spam.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  Termtter::Twitter.new(configatron.user_name, configatron.password).update_status('*super spam time*')
2
4
  module Termtter::Client
3
5
  clear_commands
@@ -1,61 +1,108 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  require 'erb'
2
4
 
3
5
  module Termtter::Client
4
6
 
5
7
  # standard commands
6
8
 
7
- add_command /^(update|u)\s+(.*)/ do |m, t|
8
- text = ERB.new(m[2]).result(binding).gsub(/\n/, ' ')
9
- unless text.empty?
10
- t.update_status(text)
9
+ register_command(
10
+ :name => :update, :aliases => [:u],
11
+ :exec_proc => proc {|arg|
12
+ text = ERB.new(arg).result(binding).gsub(/\n/, ' ')
13
+ Termtter::API.twitter.update_status(text)
11
14
  puts "=> #{text}"
12
- end
13
- end
15
+ },
16
+ :completion_proc => proc {|cmd, args|
17
+ if /(.*)@([^\s]*)$/ =~ args
18
+ find_user_candidates $2, "#{cmd} #{$1}@%s"
19
+ end
20
+ }
21
+ )
14
22
 
15
- add_command /^(direct|d)\s+([^\s]+)\s+(.*)\s*$/ do |m, t|
16
- user = m[2]
17
- text = ERB.new(m[3]).result(binding).gsub(/\n/, ' ')
18
- unless text.empty?
19
- t.direct_message(user, text)
20
- puts "=> to:#{user} message:#{text}"
21
- end
22
- end
23
+ register_command(
24
+ :name => :direct, :aliases => [:d],
25
+ :exec_proc => proc {|arg|
26
+ if arg =~ /^([^\s]+)\s+(.*)\s*$/
27
+ user, text = $1, $2
28
+ Termtter::API.twitter.direct_message(user, text)
29
+ puts "=> to:#{user} message:#{text}"
30
+ end
31
+ },
32
+ :completion_proc => proc {|cmd, args|
33
+ if args =~ /^([^\s]+)$/
34
+ find_user_candidates $1, "#{cmd} %s"
35
+ end
36
+ }
37
+ )
23
38
 
24
- add_command /^(profile|p)\s+([^\s]+)/ do |m, t|
25
- profile = t.get_user_profile(m[2])
26
- if profile
27
- %w[ name favourites_count url id description protected utc_offset time_zone screen_name notifications statuses_count followers_count friends_count profile_image_url location following created_at ].each do |key|
28
- puts "#{key} : #{profile[key]}" if profile.key?(key)
39
+ register_command(
40
+ :name => :profile, :aliases => [:p],
41
+ :exec_proc => proc {|arg|
42
+ user = Termtter::API.twitter.get_user_profile(arg)
43
+ attrs = %w[ name screen_name url description profile_image_url location protected following
44
+ friends_count followers_count statuses_count favourites_count
45
+ id time_zone created_at utc_offset notifications
46
+ ]
47
+ label_width = attrs.map{|i|i.size}.max
48
+ attrs.each do |attr|
49
+ value = user.__send__(attr.to_sym)
50
+ puts "#{attr.gsub('_', ' ').rjust(label_width)}: #{value}"
29
51
  end
30
- end
31
- end
52
+ },
53
+ :completion_proc => proc {|cmd, arg|
54
+ find_user_candidates arg, "#{cmd} %s"
55
+ }
56
+ )
32
57
 
33
- add_command /^(list|l)\s*$/ do |m, t|
34
- statuses = t.get_friends_timeline()
35
- call_hooks(statuses, :list_friends_timeline, t)
36
- end
58
+ register_command(
59
+ :name => :list, :aliases => [:l],
60
+ :exec_proc => proc {|arg|
61
+ unless arg.empty?
62
+ call_hooks(Termtter::API.twitter.get_user_timeline(arg), :list_user_timeline)
63
+ else
64
+ call_hooks(Termtter::API.twitter.get_friends_timeline(), :list_friends_timeline)
65
+ end
66
+ },
67
+ :completion_proc => proc {|cmd, arg|
68
+ find_user_candidates arg, "#{cmd} %s"
69
+ }
70
+ )
37
71
 
38
- add_command /^(list|l)\s+([^\s]+)/ do |m, t|
39
- statuses = t.get_user_timeline(m[2])
40
- call_hooks(statuses, :list_user_timeline, t)
41
- end
72
+ register_command(
73
+ :name => :search, :aliases => [:s],
74
+ :exec_proc => proc {|arg|
75
+ call_hooks(Termtter::API.twitter.search(arg), :search)
76
+ }
77
+ )
42
78
 
43
- add_command /^(search|s)\s+(.+)/ do |m, t|
44
- call_hooks(t.search(m[2]), :search, t)
45
- end
79
+ register_command(
80
+ :name => :replies, :aliases => [:r],
81
+ :exec_proc => proc {
82
+ call_hooks(Termtter::API.twitter.replies(), :replies)
83
+ }
84
+ )
46
85
 
47
- add_command /^(replies|r)\s*$/ do |m, t|
48
- call_hooks(t.replies(), :replies, t)
49
- end
86
+ register_command(
87
+ :name => :show,
88
+ :exec_proc => proc {|arg|
89
+ id = arg.gsub(/.*:/, '')
90
+ call_hooks(Termtter::API.twitter.show(id), :show)
91
+ }
92
+ )
50
93
 
51
- add_command /^show(s)?\s+(?:[\w\d]+:)?(\d+)/ do |m, t|
52
- call_hooks(t.show(m[2], m[1]), :show, t)
53
- end
94
+ register_command(
95
+ :name => :shows,
96
+ :exec_proc => proc {|arg|
97
+ id = arg.gsub(/.*:/, '')
98
+ call_hooks(Termtter::API.twitter.show(id, true), :show)
99
+ }
100
+ )
54
101
 
55
102
  # TODO: Change colors when remaining_hits is low.
56
103
  # TODO: Simmulate remaining_hits.
57
104
  register_command(
58
- :name => :limit, :aliases => ['lm'],
105
+ :name => :limit, :aliases => [:lm],
59
106
  :exec_proc => proc {|arg|
60
107
  limit = Termtter::API.twitter.get_rate_limit_status
61
108
  remaining_time = "%dmin %dsec" % (limit.reset_time - Time.now).divmod(60)
@@ -83,11 +130,22 @@ module Termtter::Client
83
130
  )
84
131
 
85
132
  register_command(
86
- :name => :exit, :aliases => ['e'],
133
+ :name => :exit, :aliases => [:e],
87
134
  :exec_proc => proc {|arg| exit},
88
135
  :help => ['exit,e', 'Exit']
89
136
  )
90
137
 
138
+ register_hook(
139
+ :name => :default_error_handler,
140
+ :points => [:on_error],
141
+ :exec_proc => proc {|e|
142
+ puts "Error: #{e}"
143
+ if configatron.debug == true
144
+ puts e.backtrace.join("\n")
145
+ end
146
+ }
147
+ )
148
+
91
149
  add_command /^(help|h)\s*$/ do |m, t|
92
150
  # TODO: migrate to use Termtter::Command#help
93
151
  helps = [
@@ -166,7 +224,7 @@ module Termtter::Client
166
224
  end
167
225
 
168
226
  def self.find_user_candidates(a, b)
169
- if a.empty?
227
+ if a.nil? || a.empty?
170
228
  public_storage[:users].to_a
171
229
  else
172
230
  public_storage[:users].grep(/^#{Regexp.quote a}/i)
@@ -177,14 +235,6 @@ module Termtter::Client
177
235
  add_completion do |input|
178
236
  standard_commands = %w[exit help list pause profile update direct resume replies search show limit]
179
237
  case input
180
- when /^(list|l)?\s+(.*)/
181
- find_user_candidates $2, "#{$1} %s"
182
- when /^(update|u)\s+(.*)@([^\s]*)$/
183
- find_user_candidates $3, "#{$1} #{$2}@%s"
184
- when /^(direct|d)\s+(.*)/
185
- find_user_candidates $2, "#{$1} %s"
186
- when /^(profile|p)\s+(.*)/
187
- find_user_candidates $2, "#{$1} %s"
188
238
  when /^show(s)?\s+(([\w\d]+):)?\s*(.*)/
189
239
  if $2
190
240
  find_status_id_candidates $4, "show#{$1} #{$2}%s", $3