ayadn 1.2.8 → 1.2.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a05ff15391beac67e7ee90c71472a52902a98018
4
- data.tar.gz: bdb58c558b8e16a55e5d1d60db39c4bf3f26a6b4
3
+ metadata.gz: 396696ba41b0ced3c60604dec4dbd72e0fce6aad
4
+ data.tar.gz: 4cc63db6bf94dd34e50947d3a40e5a6faf33bbd4
5
5
  SHA512:
6
- metadata.gz: 7158eb289115d85c4dfbb31e7f32de9f268f82f418cf188e6c1f38ea545117fc4cdd0f18d96aeb7b37414fa2fada0191b13bb0fdc062ddafa2d250a83d6a18ff
7
- data.tar.gz: f71e3a75b986786b21810b399c4975bd337a614e6eec9ada372c7f0b09ae47c247c4d015e9f1a7cb6a675d3b6ab4dea1c38bd0e8d166fbc0e5bb30a3ee949b90
6
+ metadata.gz: 66a344b2aa29c53ff5a4b131d1b760f9e493dba8d3644a65381187d4c3fb386bb3ac1b00502dffb29a1dc03d42578d80a6e9d57b4f635203c7d6ba8d5c8d69c7
7
+ data.tar.gz: 4d0c31c8dac46ccd6a5359af261bcf76af857f6d27b7190d027396dd3cf8c4203c83773ef184f1836f12e2712a4c70403445e93a27e8de918a0e5c95ab520dea
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # 1.2.9 - 'Kirschen'
2
+
3
+ - NiceRank database auto-limits to 10000 users
4
+ - Better handling of connection errors
5
+ - Better display of emojis
6
+ - General code cleaning
7
+
1
8
  # 1.2.8 - 'Hans'
2
9
 
3
10
  - No more Ruby 1.9.3
data/lib/ayadn/action.rb CHANGED
@@ -460,7 +460,7 @@ module Ayadn
460
460
  if options[:users]
461
461
  stream['data'].sort_by! {|obj| obj['counts']['followers']}
462
462
  stream['data'].each do |obj|
463
- puts "----------\n\n\n"
463
+ puts @view.big_separator
464
464
  @view.show_userinfos(obj, nil)
465
465
  end
466
466
  elsif options[:channels]
@@ -874,9 +874,7 @@ module Ayadn
874
874
  Databases.close_all
875
875
  abort(Status.error_only_osx) unless Settings.config[:platform] =~ /darwin/
876
876
  itunes = get_track_infos
877
- itunes.each do |el|
878
- abort(Status.empty_fields) if el.length == 0
879
- end
877
+ itunes.each {|el| abort(Status.empty_fields) if el.length == 0}
880
878
  @view.clear_screen
881
879
  text_to_post = "#nowplaying\nTitle: ‘#{itunes.track}’\nArtist: #{itunes.artist}\nfrom ‘#{itunes.album}’"
882
880
  puts Status.writing
@@ -886,9 +884,8 @@ module Ayadn
886
884
  exit
887
885
  end
888
886
  puts "\n"
889
- resp = Post.new.post([text_to_post])
890
887
  puts Status.yourpost
891
- @view.show_posted(resp)
888
+ @view.show_posted(Post.new.post([text_to_post]))
892
889
  rescue => e
893
890
  puts Status.wtf
894
891
  Errors.global_error("action/nowplaying", itunes, e)
@@ -1082,13 +1079,13 @@ module Ayadn
1082
1079
  end
1083
1080
 
1084
1081
  def user_404(username)
1085
- puts "\nUser #{username} doesn't exist. It could be a deleted account.\n".color(:red)
1082
+ puts Status.user_404 username
1086
1083
  Errors.info("User #{username} doesn't exist")
1087
1084
  exit
1088
1085
  end
1089
1086
 
1090
1087
  def post_404(post_id)
1091
- puts "\nImpossible to find #{post_id}. This post may have been deleted.\n".color(:red)
1088
+ puts Status.post_404 post_id
1092
1089
  Errors.info("Impossible to find #{post_id}")
1093
1090
  exit
1094
1091
  end
@@ -1172,7 +1169,7 @@ module Ayadn
1172
1169
  channel_id = Databases.get_channel_id(orig)
1173
1170
  if channel_id.nil?
1174
1171
  Errors.warn("Alias '#{orig}' doesn't exist.")
1175
- puts "\nThis alias doesn't exist.\n\n".color(:red)
1172
+ puts Status.no_alias
1176
1173
  exit
