jugyo-termtter 1.0.8 → 1.1.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.
@@ -3,7 +3,8 @@
3
3
  URL_SHORTTERS = [
4
4
  { :host => "tinyurl.com", :pattern => %r'(http://tinyurl\.com(/[\w/]+))' },
5
5
  { :host => "is.gd", :pattern => %r'(http://is\.gd(/[\w/]+))' },
6
- # { :host => "bit.ly", :pattern => %r'(http://bit\.ly(/[\w/]+))' }
6
+ { :host => "bit.ly", :pattern => %r'(http://bit\.ly(/[\w/]+))' },
7
+ { :host => "ff.im", :pattern => %r'(http://ff\.im(/[\w/]+))'},
7
8
  ]
8
9
 
9
10
  module Termtter::Client
@@ -27,7 +28,7 @@ def expand_url(host, path)
27
28
  config.proxy.user_name,
28
29
  config.proxy.password)
29
30
  end
30
- res = http_class.new('tinyurl.com').head(path)
31
+ res = http_class.new(host).head(path)
31
32
  return nil unless res.code == "301" or res.code == "302"
32
33
  res['Location']
33
34
  end
@@ -0,0 +1,12 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module Termtter::Client
4
+ register_command(
5
+ :name => :search_url, :aliases => [],
6
+ :exec_proc => lambda{|arg|
7
+ statuses = public_storage[:log].select {|s| s.text =~ %r!https?://!}
8
+ output(statuses, :search)
9
+ },
10
+ :help => ['search_url', 'Search log for URL']
11
+ )
12
+ end
@@ -334,7 +334,6 @@ module Termtter::Client
334
334
 
335
335
  public_storage[:users] ||= Set.new
336
336
  public_storage[:status_ids] ||= Set.new
337
- public_storage[:last_status_id] ||= Hash.new
338
337
 
339
338
  register_hook(
340
339
  :name => :for_completion,
@@ -345,7 +344,6 @@ module Termtter::Client
345
344
  public_storage[:users] += s.text.scan(/@([a-zA-Z_0-9]*)/).flatten
346
345
  public_storage[:status_ids].add(s.id)
347
346
  public_storage[:status_ids].add(s.in_reply_to_status_id) if s.in_reply_to_status_id
348
- public_storage[:last_status_id].store(s.user.screen_name, s.id)
349
347
  end
350
348
  }
351
349
  )
@@ -427,7 +425,8 @@ module Termtter::Client
427
425
  when /(\d+)/
428
426
  find_status_ids(arg).map{|id| "#{cmd} #{id}"}
429
427
  end
430
- }
428
+ },
429
+ :help => ["reply,re @USERNAME or STATUS_ID", "Send a reply"]
431
430
  )
432
431
 
