jugyo-termtter 0.8.2 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/README.rdoc +9 -0
  2. data/Rakefile +46 -64
  3. data/lib/filter/url_addspace.rb +16 -0
  4. data/lib/plugin/april_fool.rb +1 -1
  5. data/lib/plugin/bomb.rb +1 -1
  6. data/lib/plugin/clear.rb +14 -0
  7. data/lib/plugin/confirm.rb +1 -1
  8. data/lib/plugin/cool.rb +1 -1
  9. data/lib/plugin/devel.rb +13 -0
  10. data/lib/plugin/erb.rb +1 -1
  11. data/lib/plugin/filter.rb +4 -4
  12. data/lib/plugin/follow.rb +5 -5
  13. data/lib/plugin/grass.rb +27 -0
  14. data/lib/plugin/group.rb +8 -4
  15. data/lib/plugin/growl.rb +1 -1
  16. data/lib/plugin/hatebu.rb +2 -2
  17. data/lib/plugin/history.rb +9 -0
  18. data/lib/plugin/log.rb +14 -6
  19. data/lib/plugin/modify_arg_hook_sample.rb +1 -1
  20. data/lib/plugin/otsune.rb +2 -2
  21. data/lib/plugin/plugin.rb +3 -3
  22. data/lib/plugin/post_exec_hook_sample.rb +1 -1
  23. data/lib/plugin/pre_exec_hook_sample.rb +1 -1
  24. data/lib/plugin/reblog.rb +2 -2
  25. data/lib/plugin/scrape.rb +2 -2
  26. data/lib/plugin/shell.rb +1 -1
  27. data/lib/plugin/sl.rb +6 -6
  28. data/lib/plugin/standard_plugins.rb +62 -44
  29. data/lib/plugin/system_status.rb +2 -2
  30. data/lib/plugin/update_editor.rb +1 -1
  31. data/lib/plugin/wassr_post.rb +1 -1
  32. data/lib/plugin/yhara.rb +2 -2
  33. data/lib/plugin/yonda.rb +9 -9
  34. data/lib/termtter/client.rb +24 -7
  35. data/lib/termtter/command.rb +2 -2
  36. data/lib/termtter/hook.rb +1 -1
  37. data/lib/termtter/task.rb +1 -1
  38. data/lib/termtter/twitter.rb +51 -27
  39. data/lib/termtter/version.rb +1 -1
  40. data/spec/plugin/cool_spec.rb +10 -0
  41. data/spec/plugin/fib_spec.rb +16 -0
  42. data/spec/plugin/filter_spec.rb +18 -0
  43. data/spec/plugin/plugin_spec.rb +25 -0
  44. data/spec/plugin/shell_spec.rb +10 -0
  45. data/spec/plugin/spam_spec.rb +17 -0
  46. data/spec/plugin/standard_plugins_spec.rb +31 -0
  47. data/spec/spec_helper.rb +4 -0
  48. data/spec/termtter/client_spec.rb +175 -0
  49. data/spec/termtter/command_spec.rb +161 -0
  50. data/spec/termtter/task_manager_spec.rb +78 -0
  51. data/spec/termtter/task_spec.rb +22 -0
  52. data/spec/termtter/user_spec.rb +27 -0
  53. data/spec/termtter_spec.rb +43 -0
  54. metadata +40 -42
  55. data/Manifest.txt +0 -77
  56. data/PostInstall.txt +0 -1
  57. data/run_termtter.rb +0 -17
@@ -3,5 +3,5 @@
3
3
  Termtter::Client.register_hook(
4
4
  :name => :modify_arg_hook_sample,
5
5
  :points => [:modify_arg_for_update],
6
- :exec_proc => proc {|cmd, arg| arg + '\(^o^)/'}
6
+ :exec_proc => lambda {|cmd, arg| arg + '\(^o^)/'}
7
7
  )