1177
1174
  end
1178
1175
  end
@@ -1221,7 +1218,7 @@ module Ayadn
1221
1218
  def get_track_infos
1222
1219
  track = `osascript -e 'tell application "iTunes"' -e 'set trackName to name of current track' -e 'return trackName' -e 'end tell'`
1223
1220
  if track.empty?
1224
- puts "\nCanceled: unable to get info from iTunes.\n".color(:red)
1221
+ puts Status.no_itunes
1225
1222
  Errors.warn "Nowplaying canceled: unable to get info from iTunes."
1226
1223
  exit
1227
1224
  end
@@ -1260,24 +1257,26 @@ module Ayadn
1260
1257
  end
1261
1258
 
1262
1259
  def view_all_hashtag_links(stream, hashtag)
1263
- links = links_from_posts(stream)
1264
1260
  @view.clear_screen
1265
1261
  puts "Links from posts containing hashtag '##{hashtag}': \n".color(:cyan)
1266
- show_links(links)
1262
+ show_links(links_from_posts(stream))
1267
1263
  end
1268
1264
 
1269
1265
  def view_all_search_links(stream, words)
1270
- links = links_from_posts(stream)
1271
1266
  @view.clear_screen
1272
1267
  puts "Links from posts containing word(s) '#{words}': \n".color(:cyan)
1273
- show_links(links)
1268
+ show_links(links_from_posts(stream))
1274
1269
  end
1275
1270
 
1276
1271
  def view_all_stars_links(stream)
1277
- links = links_from_posts(stream)
1278
1272
  @view.clear_screen
1279
1273
  puts "Links from your starred posts: \n".color(:cyan)
1280
- show_links(links)
1274
+ show_links(links_from_posts(stream))
1275
+ end
1276
+
1277
+ def self.quit msg
1278
+ puts msg
1279
+ exit
1281
1280
  end
1282
1281
 
1283
1282
  end
data/lib/ayadn/alias.rb CHANGED
@@ -10,8 +10,7 @@ module Ayadn
10
10
  unless args.empty?
11
11
  channel, channel_alias = args[0], args[1]
12
12
  else
13
- puts Status.wrong_arguments
14
- exit
13
+ Action.quit Status.wrong_arguments
15
14
  end
16
15
  if channel.is_integer?
17
16
  Databases.create_alias(channel, channel_alias)
@@ -37,8 +36,7 @@ module Ayadn
37
36
  Logs.rec.info "Deleted alias '#{args[0]}'."
38
37
  puts Status.done
39
38
  else
40
- puts Status.wrong_arguments
41
- exit
39
+ Action.quit Status.wrong_arguments
42
40
  end
43
41
  rescue => e
44
42
  Errors.global_error("alias/delete", args, e)
@@ -55,8 +53,7 @@ module Ayadn
55
53
  unless database.nil?
56
54
  new_db = File.realpath(database)
57
55
  else
58
- puts Status.wrong_arguments
59
- exit
56
+ Action.quit Status.wrong_arguments
60
57
  end
61
58
  if File.exist?(new_db)
62
59
  Databases.import_aliases(new_db)
@@ -85,9 +82,7 @@ module Ayadn
85
82
  list.each {|k,v| h[k] = v}
86
83
  puts h.to_json
87
84
  else
88
- puts "\e[H\e[2J"
89
- puts Workers.new.build_aliases_list(list)
90
- puts "\n"
85
+ View.new.page Workers.new.build_aliases_list(list)
91
86
  end
92
87
  else
93
88
  puts Status.empty_list
data/lib/ayadn/api.rb CHANGED
@@ -3,42 +3,30 @@ module Ayadn
3
3
  class API
4
4
 
5
5
  def get_unified(options)
6
- if options[:new] || options[:scroll]
7
- options = {since_id: Databases.pagination['unified']}
8
- end
6
+ options = paginate options, 'unified'
9
7
  get_parsed_response(Endpoints.new.unified(options))
10
8
  end
11
9
 
12
10
  def get_checkins(options)
13
- if options[:new] || options[:scroll]
14
- options = {since_id: Databases.pagination['explore:checkins']}
15
- end
11
+ options = paginate options, 'explore:checkins'
16
12
  get_parsed_response(Endpoints.new.checkins(options))
17
13
  end
18
14
 
19
15
  def get_global(options)
20
- if options[:new] || options[:scroll]
21
- options = {since_id: Databases.pagination['global']}
22
- end
16
+ options = paginate options, 'global'
23
17
  get_parsed_response(Endpoints.new.global(options))