433
432
  register_command(
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'termcolor'
4
4
  require 'erb'
5
+ require 'tempfile'
5
6
 
6
7
  config.plugins.stdout.set_default(
7
8
  :colors,
@@ -0,0 +1,32 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Termtter::Client
3
+ register_command(
4
+ :name => :_update_timeline,
5
+ :exec_proc => lambda {|arg|
6
+ begin
7
+ args = @since_id ? [{:since_id => @since_id}] : []
8
+ statuses = Termtter::API.twitter.friends_timeline(*args)
9
+ unless statuses.empty?
10
+ print "\e[1K\e[0G" unless win?
11
+ @since_id = statuses[0].id
12
+ output(statuses, :update_friends_timeline)
13
+ Readline.refresh_line
14
+ end
15
+ rescue OpenURI::HTTPError => e
16
+ if e.message == '401 Unauthorized'
17
+ puts 'Could not login'
18
+ puts 'plese check your account settings'
19
+ exit!
20
+ end
21
+ rescue => e
22
+ handle_error(e)
23
+ end
24
+ }
25
+ )
26
+
27
+ add_task(:name => :update_timeline, :interval => config.update_interval, :after => config.update_interval) do
28
+ call_commands('_update_timeline')
29
+ end
30
+
31
+ call_commands('_update_timeline')
32
+ end
@@ -239,39 +239,6 @@ module Termtter
239
239
  end
240
240
  end
241
241
 
242
- # TODO: Make pluggable
243
- def setup_update_timeline_task()
244
- register_command(
245
- :name => :_update_timeline,
246
- :exec_proc => lambda {|arg|
247
- begin
248
- args = @since_id ? [{:since_id => @since_id}] : []
249
- statuses = Termtter::API.twitter.friends_timeline(*args)
250
- unless statuses.empty?
251
- print "\e[1K\e[0G" unless win?
252
- @since_id = statuses[0].id
253
- output(statuses, :update_friends_timeline)
254
- Readline.refresh_line
255
- end
256
- rescue OpenURI::HTTPError => e
257
- if e.message == '401 Unauthorized'
258
- puts 'Could not login'
259
- puts 'plese check your account settings'
260
- exit!
261
- end
262
- rescue => e
263
- handle_error(e)
264
- end
265
- }
266
- )
267
-
268
- add_task(:name => :update_timeline, :interval => config.update_interval, :after => config.update_interval) do
269
- call_commands('_update_timeline')
270
- end
271
-
272
- call_commands('_update_timeline')
273
- end
274
-
275
242
  def trap_setting()
276
243
  begin
277
244
  stty_save = `stty -g`.chomp
@@ -343,12 +310,22 @@ module Termtter
343
310
  setup_logger()
344
311
  post_config_load()
345
312
 
346
- call_hooks(:initialize)
313
+ config.system.eval_scripts.each do |script|
314
+ begin
315
+ eval script
316
+ rescue Exception => e
317
+ handle_error(e)
318
+ end
319
+ end
347
320
 
348
- setup_update_timeline_task()
321
+ config.system.run_commands.each { |cmd| call_commands(cmd) }
349
322
 
350
- @task_manager.run()
351
- start_input_thread()
323
+ unless config.system.cmd_mode
324
+ call_hooks(:initialize)
325
+ plugin('update_timeline')
326
+ @task_manager.run()
327
+ start_input_thread()
328
+ end
352
329
  end
353
330
 
354
331
  def handle_error(e)
@@ -1,14 +1,33 @@
1
1
  OptionParser.new { |opt|
2
- opt.on('-f', '--file config_file', 'Set path to configfile') do |val|
2
+ opt.program_name = 'Termtter'
3
+
4
+ opt.on('-f', '--config-file file', 'Set path to configfile') do |val|
3
5
  config.system.__assign__(:conf_file, val)
4
6
  end
7
+
5
8
  opt.on('-t', '--termtter-directory directory', 'Set termtter directory') do |val|
6
9
  config.system.__assign__(:conf_dir, val)
7
10
  end
11
+
8
12
  opt.on('-d', '--devel', 'Start in developer mode') do |flg|
9
13
  config.system.__assign__(:devel, true) if flg
10
14
  end
11
15
 
12
- Version = Termtter::VERSION
16
+ config.system.cmd_mode = false
17
+ opt.on('-c', '--command-mode', 'Run as command mode') do |flg|
18
+ config.system.cmd_mode = flg
19
+ end
20
+
21
+ config.system.run_commands = []
22
+ opt.on('-r', '--run-command command', 'Run command') do |cmd|
23
+ config.system.run_commands << cmd
24
+ end
25
+
26
+ config.system.eval_scripts = []
27
+ opt.on('-e', '--eval-script script', 'Eval script') do |script|
28
+ config.system.eval_scripts << script
29
+ end
30
+
31
+ opt.version = Termtter::VERSION
13
32
  opt.parse!(ARGV)
14
33
  }
@@ -1,4 +1,4 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  module Termtter
3
- VERSION = '1.0.8'
3
+ VERSION = '1.1.0'
4
4
  end
@@ -181,8 +181,6 @@ module Termtter
181
181
  Client.should_receive(:load_config)
182
182
  Termtter::API.should_receive(:setup)
183
183
  Client.should_receive(:post_config_load)
184
- Client.should_receive(:call_hooks)
185
- Client.should_receive(:setup_update_timeline_task)
186
184
  Client.should_receive(:start_input_thread)
187
185
  Client.run
188
186
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jugyo-termtter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - jugyo
@@ -120,6 +120,7 @@ files:
120
120
  - lib/plugins/scrape.rb
121
121
  - lib/plugins/screen-notify.rb
122
122
  - lib/plugins/screen.rb
123
+ - lib/plugins/search_url.rb
123
124
  - lib/plugins/shell.rb
124
125
  - lib/plugins/sl.rb
125
126
  - lib/plugins/spam.rb
@@ -136,6 +137,7 @@ files:
136
137
  - lib/plugins/translation.rb
137
138
  - lib/plugins/typable_id.rb
138
139
  - lib/plugins/update_editor.rb
140
+ - lib/plugins/update_timeline.rb
139
141
  - lib/plugins/uri-open.rb
140
142
  - lib/plugins/wassr_post.rb
141
143
  - lib/plugins/yhara.rb