data/lib/plugin/otsune.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  module Termtter::Client
4
4
  register_macro(:otsune, "update @%s 頭蓋骨の中身がお気の毒です.",
5
5
  :help => ['otsune {SCREENNAME}', 'update "@{SCREENNAME} 頭蓋骨の中身がお気の毒です"'],
6
- :completion_proc => proc {|cmd, args|
6
+ :completion_proc => lambda {|cmd, args|
7
7
  find_user_candidates args, "#{cmd} %s"
8
8
  }
9
9
  )
@@ -12,7 +12,7 @@ end
12
12
  module Termtter::Client
13
13
  register_macro(:otsnue, "update @%s 頭蓋骨の中身がお気の毒です.",
14
14
  :help => ['otsnue {SCREENNAME}', 'update @%s 頭が気の毒です.'],
15
- :completion_proc => proc {|cmd, args|
15
+ :completion_proc => lambda {|cmd, args|
16
16
  find_user_candidates args, "#{cmd} %s"
17
17
  }
18
18
  )
data/lib/plugin/plugin.rb CHANGED
@@ -8,7 +8,7 @@ module Termtter::Client
8
8
 
9
9
  register_command(
10
10
  :name => :plugin, :aliases => [],
11
- :exec_proc => proc {|arg|
11
+ :exec_proc => lambda {|arg|
12
12
  begin
13
13
  result = plugin arg.strip
14
14
  rescue LoadError
@@ -16,7 +16,7 @@ module Termtter::Client
16
16
  puts "=> #{result.inspect}"
17
17
  end
18
18
  },
19
- :completion_proc => proc {|cmd, args|
19
+ :completion_proc => lambda {|cmd, args|
20
20
  find_user_candidates args, "#{cmd} %s"
21
21
  unless args.empty?
22
22
  find_plugin_candidates args, "#{cmd} %s"
@@ -29,7 +29,7 @@ module Termtter::Client
29
29
 
30
30
  register_command(
31
31
  :name => :plugins, :aliases => [],
32
- :exec_proc => proc {|arg|
32
+ :exec_proc => lambda {|arg|
33
33
  puts public_storage[:plugins].sort.join("\n")
34
34
  },
35
35
  :help => ['plugins', 'Show list of plugins']
@@ -3,7 +3,7 @@
3
3
  Termtter::Client.register_hook(
4
4
  :name => :post_exec_hook_sample,
5
5
  :points => [:post_exec_list],
6
- :exec_proc => proc {|cmd, arg, result|
6
+ :exec_proc => lambda {|cmd, arg, result|
7
7
  p result
8
8
  }
9
9
  )
@@ -3,7 +3,7 @@
3
3
  Termtter::Client.register_hook(
4
4
  :name => :pre_exec_hook_sample,
5
5
  :points => [:pre_exec_update],
6
- :exec_proc => proc {|cmd, arg|
6
+ :exec_proc => lambda {|cmd, arg|
7
7
  false if /^y?$/i !~ Readline.readline("update? #{arg} [Y/n] ", false)
8
8
  }
9
9
  )
data/lib/plugin/reblog.rb CHANGED
@@ -6,7 +6,7 @@ require 'tumblr'
6
6
  module Termtter::Client
7
7
  register_command(
8
8
  :name => :reblog, :aliases => [],
9
- :exec_proc => proc {|arg|
9
+ :exec_proc => lambda {|arg|
10
10
  if arg =~ /^reblog\s+(\d+)(.*)$/
11
11
  id = $1.strip
12
12
  comment = $2.strip
@@ -22,7 +22,7 @@ module Termtter::Client
22
22
  end
23
23
  end
24
24
  },
25
- :completion_proc => proc {|cmd, args|
25
+ :completion_proc => lambda {|cmd, args|
26
26
  if args =~ /^(\d*)$/
27
27
  find_status_id_candidates $1, "#{cmd} %s"
28
28
  end
data/lib/plugin/scrape.rb CHANGED
@@ -18,7 +18,7 @@ module Termtter::Client
18
18
 
19
19
  register_command(
20
20
  :name => :scrape_group,
21
- :exec_proc => proc{ |args|
21
+ :exec_proc => lambda{ |args|
22
22
  groups = args.split(' ').map{|g| g.to_sym}
23
23
  if groups.include? :all
24
24
  groups = configatron.plugins.group.groups.keys
@@ -31,7 +31,7 @@ module Termtter::Client
31
31
  statuses = scrape_members(members.uniq.compact.sort)
32
32
  call_hooks(statuses, :pre_filter)
33
33
  },
34
- :completion_proc => proc {|cmd, args|
34
+ :completion_proc => lambda {|cmd, args|
35
35
  arg = args.split(' ').last
36
36
  prefix = args.split(' ')[0..-2].join(' ')
37
37
  find_group_candidates arg, "#{cmd} #{prefix} %s"
data/lib/plugin/shell.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  module Termtter::Client
4
4
  register_command :name => :shell, :aliases => [:sh],
5
5
  :help => ['shell,sh', 'Start your shell'],
6
- :exec_proc => proc {|args|
6
+ :exec_proc => lambda {|args|
7
7
  begin
8
8
  pause
9
9
  system ENV['SHELL'] || ENV['COMSPEC']
data/lib/plugin/sl.rb CHANGED
@@ -10,22 +10,22 @@ module Termtter
10
10
 
11
11
  register_command(
12
12
  :name => :sl, :aliases => [],
13
- :exec_proc => proc {|arg| system("sl") },
13
+ :exec_proc => lambda {|arg| system("sl") },
14
14
  :help => ['sl', 'The train pass in front of your screen']
15
15
  )
16
16
 
17
17
  register_command(
18
18
  :name => :pwd, :aliases => [],
19
- :exec_proc => proc {|arg| public_storage[:current] },
19
+ :exec_proc => lambda {|arg| public_storage[:current] },
20
20
  :help => ['pwd', 'Show current direcroty']
21
21
  )
22
22
 
23
23
  register_command(
24
24
  :name => :ls, :aliases => [],
25
- :exec_proc => proc {|arg|
25
+ :exec_proc => lambda {|arg|
26
26
  call_commands("list #{arg.empty? ? public_storage[:current] : arg}", API.twitter)
27
27
  },
28
- :completion_proc => proc {|cmd, args|
28
+ :completion_proc => lambda {|cmd, args|
29
29
  find_user_candidates args, "#{cmd} %s"
30
30
  },
31
31
  :help => ['ls', 'Show list in current directory']
@@ -33,12 +33,12 @@ module Termtter
33
33
 
34
34
  register_command(
35
35
  :name => :cd, :aliases => [],
36
- :exec_proc => proc {|arg|
36
+ :exec_proc => lambda {|arg|
37
37
  public_storage[:current] =
38
38
  (arg.nil? || /\~/ =~ arg) ? '' : arg
39
39
  configatron.prompt = "~/#{public_storage[:current]} #{public_storage[:orig_prompt]}"
40
40
  },
41
- :completion_proc => proc {|cmd, args|
41
+ :completion_proc => lambda {|cmd, args|
42
42
  find_user_candidates args, "#{cmd} %s"
43
43
  },
44
44
  :help => ['cd USER', 'Change current directory']
@@ -8,12 +8,12 @@ module Termtter::Client
8
8
 
9
9
  register_command(
10
10
  :name => :update, :aliases => [:u],
11
- :exec_proc => proc {|arg|
11
+ :exec_proc => lambda {|arg|
12
12
  text = ERB.new(arg).result(binding).gsub(/\n/, ' ')
13
13
  Termtter::API.twitter.update_status(text)
14
14
  puts "=> #{text}"
15
15
  },
16
- :completion_proc => proc {|cmd, args|
16
+ :completion_proc => lambda {|cmd, args|
17
17
  if /(.*)@([^\s]*)$/ =~ args
18
18
  find_user_candidates $2, "#{cmd} #{$1}@%s"
19
19
  end
@@ -22,14 +22,14 @@ module Termtter::Client
22
22
 
23
23
  register_command(
24
24
  :name => :direct, :aliases => [:d],
25
- :exec_proc => proc {|arg|
25
+ :exec_proc => lambda {|arg|
26
26
  if arg =~ /^([^\s]+)\s+(.*)\s*$/
27
27
  user, text = $1, $2
28
28
  Termtter::API.twitter.direct_message(user, text)
29
29
  puts "=> to:#{user} message:#{text}"
30
30
  end
31
31
  },
32
- :completion_proc => proc {|cmd, args|
32
+ :completion_proc => lambda {|cmd, args|
33
33
  if args =~ /^([^\s]+)$/
34
34
  find_user_candidates $1, "#{cmd} %s"
35
35
  end
@@ -38,7 +38,7 @@ module Termtter::Client
38
38
 
39
39
  register_command(
40
40
  :name => :profile, :aliases => [:p],
41
- :exec_proc => proc {|arg|
41
+ :exec_proc => lambda {|arg|
42
42
  user = Termtter::API.twitter.get_user_profile(arg)
43
43
  attrs = %w[ name screen_name url description profile_image_url location protected following
44
44
  friends_count followers_count statuses_count favourites_count
@@ -50,42 +50,51 @@ module Termtter::Client
50
50
  puts "#{attr.gsub('_', ' ').rjust(label_width)}: #{value}"
51
51
  end
52
52
  },
53
- :completion_proc => proc {|cmd, arg|
53
+ :completion_proc => lambda {|cmd, arg|
54
54
  find_user_candidates arg, "#{cmd} %s"
55
55
  }
56
56
  )
57
57
 
58
+ register_command(
59
+ :name => :followers,
60
+ :exec_proc => lambda {|arg|
61
+ followers = Termtter::API.twitter.followers
62
+ Termtter::Client.public_storage[:followers] = followers
63
+ p followers.map{|f|f.screen_name}
64
+ }
65
+ )
66
+
58
67
  register_command(
59
68
  :name => :list, :aliases => [:l],
60
- :exec_proc => proc {|arg|
69
+ :exec_proc => lambda {|arg|
61
70
  unless arg.empty?
62
71
  call_hooks(Termtter::API.twitter.get_user_timeline(arg), :list_user_timeline)
63
72
  else
64
73
  call_hooks(Termtter::API.twitter.get_friends_timeline(), :list_friends_timeline)
65
74
  end
66
75
  },
67
- :completion_proc => proc {|cmd, arg|
76
+ :completion_proc => lambda {|cmd, arg|
68
77
  find_user_candidates arg, "#{cmd} %s"
69
78
  }
70
79
  )
71
80
 
72
81
  register_command(
73
82
  :name => :search, :aliases => [:s],
74
- :exec_proc => proc {|arg|
83
+ :exec_proc => lambda {|arg|
75
84
  call_hooks(Termtter::API.twitter.search(arg), :search)
76
85
  }
77
86
  )
78
87
 
79
88
  register_command(
80
89
  :name => :replies, :aliases => [:r],
81
- :exec_proc => proc {
90
+ :exec_proc => lambda {|arg|
82
91
  call_hooks(Termtter::API.twitter.replies(), :replies)
83
92
  }
84
93
  )
85
94
 
86
95
  register_command(
87
96
  :name => :show,
88
- :exec_proc => proc {|arg|
97
+ :exec_proc => lambda {|arg|
89
98
  id = arg.gsub(/.*:/, '')
90
99
  call_hooks(Termtter::API.twitter.show(id), :show)
91
100
  }
@@ -93,7 +102,7 @@ module Termtter::Client
93
102
 
94
103
  register_command(
95
104
  :name => :shows,
96
- :exec_proc => proc {|arg|
105
+ :exec_proc => lambda {|arg|
97
106
  id = arg.gsub(/.*:/, '')
98
107
  call_hooks(Termtter::API.twitter.show(id, true), :show)
99
108
  }
@@ -103,7 +112,7 @@ module Termtter::Client
103
112
  # TODO: Simmulate remaining_hits.
104
113
  register_command(
105
114
  :name => :limit, :aliases => [:lm],
106
- :exec_proc => proc {|arg|
115
+ :exec_proc => lambda {|arg|
107
116
  limit = Termtter::API.twitter.get_rate_limit_status
108
117
  remaining_time = "%dmin %dsec" % (limit.reset_time - Time.now).divmod(60)
109
118
  remaining_color =
@@ -119,62 +128,71 @@ module Termtter::Client
119
128
 
120
129
  register_command(
121
130
  :name => :pause,
122
- :exec_proc => proc {|arg| pause},
131
+ :exec_proc => lambda {|arg| pause},
123
132
  :help => ["pause", "Pause updating"]
124
133
  )
125
134
 
126
135
  register_command(
127
136
  :name => :resume,
128
- :exec_proc => proc {|arg| resume},
137
+ :exec_proc => lambda {|arg| resume},
129
138
  :help => ["resume", "Resume updating"]
130
139
  )
131
140
 
132
141
  register_command(
133
142
  :name => :exit, :aliases => [:e],
134
- :exec_proc => proc {|arg| exit},
143
+ :exec_proc => lambda {|arg| exit},
135
144
  :help => ['exit,e', 'Exit']
136
145
  )
137
146
 
138
147
  register_hook(
139
148
  :name => :default_error_handler,
140
149
  :points => [:on_error],
141
- :exec_proc => proc {|e|
150
+ :exec_proc => lambda {|e|
142
151
  puts "Error: #{e}"
143
- if configatron.debug == true
152
+ if configatron.devel == true
144
153
  puts e.backtrace.join("\n")
145
154
  end
146
155
  }
147
156
  )
148
157
 
149
- add_command /^(help|h)\s*$/ do |m, t|
150
- # TODO: migrate to use Termtter::Command#help
151
- helps = [
152
- ["help,h", "Print this help message"],
153
- ["list,l", "List the posts in your friends timeline"],
154
- ["list,l USERNAME", "List the posts in the the given user's timeline"],
155
- ["update,u TEXT", "Post a new message"],
156
- ["direct,d @USERNAME TEXT", "Send direct message"],
157
- ["profile,p USERNAME", "Show user's profile"],
158
- ["replies,r", "List the most recent @replies for the authenticating user"],
159
- ["search,s TEXT", "Search for Twitter"],
160
- ["show ID", "Show a single status"]
161
- ]
162
- helps += @@helps
163
- helps += @@new_commands.map {|name, command| command.help}
164
- helps.compact!
165
- puts formatted_help(helps)
166
- end
158
+ register_command(
159
+ :name => :help, :aliases => [:h],
160
+ :exec_proc => lambda {|arg|
161
+ helps = [
162
+ ["help,h", "Print this help message"],
163
+ ["list,l", "List the posts in your friends timeline"],
164
+ ["list,l USERNAME", "List the posts in the the given user's timeline"],
165
+ ["update,u TEXT", "Post a new message"],
166
+ ["direct,d @USERNAME TEXT", "Send direct message"],
167
+ ["profile,p USERNAME", "Show user's profile"],
168
+ ["replies,r", "List the most recent @replies for the authenticating user"],
169
+ ["search,s TEXT", "Search for Twitter"],
170
+ ["show ID", "Show a single status"]
171
+ ]
172
+ helps += @@helps
173
+ helps += @@new_commands.map {|name, command| command.help}
174
+ helps.compact!
175
+ puts formatted_help(helps)
176
+ }
177
+ )
167
178
 
168
- add_command /^eval\s+(.*)$/ do |m, t|
169
- begin
170
- result = eval(m[1]) unless m[1].empty?
171
- puts "=> #{result.inspect}"
172
- rescue SyntaxError => e
173
- puts e
174
- end
175
- end
179
+ register_command(
180
+ :name => :execute,
181
+ :exec_proc => lambda{|arg|
182
+ if arg
183
+ `#{arg}`.each_line do |line|
184
+ unless line.strip.empty?
185
+ Termtter::API.twitter.update_status(line)
186
+ puts "=> #{line}"
187
+ end
188
+ end
189
+ end
190
+ },
191
+ :help => ['execute COMMAND', 'execute the command']
192
+ )
176
193
 
177
194
  add_command /^!(!)?\s*(.*)$/ do |m, t|
195
+ warn '!COMMAND command will be removed. Use command execute instead.'
178
196
  begin
179
197
  result = `#{m[2]}` unless m[2].empty?
180
198
  unless m[1].nil? || result.empty?
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'erb'
4
4
 
5
- configatron.plugins.system_status.set_default(:default_status_proc, proc { Time.now.strftime("%x %X") })
5
+ configatron.plugins.system_status.set_default(:default_status_proc, lambda { Time.now.strftime("%x %X") })
6
6
  configatron.plugins.system_status.set_default(:interval, 1)
7
7
  configatron.plugins.system_status.set_default(:default_color, :on_blue)
8
8
  configatron.plugins.system_status.set_default(:format, '<%= status %>')
@@ -27,7 +27,7 @@ end
27
27
  # show system status on left side.
28
28
  # output public_storage[:system_status] or Time.now.strftime("%x %X") if nil
29
29
  # example config
30
- # configatron.plugins.system_status.default_status_proc = proc { Time.now.strftime("%x %X") }
30
+ # configatron.plugins.system_status.default_status_proc = lambda { Time.now.strftime("%x %X") }
31
31
  # configatron.plugins.system_status.interval = 1
32
32
  # configatron.plugins.system_status.default_color = :on_blue
33
33
  # configatron.plugins.system_status.format = '<%= status %>'
@@ -26,7 +26,7 @@ module Termtter::Client
26
26
 
27
27
  register_command(
28
28
  :name => :update_editor, :aliases => [:ue],
29
- :exec_proc => proc{|arg|
29
+ :exec_proc => lambda{|arg|
30
30
  pause
31
31
  text = input_editor
32
32
  unless text.empty?
@@ -6,7 +6,7 @@ require 'net/http'
6
6
  Termtter::Client.register_hook(
7
7
  :name => :wassr_post,
8
8
  :points => [:modify_arg_for_update],
9
- :exec_proc => proc {|cmd, arg|
9
+ :exec_proc => lambda {|cmd, arg|
10
10
  begin
11
11
  Net::HTTP.version_1_2
12
12
  req = Net::HTTP::Post.new("/statuses/update.json?")
data/lib/plugin/yhara.rb CHANGED
@@ -127,12 +127,12 @@ end
127
127
  module Termtter::Client
128
128
  register_command(
129
129
  :name => :yhara,
130
- :exec_proc => proc{|arg|
130
+ :exec_proc => lambda{|arg|
131
131
  text = "#{'@' if arg[0..0] != '@'}#{arg} #{Yharian::text}"
132
132
  Termtter::API.twitter.update_status(text)
133
133
  puts "=> #{text}"
134
134
  },
135
- :completion_proc => proc {|cmd, args|
135
+ :completion_proc => lambda {|cmd, args|
136
136
  if /(.*)@([^\s]*)$/ =~ args
137
137
  find_user_candidates $2, "#{cmd} #{$1}@%s"
138
138
  end
data/lib/plugin/yonda.rb CHANGED
@@ -1,15 +1,15 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  module Termtter::Client
4
- public_storage[:unread_count] = 0
5
-
6
- add_help 'yonda,y', 'Mark as read'
7
-
8
- add_command %r'^y(?:onda)?\s*$' do |m, t|
9
- public_storage[:unread_count] = 0
10
- print "\033[2J\033[H" # FIXME
11
- call_hooks [], :plugin_yonda_yonda, t
12
- end
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
13
 
14
14
  add_hook do |statuses, event|
15
15
  case event