24
18
  end
25
19
 
26
20
  def get_trending(options)
27
- if options[:new] || options[:scroll]
28
- options = {since_id: Databases.pagination['explore:trending']}
29
- end
21
+ options = paginate options, 'explore:trending'
30
22
  get_explore(:trending, options)
31
23
  end
32
24
  def get_photos(options)
33
- if options[:new] || options[:scroll]
34
- options = {since_id: Databases.pagination['explore:photos']}
35
- end
25
+ options = paginate options, 'explore:photos'
36
26
  get_explore(:photos, options)
37
27
  end
38
28
  def get_conversations(options)
39
- if options[:new] || options[:scroll]
40
- options = {since_id: Databases.pagination['explore:replies']}
41
- end
29
+ options = paginate options, 'explore:replies'
42
30
  get_explore(:conversations, options)
43
31
  end
44
32
 
@@ -125,8 +113,7 @@ module Ayadn
125
113
  options = {:count => 200, :before_id => nil}
126
114
  big = []
127
115
  loop do
128
- url = get_list_url(username, target, options)
129
- resp = get_parsed_response(url)
116
+ resp = get_parsed_response(get_list_url(username, target, options))
130
117
  big << resp
131
118
  break if resp['meta']['min_id'] == nil || resp['meta']['more'] == false
132
119
  options = {:count => 200, :before_id => resp['meta']['min_id']}
@@ -231,9 +218,7 @@ module Ayadn
231
218
  end
232
219
 
233
220
  def get_messages(channel_id, options)
234
- if options[:new] || options[:scroll]
235
- options = {since_id: Databases.pagination["channel:#{channel_id}"]}
236
- end
221
+ options = paginate options, "channel:#{channel_id}"
237
222
  get_parsed_response(Endpoints.new.messages(channel_id, options))
238
223
  end
239
224
 
@@ -291,6 +276,13 @@ module Ayadn
291
276
 
292
277
  private
293
278
 
279
+ def paginate options, target
280
+ if options[:new] || options[:scroll]
281
+ return {since_id: Databases.pagination[target]}
282
+ end
283
+ return options
284
+ end
285
+
294
286
  def get_parsed_response(url)
295
287
  JSON.parse(CNX.get_response_from(url))
296
288
  end
@@ -307,8 +299,7 @@ module Ayadn
307
299
  options = {:count => 200, :before_id => nil}
308
300
  big_hash = {}
309
301
  loop do
310
- url = get_list_url(username, target, options)
311
- resp = get_parsed_response(url)
302
+ resp = get_parsed_response(get_list_url(username, target, options))
312
303
  big_hash.merge!(Workers.extract_users(resp))
313
304
  break if resp['meta']['min_id'] == nil
314
305
  options = {:count => 200, :before_id => resp['meta']['min_id']}
data/lib/ayadn/app.rb CHANGED
@@ -3,7 +3,7 @@ module Ayadn
3
3
  class App < Thor
4
4
  package_name "Ayadn"
5
5
 
6
- %w{action api descriptions endpoints cnx view workers settings post status extend databases fileops logs pinboard set alias errors blacklist scroll authorize switch mark nicerank}.each { |r| require_relative "#{r}" }
6
+ %w{action api descriptions endpoints cnx view workers settings post status extend databases fileops logs pinboard set alias errors blacklist scroll authorize switch mark nicerank debug}.each { |r| require_relative "#{r}" }
7
7
 
8
8
  desc "timeline", "Show your App.net timeline, aka the Unified Stream (-tl)"
9
9
  map "unified" => :timeline
@@ -4,22 +4,16 @@ module Ayadn
4
4
  desc "add TYPE TARGET", "Adds a mention, hashtag or client to your blacklist"
5
5
  long_desc Descriptions.blacklist_add
6
6
  def add(*args)
7
- if args.length < 2
8
- puts Status.type_and_target_missing
9
- end
10
- blacklist = BlacklistWorkers.new
11
- blacklist.add(args)
7
+ Action.quit(Status.type_and_target_missing) if args.length < 2
8
+ BlacklistWorkers.new.add(args)
12
9
  puts Status.done
13
10
  end
14
11
 
15
12
  desc "remove TYPE TARGET", "Removes a mention, hashtag or client from your blacklist"
16
13
  long_desc Descriptions.blacklist_remove
17
14
  def remove(*args)
