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/Manifest.txt CHANGED
@@ -3,6 +3,7 @@ Manifest.txt
3
3
  PostInstall.txt
4
4
  README.rdoc
5
5
  Rakefile
6
+ bin/kill_termtter
6
7
  bin/termtter
7
8
  lib/filter/en2ja.rb
8
9
  lib/filter/english.rb
@@ -12,6 +13,7 @@ lib/filter/ignore.rb
12
13
  lib/filter/reply.rb
13
14
  lib/filter/reverse.rb
14
15
  lib/filter/yhara.rb
16
+ lib/plugin/april_fool.rb
15
17
  lib/plugin/bomb.rb
16
18
  lib/plugin/confirm.rb
17
19
  lib/plugin/cool.rb
@@ -28,12 +30,16 @@ lib/plugin/hatebu.rb
28
30
  lib/plugin/history.rb
29
31
  lib/plugin/keyword.rb
30
32
  lib/plugin/log.rb
33
+ lib/plugin/modify_arg_hook_sample.rb
31
34
  lib/plugin/msagent.rb
32
35
  lib/plugin/multi_reply.rb
33
36
  lib/plugin/notify-send.rb
34
37
  lib/plugin/otsune.rb
35
38
  lib/plugin/outputz.rb
39
+ lib/plugin/pause.rb
36
40
  lib/plugin/plugin.rb
41
+ lib/plugin/post_exec_hook_sample.rb
42
+ lib/plugin/pre_exec_hook_sample.rb
37
43
  lib/plugin/primes.rb
38
44
  lib/plugin/quicklook.rb
39
45
  lib/plugin/reblog.rb
@@ -58,8 +64,12 @@ lib/termtter/api.rb
58
64
  lib/termtter/client.rb
59
65
  lib/termtter/command.rb
60
66
  lib/termtter/connection.rb
67
+ lib/termtter/hook.rb
61
68
  lib/termtter/status.rb
69
+ lib/termtter/task.rb
70
+ lib/termtter/task_manager.rb
62
71
  lib/termtter/twitter.rb
72
+ lib/termtter/user.rb
63
73
  run_termtter.rb
64
74
  test/friends_timeline.json
65
75
  test/search.json
data/Rakefile CHANGED
@@ -37,3 +37,28 @@ Spec::Rake::SpecTask.new do |t|
37
37
  t.spec_opts = ['-c']
38
38
  end
39
39
 
40
+ def egrep(pattern)
41
+ res = []
42
+ Dir['**/*.rb'].each do |fn|
43
+ count = 0
44
+ open(fn) do |f|
45
+ while line = f.gets
46
+ count += 1
47
+ if line =~ pattern
48
+ res << [fn, count.to_s, line.gsub(/\A\s+/, '')]
49
+ end
50
+ end
51
+ end
52
+ end
53
+ fmax = res.map {|i| i[0] }.map(&:size).max
54
+ cmax = res.map {|i| i[1] }.map(&:size).max
55
+ res.each do |fn, count, line|
56
+ puts "%s :%s:%s" % [fn.ljust(fmax), count.rjust(cmax), line]
57
+ end
58
+ end
59
+
60
+ desc "Look for TODO and FIXME tags in the code"
61
+ task :todo do
62
+ egrep /(FIXME|TODO)/
63
+ end
64
+
data/bin/kill_termtter ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+ # If your termtter can't be exited, you might use this script.
3
+ #
4
+ # > exit
5
+ # (no response...)
6
+ # C-z
7
+ # $ kill_termtter -i
8
+ # y
9
+ #
10
+ # OPTION
11
+ # -i interactive
12
+ def s(a)
13
+ puts a
14
+ system a
15
+ end
16
+
17
+ `ps`.map(&:split).map {|i|
18
+ pid, runner, file = i[0], i[4], i[5]
19
+ if runner == 'ruby' && $$ != pid.to_i && /termtter/ =~ file
20
+ s "kill -KILL #{pid}"
21
+ end
22
+ }
data/lib/filter/en2ja.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  plugin 'translation'
2
4
 
3
5
  Termtter::Client.add_filter do |statuses|
@@ -1,3 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  module Termtter::Client
2
4
  add_filter do |statuses|
3
5
  statuses.each do |s|
data/lib/filter/fib.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  def fib(n)i=0;j=1;n.times{j=i+i=j};i end
2
4
  module Termtter::Client
3
5
  add_filter do |statuses|
data/lib/filter/ignore.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
 
2
4
  configatron.filters.ignore.set_default(:words, [])
3
5
 
@@ -1,3 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  module Termtter::Client
2
4
  add_filter do |statuses|
3
5
  statuses.map do |s|
@@ -0,0 +1,15 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ def april_fool?;true;end
4
+ def april_fool;april_fool? ? "今日はエイプリルフールではありません。" : "今日はエイプリルフールです。";end
5
+
6
+ Termtter::Client.register_command(
7
+ :name => :april_fool, :aliases => [:af],
8
+ :exec_proc => proc {|arg|
9
+ if arg =~ /^\?you\s(\w+)/
10
+ puts "=> #{Termtter::Client.update_status("@#{$1} #{april_fool}")}"
11
+ else
12
+ puts "=> #{Termtter::Client.update_status(april_fool)}"
13
+ end
14
+ }
15
+ )
data/lib/plugin/bomb.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  module Termtter
2
4
  class Status
