jugyo-termtter 1.0.3 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/plugins/addspace.rb +27 -0
- data/lib/plugins/bomb.rb +9 -12
- data/lib/plugins/expand-tinyurl.rb +12 -3
- data/lib/plugins/group.rb +10 -6
- data/lib/plugins/growl.rb +3 -3
- data/lib/plugins/history.rb +21 -10
- data/lib/plugins/log.rb +10 -10
- data/lib/plugins/msagent.rb +23 -11
- data/lib/plugins/notify-send.rb +17 -12
- data/lib/plugins/plugin.rb +1 -1
- data/lib/plugins/say.rb +8 -6
- data/lib/plugins/scrape.rb +1 -1
- data/lib/plugins/screen-notify.rb +17 -10
- data/lib/plugins/standard_plugins.rb +30 -19
- data/lib/plugins/stdout.rb +35 -54
- data/lib/plugins/storage/status.rb +23 -20
- data/lib/plugins/storage.rb +17 -23
- data/lib/plugins/update_editor.rb +1 -1
- data/lib/plugins/uri-open.rb +7 -5
- data/lib/plugins/url_addspace.rb +1 -1
- data/lib/termtter/api.rb +2 -1
- data/lib/termtter/client.rb +90 -118
- data/lib/termtter/command.rb +6 -1
- data/lib/termtter/hook.rb +7 -2
- data/lib/termtter/system_extensions.rb +15 -10
- data/lib/termtter/version.rb +1 -1
- data/lib/termtter.rb +11 -0
- data/spec/{plugin → plugins}/cool_spec.rb +0 -0
- data/spec/{plugin → plugins}/english_spec.rb +0 -0
- data/spec/{plugin → plugins}/favorite_spec.rb +0 -0
- data/spec/{plugin → plugins}/fib_spec.rb +0 -0
- data/spec/{plugin → plugins}/filter_spec.rb +0 -0
- data/spec/{plugin → plugins}/pause_spec.rb +0 -0
- data/spec/{plugin → plugins}/plugin_spec.rb +0 -0
- data/spec/{plugin → plugins}/primes_spec.rb +0 -0
- data/spec/{plugin → plugins}/shell_spec.rb +0 -0
- data/spec/{plugin → plugins}/sl_spec.rb +0 -0
- data/spec/{plugin → plugins}/spam_spec.rb +0 -0
- data/spec/{plugin → plugins}/standard_plugins_spec.rb +0 -0
- data/spec/{plugin → plugins}/storage/DB_spec.rb +0 -0
- data/spec/{plugin → plugins}/storage/status_spec.rb +1 -1
- data/spec/termtter/client_spec.rb +5 -8
- data/spec/termtter/command_spec.rb +10 -10
- metadata +18 -17
data/Rakefile
CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
s.add_dependency("json_pure", ">= 1.1.3")
|
27
27
|
s.add_dependency("highline", ">= 1.5.0")
|
28
28
|
s.add_dependency("termcolor", ">= 0.3.1")
|
29
|
-
s.add_dependency("rubytter", ">= 0.
|
29
|
+
s.add_dependency("rubytter", ">= 0.6.3")
|
30
30
|
s.add_dependency("sqlite3-ruby", ">= 1.2.4")
|
31
31
|
s.authors = %w(jugyo ujihisa)
|
32
32
|
s.email = 'jugyo.org@gmail.com'
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
config.plugins.addspace.set_default( :before, [ %r{https?://} ] )
|
4
|
+
config.plugins.addspace.set_default( :after, %w{ ★ ☆ △ ▽})
|
5
|
+
|
6
|
+
module Termtter::Client
|
7
|
+
add_filter do |statuses, event|
|
8
|
+
statuses.each do |s|
|
9
|
+
config.plugins.addspace.before.each do |c|
|
10
|
+
s.text.gsub!(/(\S)(#{c})/, '\1 \2' )
|
11
|
+
end
|
12
|
+
end
|
13
|
+
statuses.each do |s|
|
14
|
+
config.plugins.addspace.after.each do |c|
|
15
|
+
s.text.gsub!(/(#{c})(\S)/, '\1 \2' )
|
16
|
+
end
|
17
|
+
statuses
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
# addspace
|
22
|
+
# add space before or after specified words.
|
23
|
+
# example:
|
24
|
+
# before: ABCDEhttp://~~~
|
25
|
+
# after: ABCDE http://~~~
|
26
|
+
# before: ★★★
|
27
|
+
# after: ★ ★ ★
|
data/lib/plugins/bomb.rb
CHANGED
@@ -1,24 +1,21 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
+
require 'enumerator'
|
2
3
|
|
3
4
|
module Termtter
|
4
|
-
|
5
5
|
module Client
|
6
|
-
config.plugins.bomb.
|
7
|
-
config.plugins.bomb.color.set_default :background, 'red'
|
6
|
+
config.plugins.bomb.set_default :format, "<on_red><white>%s</white></on_red>"
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
bg = config.plugins.bomb.color.background
|
14
|
-
statuses = [statuses] unless statuses.instance_of? Array
|
8
|
+
register_hook(
|
9
|
+
:name => :bomb,
|
10
|
+
:points => [:post_filter],
|
11
|
+
:exec_proc => lambda{|statuses, event|
|
15
12
|
statuses.each do |status|
|
16
13
|
if /爆発|bomb/ =~ status.text
|
17
|
-
status.text =
|
14
|
+
status.text = config.plugins.bomb.format % status.text
|
18
15
|
end
|
19
16
|
end
|
20
|
-
|
21
|
-
|
17
|
+
}
|
18
|
+
)
|
22
19
|
|
23
20
|
register_command(
|
24
21
|
:name => :bomb, :aliases => [],
|
@@ -1,17 +1,25 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
|
+
URL_SHORTTERS = [
|
4
|
+
{ :host => "tinyurl.com", :pattern => %r'(http://tinyurl\.com(/[\w/]+))' },
|
5
|
+
{ :host => "is.gd", :pattern => %r'(http://is\.gd(/[\w/]+))' },
|
6
|
+
# { :host => "bit.ly", :pattern => %r'(http://bit\.ly(/[\w/]+))' }
|
7
|
+
]
|
8
|
+
|
3
9
|
module Termtter::Client
|
4
10
|
add_filter do |statuses, event|
|
5
11
|
statuses.each do |s|
|
6
|
-
|
7
|
-
|
12
|
+
URL_SHORTTERS.each do |site|
|
13
|
+
s[:text].gsub!(site[:pattern]) do |m|
|
14
|
+
expand_url(site[:host], $2) || $1
|
15
|
+
end
|
8
16
|
end
|
9
17
|
end
|
10
18
|
statuses
|
11
19
|
end
|
12
20
|
end
|
13
21
|
|
14
|
-
def
|
22
|
+
def expand_url(host, path)
|
15
23
|
http_class = Net::HTTP
|
16
24
|
unless config.proxy.host.nil? or config.proxy.host.empty?
|
17
25
|
http_class = Net::HTTP::Proxy(config.proxy.host,
|
@@ -20,5 +28,6 @@ def expand_tinyurl(path)
|
|
20
28
|
config.proxy.password)
|
21
29
|
end
|
22
30
|
res = http_class.new('tinyurl.com').head(path)
|
31
|
+
return nil unless res.code == "301" or res.code == "302"
|
23
32
|
res['Location']
|
24
33
|
end
|
data/lib/plugins/group.rb
CHANGED
@@ -22,6 +22,10 @@ module Termtter::Client
|
|
22
22
|
map {|u| b % u }
|
23
23
|
end
|
24
24
|
|
25
|
+
def self.get_group_of(screen_name)
|
26
|
+
config.plugins.group.groups.select{ |k, v| v.include? screen_name}.map{|a| a.first}
|
27
|
+
end
|
28
|
+
|
25
29
|
register_command(
|
26
30
|
:name => :group,
|
27
31
|
:aliases => [:g],
|
@@ -29,14 +33,14 @@ module Termtter::Client
|
|
29
33
|
unless arg.empty?
|
30
34
|
group_name = arg.to_sym
|
31
35
|
if group_name == :all
|
32
|
-
|
36
|
+
targets = config.plugins.group.groups.values.flatten.uniq
|
33
37
|
else
|
34
|
-
|
38
|
+
targets = config.plugins.group.groups[group_name]
|
35
39
|
end
|
36
|
-
statuses =
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
+
statuses = targets ? targets.map { |target|
|
41
|
+
public_storage[:tweet][target]
|
42
|
+
}.flatten.uniq.compact.sort_by{ |s| s[:id]} : []
|
43
|
+
output(statuses, :search)
|
40
44
|
else
|
41
45
|
config.plugins.group.groups.each_pair do |key, value|
|
42
46
|
puts "#{key}: #{value.join(',')}"
|
data/lib/plugins/growl.rb
CHANGED
@@ -54,8 +54,8 @@ Thread.new do
|
|
54
54
|
end
|
55
55
|
|
56
56
|
Termtter::Client.register_hook(:name => :growl,
|
57
|
-
:points => [:
|
58
|
-
:exec_proc => lambda {
|
59
|
-
|
57
|
+
:points => [:post_filter],
|
58
|
+
:exec_proc => lambda {|statuses, event|
|
59
|
+
statuses.each {|s| queue << s} if event == :update_friends_timeline
|
60
60
|
}
|
61
61
|
)
|
data/lib/plugins/history.rb
CHANGED
@@ -3,9 +3,9 @@
|
|
3
3
|
require 'zlib'
|
4
4
|
|
5
5
|
config.plugins.history.
|
6
|
-
set_default(:filename, '
|
6
|
+
set_default(:filename, Termtter::CONF_DIR + '/history')
|
7
7
|
config.plugins.history.
|
8
|
-
set_default(:keys, [:
|
8
|
+
set_default(:keys, [:users, :status_ids])
|
9
9
|
config.plugins.history.
|
10
10
|
set_default(:max_of_history, 100)
|
11
11
|
config.plugins.history.
|
@@ -51,14 +51,17 @@ module Termtter::Client
|
|
51
51
|
puts "history saved(#{File.size(filename)/1000}kb)"
|
52
52
|
end
|
53
53
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
54
|
+
register_hook(
|
55
|
+
:name => :history_initialize,
|
56
|
+
:points => [:initialize],
|
57
|
+
:exec_proc => lambda { load_history; logger.debug('load_history') }
|
58
|
+
)
|
59
|
+
|
60
|
+
register_hook(
|
61
|
+
:name => :history_exit,
|
62
|
+
:points => [:exit],
|
63
|
+
:exec_proc => lambda { save_history; logger.debug('save_history') }
|
64
|
+
)
|
62
65
|
|
63
66
|
if config.plugins.history.enable_autosave
|
64
67
|
Termtter::Client.add_task(:interval => config.plugins.history.autosave_interval,
|
@@ -75,6 +78,14 @@ module Termtter::Client
|
|
75
78
|
:help => ['save', 'Save hisory']
|
76
79
|
)
|
77
80
|
|
81
|
+
register_command(
|
82
|
+
:name => :load,
|
83
|
+
:exec_proc => lambda{|arg|
|
84
|
+
load_history
|
85
|
+
},
|
86
|
+
:help => ['load', 'Load hisory']
|
87
|
+
)
|
88
|
+
|
78
89
|
|
79
90
|
end
|
80
91
|
|
data/lib/plugins/log.rb
CHANGED
@@ -6,19 +6,19 @@ module Termtter::Client
|
|
6
6
|
config.plugins.log.set_default('max_size', 1/0.0)
|
7
7
|
config.plugins.log.set_default('print_max_size', 30)
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
register_hook(
|
10
|
+
:name => :log,
|
11
|
+
:points => [:pre_filter],
|
12
|
+
:exec_proc => lambda {|statuses, event|
|
12
13
|
# log(sequential storage)
|
13
14
|
public_storage[:log] += statuses
|
14
15
|
max_size = config.plugins.log.max_size
|
15
16
|
if public_storage[:log].size > max_size
|
16
17
|
public_storage[:log] = public_storage[:log][-max_size..-1]
|
17
18
|
end
|
18
|
-
public_storage[:log] = public_storage[:log].uniq.sort_by{|
|
19
|
+
public_storage[:log] = public_storage[:log].uniq.sort_by{|s| s.created_at} if statuses.first
|
19
20
|
|
20
21
|
# tweet(storage for each user)
|
21
|
-
|
22
22
|
statuses.each do |s|
|
23
23
|
public_storage[:tweet][s.user.screen_name] = [] unless public_storage[:tweet][s.user.screen_name]
|
24
24
|
public_storage[:tweet][s.user.screen_name] << s
|
@@ -26,8 +26,8 @@ module Termtter::Client
|
|
26
26
|
public_storage[:tweet] = public_storage[:tweet][-max_size..-1]
|
27
27
|
end
|
28
28
|
end
|
29
|
-
|
30
|
-
|
29
|
+
}
|
30
|
+
)
|
31
31
|
|
32
32
|
register_command(
|
33
33
|
:name => :log,
|
@@ -37,7 +37,7 @@ module Termtter::Client
|
|
37
37
|
statuses = public_storage[:log]
|
38
38
|
print_max = config.plugins.log.print_max_size
|
39
39
|
print_max = 0 if statuses.size < print_max
|
40
|
-
|
40
|
+
output(statuses[-print_max..-1], :search)
|
41
41
|
else
|
42
42
|
# log (user) (max)
|
43
43
|
vars = arg.split(' ')
|
@@ -45,7 +45,7 @@ module Termtter::Client
|
|
45
45
|
id = vars
|
46
46
|
statuses = id.first ? public_storage[:log].select{ |s| id.include? s.user.screen_name} : public_storage[:log]
|
47
47
|
print_max = 0 if statuses.size < print_max
|
48
|
-
|
48
|
+
output(statuses[-print_max..-1], :search)
|
49
49
|
end
|
50
50
|
},
|
51
51
|
:completion_proc => lambda {|cmd, arg|
|
@@ -60,7 +60,7 @@ module Termtter::Client
|
|
60
60
|
unless arg.strip.empty?
|
61
61
|
pat = Regexp.new arg
|
62
62
|
statuses = public_storage[:log].select { |s| s.text =~ pat }
|
63
|
-
|
63
|
+
output(statuses, :search)
|
64
64
|
end
|
65
65
|
},
|
66
66
|
:help => [ 'search_log WORD', 'Search log for WORD' ]
|
data/lib/plugins/msagent.rb
CHANGED
@@ -11,16 +11,28 @@ achar = agent.characters.character("Merlin")
|
|
11
11
|
achar.languageID = 0x411
|
12
12
|
achar.show
|
13
13
|
|
14
|
-
Termtter::Client.
|
15
|
-
|
14
|
+
Termtter::Client.register_hook(
|
15
|
+
:name => :msagent,
|
16
|
+
:points => [:post_filter],
|
17
|
+
:exec_proc => lambda {|statuses, event|
|
18
|
+
if !statuses.empty? && event == :update_friends_timeline
|
19
|
+
Thread.start do
|
20
|
+
statuses.reverse.each do |s|
|
21
|
+
req = achar.speak("#{s[:screen_name]}: #{s[:text]}".tosjis)
|
22
|
+
sleep 1
|
23
|
+
WIN32OLE_EVENT.message_loop
|
24
|
+
achar.stop(req)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
}
|
29
|
+
)
|
30
|
+
|
31
|
+
Termtter::Client.register_hook(
|
32
|
+
:name => :msagent_exit,
|
33
|
+
:points => [:exit],
|
34
|
+
:exec_proc => lambda {
|
16
35
|
achar.hide
|
17
36
|
GC.start
|
18
|
-
|
19
|
-
|
20
|
-
req = achar.speak("#{s.user.screen_name}: #{s.text}".tosjis)
|
21
|
-
sleep 3
|
22
|
-
WIN32OLE_EVENT.message_loop
|
23
|
-
achar.stop(req)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
37
|
+
}
|
38
|
+
)
|
data/lib/plugins/notify-send.rb
CHANGED
@@ -1,17 +1,22 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
|
-
Termtter::Client.
|
4
|
-
|
5
|
-
|
3
|
+
Termtter::Client.register_hook(
|
4
|
+
:name => :notify_send,
|
5
|
+
:points => [:post_filter],
|
6
|
+
:exec_proc => lambda {|statuses, event|
|
7
|
+
if event == :update_friends_timeline
|
8
|
+
max = 10
|
6
9
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
text = statuses.take(max).map {|s|
|
11
|
+
status_text = CGI.escapeHTML(s[:text])
|
12
|
+
status_text.gsub!(%r{https?://[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+},'<a href="\0">\0</a>')
|
13
|
+
"<b>#{s[:screen_name]}:</b> <span font=\"9.0\">#{status_text}</span>"
|
14
|
+
}.join("\n")
|
12
15
|
|
13
|
-
|
16
|
+
text << %Q|\n<a href="http://twitter.com/">more...</a>| if statuses.size > max
|
17
|
+
|
18
|
+
system 'notify-send', 'Termtter', text, '-t', '60000'
|
19
|
+
end
|
20
|
+
}
|
21
|
+
)
|
14
22
|
|
15
|
-
system 'notify-send', 'Termtter', text, '-t', '60000'
|
16
|
-
end
|
17
|
-
end
|
data/lib/plugins/plugin.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Termtter::Client
|
4
4
|
|
5
|
-
public_storage[:plugins] = Dir["#{File.dirname(__FILE__)}/*.rb"].map do |f|
|
5
|
+
public_storage[:plugins] = (Dir["#{File.dirname(__FILE__)}/*.rb"] + Dir["#{Termtter::CONF_DIR}/plugins/*.rb"]).map do |f|
|
6
6
|
f.match(%r|([^/]+).rb$|)[1]
|
7
7
|
end
|
8
8
|
|
data/lib/plugins/say.rb
CHANGED
@@ -10,14 +10,16 @@ def say(who, what)
|
|
10
10
|
end
|
11
11
|
|
12
12
|
module Termtter::Client
|
13
|
-
|
14
|
-
|
13
|
+
register_hook(
|
14
|
+
:name => :say,
|
15
|
+
:points => [:post_filter],
|
16
|
+
:exec_proc => lambda {|statuses, event|
|
15
17
|
statuses.reverse.each do |s|
|
16
|
-
text_without_uri = s
|
17
|
-
say s
|
18
|
+
text_without_uri = s[:text].gsub(%r|https?://[^\s]+|, 'U.R.I.')
|
19
|
+
say s[:screen_name], text_without_uri
|
18
20
|
end
|
19
|
-
|
20
|
-
|
21
|
+
}
|
22
|
+
)
|
21
23
|
end
|
22
24
|
|
23
25
|
# KNOWN BUG:
|
data/lib/plugins/scrape.rb
CHANGED
@@ -29,7 +29,7 @@ module Termtter::Client
|
|
29
29
|
members += config.plugins.group.groups[group]
|
30
30
|
end
|
31
31
|
statuses = scrape_members(members.uniq.compact.sort)
|
32
|
-
|
32
|
+
output(statuses_to_hash(statuses), :pre_filter)
|
33
33
|
},
|
34
34
|
:completion_proc => lambda {|cmd, args|
|
35
35
|
arg = args.split(' ').last
|
@@ -1,13 +1,20 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
1
2
|
|
2
|
-
|
3
|
-
config.screen_notify.format = "[termtter] @%s"
|
4
|
-
end
|
3
|
+
config.screen_notify.set_default(:format, "[termtter] %s")
|
5
4
|
|
6
|
-
Termtter::Client
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
module Termtter::Client
|
6
|
+
register_hook(
|
7
|
+
:name => :screen_notify,
|
8
|
+
:points => [:post_filter],
|
9
|
+
:exec_proc => lambda{|statuses, event|
|
10
|
+
return unless event = :update_friends_timeline
|
11
|
+
Thread.new(statuses) do |ss|
|
12
|
+
ss.each do |s|
|
13
|
+
msg = config.screen_notify.format % s.user.screen_name
|
14
|
+
system 'screen', '-X', 'eval', "bell_msg '#{msg}'", 'bell'
|
15
|
+
sleep 1
|
16
|
+
end
|
17
|
+
end
|
18
|
+
}
|
19
|
+
)
|
13
20
|
end
|
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
require 'erb'
|
4
4
|
|
5
|
+
config.plugins.standard.set_default(
|
6
|
+
:limit_format,
|
7
|
+
'<<%=remaining_color%>><%=limit.remaining_hits%></<%=remaining_color%>>/<%=limit.hourly_limit%> until <%=limit.reset_time%> (<%=remaining_time%> remaining)')
|
8
|
+
|
5
9
|
module Termtter::Client
|
6
10
|
|
7
11
|
# standard commands
|
@@ -10,8 +14,9 @@ module Termtter::Client
|
|
10
14
|
:name => :update, :aliases => [:u],
|
11
15
|
:exec_proc => lambda {|arg|
|
12
16
|
unless arg =~ /^\s*$/
|
17
|
+
# TODO: Change to able to disable erb.
|
13
18
|
text = ERB.new(arg).result(binding).gsub(/\n/, ' ')
|
14
|
-
result = Termtter::API.twitter.update(text
|
19
|
+
result = Termtter::API.twitter.update(text)
|
15
20
|
puts "=> #{text}"
|
16
21
|
result
|
17
22
|
end
|
@@ -78,11 +83,14 @@ module Termtter::Client
|
|
78
83
|
register_command(
|
79
84
|
:name => :list, :aliases => [:l],
|
80
85
|
:exec_proc => lambda {|arg|
|
81
|
-
|
82
|
-
|
86
|
+
if arg.empty?
|
87
|
+
event = :list_friends_timeline
|
88
|
+
statuses = Termtter::API.twitter.friends_timeline()
|
83
89
|
else
|
84
|
-
|
90
|
+
event = :list_user_timeline
|
91
|
+
statuses = Termtter::API.twitter.user_timeline(arg)
|
85
92
|
end
|
93
|
+
output(statuses, event)
|
86
94
|
},
|
87
95
|
:completion_proc => lambda {|cmd, arg|
|
88
96
|
find_user_candidates arg, "#{cmd} %s"
|
@@ -92,14 +100,15 @@ module Termtter::Client
|
|
92
100
|
register_command(
|
93
101
|
:name => :search, :aliases => [:s],
|
94
102
|
:exec_proc => lambda {|arg|
|
95
|
-
|
103
|
+
statuses = Termtter::API.twitter.search(arg)
|
104
|
+
output(statuses, :search)
|
96
105
|
}
|
97
106
|
)
|
98
107
|
|
99
108
|
register_command(
|
100
109
|
:name => :replies, :aliases => [:r],
|
101
110
|
:exec_proc => lambda {|arg|
|
102
|
-
|
111
|
+
output(Termtter::API.twitter.replies(), :replies)
|
103
112
|
}
|
104
113
|
)
|
105
114
|
|
@@ -107,7 +116,7 @@ module Termtter::Client
|
|
107
116
|
:name => :show,
|
108
117
|
:exec_proc => lambda {|arg|
|
109
118
|
id = arg.gsub(/.*:\s*/, '')
|
110
|
-
|
119
|
+
output([Termtter::API.twitter.show(id)], :show)
|
111
120
|
},
|
112
121
|
:completion_proc => lambda {|cmd, arg|
|
113
122
|
case arg
|
@@ -128,7 +137,8 @@ module Termtter::Client
|
|
128
137
|
:name => :shows,
|
129
138
|
:exec_proc => lambda {|arg|
|
130
139
|
id = arg.gsub(/.*:\s*/, '')
|
131
|
-
|
140
|
+
# TODO: Implement
|
141
|
+
output([Termtter::API.twitter.show(id)], :show)
|
132
142
|
},
|
133
143
|
:completion_proc => get_command(:show).completion_proc
|
134
144
|
)
|
@@ -176,7 +186,8 @@ module Termtter::Client
|
|
176
186
|
when 0..0.2 then :red
|
177
187
|
else :green
|
178
188
|
end
|
179
|
-
|
189
|
+
erbed_text = ERB.new(config.plugins.standard.limit_format).result(binding)
|
190
|
+
puts TermColor.parse(erbed_text)
|
180
191
|
},
|
181
192
|
:help => ["limit,lm", "Show the API limit status"]
|
182
193
|
)
|
@@ -229,14 +240,13 @@ module Termtter::Client
|
|
229
240
|
["list,l", "List the posts in your friends timeline"],
|
230
241
|
["list,l USERNAME", "List the posts in the the given user's timeline"],
|
231
242
|
["update,u TEXT", "Post a new message"],
|
232
|
-
["direct,d
|
243
|
+
["direct,d USERNAME TEXT", "Send direct message"],
|
233
244
|
["profile,p USERNAME", "Show user's profile"],
|
234
245
|
["replies,r", "List the most recent @replies for the authenticating user"],
|
235
246
|
["search,s TEXT", "Search for Twitter"],
|
236
247
|
["show ID", "Show a single status"]
|
237
248
|
]
|
238
|
-
helps +=
|
239
|
-
helps += @@new_commands.map {|name, command| command.help}
|
249
|
+
helps += @commands.map {|name, command| command.help}
|
240
250
|
helps.compact!
|
241
251
|
puts formatted_help(helps)
|
242
252
|
}
|
@@ -272,17 +282,18 @@ module Termtter::Client
|
|
272
282
|
public_storage[:users] ||= Set.new
|
273
283
|
public_storage[:status_ids] ||= Set.new
|
274
284
|
|
275
|
-
|
276
|
-
|
277
|
-
|
285
|
+
register_hook(
|
286
|
+
:name => :for_completion,
|
287
|
+
:points => [:pre_filter],
|
288
|
+
:exec_proc => lambda {|statuses, event|
|
278
289
|
statuses.each do |s|
|
279
290
|
public_storage[:users].add(s.user.screen_name)
|
280
291
|
public_storage[:users] += s.text.scan(/@([a-zA-Z_0-9]*)/).flatten
|
281
|
-
public_storage[:status_ids].add(s.id
|
282
|
-
public_storage[:status_ids].add(s.in_reply_to_status_id
|
292
|
+
public_storage[:status_ids].add(s.id)
|
293
|
+
public_storage[:status_ids].add(s.in_reply_to_status_id) if s.in_reply_to_status_id
|
283
294
|
end
|
284
|
-
|
285
|
-
|
295
|
+
}
|
296
|
+
)
|
286
297
|
|
287
298
|
def self.find_status_ids(text)
|
288
299
|
public_storage[:status_ids].select{|id| id =~ /#{Regexp.quote(text)}/}
|
data/lib/plugins/stdout.rb
CHANGED
@@ -11,68 +11,49 @@ config.plugins.stdout.set_default(
|
|
11
11
|
'<90><%=time%></90> <<%=status_color%>><%=status%></<%=status_color%>> <90><%=id%></90>')
|
12
12
|
config.plugins.stdout.set_default(:search_highlihgt_format, '<on_magenta><white>\1</white></on_magenta>')
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
def
|
17
|
-
|
18
|
-
case value
|
19
|
-
when String, Symbol
|
20
|
-
$highline.color(str, value)
|
21
|
-
else
|
22
|
-
"\e[#{value}m#{str}\e[0m"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
module Termtter::Client
|
27
|
-
|
28
|
-
def self.print_statuses(statuses, sort = true, time_format = '%H:%M:%S')
|
29
|
-
(sort ? statuses.sort_by{ |s| s.id} : statuses).each do |s|
|
30
|
-
text = s.text
|
31
|
-
status_color = config.plugins.stdout.colors[s.user.screen_name.hash % config.plugins.stdout.colors.size]
|
32
|
-
status = "#{s.user.screen_name}: #{text}"
|
33
|
-
if s.in_reply_to_status_id
|
34
|
-
status += " (repl. to #{s.in_reply_to_status_id})"
|
35
|
-
end
|
36
|
-
|
37
|
-
time = "(#{Time.parse(s.created_at).strftime(time_format)})"
|
38
|
-
id = s.id
|
39
|
-
erbed_text = ERB.new(config.plugins.stdout.timeline_format).result(binding)
|
40
|
-
puts TermColor.parse(erbed_text)
|
14
|
+
module Termtter
|
15
|
+
class StdOut < Hook
|
16
|
+
def initialize
|
17
|
+
super(:name => :stdout, :points => [:output])
|
41
18
|
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def self.print_statuses_with_date(statuses, sort = true)
|
45
|
-
print_statuses(statuses, sort, '%m-%d %H:%M')
|
46
|
-
end
|
47
19
|
|
48
|
-
|
49
|
-
|
50
|
-
text = r.text.
|
51
|
-
gsub(/(\n|\r)/, '').
|
52
|
-
gsub(/(#{Regexp.escape(result.query)})/i, config.plugins.stdout.search_highlihgt_format)
|
53
|
-
status_color = config.plugins.stdout.colors[r.from_user_id.to_i.hash % config.plugins.stdout.colors.size]
|
54
|
-
status = "#{r.from_user}: #{text}"
|
55
|
-
time = "(#{Time.parse(r.created_at).strftime(time_format)})"
|
56
|
-
id = r.id
|
57
|
-
erbed_text = ERB.new(config.plugins.stdout.timeline_format).result(binding)
|
58
|
-
puts TermColor.parse(erbed_text)
|
20
|
+
def call(statuses, event)
|
21
|
+
print_statuses(statuses)
|
59
22
|
end
|
60
|
-
end
|
61
23
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
24
|
+
def print_statuses(statuses, sort = true, time_format = nil)
|
25
|
+
return unless statuses and statuses.first
|
26
|
+
unless time_format
|
27
|
+
# 最初と最後の日付がちがうとき日付も出す
|
28
|
+
t1 = Time.parse(statuses.first[:created_at])
|
29
|
+
t2 = Time.parse(statuses.last[:created_at])
|
30
|
+
time_format =
|
31
|
+
if [t1.year, t1.month, t1.day] == [t2.year, t2.month, t2.day]
|
32
|
+
'%H:%M:%S'
|
33
|
+
else
|
34
|
+
'%y/%m/%d %H:%M'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
statuses.each do |s|
|
39
|
+
text = s.text
|
40
|
+
status_color = config.plugins.stdout.colors[s.user.id.hash % config.plugins.stdout.colors.size]
|
41
|
+
status = "#{s.user.screen_name}: #{text}"
|
42
|
+
if s.in_reply_to_status_id
|
43
|
+
status += " (repl. to #{s.in_reply_to_status_id})"
|
44
|
+
end
|
45
|
+
|
46
|
+
time = "(#{Time.parse(s.created_at).strftime(time_format)})"
|
47
|
+
id = s.id
|
48
|
+
erbed_text = ERB.new(config.plugins.stdout.timeline_format).result(binding)
|
49
|
+
puts TermColor.parse(erbed_text)
|
50
|
+
end
|
72
51
|
end
|
73
52
|
end
|
74
53
|
|
54
|
+
Client.register_hook(StdOut.new)
|
75
55
|
end
|
56
|
+
|
76
57
|
# stdout.rb
|
77
58
|
# output statuses to stdout
|
78
59
|
# example config
|