jugyo-termtter 0.7.6 → 0.7.7
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.
- data/Manifest.txt +23 -0
- data/bin/termtter +0 -39
- data/lib/filter/english.rb +1 -1
- data/lib/filter/ignore.rb +17 -0
- data/lib/filter/reply.rb +8 -0
- data/lib/filter/yhara.rb +1 -1
- data/lib/plugin/cool.rb +12 -0
- data/lib/plugin/favorite.rb +10 -7
- data/lib/plugin/fib.rb +1 -0
- data/lib/plugin/follow.rb +2 -2
- data/lib/plugin/graduatter.rb +7 -0
- data/lib/plugin/group.rb +15 -3
- data/lib/plugin/growl.rb +15 -4
- data/lib/plugin/hatebu.rb +57 -0
- data/lib/plugin/history.rb +10 -2
- data/lib/plugin/log.rb +33 -2
- data/lib/plugin/msagent.rb +24 -0
- data/lib/plugin/multi_reply.rb +34 -0
- data/lib/plugin/otsune.rb +17 -0
- data/lib/plugin/outputz.rb +33 -0
- data/lib/plugin/primes.rb +21 -0
- data/lib/plugin/reblog.rb +38 -0
- data/lib/plugin/say.rb +1 -1
- data/lib/plugin/scrape.rb +43 -0
- data/lib/plugin/screen.rb +22 -0
- data/lib/plugin/shell.rb +1 -1
- data/lib/plugin/sl.rb +7 -7
- data/lib/plugin/standard_plugins.rb +100 -48
- data/lib/plugin/stdout.rb +27 -71
- data/lib/plugin/system_status.rb +41 -0
- data/lib/plugin/update_editor.rb +53 -0
- data/lib/plugin/wassr_post.rb +21 -0
- data/lib/plugin/yonda.rb +18 -0
- data/lib/termtter/api.rb +12 -0
- data/lib/termtter/client.rb +298 -0
- data/lib/termtter/command.rb +67 -0
- data/lib/termtter/connection.rb +37 -0
- data/lib/termtter/status.rb +24 -0
- data/lib/termtter/twitter.rb +138 -0
- data/lib/termtter.rb +90 -410
- data/run_termtter.rb +0 -11
- metadata +25 -2
@@ -0,0 +1,43 @@
|
|
1
|
+
module Termtter::Client
|
2
|
+
def self.scrape_group(group, t)
|
3
|
+
members = configatron.plugins.group.groups[group] || []
|
4
|
+
members.map {|member|
|
5
|
+
t.get_user_timeline(member)
|
6
|
+
}.flatten
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.scrape_groups(t)
|
10
|
+
groups = configatron.plugins.group.groups
|
11
|
+
groups.map {|group|
|
12
|
+
scrape_group(group, t)
|
13
|
+
}.flatten
|
14
|
+
end
|
15
|
+
|
16
|
+
add_help 'scrape_group GROUPNAME', 'Get the group timeline'
|
17
|
+
add_help 'scrape_groups', 'Get all groups timeline'
|
18
|
+
|
19
|
+
add_command /^(?:scrape_group)\s+(.+)/ do |m, t|
|
20
|
+
group_name = m[1].to_sym
|
21
|
+
statuses = scrape_group(group_name, t)
|
22
|
+
call_hooks(statuses, :pre_filter, t)
|
23
|
+
puts "done"
|
24
|
+
end
|
25
|
+
|
26
|
+
add_command /^(?:scrape_groups)\s*$/ do |m, t|
|
27
|
+
statuses = scrape_groups(t)
|
28
|
+
call_hooks(statuses, :pre_filter, t)
|
29
|
+
puts "done"
|
30
|
+
end
|
31
|
+
|
32
|
+
add_completion do |input|
|
33
|
+
case input
|
34
|
+
when /^(scrape_group)?\s+(.+)/
|
35
|
+
find_group_candidates($2, "#{$1} %s") if defined? find_group_candidates
|
36
|
+
when /^(scrape_group)\s+$/
|
37
|
+
configatron.plugins.group.groups.keys
|
38
|
+
else
|
39
|
+
%w(scrape_group scrape_groups).grep(/^#{Regexp.quote input}/)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Termtter
|
2
|
+
module Plugin
|
3
|
+
module Screen
|
4
|
+
def self.set_title(title)
|
5
|
+
print "\033k#{title}\033\\"
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
# Add below to your ~/.termtter
|
12
|
+
#
|
13
|
+
# require 'plugin/yonda'
|
14
|
+
# require 'plugin/screen'
|
15
|
+
# module Termtter::Client
|
16
|
+
# add_hook do |statuses, event|
|
17
|
+
# case event
|
18
|
+
# when :update_friends_timeline, :plugin_yonda_yonda
|
19
|
+
# Termtter::Plugin::Screen::set_title("termtter(#{public_storage[:unread_count]})")
|
20
|
+
# end
|
21
|
+
# end
|
22
|
+
# end
|
data/lib/plugin/shell.rb
CHANGED
data/lib/plugin/sl.rb
CHANGED
@@ -12,20 +12,20 @@ module Termtter::Client
|
|
12
12
|
end
|
13
13
|
|
14
14
|
add_help 'cd USER', 'Change current directory'
|
15
|
-
add_command /^cd\s
|
15
|
+
add_command /^(?:cd\s+|\.\/)(.*)/ do |m, t|
|
16
16
|
directory = m[1].strip
|
17
|
-
|
18
|
-
public_storage[:current] =
|
19
|
-
puts "=> #{
|
17
|
+
directory = '' if /\~/ =~ directory
|
18
|
+
public_storage[:current] = directory
|
19
|
+
puts "=> #{directory}"
|
20
20
|
end
|
21
21
|
add_macro /^cd$/, 'eval public_storage[:current] = ""'
|
22
22
|
|
23
23
|
add_completion do |input|
|
24
24
|
case input
|
25
|
-
when /^(cd
|
26
|
-
find_user_candidates $2, "#{$1}
|
25
|
+
when /^(cd\s+|\.\/)(.*)/
|
26
|
+
find_user_candidates $2, "#{$1.gsub(/\s+/, ' ')}%s"
|
27
27
|
else
|
28
|
-
%w[ sl ls cd pwd ].grep(/^#{Regexp.quote input}/)
|
28
|
+
%w[ sl ls cd pwd ./ ].grep(/^#{Regexp.quote input}/)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
@@ -1,15 +1,35 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
1
3
|
module Termtter::Client
|
2
4
|
|
3
5
|
# standard commands
|
4
6
|
|
5
7
|
add_command /^(update|u)\s+(.*)/ do |m, t|
|
6
|
-
text = m[2]
|
8
|
+
text = ERB.new(m[2]).result(binding).gsub(/\n/, ' ')
|
7
9
|
unless text.empty?
|
8
10
|
t.update_status(text)
|
9
11
|
puts "=> #{text}"
|
10
12
|
end
|
11
13
|
end
|
12
14
|
|
15
|
+
add_command /^(direct|d)\s+([^\s]+)\s+(.*)\s*$/ do |m, t|
|
16
|
+
user = m[2]
|
17
|
+
text = ERB.new(m[3]).result(binding).gsub(/\n/, ' ')
|
18
|
+
unless text.empty?
|
19
|
+
t.direct_message(user, text)
|
20
|
+
puts "=> to:#{user} message:#{text}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
add_command /^(profile|p)\s+([^\s]+)/ do |m, t|
|
25
|
+
profile = t.get_user_profile(m[2])
|
26
|
+
if profile
|
27
|
+
%w[ name favourites_count url id description protected utc_offset time_zone screen_name notifications statuses_count followers_count friends_count profile_image_url location following created_at ].each do |key|
|
28
|
+
puts "#{key} : #{profile[key]}" if profile.key?(key)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
13
33
|
add_command /^(list|l)\s*$/ do |m, t|
|
14
34
|
statuses = t.get_friends_timeline()
|
15
35
|
call_hooks(statuses, :list_friends_timeline, t)
|
@@ -28,45 +48,63 @@ module Termtter::Client
|
|
28
48
|
call_hooks(t.replies(), :replies, t)
|
29
49
|
end
|
30
50
|
|
31
|
-
add_command /^show
|
32
|
-
call_hooks(t.show(m[1]), :show, t)
|
51
|
+
add_command /^show(s)?\s+(?:[\w\d]+:)?(\d+)/ do |m, t|
|
52
|
+
call_hooks(t.show(m[2], m[1]), :show, t)
|
33
53
|
end
|
34
54
|
|
35
55
|
# TODO: Change colors when remaining_hits is low.
|
36
56
|
# TODO: Simmulate remaining_hits.
|
37
|
-
|
38
|
-
limit
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
57
|
+
register_command(
|
58
|
+
:name => :limit, :aliases => ['lm'],
|
59
|
+
:exec_proc => proc {|arg|
|
60
|
+
limit = Termtter::API.twitter.get_rate_limit_status
|
61
|
+
remaining_time = "%dmin %dsec" % (limit.reset_time - Time.now).divmod(60)
|
62
|
+
remaining_color =
|
63
|
+
case limit.remaining_hits / limit.hourly_limit.to_f
|
64
|
+
when 0.2..0.4 then :yellow
|
65
|
+
when 0..0.2 then :red
|
66
|
+
else :green
|
67
|
+
end
|
68
|
+
puts "=> #{color(limit.remaining_hits, remaining_color)}/#{limit.hourly_limit} until #{limit.reset_time} (#{remaining_time} remaining)"
|
69
|
+
},
|
70
|
+
:help => ["limit,lm", "Show the API limit status"]
|
71
|
+
)
|
72
|
+
|
73
|
+
register_command(
|
74
|
+
:name => :pause,
|
75
|
+
:exec_proc => proc {|arg| pause},
|
76
|
+
:help => ["pause", "Pause updating"]
|
77
|
+
)
|
78
|
+
|
79
|
+
register_command(
|
80
|
+
:name => :resume,
|
81
|
+
:exec_proc => proc {|arg| resume},
|
82
|
+
:help => ["resume", "Resume updating"]
|
83
|
+
)
|
84
|
+
|
85
|
+
register_command(
|
86
|
+
:name => :exit, :aliases => ['e'],
|
87
|
+
:exec_proc => proc {|arg| exit},
|
88
|
+
:help => ['exit,e', 'Exit']
|
89
|
+
)
|
90
|
+
|
91
|
+
add_command /^(help|h)\s*$/ do |m, t|
|
92
|
+
# TODO: migrate to use Termtter::Command#help
|
93
|
+
helps = [
|
94
|
+
["help,h", "Print this help message"],
|
95
|
+
["list,l", "List the posts in your friends timeline"],
|
96
|
+
["list,l USERNAME", "List the posts in the the given user's timeline"],
|
97
|
+
["update,u TEXT", "Post a new message"],
|
98
|
+
["direct,d @USERNAME TEXT", "Send direct message"],
|
99
|
+
["profile,p USERNAME", "Show user's profile"],
|
100
|
+
["replies,r", "List the most recent @replies for the authenticating user"],
|
101
|
+
["search,s TEXT", "Search for Twitter"],
|
102
|
+
["show ID", "Show a single status"]
|
103
|
+
]
|
104
|
+
helps += @@helps
|
105
|
+
helps += @@new_commands.map {|name, command| command.help}
|
106
|
+
helps.compact!
|
107
|
+
puts formatted_help(helps)
|
70
108
|
end
|
71
109
|
|
72
110
|
add_command /^eval\s+(.*)$/ do |m, t|
|
@@ -90,13 +128,13 @@ show ID Show a single status
|
|
90
128
|
end
|
91
129
|
end
|
92
130
|
|
93
|
-
def self.formatted_help
|
94
|
-
|
131
|
+
def self.formatted_help(helps)
|
132
|
+
helps = helps.sort_by{|help| help[0]}
|
133
|
+
width = helps.map {|n, d| n.size }.max
|
95
134
|
space = 3
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
}.join("\n")
|
135
|
+
helps.map {|name, desc|
|
136
|
+
name.to_s.ljust(width + space) + desc.to_s
|
137
|
+
}.join("\n")
|
100
138
|
end
|
101
139
|
|
102
140
|
# completion for standard commands
|
@@ -114,11 +152,15 @@ show ID Show a single status
|
|
114
152
|
end
|
115
153
|
end
|
116
154
|
|
117
|
-
def self.find_status_id_candidates(a, b)
|
155
|
+
def self.find_status_id_candidates(a, b, u = nil)
|
156
|
+
candidates = public_storage[:status_ids].to_a
|
157
|
+
if u && c = public_storage[:log].select {|s| s.user_screen_name == u }.map {|s| s.id.to_s }
|
158
|
+
candidates = c unless c.empty?
|
159
|
+
end
|
118
160
|
if a.empty?
|
119
|
-
|
161
|
+
candidates
|
120
162
|
else
|
121
|
-
|
163
|
+
candidates.grep(/#{Regexp.quote a}/)
|
122
164
|
end.
|
123
165
|
map {|u| b % u }
|
124
166
|
end
|
@@ -133,14 +175,24 @@ show ID Show a single status
|
|
133
175
|
end
|
134
176
|
|
135
177
|
add_completion do |input|
|
136
|
-
standard_commands = %w[exit help list pause update resume replies search show limit]
|
178
|
+
standard_commands = %w[exit help list pause profile update direct resume replies search show limit]
|
137
179
|
case input
|
138
180
|
when /^(list|l)?\s+(.*)/
|
139
181
|
find_user_candidates $2, "#{$1} %s"
|
140
182
|
when /^(update|u)\s+(.*)@([^\s]*)$/
|
141
183
|
find_user_candidates $3, "#{$1} #{$2}@%s"
|
142
|
-
when /^
|
143
|
-
|
184
|
+
when /^(direct|d)\s+(.*)/
|
185
|
+
find_user_candidates $2, "#{$1} %s"
|
186
|
+
when /^(profile|p)\s+(.*)/
|
187
|
+
find_user_candidates $2, "#{$1} %s"
|
188
|
+
when /^show(s)?\s+(([\w\d]+):)?\s*(.*)/
|
189
|
+
if $2
|
190
|
+
find_status_id_candidates $4, "show#{$1} #{$2}%s", $3
|
191
|
+
else
|
192
|
+
result = find_user_candidates $4, "show#{$1} %s:"
|
193
|
+
result = find_status_id_candidates $4, "show#{$1} %s" if result.empty?
|
194
|
+
result
|
195
|
+
end
|
144
196
|
else
|
145
197
|
standard_commands.grep(/^#{Regexp.quote input}/)
|
146
198
|
end
|
data/lib/plugin/stdout.rb
CHANGED
@@ -3,53 +3,15 @@ require 'erb'
|
|
3
3
|
|
4
4
|
configatron.plugins.stdout.set_default(
|
5
5
|
:colors,
|
6
|
-
[:
|
6
|
+
[:none, :red, :green, :yellow, :blue, :magenta, :cyan])
|
7
7
|
configatron.plugins.stdout.set_default(
|
8
8
|
:timeline_format,
|
9
9
|
'<%= color(time, 90) %> <%= color(status, status_color) %> <%= color(id, 90) %>')
|
10
10
|
|
11
11
|
$highline = HighLine.new
|
12
12
|
|
13
|
-
if win?
|
14
|
-
require 'kconv'
|
15
|
-
require 'Win32API'
|
16
|
-
STD_OUTPUT_HANDLE = 0xFFFFFFF5
|
17
|
-
$wSetConsoleTextAttribute = Win32API.new('kernel32','SetConsoleTextAttribute','II','I')
|
18
|
-
$wGetConsoleScreenBufferInfo = Win32API.new("kernel32", "GetConsoleScreenBufferInfo", ['l', 'p'], 'i')
|
19
|
-
$wGetStdHandle = Win32API.new('kernel32','GetStdHandle','I','I')
|
20
|
-
|
21
|
-
$hStdOut = $wGetStdHandle.call(STD_OUTPUT_HANDLE)
|
22
|
-
lpBuffer = ' ' * 22
|
23
|
-
$wGetConsoleScreenBufferInfo.call($hStdOut, lpBuffer)
|
24
|
-
$oldColor = lpBuffer.unpack('SSSSSssssSS')[4]
|
25
|
-
|
26
|
-
$colorMap = {
|
27
|
-
0 => 7, # black/white
|
28
|
-
37 => 8, # white/intensity
|
29
|
-
31 => 4 + 8, # red/red
|
30
|
-
32 => 2 + 8, # green/green
|
31
|
-
33 => 6 + 8, # yellow/yellow
|
32
|
-
34 => 1 + 8, # blue/blue
|
33
|
-
35 => 5 + 8, # magenta/purple
|
34
|
-
36 => 3 + 8, # cyan/aqua
|
35
|
-
90 => 7, # erase/white
|
36
|
-
}
|
37
|
-
def puts(str)
|
38
|
-
str = str.tosjis
|
39
|
-
tokens = str.split(/(\e\[\d+m)/)
|
40
|
-
tokens.each do |token|
|
41
|
-
if token =~ /\e\[(\d+)m/
|
42
|
-
$wSetConsoleTextAttribute.call $hStdOut, $colorMap[$1.to_i].to_i
|
43
|
-
else
|
44
|
-
STDOUT.print token
|
45
|
-
end
|
46
|
-
end
|
47
|
-
$wSetConsoleTextAttribute.call $hStdOut, $oldColor
|
48
|
-
STDOUT.puts
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
13
|
def color(str, value)
|
14
|
+
return str if value == :none
|
53
15
|
case value
|
54
16
|
when String, Symbol
|
55
17
|
$highline.color(str, value)
|
@@ -58,47 +20,41 @@ def color(str, value)
|
|
58
20
|
end
|
59
21
|
end
|
60
22
|
|
61
|
-
Termtter::Client
|
62
|
-
case event
|
63
|
-
when :update_friends_timeline, :list_friends_timeline, :list_user_timeline, :show, :replies
|
64
|
-
unless statuses.empty?
|
65
|
-
statuses.reverse! if event == :update_friends_timeline
|
66
|
-
statuses.each do |s|
|
67
|
-
text = s.text
|
68
|
-
status_color = configatron.plugins.stdout.colors[s.user_screen_name.hash % configatron.plugins.stdout.colors.size]
|
69
|
-
status = "#{s.user_screen_name}: #{text}"
|
70
|
-
if s.in_reply_to_status_id
|
71
|
-
status += " (reply to #{s.in_reply_to_status_id})"
|
72
|
-
end
|
73
|
-
|
74
|
-
time_format = case event
|
75
|
-
when :update_friends_timeline, :list_friends_timeline
|
76
|
-
'%H:%M:%S'
|
77
|
-
else
|
78
|
-
'%m-%d %H:%M'
|
79
|
-
end
|
80
|
-
time = "(#{s.created_at.strftime(time_format)})"
|
81
|
-
|
82
|
-
id = s.id
|
23
|
+
module Termtter::Client
|
83
24
|
|
84
|
-
|
85
|
-
|
86
|
-
end
|
87
|
-
when :search
|
88
|
-
statuses.each do |s|
|
25
|
+
def self.print_statuses(statuses, sort = true, time_format = '%H:%M:%S')
|
26
|
+
(sort ? statuses.sort_by{ |s| s.id} : statuses).each do |s|
|
89
27
|
text = s.text
|
90
28
|
status_color = configatron.plugins.stdout.colors[s.user_screen_name.hash % configatron.plugins.stdout.colors.size]
|
91
|
-
|
92
29
|
status = "#{s.user_screen_name}: #{text}"
|
93
|
-
|
30
|
+
if s.in_reply_to_status_id
|
31
|
+
status += " (reply to #{s.in_reply_to_status_id})"
|
32
|
+
end
|
33
|
+
|
34
|
+
time = "(#{s.created_at.strftime(time_format)})"
|
94
35
|
id = s.id
|
95
36
|
puts ERB.new(configatron.plugins.stdout.timeline_format).result(binding)
|
96
37
|
end
|
97
38
|
end
|
98
|
-
end
|
99
39
|
|
40
|
+
def self.print_statuses_with_date(statuses, sort = true)
|
41
|
+
print_statuses(statuses, sort, '%m-%d %H:%M')
|
42
|
+
end
|
43
|
+
|
44
|
+
add_hook do |statuses, event|
|
45
|
+
next if statuses.empty?
|
46
|
+
|
47
|
+
case event
|
48
|
+
when :update_friends_timeline, :list_friends_timeline
|
49
|
+
print_statuses(statuses)
|
50
|
+
when :search, :list_user_timeline, :show, :replies
|
51
|
+
print_statuses_with_date(statuses)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
100
56
|
# stdout.rb
|
101
57
|
# output statuses to stdout
|
102
58
|
# example config
|
103
|
-
# configatron.plugins.stdout.colors = [:
|
59
|
+
# configatron.plugins.stdout.colors = [:none, :red, :green, :yellow, :blue, :magenta, :cyan]
|
104
60
|
# configatron.plugins.stdout.timeline_format = '<%= color(time, 90) %> <%= color(status, status_color) %> <%= color(id, 90) %>'
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
configatron.plugins.system_status.set_default(:default_status_proc, proc { Time.now.strftime("%x %X") })
|
4
|
+
configatron.plugins.system_status.set_default(:interval, 1)
|
5
|
+
configatron.plugins.system_status.set_default(:default_color, :on_blue)
|
6
|
+
configatron.plugins.system_status.set_default(:format, '<%= status %>')
|
7
|
+
|
8
|
+
def out_put_status(status, color)
|
9
|
+
formatted_status = ERB.new(configatron.plugins.system_status.format).result(binding)
|
10
|
+
colored_status = color(formatted_status, color)
|
11
|
+
print "\e[s\e[1000G\e[#{status.size - 1}D#{colored_status}\e[u"
|
12
|
+
$stdout.flush
|
13
|
+
end
|
14
|
+
|
15
|
+
module Termtter::Client
|
16
|
+
Thread.new do
|
17
|
+
loop do
|
18
|
+
begin
|
19
|
+
status = public_storage[:system_status] ||
|
20
|
+
configatron.plugins.system_status.default_status_proc.call
|
21
|
+
color = public_storage[:system_status_color] ||
|
22
|
+
configatron.plugins.system_status.default_color
|
23
|
+
rescue => e
|
24
|
+
status = e.message
|
25
|
+
color = :on_red
|
26
|
+
end
|
27
|
+
out_put_status(status, color)
|
28
|
+
sleep configatron.plugins.system_status.interval
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# system_status.rb
|
34
|
+
# show system status on left side.
|
35
|
+
# output public_storage[:system_status] or Time.now.strftime("%x %X") if nil
|
36
|
+
# example config
|
37
|
+
# configatron.plugins.system_status.default_status_proc = proc { Time.now.strftime("%x %X") }
|
38
|
+
# configatron.plugins.system_status.interval = 1
|
39
|
+
# configatron.plugins.system_status.default_color = :on_blue
|
40
|
+
# configatron.plugins.system_status.format = '<%= status %>'
|
41
|
+
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
|
3
|
+
module Termtter::Client
|
4
|
+
if ENV['EDITOR']
|
5
|
+
configatron.plugins.update_editor.set_default('editor', ENV['EDITOR'])
|
6
|
+
else
|
7
|
+
configatron.plugins.update_editor.set_default('editor', 'vi')
|
8
|
+
end
|
9
|
+
configatron.plugins.update_editor.set_default('add_completion', false)
|
10
|
+
|
11
|
+
|
12
|
+
def self.input_editor
|
13
|
+
file = Tempfile.new('termtter')
|
14
|
+
editor = configatron.plugins.update_editor.editor
|
15
|
+
if configatron.plugins.update_editor.add_completion
|
16
|
+
file.puts "\n"*100 + "__END__\n" + public_storage[:users].to_a.join(' ')
|
17
|
+
end
|
18
|
+
file.close
|
19
|
+
system("#{editor} #{file.path}")
|
20
|
+
result = file.open.read
|
21
|
+
file.close(false)
|
22
|
+
result
|
23
|
+
end
|
24
|
+
|
25
|
+
add_command /^(update_editor|ue)\s*$/ do |m, t|
|
26
|
+
pause
|
27
|
+
text = input_editor
|
28
|
+
unless text.empty?
|
29
|
+
text = ERB.new(text).result(binding)
|
30
|
+
text.split("\n").each do |post|
|
31
|
+
break if post =~ /^__END__$/
|
32
|
+
unless post.empty?
|
33
|
+
t.update_status(post)
|
34
|
+
puts "=> #{post}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
resume
|
39
|
+
end
|
40
|
+
|
41
|
+
add_help 'update_editor,ue', 'Update status from editor.'
|
42
|
+
|
43
|
+
add_completion do |input|
|
44
|
+
%w[ update_editor ].grep(/^#{Regexp.quote input}/)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# update_editor.rb
|
49
|
+
# update status from editor.
|
50
|
+
# example:
|
51
|
+
# > update_editor
|
52
|
+
# (type your status, save, close the editor)
|
53
|
+
# => (your status)
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/http'
|
3
|
+
|
4
|
+
module Termtter::Client
|
5
|
+
# NOTE: overwrite original update command
|
6
|
+
add_command /^(update|u)\s+(.*)/ do |m, t|
|
7
|
+
text = ERB.new(m[2]).result(binding).gsub(/\n/, ' ')
|
8
|
+
t.update_status(text)
|
9
|
+
puts "=> #{text}"
|
10
|
+
begin
|
11
|
+
Net::HTTP.version_1_2
|
12
|
+
req = Net::HTTP::Post.new("/statuses/update.json?")
|
13
|
+
req.basic_auth configatron.plugins.wassr_post.username, configatron.plugins.wassr_post.password
|
14
|
+
Net::HTTP.start('api.wassr.jp', 80) do |http|
|
15
|
+
res = http.request(req, "status=#{URI.escape(text)}&source=Termtter")
|
16
|
+
end
|
17
|
+
rescue
|
18
|
+
puts "RuntimeError: #{$!}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/plugin/yonda.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
module Termtter::Client
|
2
|
+
public_storage[:unread_count] = 0
|
3
|
+
|
4
|
+
add_help 'yonda,y', 'Mark as read'
|
5
|
+
|
6
|
+
add_command %r'^y(?:onda)?\s*$' do |m, t|
|
7
|
+
public_storage[:unread_count] = 0
|
8
|
+
print "\033[2J\033[H" # FIXME
|
9
|
+
call_hooks [], :plugin_yonda_yonda, t
|
10
|
+
end
|
11
|
+
|
12
|
+
add_hook do |statuses, event|
|
13
|
+
case event
|
14
|
+
when :update_friends_timeline
|
15
|
+
public_storage[:unread_count] += statuses.size
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/termtter/api.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
module Termtter
|
2
|
+
module API
|
3
|
+
class << self
|
4
|
+
attr_reader :connection, :twitter
|
5
|
+
def setup
|
6
|
+
@connection = Connection.new
|
7
|
+
@twitter = Termtter::Twitter.new(configatron.user_name, configatron.password, @connection)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
# Termtter::API.connection, Termtter::API.twitter can be accessed.
|