18
- if args.length < 2
19
- puts Status.type_and_target_missing
20
- end
21
- blacklist = BlacklistWorkers.new
22
- blacklist.remove(args)
15
+ Action.quit(Status.type_and_target_missing) if args.length < 2
16
+ BlacklistWorkers.new.remove(args)
23
17
  puts Status.done
24
18
  end
25
19
 
@@ -27,23 +21,19 @@ module Ayadn
27
21
  long_desc Descriptions.blacklist_list
28
22
  option :raw, aliases: "-x", type: :boolean, desc: "Outputs the raw list in CSV"
29
23
  def list
30
- blacklist = BlacklistWorkers.new
31
- blacklist.list(options)
24
+ BlacklistWorkers.new.list(options)
32
25
  end
33
26
 
34
27
  desc "import DATABASE", "Imports a blacklist database from another Ayadn account"
35
28
  long_desc Descriptions.blacklist_import
36
29
  def import(database)
37
- blacklist = BlacklistWorkers.new
38
- blacklist.import(database)
39
- puts Status.done
30
+ BlacklistWorkers.new.import(database)
40
31
  end
41
32
 
42
33
  desc "convert", "Convert your current blacklist database to the new format"
43
34
  long_desc Descriptions.blacklist_convert
44
35
  def convert
45
- blacklist = BlacklistWorkers.new
46
- blacklist.convert
36
+ BlacklistWorkers.new.convert
47
37
  puts Status.done
48
38
  end
49
39
 
data/lib/ayadn/cnx.rb CHANGED
@@ -3,18 +3,28 @@ module Ayadn
3
3
  class CNX
4
4
 
5
5
  def self.get url
6
+ working = true
6
7
  begin
7
8
  RestClient.get(url) do |response, request, result|
8
- debug(response, url) if Settings.options[:timeline][:show_debug] == true
9
- #response
9
+ Debug.http response, url
10
10
  check_nr response, url
11
11
  end
12
12
  rescue SocketError => e
13
- puts "\nConnection error.".color(:red)
14
- Errors.global_error("cnx.rb/get", url, e)
13
+ if working == true
14
+ working = false
15
+ sleep 0.5
16
+ retry
17
+ end
18
+ Errors.nr "URL: #{url}"
19
+ return {'meta' => {'code' => 666}, 'data' => "#{e}"}.to_json
15
20
  rescue SystemCallError => e
16
- puts "\nConnection error.".color(:red)
17
- Errors.global_error("cnx.rb/get", url, e)
21
+ if working == true
22
+ working = false
23
+ sleep 0.5
24
+ retry
25
+ end
26
+ Errors.nr "URL: #{url}"
27
+ return {'meta' => {'code' => 666}, 'data' => "#{e}"}.to_json
18
28
  rescue => e
19
29
  Errors.global_error("cnx.rb/get", url, e)
20
30
  end
@@ -25,39 +35,49 @@ module Ayadn
25
35
  when 200
26
36
  response
27
37
  when 204
28
- puts "\nError: the NiceRank filter made too many requests to the server. You may either wait for a little while before scrolling the filtered Global again, or set the scroll timer to a greater value (example: `ayadn set scroll timer 5`). You can also let the unranked posts appear in the stream if you prefer (see http://ayadn-app.net/doc).\n".color(:red)
38
+ puts "\nError: the NiceRank filter made too many requests to the server. You may either wait for a little while before scrolling the filtered Global again, or set the scroll timer to a greater value (example: `ayadn set scroll timer 5`). (see http://ayadn-app.net/doc).\n".color(:red)
29
39
  Errors.global_error("cnx.rb/get", [url, response.inspect, response.headers], "NiceRank: TOO MANY REQUESTS")
30
40
  else
31
41
  response
32
42
  end
33
43
  end
34
44
 
35
- def self.debug response, url
36
- deb = ":::::\n"
37
- deb << "Url:\t\t#{url}\n\n"
38
- deb << "Headers:\t#{response.headers}\n"
39
- deb << ":::::\n"
40
- puts deb.color(Settings.options[:colors][:debug])
41
- end
42
-
43
45
  def self.get_response_from(url)
46
+ try_cnx = 1
44
47
  begin
45
48
  RestClient.get(url) do |response, request, result| #, :verify_ssl => OpenSSL::SSL::VERIFY_NONE
46
- debug(response, url) if Settings.options[:timeline][:show_debug] == true
47
- check(response)
49
+ Debug.http response, url
50
+ check response
48
51
  end
49
52
  rescue SocketError => e
