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
@@ -1,3 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  module Termtter
2
4
  class Command
3
5
  attr_accessor :name, :aliases, :exec_proc, :completion_proc, :help
@@ -11,7 +13,7 @@ module Termtter
11
13
  def initialize(args)
12
14
  raise ArgumentError, ":name is not given." unless args.has_key?(:name)
13
15
  @name = args[:name].to_sym
14
- @aliases = args[:aliases] || []
16
+ @aliases = args[:aliases] ? args[:aliases].map {|i| i.to_sym } : []
15
17
  @exec_proc = args[:exec_proc] || proc {|arg|}
16
18
  @completion_proc = args[:completion_proc] || proc {|command, arg| [] }
17
19
  @help = args[:help]
@@ -20,7 +22,7 @@ module Termtter
20
22
  def complement(input)
21
23
  command_info = match?(input)
22
24
  if command_info
23
- [completion_proc.call(command_info[0], command_info[1])].flatten.compact
25
+ [completion_proc.call(command_info[0], command_info[1] || '')].flatten.compact
24
26
  else
25
27
  [name.to_s].grep(/^#{Regexp.quote(input)}/)
26
28
  end
@@ -51,16 +53,24 @@ module Termtter
51
53
  end
52
54
 
53
55
  def execute(arg)
56
+ arg = case arg
57
+ when nil
58
+ ''
59
+ when String
60
+ arg
61
+ else
62
+ raise ArgumentError, 'arg should be String or nil'
63
+ end
54
64
  exec_proc.call(arg)
55
65
  end
56
66
 
57
67
  def pattern
58
- commands_regex = commands.map {|i| Regexp.quote(i) }.join('|')
59
- /^\s*((#{commands_regex})|(#{commands_regex})\s+(.*?))\s*$/
68
+ commands_regex = commands.map {|i| Regexp.quote(i.to_s) }.join('|')
69
+ /^((#{commands_regex})|(#{commands_regex})\s+(.*?))\s*$/
60
70
  end
61
71
 
62
72
  def commands
63
- aliases.unshift(name.to_s)
73
+ aliases.unshift(name)
64
74
  end
65
75
  end
66
76
  end
@@ -1,3 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  module Termtter
2
4
  class Connection
3
5
  attr_reader :protocol, :port, :proxy_uri
@@ -29,7 +31,7 @@ module Termtter
29
31
  def start(host, port, &block)
30
32
  http = @http_class.new(host, port)
31
33
  http.use_ssl = @enable_ssl
32
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE if http.use_ssl
34
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE if http.use_ssl?
33
35
  http.start(&block)
34
36
  end
35
37
  end
@@ -0,0 +1,18 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module Termtter
4
+ class Hook
5
+ attr_accessor :name, :points, :exec_proc
6
+
7
+ def initialize(args)
8
+ raise ArgumentError, ":name is not given." unless args.has_key?(:name)
9
+ @name = args[:name].to_sym
10
+ @points = args[:points] ? args[:points].map {|i| i.to_sym } : []
11
+ @exec_proc = args[:exec_proc] || proc {}
12
+ end
13
+
14
+ def match?(point)
15
+ points.include?(point.to_sym)
16
+ end
17
+ end
18
+ end
@@ -1,3 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  module Termtter
2
4
  class Status
3
5
  %w(
@@ -0,0 +1,16 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module Termtter
4
+ class Task
5
+ attr_accessor :name, :exec_at, :exec_proc, :interval
6
+ def initialize(args = {}, &block)
7
+ @name = args[:name]
8
+ @exec_at = Time.now + (args[:after] || 0)
9
+ @interval = args[:interval]
10
+ @exec_proc = block || proc {}
11
+ end
12
+ def execute
13
+ exec_proc.call
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,116 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module Termtter
4
+ class TaskManager
5
+
6
+ INTERVAL = 1
7
+
8
+ def initialize()
9
+ @tasks = {}
10
+ @work = true
11
+ @mutex = Mutex.new
12
+ @pause = false
13
+ end
14
+
15
+ def pause
16
+ @pause = true
17
+ end
18
+
19
+ def resume
20
+ @pause = false
21
+ end
22
+
23
+ def kill
24
+ @work = false
25
+ end
26
+
27
+ def run
28
+ Thread.new do
29
+ while @work
30
+ step unless @pause
31
+ sleep INTERVAL
32
+ end
33
+ end
34
+ end
35
+
36
+ def step
37
+ pull_due_tasks().each do |task|
38
+ invoke_and_wait do
39
+ task.execute
40
+ end
41
+ end
42
+ end
43
+
44
+ def invoke_later
45
+ Thread.new do
46
+ invoke_and_wait do
47
+ yield
48
+ end
49
+ end
50
+ end
51
+
52
+ def invoke_and_wait(&block)
53
+ synchronize do
54
+ begin
55
+ yield
56
+ rescue => e
57
+ Termtter::Client.handle_error(e)
58
+ end
59
+ end
60
+ end
61
+
62
+ def add_task(args = {}, &block)
63
+ synchronize do
64
+ task = Task.new(args, &block)
65
+ @tasks[task.name || task.object_id] = task
66
+ end
67
+ end
68
+
69
+ def get_task(key)
70
+ synchronize do
71
+ @tasks[key]
72
+ end
73
+ end
74
+
75
+ def delete_task(key)
76
+ synchronize do
77
+ @tasks.delete(key)
78
+ end
79
+ end
80
+
81
+ private
82
+
83
+ def synchronize
84
+ unless Thread.current == @thread_in_sync
85
+ @mutex.synchronize do
86
+ @thread_in_sync = Thread.current
87
+ yield
88
+ end
89
+ else
90
+ yield
91
+ end
92
+ end
93
+
94
+ def pull_due_tasks()
95
+ synchronize do
96
+ time_now = Time.now
97
+ due_tasks = []
98
+ @tasks.delete_if do |key, task|
99
+ if task.exec_at <= time_now
100
+ due_tasks << task
101
+ if task.interval
102
+ task.exec_at = time_now + task.interval
103
+ false
104
+ else
105
+ true
106
+ end
107
+ else
108
+ false
109
+ end
110
+ end
111
+ return due_tasks
112
+ end
113
+ end
114
+
115
+ end
116
+ end
@@ -1,4 +1,7 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  require 'highline'
4
+ require 'time'
2
5
 
3
6
  module Termtter
4
7
  class Twitter
@@ -27,7 +30,15 @@ module Termtter
27
30
 
28
31
  def get_user_profile(screen_name)
29
32
  uri = "#{@connection.protocol}://twitter.com/users/show/#{screen_name}.json"
30
- return JSON.parse(open(uri, :http_basic_authentication => [user_name, password], :proxy => @connection.proxy_uri).read)
33
+ result = JSON.parse(open(uri, :http_basic_authentication => [user_name, password], :proxy => @connection.proxy_uri).read)
34
+ user = User.new
35
+ %w[ name favourites_count url id description protected utc_offset time_zone
36
+ screen_name notifications statuses_count followers_count friends_count
37
+ profile_image_url location following created_at
38
+ ].each do |attr|
39
+ user.__send__("#{attr}=".to_sym, result[attr])
40
+ end
41
+ return user
31
42
  end
32
43
 
33
44
  def get_friends_timeline(since_id = nil)
@@ -50,8 +61,8 @@ module Termtter
50
61
  return results.map do |s|
51
62
  status = Status.new
52
63
  status.id = s['id']
53
- status.text = CGI.unescapeHTML(s['text']).gsub(/(\n|\r)/, '').gsub(query, color(color(query, 41), 37))
54
- status.created_at = Time.utc(*ParseDate::parsedate(s["created_at"])).localtime
64
+ status.text = CGI.unescapeHTML(s['text']).gsub(/(\n|\r)/, '').gsub(/#{Regexp.escape(query)}/i, color(color('\0', 41), 37))
65
+ status.created_at = Time.parse(s["created_at"])
55
66
  status.user_screen_name = s['from_user']
56
67
  status
57
68
  end
@@ -74,7 +85,7 @@ module Termtter
74
85
  data = [data] unless data.instance_of? Array
75
86
  return data.map do |s|
76
87
  status = Status.new
77
- status.created_at = Time.utc(*ParseDate::parsedate(s["created_at"])).localtime
88
+ status.created_at = Time.parse(s["created_at"])
78
89
  %w(id text truncated in_reply_to_status_id in_reply_to_user_id in_reply_to_screen_name).each do |key|
79
90
  status.__send__("#{key}=".to_sym, s[key])
80
91
  end
@@ -0,0 +1,13 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module Termtter
4
+ class User
5
+ %w[ name favourites_count url id description protected utc_offset time_zone
6
+ screen_name notifications statuses_count followers_count friends_count
7
+ profile_image_url location following created_at
8
+ ].each do |attr|
9
+ attr_accessor attr.to_sym
10
+ end
11
+ end
12
+ end
13
+
data/run_termtter.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
2
3
 
3
4
  $KCODE = 'u'
4
5
 
@@ -1,3 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
1
3
  require 'rubygems'
2
4
  require 'configatron'
3
5
  require 'test/unit'
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: 0.7.7
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - bubblegum
@@ -18,8 +18,8 @@ autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
20
 
21
- date: 2009-01-17 00:00:00 -08:00
22
- default_executable: termtter
21
+ date: 2009-02-01 00:00:00 -08:00
22
+ default_executable:
23
23
  dependencies:
24
24
  - !ruby/object:Gem::Dependency
25
25
  name: json
@@ -61,6 +61,7 @@ description: Termtter is a terminal based Twitter client
61
61
  email:
62
62
  - jugyo.org@gmail.com
63
63
  executables:
64
+ - kill_termtter
64
65
  - termtter
65
66
  extensions: []
66
67
 
@@ -75,6 +76,7 @@ files:
75
76
  - PostInstall.txt
76
77
  - README.rdoc
77
78
  - Rakefile
79
+ - bin/kill_termtter
78
80
  - bin/termtter
79
81
  - lib/filter/en2ja.rb
80
82
  - lib/filter/english.rb
@@ -84,6 +86,7 @@ files:
84
86
  - lib/filter/reply.rb
85
87
  - lib/filter/reverse.rb
86
88
  - lib/filter/yhara.rb
89
+ - lib/plugin/april_fool.rb
87
90
  - lib/plugin/bomb.rb
88
91
  - lib/plugin/confirm.rb
89
92
  - lib/plugin/cool.rb
@@ -100,12 +103,16 @@ files:
100
103
  - lib/plugin/history.rb
101
104
  - lib/plugin/keyword.rb
102
105
  - lib/plugin/log.rb
106
+ - lib/plugin/modify_arg_hook_sample.rb
103
107
  - lib/plugin/msagent.rb
104
108
  - lib/plugin/multi_reply.rb
105
109
  - lib/plugin/notify-send.rb
106
110
  - lib/plugin/otsune.rb
107
111
  - lib/plugin/outputz.rb
112
+ - lib/plugin/pause.rb
108
113
  - lib/plugin/plugin.rb
114
+ - lib/plugin/post_exec_hook_sample.rb
115
+ - lib/plugin/pre_exec_hook_sample.rb
109
116
  - lib/plugin/primes.rb
110
117
  - lib/plugin/quicklook.rb
111
118
  - lib/plugin/reblog.rb
@@ -130,8 +137,12 @@ files:
130
137
  - lib/termtter/client.rb
131
138
  - lib/termtter/command.rb
132
139
  - lib/termtter/connection.rb
140
+ - lib/termtter/hook.rb
133
141
  - lib/termtter/status.rb
142
+ - lib/termtter/task.rb
143
+ - lib/termtter/task_manager.rb
134
144
  - lib/termtter/twitter.rb
145
+ - lib/termtter/user.rb
135
146
  - run_termtter.rb
136
147
  - test/friends_timeline.json
137
148
  - test/search.json