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,4 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Termtter
3
+ VERSION = '1.0.8'
4
+ end
@@ -0,0 +1,10 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/../spec_helper'
4
+
5
+ describe Termtter::Client, 'when the plugin cool is loaded' do
6
+ it 'should add something about cool' do
7
+ Termtter::Client.should_receive(:register_macro)
8
+ plugin 'cool'
9
+ end
10
+ end
@@ -0,0 +1,19 @@
1
+ # -*- coding: utf-8 -*-
2
+ # vim: set fenc=utf-8
3
+ require File.dirname(__FILE__) + '/../spec_helper'
4
+
5
+ describe Termtter do
6
+ it 'english? method' do
7
+ Termtter::Client.should_receive(:add_filter)
8
+ plugin 'english'
9
+ Termtter::English.english?('This is a pen.').should be_true
10
+ Termtter::English.english?('これはペンです.').should be_false
11
+ Termtter::English.english?('これはpenです.').should be_false
12
+ end
13
+
14
+ it 'apply filter english only update_friends_timeline'
15
+ # NOTE: when below code is evaluated,
16
+ # plugin 'english', :only => [:update_friends_timeline]
17
+ # in update_friends_timeline there are English posts only but in replies there are both Japanese posts and English posts.
18
+ # It's too difficult for me to write that spec, so this spec is pending now. Please write this spec, hey, you, a cool hacker!
19
+ end
@@ -0,0 +1,15 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/../spec_helper'
4
+
5
+ describe Termtter::Client, 'when the plugin fib is loaded' do
6
+ it 'should add command fib' do
7
+ Termtter::Client.should_receive(:register_command).twice
8
+ plugin 'fib'
9
+ end
10
+
11
+ it 'should define fib method' do
12
+ plugin 'fib'
13
+ (0..10).map {|i| fib i }.should == [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
14
+ end
15
+ end
@@ -0,0 +1,18 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/../spec_helper'
4
+
5
+ module Termtter
6
+ describe Client, 'when the filter plugin is loaded' do
7
+ it 'should add command filter, filters and unfilter' do
8
+ Termtter::Client.should_receive(:register_command).exactly(3)
9
+ plugin 'filter'
10
+ end
11
+
12
+ it 'should set public_storage[:filters]' do
13
+ plugin 'filter'
14
+ Client::public_storage.keys.should be_include(:filters)
15
+ end
16
+ end
17
+ end
18
+
@@ -0,0 +1,8 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.dirname(__FILE__) + '/../spec_helper'
3
+ describe Termtter do
4
+ it 'pause plugin' do
5
+ Termtter::Client.should_receive(:pause)
6
+ plugin 'pause'
7
+ end
8
+ end
@@ -0,0 +1,15 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/../spec_helper'
4
+
5
+ describe Termtter::Client, 'when the plugin primes is loaded' do
6
+ it 'should add command primes' do
7
+ Termtter::Client.should_receive(:register_command).once
8
+ plugin 'primes'
9
+ end
10
+
11
+ it 'should define primes method' do
12
+ plugin 'primes'
13
+ (0..10).map {|i| primes i }.should == ["", "", "", "2, 3", "2, 3", "2, 3, 5", "2, 3, 5", "2, 3, 5, 7", "2, 3, 5, 7", "2, 3, 5, 7", "2, 3, 5, 7"]
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/../spec_helper'
4
+
5
+ describe Termtter::Client, 'when the plugin shell is loaded' do
6
+ it 'should add command shell' do
7
+ Termtter::Client.should_receive(:register_command)
8
+ plugin 'shell'
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.dirname(__FILE__) + '/../spec_helper'
3
+ describe Termtter do
4
+ it 'plugin sl' do
5
+ Termtter::Client.should_receive(:register_command).exactly(4).times
6
+ plugin 'sl'
7
+ end
8
+ end
@@ -0,0 +1,4 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/../spec_helper'
4
+
@@ -0,0 +1,23 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/../spec_helper'
4
+ plugin 'standard_plugins'
5
+
6
+ module Termtter
7
+ describe Client do
8
+ it 'shold return registerd commands' do
9
+ [
10
+ [:update, [:u]], [:direct, [:d]],
11
+ [:profile, [:p]], [:list, [:l]],
12
+ [:search, [:s]], [:replies, [:r]],
13
+ [:show, [ ]], [:shows, [ ]],
14
+ [:limit, [:lm]], [:pause, [ ]],
15
+ [:resume, [ ]], [:exit, [:e]],
16
+ ].each do |name, aliases|
17
+ command = Client.get_command(name)
18
+ command.name.should == name
19
+ command.aliases.should == aliases
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,12 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/../../spec_helper'
4
+ require File.dirname(__FILE__) + '/../../../lib/plugins/storage/DB'
5
+
6
+ module Termtter::Storage
7
+ describe DB do
8
+ before do
9
+ @db = DB.instance.db
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,24 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/../../spec_helper'
4
+ require File.dirname(__FILE__) + '/../../../lib/plugins/storage/status'
5
+
6
+ module Termtter::Storage
7
+ describe Status do
8
+ before do
9
+ @status = Status.new
10
+ end
11
+ end
12
+
13
+ describe Status do
14
+ it 'self.insert should not return false' do
15
+ Status.insert(
16
+ :post_id => 1,
17
+ :created_at => 12345,
18
+ :in_reply_to_status_id => -1,
19
+ :in_reply_to_user_id => -1,
20
+ :text => 'bomb',
21
+ :user_id => 1).should_not be_false
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,7 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
4
+ ARGV.delete '-c'
5
+ require 'termtter'
6
+
7
+
@@ -0,0 +1,255 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + '/../spec_helper'
4
+
5
+ module Termtter
6
+
7
+ describe Client do
8
+
9
+ it 'should take command' do
10
+ Client.setup_logger
11
+ command = Command.new(:name => :test)
12
+ Client.register_command(command)
13
+ Client.get_command(:test).should == command
14
+ end
15
+
16
+ it 'should take command as Hash' do
17
+ Client.register_command(:name => :test)
18
+ Client.get_command(:test).name.should == :test
19
+ end
20
+
21
+ it 'should call command' do
22
+ command_arg = nil
23
+ command = Command.new(:name => :test, :exec_proc => lambda {|arg| command_arg = arg})
24
+ Client.register_command(command)
25
+ command_arg.should == nil
26
+
27
+ [
28
+ ['test', ''],
29
+ ['test foo bar', 'foo bar'],
30
+ ['test foo bar ', 'foo bar'],
31
+ ['test foo bar ', 'foo bar'],
32
+ ].each do |input, args|
33
+ Client.call_commands(input, nil)
34
+ command_arg.should == args
35
+ end
36
+ end
37
+
38
+ it 'should take new_hook' do
39
+ hook = Hook.new(:name => :test)
40
+ Client.register_hook(hook)
41
+ Client.get_hook(:test).should == hook
42
+ end
43
+
44
+ it 'should take hook as Hash' do
45
+ Client.register_hook(:name => :test)
46
+ Client.get_hook(:test).name.should == :test
47
+ end
48
+
49
+ it 'should call new_hook' do
50
+ hook_called = false
51
+ Client.register_hook(:name => :test1, :points => [:point1], :exec_proc => lambda {hook_called = true})
52
+ hook_called.should == false
53
+ Client.call_hooks(:point1)
54
+ hook_called.should == true
55
+ end
56
+
57
+ it 'should call new_hook with args' do
58
+ arg1 = nil
59
+ arg2 = nil
60
+ Client.register_hook(:name => :test1, :points => [:point1], :exec_proc => lambda {|a1, a2| arg1 = a1; arg2 = a2})
61
+ arg1.should == nil
62
+ arg2.should == nil
63
+ Client.call_hooks(:point1, 'foo', 'bar')
64
+ arg1.should == 'foo'
65
+ arg2.should == 'bar'
66
+ end
67
+
68
+ it 'should return hooks when call get_hooks' do
69
+ hook1 = Client.register_hook(:name => :test1, :points => [:point1])
70
+ hook2 = Client.register_hook(:name => :test2, :points => [:point1])
71
+ hook3 = Client.register_hook(:name => :test3, :points => [:point2])
72
+
73
+ hooks = Client.get_hooks(:point1)
74
+ hooks.size.should == 2
75
+ hooks.include?(hook1).should == true
76
+ hooks.include?(hook2).should == true
77
+ hooks.include?(hook3).should == false
78
+ end
79
+
80
+ it 'should call decide_arg hooks' do
81
+ input_command = nil
82
+ input_arg = nil
83
+ decided_arg = nil
84
+ Client.register_hook( :name => :test1,
85
+ :points => [:modify_arg_for_update],
86
+ :exec_proc => lambda {|cmd, arg| input_command = cmd; input_arg = arg; arg.upcase})
87
+ Client.register_hook( :name => :test2,
88
+ :points => [:pre_exec_update],
89
+ :exec_proc => lambda {|cmd, arg| decided_arg = arg})
90
+ Client.register_command(:name => :update, :aliases => [:u])
91
+
92
+ input_command.should == nil
93
+ input_arg.should == nil
94
+ decided_arg.should == nil
95
+ Client.call_commands('u foo')
96
+ input_command.should == 'u'
97
+ input_arg.should == 'foo'
98
+ decided_arg.should == 'FOO'
99
+ end
100
+
101
+ it 'should call pre_exec hooks' do
102
+ hook_called = false
103
+ Client.register_hook( :name => :test,
104
+ :points => [:pre_exec_update],
105
+ :exec_proc => lambda {|cmd, arg| hook_called = true})
106
+ Client.register_command(:name => :update)
107
+
108
+ hook_called.should == false
109
+ Client.call_commands('update foo')
110
+ hook_called.should == true
111
+ end
112
+
113
+ it 'should able to cancel exec command' do
114
+ command_called = false
115
+ Client.register_hook( :name => :test,
116
+ :points => [:pre_exec_update],
117
+ :exec_proc => lambda {|cmd, arg| false})
118
+ Client.register_command(:name => :update, :exec_proc => lambda {|cmd, arg| command_called = true})
119
+
120
+ command_called.should == false
121
+ Client.call_commands('update foo')
122
+ command_called.should == false
123
+ end
124
+
125
+ it 'should call post_exec hooks' do
126
+ command_result = nil
127
+ Client.register_hook( :name => :test,
128
+ :points => [:post_exec_update],
129
+ :exec_proc => lambda {|cmd, arg, result| command_result = result })
130
+ Client.register_command(:name => :update, :exec_proc => lambda {|arg| 'foo'})
131
+
132
+ command_result.should == nil
133
+ Client.call_commands('update foo')
134
+ command_result.should == 'foo'
135
+ end
136
+
137
+ it 'should call exit hooks' do
138
+ hook_called = false
139
+ Client.register_hook(
140
+ :name => :test,
141
+ :points => [:exit],
142
+ :exec_proc => lambda { hook_called = true }
143
+ )
144
+
145
+ hook_called.should == false
146
+ Client.should_receive(:puts)
147
+ Client.exit
148
+ hook_called.should == true
149
+ end
150
+
151
+ it 'should call plural hooks' do
152
+ hook1_called = false
153
+ hook2_called = false
154
+ Client.register_hook(:name => :hook1, :points => [:exit], :exec_proc => lambda {hook1_called = true})
155
+ Client.register_hook(:name => :hook2, :points => [:exit], :exec_proc => lambda {hook2_called = true})
156
+
157
+ hook1_called.should == false
158
+ hook2_called.should == false
159
+ Client.should_receive(:puts)
160
+ Client.exit
161
+ hook1_called.should == true
162
+ hook2_called.should == true
163
+ end
164
+
165
+ it 'should be able to override hooks' do
166
+ hook1_called = false
167
+ hook2_called = false
168
+ Client.register_hook(:name => :hook, :points => [:exit], :exec_proc => lambda {hook1_called = true})
169
+ Client.register_hook(:name => :hook, :points => [:exit], :exec_proc => lambda {hook2_called = true})
170
+
171
+ hook1_called.should == false
172
+ hook2_called.should == false
173
+ Client.should_receive(:puts)
174
+ Client.exit
175
+ hook1_called.should == false
176
+ hook2_called.should == true
177
+ end
178
+
179
+ it 'run' do
180
+ Client.should_receive(:load_default_plugins)
181
+ Client.should_receive(:load_config)
182
+ Termtter::API.should_receive(:setup)
183
+ Client.should_receive(:post_config_load)
184
+ Client.should_receive(:call_hooks)
185
+ Client.should_receive(:setup_update_timeline_task)
186
+ Client.should_receive(:start_input_thread)
187
+ Client.run
188
+ end
189
+
190
+ it 'load_config'
191
+
192
+ it 'should do nothing when ~/.termtter is directory' do
193
+ File.should_receive(:ftype).and_return('directory')
194
+ Client.should_not_receive(:move_legacy_config_file)
195
+ Client.legacy_config_support
196
+ end
197
+
198
+ it 'should do "move_legacy_config_file" when ~/.termtter is file' do
199
+ File.should_receive(:ftype).and_return('file')
200
+ Client.should_receive(:move_legacy_config_file)
201
+ Client.legacy_config_support
202
+ end
203
+
204
+ it 'should move legacy config file' do
205
+ FileUtils.should_receive(:mv).twice
206
+ Dir.should_receive(:mkdir)
207
+ Client.move_legacy_config_file
208
+ end
209
+
210
+ it 'should handle error' do
211
+ logger = Client.instance_eval{@logger}
212
+ logger.should_receive(:error).with("StandardError: error")
213
+ Client.handle_error StandardError.new('error')
214
+ end
215
+
216
+ it 'should cancel command by hook' do
217
+ command = Command.new(:name => :test)
218
+ Client.register_command(command)
219
+ Client.register_hook(
220
+ :name => :test,
221
+ :point => /^pre_exec/,
222
+ :exec => lambda{|*arg|
223
+ raise Termtter::CommandCanceled
224
+ }
225
+ )
226
+ command.should_not_receive(:call)
227
+ Client.call_commands('test')
228
+ end
229
+
230
+ it 'should get default help' do
231
+ $stdout, old_stdout = StringIO.new, $stdout # FIXME That suspends any debug informations!
232
+ help_command = Client.get_command(:help)
233
+ help_command.should_not be_nil
234
+ help_command.call
235
+ $stdout.string.should_not == '' # 何がか出力されていること
236
+ $stdout = old_stdout
237
+ end
238
+
239
+ it 'should get an added help' do
240
+ Client.register_command(
241
+ :name => :foo,
242
+ :help => [
243
+ ['foo USER', 'foo to USER'],
244
+ ['foo list', 'list foo'],
245
+ ]
246
+ )
247
+ $stdout, old_stdout = StringIO.new, $stdout # FIXME That suspends any debug informations!
248
+ help_command = Client.get_command(:help)
249
+ help_command.should_not be_nil
250
+ help_command.call
251
+ $stdout.string.should match(/foo USER/)
252
+ $stdout.string.should match(/foo list/)
253
+ end
254
+ end
255
+ end