3
5
  def bomb?
@@ -6,14 +8,15 @@ module Termtter
6
8
  end
7
9
 
8
10
  module Client
9
- add_help 'bomb WORD', 'Bomb it'
10
- add_command %r'^bomb\s+(.+)$' do |m, t|
11
- bomb = m[1]
12
- msg = "#{bomb} 爆発しろ!"
13
-
14
- puts msg
15
- t.update_status msg
16
- end
11
+ register_command(
12
+ :name => :bomb, :aliases => [],
13
+ :exec_proc => proc {|arg|
14
+ text = "#{arg.strip} 爆発しろ!"
15
+ Termtter::API::twitter.update_status(text)
16
+ puts "=> #{text}"
17
+ },
18
+ :help => ['bomb WORD', 'Bomb it']
19
+ )
17
20
  end
18
21
  end
19
22
 
@@ -1,24 +1,9 @@
1
- module Termtter::Client
2
-
3
- add_command /^confirm\s+(.*)/ do |m, t|
4
- text = m[1]
5
- unless text.empty?
6
- pause
7
- print "update? #{text} [Y/n] "
8
- buf = Readline.readline("", false)
9
- t.update_status(text) if /^y?$/i =~ buf
10
- resume
11
- end
12
- end
13
-
14
- add_completion do |input|
15
- case input
16
- when /^(confirm)\s+(.*)@([^\s]*)$/
17
- find_user_candidates $3, "#{$1} #{$2}@%s"
18
- else
19
- ['confirm'].grep(/^#{Regexp.quote input}/)
20
- end
21
- end
22
-
23
- end
24
-
1
+ # -*- coding: utf-8 -*-
2
+
3
+ Termtter::Client.register_hook(
4
+ :name => :confirm,
5
+ :points => [:pre_exec_update],
6
+ :exec_proc => proc {|cmd, arg|
7
+ false if arg.empty? || /^y?$/i !~ Readline.readline("update? #{arg} [Y/n] ", false)
8
+ }
9
+ )
data/lib/plugin/cool.rb CHANGED
@@ -1,12 +1,10 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  module Termtter::Client
2
- add_help 'cool {SCREENNAME}', 'update "@{SCREENNAME} cool."'
3
- add_macro /^cool ([^\s]*)/, "update @%s cool."
4
- add_completion do |input|
5
- case input
6
- when /^c$/
7
- ['cool']
8
- when /^cool ([^\s]*)/
9
- find_user_candidates $1, "cool %s"
10
- end
11
- end
4
+ register_macro(:cool, "update @%s cool.",
5
+ :help => ['cool {SCREENNAME}', 'update "@{SCREENNAME} cool."'],
6
+ :completion_proc => proc {|cmd, args|
7
+ find_user_candidates args, "#{cmd} %s"
8
+ }
9
+ )
12
10
  end
@@ -1,3 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  require 'erb'
2
4
 
3
5
  module Termtter
data/lib/plugin/erb.rb CHANGED
@@ -1,14 +1,14 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  require 'erb'
2
4
 
3
- module Termtter::Client
4
- add_command /^(update|u)\s+(.*)/ do |m, t|
5
- text = ERB.new(m[2]).result(binding).gsub(/\n/, ' ')
6
- unless text.empty?
7
- t.update_status(text)
8
- puts "=> #{text}"
9
- end
10
- end
11
- end
5
+ Termtter::Client.register_hook(
6
+ :name => :erb,
7
+ :points => [:pre_exec_update],
8
+ :exec_proc => proc {|cmd, arg|
9
+ ERB.new(arg).result(binding)
10
+ }
11
+ )
12
12
 
13
13
  # erb.rb
14
14
  # enable to <%= %> in the command update
@@ -1,3 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  module Termtter::Client
2
4
  add_help 'favorite,fav ID', 'Favorite a status'
3
5
 
data/lib/plugin/fib.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  def fib(n)i=0;j=1;n.times{j=i+i=j};i end
2
4
  module Termtter::Client
3
5
  add_command /^fib\s+(\d+)/ do|m,t|t.update_status x="fib(#{n=m[1].to_i}) = #{fib n}"
data/lib/plugin/filter.rb CHANGED
@@ -1,34 +1,50 @@
1
+ # -*- coding: utf-8 -*-
1
2
 
2
- module Termtter::Client
3
3
 
4
+ module Termtter::Client
4
5
  public_storage[:filters] = []
5
-
6
- add_help 'filter FILE', 'Apply a filter'
7
- add_command /^filter\s+(.*)/ do |m, t|
8
- begin
9
- result = filter m[1].strip
10
- rescue LoadError
11
- result = false
12
- ensure
13
- puts "=> #{result.inspect}"
14
- end
6
+ filters = Dir["#{File.dirname(__FILE__)}/../filter/*.rb"].map do |f|
7
+ f.match(%r|([^/]+).rb$|)[1]
15
8
  end
16
9
 
17
- add_help 'unfilter', 'Clear all filters'
18
- add_command /^unfilter\s*$/ do |m, t|
19
- clear_filters
20
- public_storage[:filters].clear
21
- puts '=> filter cleared'
22
- end
10
+ register_command(
11
+ :name => :filter, :aliases => [],
12
+ :exec_proc => proc {|arg|
13
+ begin
14
+ result = filter arg.strip
15
+ rescue LoadError
16
+ result = false
17
+ ensure
18
+ puts "=> #{result.inspect}"
19
+ end
20
+ },
21
+ :completion_proc => proc {|cmd, args|
22
+ find_filter_candidates args, "#{cmd} %s", filters
23
+ },
24
+ :help => ['filter FILE', 'Apply a filter']
25
+ )
23
26
 
24
- add_help 'filters', 'Show list of applied filters'
25
- add_command /^filters\s*$/ do |m, t|
26
- unless public_storage[:filters].empty?
27
- puts public_storage[:filters].join(', ')
28
- else
29
- puts 'no filter was applied'
30
- end
31
- end
27
+ register_command(
28
+ :name => :unfilter, :aliases => [],
29
+ :exec_proc => proc {|arg|
30
+ clear_filters
31
+ public_storage[:filters].clear
32
+ puts '=> filter cleared'
33
+ },
34
+ :help => ['ufilter', 'Clear all filters']
35
+ )
36
+
37
+ register_command(
38
+ :name => :filters, :aliases => [],
39
+ :exec_proc => proc {|arg|
40
+ unless public_storage[:filters].empty?
41
+ puts public_storage[:filters].join(', ')
42
+ else
43
+ puts 'no filter was applied'
44
+ end
45
+ },
46
+ :help => ['filters', 'Show list of applied filters']
47
+ )
32
48
 
33
49
  def self.find_filter_candidates(a, b, filters)
34
50
  if a.empty?
@@ -38,17 +54,6 @@ module Termtter::Client
38
54
  end.
39
55
  map {|u| b % u }
40
56
  end
41
-
42
- filters = Dir["#{File.dirname(__FILE__)}/../filter/*.rb"].map do |f|
43
- f.match(%r|([^/]+).rb$|)[1]
44
- end
45
- add_completion do |input|
46
- if input =~ /^(filter)\s+(.*)/
47
- find_filter_candidates $2, "#{$1} %s", filters
48
- else
49
- %w[ filter filters unfilter ].grep(/^#{Regexp.quote input}/)
50
- end
51
- end
52
57
  end
53
58
 
54
59
  # filter.rb
data/lib/plugin/follow.rb CHANGED
@@ -1,25 +1,41 @@
1
- module Termtter::Client
2
- add_help 'follow USER', 'Follow user'
3
- add_help 'leave USER', 'Leave user'
1
+ # -*- coding: utf-8 -*-
4
2
 
5
- add_command %r'^(follow|leave)\s+(\w+)\s*$' do |m, t|
6
- user = m[2]
7
- res = t.social(user, m[1].to_sym)
8
- if res.code == '200'
9
- puts "#{m[1].capitalize}ed user @#{user}"
10
- else
11
- puts "Failed: #{res}"
12
- end
13
- end
3
+ module Termtter::Client
4
+ register_command(
5
+ :name => :follow, :aliases => [],
6
+ :exec_proc => proc {|arg|
7
+ if arg =~ /^(\w+)/
8
+ res = Termtter::API::twitter.social($1.strip, :follow)
9
+ if res.code == '200'
10
+ puts "Followed user @#{$1}"
11
+ else
12
+ puts "Failed: #{res}"
13
+ end
14
+ end
15
+ },
16
+ :completion_proc => proc {|cmd, args|
17
+ find_user_candidates args, "#{cmd} %s"
18
+ },
19
+ :help => ['follow USER', 'Follow user']
20
+ )
14
21
 
15
- add_completion do |input|
16
- case input
17
- when /^(follow|leave)?\s+(.*)/
18
- find_user_candidates $2, "#{$1} %s"
19
- else
20
- %w[follow leave].grep(/^#{Regexp.quote input}/)
21
- end
22
- end
22
+ register_command(
23
+ :name => :leave, :aliases => [],
24
+ :exec_proc => proc {|arg|
25
+ if arg =~ /^(\w+)/
26
+ res = t.social($1.strip, :leave)
27
+ if res.code == '200'
28
+ puts "Leaved user @#{$1}"
29
+ else
30
+ puts "Failed: #{res}"
31
+ end
32
+ end
33
+ },
34
+ :completion_proc => proc {|cmd, args|
35
+ find_user_candidates args, "#{cmd} %s"
36
+ },
37
+ :help => ['leave USER', 'Leave user']
38
+ )
23
39
  end
24
40
 
25
41
  module Termtter
@@ -1,3 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  twitter = Termtter::Twitter.new(configatron.user_name, configatron.password)
2
4
  Thread.start do
3
5
  100.times do |i|