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
data/lib/plugin/group.rb CHANGED
@@ -1,4 +1,4 @@
1
- configatron.set_default('plugins.group.groups', {})
1
+ # -*- coding: utf-8 -*-
2
2
 
3
3
  module Termtter
4
4
  class Status
@@ -13,41 +13,38 @@ module Termtter
13
13
  end
14
14
 
15
15
  module Termtter::Client
16
- if public_storage[:log]
17
- add_help 'group,g GROUPNAME', 'Filter by group members'
16
+ configatron.plugins.group.
17
+ set_default(:groups, {})
18
18
 
19
- add_command /^(?:group|g)\s*$/ do |m, t|
20
- configatron.plugins.group.groups.each_pair do |key, value|
21
- puts "#{key}: #{value.join(',')}"
22
- end
23
- end
24
-
25
- add_command /^(?:group|g)\s+(.+)/ do |m, t|
26
- group_name = m[1].to_sym
27
- group = configatron.plugins.group.groups[group_name]
28
- statuses = group ? public_storage[:log].select { |s|
29
- group.include?(s.user_screen_name)
30
- } : []
31
- call_hooks(statuses, :search, t)
32
- end
33
-
34
- def self.find_group_candidates(a, b)
35
- configatron.plugins.group.groups.keys.map {|k| k.to_s}.
36
- grep(/^#{Regexp.quote a}/).
37
- map {|u| b % u }
38
- end
39
-
40
- add_completion do |input|
41
- case input
42
- when /^(group|g)\s+(.+)/
43
- find_group_candidates($2, "#{$1} %s")
44
- when /^(group|g)\s+$/
45
- configatron.plugins.group.groups.keys
46
- else
47
- %w(group).grep(/^#{Regexp.quote input}/)
48
- end
49
- end
19
+ def self.find_group_candidates(a, b)
20
+ configatron.plugins.group.groups.keys.map {|k| k.to_s}.
21
+ grep(/^#{Regexp.quote a}/).
22
+ map {|u| b % u }
50
23
  end
24
+
25
+ register_command(
26
+ :name => :group,
27
+ :aliases => [:g],
28
+ :exec_proc => proc {|arg|
29
+ unless arg.empty?
30
+ group_name = arg.to_sym
31
+ group = configatron.plugins.group.groups[group_name]
32
+ statuses = group ? public_storage[:log].select { |s|
33
+ group.include?(s.user_screen_name)
34
+ } : []
35
+ call_hooks(statuses, :search)
36
+ else
37
+ configatron.plugins.group.groups.each_pair do |key, value|
38
+ puts "#{key}: #{value.join(',')}"
39
+ end
40
+ end
41
+ },
42
+ :completion_proc => proc {|cmd, arg|
43
+ find_group_candidates arg, "#{cmd} %s"
44
+ },
45
+ :help => ['group,g GROUPNAME', 'Filter by group members']
46
+ )
47
+
51
48
  end
52
49
 
53
50
  # group.rb
@@ -56,3 +53,4 @@ end
56
53
  # :rits => %w(hakobe isano hitode909)
57
54
  # }
58
55
  # NOTE: group.rb needs plugin/log
56
+
data/lib/plugin/growl.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  require 'tmpdir'
2
4
  require 'open-uri'
3
5
  require 'uri'
@@ -35,7 +37,7 @@ Thread.new do
35
37
  begin
36
38
  if s = queue.pop
37
39
  unless growl
38
- arg = ['growlnotify', s.user_screen_name, '-m', s.text.gsub("\n",''), '-n', 'termtter']
40
+ arg = ['growlnotify', s.user_screen_name, '-m', s.text.gsub("\n",''), '-n', 'termtter', '-H', 'localhost']
39
41
  #icon_path = get_icon_path(s)
40
42
  #arg += ['--image', icon_path] if icon_path
41
43
  system *arg
data/lib/plugin/hatebu.rb CHANGED
@@ -1,51 +1,53 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  require 'rubygems'
2
4
  require 'atomutil'
3
5
 
4
6
  module Termtter::Client
5
- add_help 'hatebu ID', 'Hatena bookmark a status'
6
-
7
- add_command %r'^hatebu\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
- auth = auth = Atompub::Auth::Wsse.new({
17
- :username => configatron.plugins.hatebu.username,
18
- :password => configatron.plugins.hatebu.password,
19
- })
20
- link = Atom::Link.new({
21
- :href => "http://twitter.com/#{status.user_screen_name}/status/#{status.id}",
22
- :rel => 'related',
23
- :type => 'text/html',
24
- })
25
- entry = Atom::Entry.new({
26
- :link => link,
27
- :title => 'dummy',
28
- :summary => comment,
29
- })
30
- req = Net::HTTP::Post.new 'http://b.hatena.ne.jp/atom/post'
31
- req['User-Agent'] = 'Mozilla/5.0'
32
- req['Content-Type'] = 'application/atom+xml'
33
- req['Slug'] = 'termtter'
34
- req.body = entry.to_s
35
- auth.authorize(req)
36
- Net::HTTP.start('b.hatena.ne.jp', 80) do |http|
37
- res = http.request(req)
38
- end
39
- end
40
-
41
- add_completion do |input|
42
- case input
43
- when /^(hatebu)\s+(\d*)$/
44
- find_status_id_candidates $2, "#{$1} %s"
45
- else
46
- %w(hatebu).grep(/^#{Regexp.quote input}/)
47
- end
48
- end
7
+ register_command(
8
+ :name => :hatebu, :aliases => [],
9
+ :exec_proc => proc {|arg|
10
+ if arg =~ /^(\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
+ auth = auth = Atompub::Auth::Wsse.new({
20
+ :username => configatron.plugins.hatebu.username,
21
+ :password => configatron.plugins.hatebu.password,
22
+ })
23
+ link = Atom::Link.new({
24
+ :href => "http://twitter.com/#{status.user_screen_name}/status/#{status.id}",
25
+ :rel => 'related',
26
+ :type => 'text/html',
27
+ })
28
+ entry = Atom::Entry.new({
29
+ :link => link,
30
+ :title => 'dummy',
31
+ :summary => comment,
32
+ })
33
+ req = Net::HTTP::Post.new 'http://b.hatena.ne.jp/atom/post'
34
+ req['User-Agent'] = 'Mozilla/5.0'
35
+ req['Content-Type'] = 'application/atom+xml'
36
+ req['Slug'] = 'termtter'
37
+ req.body = entry.to_s
38
+ auth.authorize(req)
39
+ Net::HTTP.start('b.hatena.ne.jp', 80) do |http|
40
+ res = http.request(req)
41
+ end
42
+ end
43
+ },
44
+ :completion_proc => proc {|cmd, args|
45
+ if args =~ /^(\d*)$/
46
+ find_status_id_candidates $1, "#{cmd} %s"
47
+ end
48
+ },
49
+ :help => ['hatebu ID', 'Hatena bookmark a status']
50
+ )
49
51
  end
50
52
 
51
53
  # hatebu.rb
@@ -1,3 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  require 'zlib'
2
4
 
3
5
  configatron.plugins.history.
@@ -6,6 +8,10 @@ configatron.plugins.history.
6
8
  set_default(:keys, [:log, :users, :status_ids])
7
9
  configatron.plugins.history.
8
10
  set_default(:max_of_history, 100)
11
+ configatron.plugins.history.
12
+ set_default(:enable_autosave, true)
13
+ configatron.plugins.history.
14
+ set_default(:autosave_interval, 3600)
9
15
 
10
16
  module Termtter::Client
11
17
  def self.load_history
@@ -15,15 +21,13 @@ module Termtter::Client
15
21
  if File.exist?(filename)
16
22
  begin
17
23
  history = Marshal.load Zlib::Inflate.inflate(File.read(filename))
18
- rescue Zlib::DataError
19
- history = Marshal.load File.read(filename)
20
24
  end
21
25
  if history
22
26
  keys.each do |key|
23
27
  public_storage[key] = history[key] if history[key]
24
28
  end
25
29
  Readline::HISTORY.push *history[:history] if history[:history]
26
- puts "history loaded(#{File.size(filename)}bytes)"
30
+ puts "history loaded(#{File.size(filename)/1000}kb)"
27
31
  end
28
32
  end
29
33
  end
@@ -44,7 +48,7 @@ module Termtter::Client
44
48
  File.open(filename, 'w') do |f|
45
49
  f.write Zlib::Deflate.deflate(Marshal.dump(history))
46
50
  end
47
- puts "history saved(#{File.size(filename)}bytes)"
51
+ puts "history saved(#{File.size(filename)/1000}kb)"
48
52
  end
49
53
 
50
54
  add_hook do |statuses, event|
@@ -55,6 +59,14 @@ module Termtter::Client
55
59
  save_history
56
60
  end
57
61
  end
62
+
63
+ if configatron.plugins.history.enable_autosave
64
+ Termtter::Client.add_task(:interval => configatron.plugins.history.autosave_interval,
65
+ :after => configatron.plugins.history.autosave_interval) do
66
+ save_history
67
+ end
68
+ end
69
+
58
70
  end
59
71
 
60
72
  # history.rb
@@ -1,3 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  configatron.set_default('plugins.keyword.keywords', [])
2
4
 
3
5
  module Termtter
data/lib/plugin/log.rb CHANGED
@@ -1,12 +1,10 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  module Termtter::Client
2
4
  public_storage[:log] = []
3
5
  configatron.plugins.log.set_default('max_size', 1/0.0)
4
6
  configatron.plugins.log.set_default('print_max_size', 30)
5
7
 
6
- add_help '/WORD', 'Search log for WORD'
7
- add_help 'log', 'Show local log'
8
- add_help 'log (USER(S)) (MAX)', 'Show local log of the user(s)'
9
-
10
8
  add_hook do |statuses, event|
11
9
  case event
12
10
  when :pre_filter
@@ -19,37 +17,39 @@ module Termtter::Client
19
17
  end
20
18
  end
21
19
 
20
+ register_command(
21
+ :name => :log,
22
+ :exec_proc => proc{|arg|
23
+ if arg.empty?
24
+ # log
25
+ statuses = public_storage[:log]
26
+ print_max = configatron.plugins.log.print_max_size
27
+ print_max = 0 if statuses.size < print_max
28
+ call_hooks(statuses[-print_max..-1], :search)
29
+ else
30
+ # log (user) (max)
31
+ vars = arg.split(' ')
32
+ print_max = vars.last =~ /^\d+$/ ? vars.pop.to_i : configatron.plugins.log.print_max_size
33
+ id = vars
34
+ statuses = id.first ? public_storage[:log].select{ |s| id.include? s.user_screen_name} : public_storage[:log]
35
+ print_max = 0 if statuses.size < print_max
36
+ call_hooks(statuses[-print_max..-1], :search)
37
+ end
38
+ },
39
+ :completion_proc => proc {|cmd, arg|
40
+ find_user_candidates arg, "#{cmd} %s"
41
+ },
42
+ :help => [ 'log (USER(S)) (MAX)', 'Show local log of the user(s)']
43
+ )
44
+
45
+ # These are old code we must fix.
46
+
47
+ add_help 'log', 'Show local log'
48
+
49
+ add_help '/WORD', 'Search log for WORD'
22
50
  add_command %r'^/(.+)' do |m, t|
23
51
  pat = Regexp.new(m[1])
24
52
  statuses = public_storage[:log].select { |s| s.text =~ pat }
25
53
  call_hooks(statuses, :search, t)
26
54
  end
27
-
28
- # log
29
- add_command /^(log)\s*$/ do |m, t|
30
- statuses = public_storage[:log]
31
- print_max = configatron.plugins.log.print_max_size
32
- print_max = 0 if statuses.size < print_max
33
- call_hooks(statuses[-print_max..-1], :search, t)
34
- end
35
-
36
- # log (user) (max)
37
- add_command /^(log)\s+(.+)\s*/ do |m, t|
38
- vars = m[2].split(' ')
39
- print_max = vars.last =~ /^\d+$/ ? vars.pop.to_i : configatron.plugins.log.print_max_size
40
- id = vars
41
- statuses = id.first ? public_storage[:log].select{ |s| id.include? s.user_screen_name} : public_storage[:log]
42
- print_max = 0 if statuses.size < print_max
43
- call_hooks(statuses[-print_max..-1], :search, t)
44
- end
45
-
46
- add_completion do |input|
47
- case input
48
- when /^(log)\s+(.*)/
49
- find_user_candidates $2, "#{$1} %s"
50
- else
51
- %w[ log ].grep(/^#{Regexp.quote input}/)
52
- end
53
- end
54
-
55
55
  end
@@ -0,0 +1,7 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ Termtter::Client.register_hook(
4
+ :name => :modify_arg_hook_sample,
5
+ :points => [:modify_arg_for_update],
6
+ :exec_proc => proc {|cmd, arg| arg + '\(^o^)/'}
7
+ )
@@ -1,3 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  raise 'msagent.rb runs only in windows' if RUBY_PLATFORM.downcase !~ /mswin(?!ce)|mingw|bccwin/
2
4
  require 'win32ole'
3
5
  require 'kconv'
@@ -1,3 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  module Termtter::Client
2
4
  add_help 'multi_reply, mp TEXT', 'reply to multi user'
3
5
  add_command /^(multi_reply|mr)\s+(.*)/ do |m, t|
@@ -1,3 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  Termtter::Client.add_hook do |statuses, event|
2
4
  if !statuses.empty? && event == :update_friends_timeline
3
5
  max = 10
data/lib/plugin/otsune.rb CHANGED
@@ -1,17 +1,21 @@
1
- module Termtter::Client
2
- add_help 'otsune {SCREENNAME}', 'update "@{SCREENNAME} 頭蓋骨の中身がお気の毒です"'
3
- add_help 'otsnue {SCREENNAME}', 'update "@{SCREENNAME} 頭が気の毒です"'
1
+ # -*- coding: utf-8 -*-
4
2
 
5
- add_macro /^otsune ([^\s]*)/, "update @%s 頭蓋骨の中身がお気の毒です."
6
- add_macro /^otsnue ([^\s]*)/, "update @%s 頭が気の毒です."
3
+ module Termtter::Client
4
+ register_macro(:otsune, "update @%s 頭蓋骨の中身がお気の毒です.",
5
+ :help => ['otsune {SCREENNAME}', 'update "@{SCREENNAME} 頭蓋骨の中身がお気の毒です"'],
6
+ :completion_proc => proc {|cmd, args|
7
+ find_user_candidates args, "#{cmd} %s"
8
+ }
9
+ )
10
+ end
7
11
 
8
- add_completion do |input|
9
- case input
10
- when /^(otsune|otsnue) ([^\s]*)/
11
- find_user_candidates $2, "#{$1} %s"
12
- else
13
- %w[otsune otsnue].grep(/^#{Regexp.quote input}/)
14
- end
15
- end
12
+ module Termtter::Client
13
+ register_macro(:otsnue, "update @%s 頭蓋骨の中身がお気の毒です.",
14
+ :help => ['otsnue {SCREENNAME}', 'update @%s 頭が気の毒です.'],
15
+ :completion_proc => proc {|cmd, args|
16
+ find_user_candidates args, "#{cmd} %s"
17
+ }
18
+ )
16
19
  end
20
+
17
21
  # vim: fenc=utf8
@@ -1,3 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
 
2
4
  module Termtter::Client
3
5
  configatron.plugins.outputz.set_default(:uri, 'termtter://twitter.com/status/update')
@@ -0,0 +1,3 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ Termtter::Client.pause
data/lib/plugin/plugin.rb CHANGED
@@ -1,40 +1,45 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  module Termtter::Client
2
4
 
3
5
  public_storage[:plugins] = Dir["#{File.dirname(__FILE__)}/*.rb"].map do |f|
4
6
  f.match(%r|([^/]+).rb$|)[1]
5
7
  end
6
8
 
7
- add_help 'plugin FILE', 'Load a plugin'
8
- add_command /^plugin\s+(.*)/ do |m, t|
9
- begin
10
- result = plugin m[1].strip
11
- rescue LoadError
12
- ensure
13
- puts "=> #{result.inspect}"
14
- end
15
- end
9
+ register_command(
10
+ :name => :plugin, :aliases => [],
11
+ :exec_proc => proc {|arg|
12
+ begin
13
+ result = plugin arg.strip
14
+ rescue LoadError
15
+ ensure
16
+ puts "=> #{result.inspect}"
17
+ end
18
+ },
19
+ :completion_proc => proc {|cmd, args|
20
+ find_user_candidates args, "#{cmd} %s"
21
+ unless args.empty?
22
+ find_plugin_candidates args, "#{cmd} %s"
23
+ else
24
+ public_storage[:plugins].sort
25
+ end
26
+ },
27
+ :help => ['plugin FILE', 'Load a plugin']
28
+ )
16
29
 
17
- add_help 'plugins', 'Show list of plugins'
18
- add_command /^plugins$/ do |m, t|
19
- puts public_storage[:plugins].sort.join("\n")
20
- end
30
+ register_command(
31
+ :name => :plugins, :aliases => [],
32
+ :exec_proc => proc {|arg|
33
+ puts public_storage[:plugins].sort.join("\n")
34
+ },
35
+ :help => ['plugins', 'Show list of plugins']
36
+ )
21
37
 
22
38
  def self.find_plugin_candidates(a, b)
23
39
  public_storage[:plugins].
24
40
  grep(/^#{Regexp.quote a}/i).
25
41
  map {|u| b % u }
26
42
  end
27
-
28
- add_completion do |input|
29
- case input
30
- when /^(plugin)\s+(.+)/
31
- find_plugin_candidates $2, "#{$1} %s"
32
- when /^(plugin)\s+$/
33
- public_storage[:plugins].sort
34
- else
35
- %w[ plugin plugins ].grep(/^#{Regexp.quote input}/)
36
- end
37
- end
38
43
  end
39
44
 
40
45
  # plugin.rb