53
+ if try_cnx < 4
54
+ try_cnx = retry_adn 10, try_cnx
55
+ retry
56
+ end
50
57
  puts "\nConnection error.".color(:red)
51
- Errors.global_error("cnx.rb/get", url, e)
58
+ Errors.global_error("cnx.rb/get_response_from", url, e)
52
59
  rescue SystemCallError => e
60
+ if try_cnx < 4
61
+ try_cnx = retry_adn 15, try_cnx
62
+ retry
63
+ end
53
64
  puts "\nConnection error.".color(:red)
54
- Errors.global_error("cnx.rb/get", url, e)
65
+ Errors.global_error("cnx.rb/get_response_from", url, e)
55
66
  rescue => e
56
- Errors.global_error("cnx.rb/get", url, e)
67
+ Errors.global_error("cnx.rb/get_response_from", url, e)
57
68
  end
58
69
  end
59
70
 
60
- def self.check(response)
71
+ def self.retry_adn seconds, try_cnx
72
+ Errors.warn "Unable to connect to App.net"
73
+ puts "\n\nUnable to connect to App.net\nRetrying in #{seconds} seconds... (#{try_cnx}/3)\n".color(:red)
74
+ try_cnx += 1
75
+ sleep seconds
76
+ puts "\e[H\e[2J"
77
+ try_cnx
78
+ end
79
+
80
+ def self.check response
61
81
  message = JSON.parse(response)['meta']['error_message'] if response.code != 200
62
82
  case response.code
63
83
  when 200
@@ -96,8 +116,8 @@ module Ayadn
96
116
  begin
97
117
  #RestClient::Resource.new(url).delete
98
118
  RestClient.delete(url) do |response, request, result|
99
- debug(response, url) if Settings.options[:timeline][:show_debug] == true
100
- check(response)
119
+ Debug.http response, url
120
+ check response
101
121
  end
102
122
  rescue SocketError => e
103
123
  puts "\nConnection error.".color(:red)
@@ -113,8 +133,8 @@ module Ayadn
113
133
  def self.post(url, payload = nil)
114
134
  begin
115
135
  RestClient.post(url, payload.to_json, :content_type => :json, :accept => :json) do |response, request, result|
116
- debug(response, url) if Settings.options[:timeline][:show_debug] == true
117
- check(response)
136
+ Debug.http response, url
137
+ check response
118
138
  end
119
139
  rescue SocketError => e
120
140
  puts "\nConnection error.".color(:red)
@@ -130,8 +150,8 @@ module Ayadn
130
150
  def self.put(url, payload)
131
151
  begin
132
152
  RestClient.put(url, payload.to_json, :content_type => :json, :accept => :json) do |response, request, result|
133
- debug(response, url) if Settings.options[:timeline][:show_debug] == true
134
- check(response)
153
+ Debug.http response, url
154
+ check response
135
155
  end
136
156
  rescue SocketError => e
137
157
  puts "\nConnection error.".color(:red)
@@ -17,35 +17,24 @@ module Ayadn
17
17
  @nicerank = self.init "#{Settings.config[:paths][:db]}/nicerank.db"
18
18
  end
19
19
 
20
+ def self.all_dbs
21
+ [@users, @index, @pagination, @aliases, @blacklist, @bookmarks, @nicerank]
22
+ end
23
+
20
24
  def self.close_all
21
25
 
22
- if @nicerank.size > 5000
23
- limit = Time.now - 432000
26
+ if @nicerank.size > 10000
27
+ limit = Time.now - (3600 * 168)
24
28
  @nicerank.each {|k,v| @nicerank.delete(k) if v[:cached] < limit}
25
- if @nicerank.size > 5000
26
- limit = Time.now - 86400
29
+ if @nicerank.size > 10000
30
+ limit = Time.now - (3600 * 48)
27
31
  @nicerank.each {|k,v| @nicerank.delete(k) if v[:cached] < limit}
28
32
  end
29
33
  end
30
34
 
31
- if Settings.options[:timeline][:show_debug] == true
32
- puts "/////\nSETTINGS\n"
33
- jj JSON.parse((Settings.config).to_json)
34
- jj JSON.parse((Settings.options).to_json)
35
- puts "/////\n\n"
35
+ Debug.db all_dbs
36
36
 
