ayadn 1.8.2 → 2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/CHANGELOG.md +73 -52
- data/README.md +17 -3
- data/ayadn.gemspec +3 -4
- data/doc/01-index.md +6 -5
- data/doc/02-install.md +23 -1
- data/doc/03-first-steps.md +22 -28
- data/doc/04-options.md +1 -1
- data/doc/05-streams.md +29 -9
- data/doc/06-post.md +13 -5
- data/doc/07-actions.md +63 -1
- data/doc/08-listings.md +112 -4
- data/doc/09-accounts.md +17 -3
- data/doc/10-nicerank.md +5 -5
- data/doc/11-blacklist.md +8 -14
- data/doc/12-alias.md +1 -13
- data/doc/14-set.md +8 -110
- data/doc/15-nowplaying.md +16 -4
- data/doc/18-contact.md +14 -13
- data/doc/19-examples.md +2 -0
- data/lib/ayadn/action.rb +322 -183
- data/lib/ayadn/alias.rb +17 -45
- data/lib/ayadn/annotations.rb +1 -1
- data/lib/ayadn/api.rb +7 -8
- data/lib/ayadn/app.rb +99 -12
- data/lib/ayadn/authorize.rb +92 -57
- data/lib/ayadn/blacklist.rb +52 -62
- data/lib/ayadn/check.rb +81 -74
- data/lib/ayadn/cnx.rb +77 -26
- data/lib/ayadn/databases.rb +890 -105
- data/lib/ayadn/debug.rb +30 -89
- data/lib/ayadn/descriptions.rb +876 -329
- data/lib/ayadn/endpoints.rb +2 -2
- data/lib/ayadn/errors.rb +9 -9
- data/lib/ayadn/extend.rb +8 -1
- data/lib/ayadn/fileops.rb +10 -8
- data/lib/ayadn/mark.rb +79 -56
- data/lib/ayadn/migration.rb +427 -0
- data/lib/ayadn/nicerank.rb +74 -72
- data/lib/ayadn/nowplaying.rb +123 -60
- data/lib/ayadn/nowwatching.rb +26 -10
- data/lib/ayadn/pinboard.rb +12 -7
- data/lib/ayadn/post.rb +40 -37
- data/lib/ayadn/profile.rb +5 -2
- data/lib/ayadn/scroll.rb +20 -5
- data/lib/ayadn/search.rb +30 -22
- data/lib/ayadn/set.rb +146 -50
- data/lib/ayadn/settings.rb +66 -67
- data/lib/ayadn/status.rb +459 -234
- data/lib/ayadn/stream.rb +80 -46
- data/lib/ayadn/switch.rb +51 -47
- data/lib/ayadn/tvshow.rb +47 -15
- data/lib/ayadn/version.rb +1 -1
- data/lib/ayadn/view.rb +119 -60
- data/lib/ayadn/workers.rb +144 -92
- data/lib/ayadn.rb +7 -8
- data/spec/mock/ayadn/accounts.sqlite +0 -0
- data/spec/mock/ayadn.sqlite +0 -0
- data/spec/unit/annotations_spec.rb +12 -13
- data/spec/unit/api_spec.rb +3 -4
- data/spec/unit/blacklistworkers_spec.rb +18 -23
- data/spec/unit/databases_spec.rb +51 -36
- data/spec/unit/endpoints_spec.rb +5 -2
- data/spec/unit/extend_spec.rb +24 -0
- data/spec/unit/nicerank_spec.rb +13 -13
- data/spec/unit/post_spec.rb +47 -36
- data/spec/unit/set_spec.rb +67 -96
- data/spec/unit/view_spec.rb +12 -6
- data/spec/unit/workers_spec.rb +38 -12
- data/tags +1285 -0
- metadata +29 -39
- data/spec/mock/aliases.db +0 -0
- data/spec/mock/blacklist.db +0 -0
- data/spec/mock/bookmarks.db +0 -0
- data/spec/mock/channels.db +0 -0
- data/spec/mock/index.db +0 -0
- data/spec/mock/nicerank.db +0 -0
- data/spec/mock/pagination.db +0 -0
- data/spec/mock/users.db +0 -0
- data/spec/unit/status_spec.rb +0 -9
data/lib/ayadn/nowplaying.rb
CHANGED
@@ -5,39 +5,72 @@ module Ayadn
|
|
5
5
|
|
6
6
|
require 'rss'
|
7
7
|
|
8
|
-
def initialize api, view, workers
|
8
|
+
def initialize api, view, workers, options = {}
|
9
9
|
@api = api
|
10
10
|
@view = view
|
11
11
|
@workers = workers
|
12
|
+
@status = Status.new
|
13
|
+
unless options[:hashtag]
|
14
|
+
@hashtag = "#nowplaying"
|
15
|
+
else
|
16
|
+
@hashtag = "##{options[:hashtag].join()}"
|
17
|
+
end
|
18
|
+
unless options[:text]
|
19
|
+
@custom_text = nil
|
20
|
+
else
|
21
|
+
@custom_text = "\n \n#{options[:text].join(' ')}"
|
22
|
+
end
|
12
23
|
end
|
13
24
|
|
14
25
|
def lastfm options
|
15
26
|
begin
|
16
27
|
user = Settings.options[:nowplaying][:lastfm] || create_lastfm_user()
|
17
|
-
|
28
|
+
@status.fetching_from('Last.fm')
|
18
29
|
artist, track = get_lastfm_track_infos(user)
|
19
|
-
|
20
|
-
store =
|
21
|
-
|
30
|
+
@status.itunes_store
|
31
|
+
store = []
|
32
|
+
unless options['no_url']
|
33
|
+
store = lastfm_istore_request(artist, track)
|
34
|
+
if store['code'] == 404 && artist =~ /(and)/
|
35
|
+
artist.gsub!('and', '&')
|
36
|
+
store = lastfm_istore_request(artist, track)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
text_to_post = "#{@hashtag}\n \nTitle: ‘#{track}’\nArtist: #{artist}#{@custom_text}"
|
22
40
|
post_nowplaying(text_to_post, store, options)
|
23
41
|
rescue => e
|
24
|
-
|
42
|
+
@status.wtf
|
25
43
|
Errors.global_error({error: e, caller: caller, data: [store, options]})
|
26
44
|
end
|
27
45
|
end
|
28
46
|
|
29
47
|
def itunes options
|
30
48
|
begin
|
31
|
-
|
32
|
-
|
49
|
+
unless Settings.config[:platform] =~ /darwin/
|
50
|
+
@status.error_only_osx
|
51
|
+
exit
|
52
|
+
end
|
53
|
+
@status.fetching_from('iTunes')
|
33
54
|
itunes = get_itunes_track_infos()
|
34
|
-
itunes.each
|
35
|
-
|
36
|
-
|
37
|
-
|
55
|
+
itunes.each do |el|
|
56
|
+
if el.length == 0
|
57
|
+
@status.empty_fields
|
58
|
+
exit
|
59
|
+
end
|
60
|
+
end
|
61
|
+
@status.itunes_store
|
62
|
+
store = []
|
63
|
+
unless options['no_url']
|
64
|
+
store = itunes_istore_request(itunes)
|
65
|
+
if store['code'] == 404 && itunes.artist =~ /(and)/
|
66
|
+
itunes.artist.gsub!('and', '&')
|
67
|
+
store = itunes_istore_request(itunes)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
text_to_post = "#{@hashtag}\n \nTitle: ‘#{itunes.track}’\nArtist: #{itunes.artist}\nfrom ‘#{itunes.album}’#{@custom_text}"
|
38
71
|
post_nowplaying(text_to_post, store, options)
|
39
72
|
rescue => e
|
40
|
-
|
73
|
+
@status.wtf
|
41
74
|
Errors.global_error({error: e, caller: caller, data: [itunes, store, options]})
|
42
75
|
end
|
43
76
|
end
|
@@ -51,24 +84,39 @@ module Ayadn
|
|
51
84
|
lfm = feed.items[0].title.split(' – ')
|
52
85
|
return lfm[0], lfm[1]
|
53
86
|
rescue Interrupt
|
54
|
-
|
87
|
+
@status.canceled
|
88
|
+
exit
|
55
89
|
end
|
56
90
|
end
|
57
91
|
|
58
92
|
def post_nowplaying text_to_post, store, options
|
59
93
|
begin
|
60
|
-
|
61
|
-
puts Status.writing
|
62
|
-
show_nowplaying("\n#{text_to_post}", options, store)
|
94
|
+
before = text_to_post
|
63
95
|
unless options[:no_url] || store.nil?
|
64
96
|
text_to_post += "\n \n[iTunes Store](#{store['link']})"
|
65
97
|
end
|
66
|
-
|
67
|
-
|
98
|
+
poster = Post.new
|
99
|
+
poster.post_size_error(text_to_post) if poster.post_size_ok?(text_to_post) == false
|
100
|
+
@view.clear_screen
|
101
|
+
@status.writing
|
102
|
+
show_nowplaying("\n#{before}", options, store)
|
103
|
+
unless STDIN.getch == ("y" || "Y")
|
104
|
+
@status.canceled
|
105
|
+
exit
|
106
|
+
end
|
107
|
+
@view.clear_screen
|
108
|
+
@status.yourpost
|
109
|
+
puts "\n\n"
|
68
110
|
if store.nil? || options[:no_url]
|
111
|
+
text_to_post = before
|
69
112
|
visible, track, artwork, artwork_thumb, link, artist = false
|
70
113
|
else
|
71
|
-
|
114
|
+
if store['link'].nil? || store['code'] == 404
|
115
|
+
text_to_post = before
|
116
|
+
visible, track, artwork, artwork_thumb, link, artist = false
|
117
|
+
else
|
118
|
+
visible, track, artwork, artwork_thumb, link, artist = true, store['track'], store['artwork'], store['artwork_thumb'], store['link'], store['artist']
|
119
|
+
end
|
72
120
|
end
|
73
121
|
options = options.dup
|
74
122
|
options[:nowplaying] = true
|
@@ -92,21 +140,23 @@ module Ayadn
|
|
92
140
|
source: source,
|
93
141
|
visible: visible
|
94
142
|
}
|
95
|
-
resp =
|
96
|
-
FileOps.save_post(resp) if Settings.options[:backup][:
|
143
|
+
resp = poster.post(dic)
|
144
|
+
FileOps.save_post(resp) if Settings.options[:backup][:posts]
|
97
145
|
@view.show_posted(resp)
|
98
146
|
rescue => e
|
99
|
-
|
147
|
+
@status.wtf
|
100
148
|
Errors.global_error({error: e, caller: caller, data: [dic, store, options]})
|
101
149
|
end
|
102
150
|
end
|
103
151
|
|
104
152
|
def ask_lastfm_user
|
105
|
-
|
153
|
+
@status.info("please", "enter your Last.fm username", "yellow")
|
154
|
+
print "> "
|
106
155
|
begin
|
107
156
|
STDIN.gets.chomp!
|
108
157
|
rescue Interrupt
|
109
|
-
|
158
|
+
@status.canceled
|
159
|
+
exit
|
110
160
|
end
|
111
161
|
end
|
112
162
|
|
@@ -117,49 +167,60 @@ module Ayadn
|
|
117
167
|
end
|
118
168
|
|
119
169
|
def itunes_istore_request itunes
|
120
|
-
|
121
|
-
itunes_url = "https://itunes.apple.com/search?term=#{infos[0]}&term=#{infos[1]}&term=#{infos[2]}&media=music&entity=musicTrack"
|
170
|
+
itunes_url = "https://itunes.apple.com/search?term=#{itunes.artist}&term=#{itunes.track}&term=#{itunes.album}&media=music&entity=musicTrack"
|
122
171
|
get_itunes_store(itunes_url, itunes.artist, itunes.track)
|
123
172
|
end
|
124
173
|
|
125
174
|
def lastfm_istore_request artist, track
|
126
|
-
|
127
|
-
itunes_url = "https://itunes.apple.com/search?term=#{infos[0]}&term=#{infos[1]}&media=music&entity=musicTrack"
|
175
|
+
itunes_url = "https://itunes.apple.com/search?term=#{artist}&term=#{track}&media=music&entity=musicTrack"
|
128
176
|
get_itunes_store(itunes_url, artist, track)
|
129
177
|
end
|
130
178
|
|
131
179
|
def get_itunes_store url, artist, track
|
132
180
|
results = JSON.load(CNX.download(URI.escape(url)))['results']
|
133
|
-
|
181
|
+
# puts results.inspect
|
134
182
|
unless results.empty? || results.nil?
|
135
|
-
|
136
|
-
|
137
|
-
|
183
|
+
# results.each {|obj| puts obj['trackName']}
|
184
|
+
# puts "-"
|
185
|
+
# puts track
|
186
|
+
one = results.select do |obj|
|
187
|
+
next if obj['trackName'].nil?
|
188
|
+
obj['trackName'].downcase == track.downcase
|
189
|
+
end
|
190
|
+
# puts one.inspect
|
191
|
+
if one.empty?
|
192
|
+
by_artist = results.select do |obj|
|
193
|
+
next if obj['artistName'].nil?
|
138
194
|
obj['artistName'].downcase == artist.downcase
|
139
195
|
end
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
196
|
+
# puts by_artist
|
197
|
+
by_exact_track = by_artist.select do |obj|
|
198
|
+
next if obj['trackName'].nil?
|
199
|
+
obj['trackName'].downcase == track.downcase
|
200
|
+
end
|
201
|
+
# puts by_exact_track
|
202
|
+
if by_exact_track.empty?
|
203
|
+
splitted = track.split(" ").first.downcase
|
204
|
+
results = by_artist.select do |obj|
|
205
|
+
next if obj['trackName'].nil?
|
206
|
+
obj['trackName'].split(" ").first.downcase == splitted
|
207
|
+
end
|
208
|
+
else
|
209
|
+
results = by_exact_track
|
210
|
+
end
|
148
211
|
|
149
|
-
if results.length > 1
|
150
|
-
resp = results.select {|obj| obj['trackName'].downcase == track.downcase}
|
151
212
|
else
|
152
|
-
|
213
|
+
results = one
|
153
214
|
end
|
154
215
|
|
155
|
-
if
|
216
|
+
if results.empty?
|
156
217
|
return {
|
157
218
|
'code' => 404,
|
158
219
|
'request' => url
|
159
220
|
}
|
160
221
|
end
|
161
222
|
|
162
|
-
candidate =
|
223
|
+
candidate = results[0]
|
163
224
|
|
164
225
|
return {
|
165
226
|
'code' => 200,
|
@@ -180,17 +241,10 @@ module Ayadn
|
|
180
241
|
end
|
181
242
|
end
|
182
243
|
|
183
|
-
def itunes_reg arr_of_itunes
|
184
|
-
regex_exotics = /[~:-;,?!\'&`^=+<>*%()\/"“”’°£$€.…]/
|
185
|
-
arr_of_itunes.map do |itune|
|
186
|
-
itune.gsub(regex_exotics, ' ').split(' ').join('+')
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
244
|
def get_itunes_track_infos
|
191
245
|
track = `osascript -e 'tell application "iTunes"' -e 'set trackName to name of current track' -e 'return trackName' -e 'end tell'`
|
192
246
|
if track.empty?
|
193
|
-
|
247
|
+
@status.no_itunes
|
194
248
|
Errors.warn "Nowplaying canceled: unable to get info from iTunes."
|
195
249
|
exit
|
196
250
|
end
|
@@ -201,13 +255,22 @@ module Ayadn
|
|
201
255
|
end
|
202
256
|
|
203
257
|
def show_nowplaying(text, options, store)
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
258
|
+
# @status.to_be_posted
|
259
|
+
thor = Thor::Shell::Basic.new
|
260
|
+
text.split("\n").each do |line|
|
261
|
+
thor.say_status(nil, line.color(Settings.options[:colors][:excerpt]))
|
262
|
+
end
|
263
|
+
puts "\n"
|
264
|
+
unless options['no_url'] || store['code'] != 200
|
265
|
+
thor.say_status(nil, "[iTunes link](#1)")
|
266
|
+
thor.say_status(nil, "[album art](#2)")
|
267
|
+
puts "\n\n"
|
268
|
+
thor.say_status(:'#1', store['link'])
|
269
|
+
thor.say_status(:'#2', store['artwork'])
|
270
|
+
puts "\n"
|
271
|
+
@status.itunes_store_track(store)
|
209
272
|
end
|
210
|
-
|
273
|
+
@status.ok?
|
211
274
|
end
|
212
275
|
|
213
276
|
end
|
data/lib/ayadn/nowwatching.rb
CHANGED
@@ -3,11 +3,18 @@ module Ayadn
|
|
3
3
|
|
4
4
|
class NowWatching
|
5
5
|
|
6
|
-
|
6
|
+
begin
|
7
|
+
require 'spotlite'
|
8
|
+
rescue LoadError => e
|
9
|
+
puts "\nAYADN: Error while loading Gems\n\n"
|
10
|
+
puts "RUBY: #{e}\n\n"
|
11
|
+
exit
|
12
|
+
end
|
7
13
|
|
8
14
|
def initialize view = nil
|
9
15
|
@view = view
|
10
16
|
@spotlite = Spotlite::Movie
|
17
|
+
@status = Status.new
|
11
18
|
end
|
12
19
|
|
13
20
|
# -----
|
@@ -36,14 +43,14 @@ module Ayadn
|
|
36
43
|
|
37
44
|
def post args, options
|
38
45
|
options = options.dup
|
39
|
-
|
46
|
+
@status.info("connected", "IMDb", "yellow")
|
40
47
|
response = find_by_title(args, options)
|
41
48
|
text = format_post(response)
|
42
49
|
show_post(text)
|
43
50
|
filename = create_filename(response)
|
44
51
|
FileOps.download_url(filename, response.poster_url)
|
45
52
|
@view.clear_screen
|
46
|
-
|
53
|
+
@status.info("uploading", "movie poster", "yellow")
|
47
54
|
options[:embed] = ["#{Settings.config[:paths][:downloads]}/#{filename}"]
|
48
55
|
options[:movie] = true
|
49
56
|
dic = {
|
@@ -53,9 +60,10 @@ module Ayadn
|
|
53
60
|
source: 'IMDb'
|
54
61
|
}
|
55
62
|
resp = Post.new.post(dic)
|
56
|
-
FileOps.save_post(resp) if Settings.options[:backup][:
|
63
|
+
FileOps.save_post(resp) if Settings.options[:backup][:posts]
|
57
64
|
@view.clear_screen
|
58
|
-
|
65
|
+
@status.yourpost
|
66
|
+
puts "\n\n"
|
59
67
|
@view.show_posted(resp)
|
60
68
|
end
|
61
69
|
|
@@ -91,11 +99,19 @@ module Ayadn
|
|
91
99
|
|
92
100
|
def show_post text
|
93
101
|
@view.clear_screen
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
puts "\
|
98
|
-
|
102
|
+
@status.writing
|
103
|
+
@status.to_be_posted
|
104
|
+
thor = Thor::Shell::Basic.new
|
105
|
+
puts "\n"
|
106
|
+
text.split("\n").each do |line|
|
107
|
+
thor.say_status(nil, line.color(Settings.options[:colors][:excerpt]))
|
108
|
+
end
|
109
|
+
puts "\n"
|
110
|
+
@status.ok?
|
111
|
+
unless STDIN.getch == ("y" || "Y")
|
112
|
+
@status.canceled
|
113
|
+
exit
|
114
|
+
end
|
99
115
|
end
|
100
116
|
|
101
117
|
end
|
data/lib/ayadn/pinboard.rb
CHANGED
@@ -2,27 +2,32 @@
|
|
2
2
|
module Ayadn
|
3
3
|
class PinBoard
|
4
4
|
|
5
|
+
def initialize
|
6
|
+
@status = Status.new
|
7
|
+
end
|
8
|
+
|
5
9
|
def has_credentials_file?
|
6
|
-
File.exist?(Ayadn::Settings.config[:paths][:
|
10
|
+
File.exist?(Ayadn::Settings.config[:paths][:auth] + '/pinboard.data')
|
7
11
|
end
|
8
12
|
|
9
13
|
def ask_credentials
|
10
14
|
begin
|
11
|
-
|
15
|
+
@status.pin_username
|
12
16
|
pin_username = STDIN.gets.chomp()
|
13
|
-
|
17
|
+
@status.pin_password
|
14
18
|
pin_password = STDIN.noecho(&:gets).chomp()
|
15
19
|
rescue Interrupt
|
16
|
-
|
20
|
+
@status.canceled
|
21
|
+
exit
|
17
22
|
rescue => e
|
18
|
-
|
23
|
+
@status.wtf
|
19
24
|
Errors.global_error({error: e, caller: caller, data: [pin_username]})
|
20
25
|
end
|
21
26
|
save_credentials(encode(pin_username, pin_password))
|
22
27
|
end
|
23
28
|
|
24
29
|
def load_credentials
|
25
|
-
decode(File.read(Ayadn::Settings.config[:paths][:
|
30
|
+
decode(File.read(Ayadn::Settings.config[:paths][:auth] + '/pinboard.data'))
|
26
31
|
end
|
27
32
|
|
28
33
|
def pin(data)
|
@@ -37,7 +42,7 @@ module Ayadn
|
|
37
42
|
end
|
38
43
|
|
39
44
|
def save_credentials(encoded_pinboard_credentials)
|
40
|
-
File.write(Ayadn::Settings.config[:paths][:
|
45
|
+
File.write(Ayadn::Settings.config[:paths][:auth] + '/pinboard.data', encoded_pinboard_credentials)
|
41
46
|
end
|
42
47
|
|
43
48
|
def encode(username, password)
|
data/lib/ayadn/post.rb
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
module Ayadn
|
3
3
|
class Post
|
4
4
|
|
5
|
+
def initialize
|
6
|
+
@status = Status.new
|
7
|
+
end
|
8
|
+
|
5
9
|
def post(dic)
|
6
10
|
send_content(Endpoints.new.posts_url, payload_basic(dic))
|
7
11
|
end
|
@@ -16,7 +20,7 @@ module Ayadn
|
|
16
20
|
next if m == Settings.config[:identity][:username]
|
17
21
|
reply << " @#{m}"
|
18
22
|
end
|
19
|
-
|
23
|
+
post_size_error(reply) if post_size_ok?(reply) == false
|
20
24
|
dic[:text] = reply
|
21
25
|
dic[:reply_to] = dic[:id]
|
22
26
|
send_content(Endpoints.new.posts_url, payload_reply(dic))
|
@@ -84,65 +88,67 @@ module Ayadn
|
|
84
88
|
#while buffer = Readline.readline("#{Settings.config[:identity][:handle]} >> ".color(:red))
|
85
89
|
while buffer = Readline.readline(">> ".color(:red))
|
86
90
|
resp = post({text: buffer})
|
87
|
-
FileOps.save_post(resp) if Settings.options[:backup][:
|
88
|
-
|
91
|
+
FileOps.save_post(resp) if Settings.options[:backup][:posts]
|
92
|
+
@status.done
|
89
93
|
end
|
90
94
|
rescue Interrupt
|
91
|
-
|
95
|
+
@status.canceled
|
96
|
+
exit
|
92
97
|
end
|
93
98
|
end
|
94
99
|
end
|
95
100
|
|
96
101
|
def readline
|
97
|
-
|
102
|
+
@status.readline
|
98
103
|
post = []
|
99
104
|
begin
|
100
105
|
while buffer = Readline.readline("> ")
|
101
106
|
post << buffer
|
102
107
|
end
|
103
108
|
rescue Interrupt
|
104
|
-
|
109
|
+
@status.canceled
|
110
|
+
exit
|
105
111
|
end
|
106
112
|
post
|
107
113
|
end
|
108
114
|
|
109
|
-
def
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
post = result.join(" ")
|
114
|
-
size, max_size = post.length, Settings.config[:post_max_length]
|
115
|
-
if size < 1
|
116
|
-
abort(error_text_empty)
|
117
|
-
elsif size > max_size
|
118
|
-
Errors.warn "Canceled: too long (#{size - max_size}chars)"
|
119
|
-
puts "\nYour text was: \n\n#{post}\n\n".color(:yellow)
|
120
|
-
abort(Status.too_long(size, max_size))
|
121
|
-
end
|
115
|
+
def post_size_ok?(post) # works on a string, returns boolean
|
116
|
+
text = keep_text_from_markdown_links(post)
|
117
|
+
size, max_size = text.length, Settings.config[:post_max_length]
|
118
|
+
(size >= 1 && size <= max_size)
|
122
119
|
end
|
123
120
|
|
124
|
-
def
|
125
|
-
|
121
|
+
def message_size_ok?(message) # works on a string, returns boolean
|
122
|
+
text = keep_text_from_markdown_links(message)
|
123
|
+
size, max_size = text.length, Settings.config[:message_max_length]
|
124
|
+
(size >= 1 && size <= max_size)
|
126
125
|
end
|
127
126
|
|
128
|
-
def
|
129
|
-
|
127
|
+
def post_size_error(post)
|
128
|
+
text = keep_text_from_markdown_links(post)
|
129
|
+
size, max_size = text.length, Settings.config[:post_max_length]
|
130
|
+
bad_text_size(post, size, max_size)
|
130
131
|
end
|
131
132
|
|
132
|
-
def
|
133
|
-
|
134
|
-
|
135
|
-
size
|
133
|
+
def message_size_error(message)
|
134
|
+
text = keep_text_from_markdown_links(message)
|
135
|
+
size, max_size = text.length, Settings.config[:message_max_length]
|
136
|
+
bad_text_size(message, size, max_size)
|
137
|
+
end
|
138
|
+
|
139
|
+
def bad_text_size(post, size, max_size)
|
136
140
|
if size < 1
|
137
|
-
error_text_empty
|
138
|
-
exit
|
141
|
+
error_text_empty()
|
139
142
|
elsif size > max_size
|
140
143
|
Errors.warn "Canceled: too long (#{size - max_size}chars)"
|
141
|
-
|
144
|
+
@status.info("info", "your text:", "cyan")
|
145
|
+
puts post
|
146
|
+
@status.too_long(size, max_size)
|
147
|
+
exit
|
142
148
|
end
|
143
149
|
end
|
144
150
|
|
145
|
-
def
|
151
|
+
def keep_text_from_markdown_links(str)
|
146
152
|
str.gsub(/\[([^\]]+)\]\(([^)]+)\)/, '\1')
|
147
153
|
end
|
148
154
|
|
@@ -151,13 +157,10 @@ module Ayadn
|
|
151
157
|
result.split('|||') #=> [text, link]
|
152
158
|
end
|
153
159
|
|
154
|
-
def text_is_empty?(args)
|
155
|
-
args.empty? || args[0] == ""
|
156
|
-
end
|
157
|
-
|
158
160
|
def error_text_empty
|
159
|
-
|
160
|
-
Errors.warn "-
|
161
|
+
@status.no_text
|
162
|
+
Errors.warn "-No text-"
|
163
|
+
exit
|
161
164
|
end
|
162
165
|
|
163
166
|
end
|
data/lib/ayadn/profile.rb
CHANGED
@@ -5,7 +5,10 @@ module Ayadn
|
|
5
5
|
attr_reader :options, :text, :payload
|
6
6
|
|
7
7
|
def initialize options
|
8
|
-
|
8
|
+
if options.empty?
|
9
|
+
@status.profile_options
|
10
|
+
exit
|
11
|
+
end
|
9
12
|
@options = options
|
10
13
|
end
|
11
14
|
|
@@ -23,8 +26,8 @@ module Ayadn
|
|
23
26
|
unless @options[:delete] || @options[:avatar] || @options[:cover]
|
24
27
|
writer = Post.new
|
25
28
|
input = writer.compose()
|
26
|
-
writer.check_post_length(input)
|
27
29
|
@text = input.join("\n")
|
30
|
+
writer.post_size_error(@text) if writer.post_size_ok?(@text) == false
|
28
31
|
end
|
29
32
|
end
|
30
33
|
|