37
- puts ">>>>>\nDATABASES\n"
38
- [@users, @index, @pagination, @aliases, @blacklist, @bookmarks, @nicerank].each do |db|
39
- puts "Path:\t#{db.file}\nLength:\t#{db.size}\nSize:\t#{db.bytesize / 1024}KB"
40
- end
41
- puts ">>>>>\n\n"
42
-
43
- puts "^^^^^\nTOKEN\n"
44
- puts Settings.user_token
45
- puts "^^^^^\n\n"
46
- end
47
-
48
- [@users, @index, @pagination, @aliases, @blacklist, @bookmarks, @nicerank].each do |db|
37
+ all_dbs.each do |db|
49
38
  db.flush
50
39
  db.compact
51
40
  db.close
@@ -63,38 +52,26 @@ module Ayadn
63
52
  end
64
53
 
65
54
  def self.add_niceranks niceranks
66
- niceranks.each do |id,infos|
67
- @nicerank[id] = infos
68
- end
55
+ niceranks.each {|id,infos| @nicerank[id] = infos}
69
56
  end
70
57
 
71
58
  def self.get_niceranks user_ids
72
59
  ids = {}
73
- user_ids.each do |id|
74
- ids[id] = @nicerank[id]
75
- end
60
+ user_ids.each {|id| ids[id] = @nicerank[id]}
76
61
  ids
77
62
  end
78
63
 
79
64
  def self.add_mention_to_blacklist(target)
80
- target.each do |username|
81
- @blacklist[username.downcase] = :mention
82
- end
65
+ target.each {|username| @blacklist[username.downcase] = :mention}
83
66
  end
84
67
  def self.add_client_to_blacklist(target)
85
- target.each do |source|
86
- @blacklist[source.downcase] = :client
87
- end
68
+ target.each {|source| @blacklist[source.downcase] = :client}
88
69
  end
89
70
  def self.add_hashtag_to_blacklist(target)
90
- target.each do |tag|
91
- @blacklist[tag.downcase] = :hashtag
92
- end
71
+ target.each {|tag| @blacklist[tag.downcase] = :hashtag}
93
72
  end
94
73
  def self.remove_from_blacklist(target)
95
- target.each do |el|
96
- @blacklist.delete(el.downcase)
97
- end
74
+ target.each {|el| @blacklist.delete(el.downcase)}
98
75
  end
99
76
  def self.import_blacklist(blacklist)
100
77
  new_list = self.init blacklist
@@ -103,13 +80,9 @@ module Ayadn
103
80
  end
104
81
  def self.convert_blacklist
105
82
  dummy = {}
106
- @blacklist.each do |v,k|
107
- dummy[v.downcase] = k
108
- end
83
+ @blacklist.each {|v,k| dummy[v.downcase] = k}
109
84
  @blacklist.clear
110
- dummy.each do |v,k|
111
- @blacklist[v] = k
112
- end
85
+ dummy.each {|v,k| @blacklist[v] = k}
113
86
  end
114
87
  def self.save_max_id(stream)
115
88
  @pagination[stream['meta']['marker']['name']] = stream['meta']['max_id']
@@ -134,17 +107,13 @@ module Ayadn
134
107
  end
135
108
 
136
109
  def self.get_alias_from_id(channel_id)
137
- @aliases.each do |al, id|
138
- return al if id == channel_id
139
- end
110
+ @aliases.each {|al, id| return al if id == channel_id}
140
111
  nil
141
112
  end
142
113
 
143
114
  def self.save_indexed_posts(posts)
144
115
  @index.clear
145
- posts.each do |id, hash|
146
- @index[id] = hash
147
- end
116
+ posts.each {|id, hash| @index[id] = hash}
148
117
  end
149
118
 
150
119
  def self.get_index_length
@@ -153,19 +122,15 @@ module Ayadn
153
122
 
154
123
  def self.get_post_from_index(number)
155
124
  unless number > @index.length || number <= 0
156
- @index.each do |id, values|
157
- return values if values[:count] == number
158
- end
125
+ @index.each {|id, values| return values if values[:count] == number}
159
126
  else
160
- puts "\nNumber must be in the range of the indexed posts.\n".color(:red)
127
+ puts Status.must_be_in_index
161
128
  Errors.global_error("databases/get_post_from_index", number, "out of range")
162
129
  end
163
130
  end
164
131
 
165
132
  def self.add_to_users_db_from_list(list)
166
- list.each do |id, content_array|
167
- @users[id] = {content_array[0] => content_array[1]}
168
- end
133
+ list.each { |id, content_array| @users[id] = {content_array[0] => content_array[1]} }
169
134
  end
170
135
 
171
136
  def self.add_to_users_db(id, username, name)