ayadn 1.0.13 → 1.1.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.
@@ -25,9 +25,10 @@ module Ayadn
25
25
 
26
26
  desc "list", "List the content of your blacklist"
27
27
  long_desc Descriptions.blacklist_list
28
+ option :raw, aliases: "-x", type: :boolean, desc: "Outputs the raw list in CSV"
28
29
  def list
29
30
  blacklist = BlacklistWorkers.new
30
- blacklist.list
31
+ blacklist.list(options)
31
32
  end
32
33
 
33
34
  desc "import DATABASE", "Imports a blacklist database from another Ayadn account"
@@ -37,6 +38,15 @@ module Ayadn
37
38
  blacklist.import(database)
38
39
  puts Status.done
39
40
  end
41
+
42
+ desc "convert", "Convert your current blacklist database to the new format"
43
+ long_desc Descriptions.blacklist_convert
44
+ def convert
45
+ blacklist = BlacklistWorkers.new
46
+ blacklist.convert
47
+ puts Status.done
48
+ end
49
+
40
50
  end
41
51
 
42
52
  class BlacklistWorkers
@@ -61,6 +71,13 @@ module Ayadn
61
71
  Databases.close_all
62
72
  end
63
73
  end
74
+ def convert
75
+ begin
76
+ Databases.convert_blacklist
77
+ ensure
78
+ Databases.close_all
79
+ end
80
+ end
64
81
  def add(args)
65
82
  begin
66
83
  type, target = args[0], args[1]
@@ -100,17 +117,27 @@ module Ayadn
100
117
  Databases.close_all
101
118
  end
102
119
  end
103
- def list
120
+ def list(options)
104
121
  begin
105
- list = Databases.blacklist
106
- unless list.empty?
107
- puts Workers.new.build_blacklist_list(list)
108
- else
109
- abort(Status.empty_list)
110
- end
122
+ show_list(options)
111
123
  ensure
112
124
  Databases.close_all
113
125
  end
114
126
  end
127
+
128
+ private
129
+
130
+ def show_list(options)
131
+ list = Databases.blacklist
132
+ unless list.empty?
133
+ if options[:raw]
134
+ list.each {|v,k| puts "#{v},#{k}"}
135
+ else
136
+ puts Workers.new.build_blacklist_list(list)
137
+ end
138
+ else
139
+ abort(Status.empty_list)
140
+ end
141
+ end
115
142
  end
116
143
  end
@@ -25,23 +25,32 @@ module Ayadn
25
25
  end
26
26
 
27
27
  def self.add_mention_to_blacklist(target)
28
- @blacklist[target] = :mention
28
+ @blacklist[target.downcase] = :mention
29
29
  end
30
30
  def self.add_client_to_blacklist(target)
31
- @blacklist[target] = :client
31
+ @blacklist[target.downcase] = :client
32
32
  end
33
33
  def self.add_hashtag_to_blacklist(target)
34
- @blacklist[target] = :hashtag
34
+ @blacklist[target.downcase] = :hashtag
35
35
  end
36
36
  def self.remove_from_blacklist(target)
37
- @blacklist.delete(target)
37
+ @blacklist.delete(target.downcase)
38
38
  end
39
39
  def self.import_blacklist(blacklist)
40
40
  new_list = Daybreak::DB.new blacklist
41
41
  new_list.each {|name,type| @blacklist[name] = type}
42
42
  new_list.close
43
43
  end
44
-
44
+ def self.convert_blacklist
45
+ dummy = {}
46
+ @blacklist.each do |v,k|
47
+ dummy[v.downcase] = k
48
+ end
49
+ @blacklist.clear
50
+ dummy.each do |v,k|
51
+ @blacklist[v] = k
52
+ end
53
+ end
45
54
  def self.save_max_id(stream)
46
55
  @pagination[stream['meta']['marker']['name']] = stream['meta']['max_id']
47
56
  end
@@ -13,6 +13,9 @@ module Ayadn
13
13
  def self.options_raw
14
14
  "Outputs the App.net raw JSON response"
15
15
  end
16
+ def self.options_extract
17
+ "Extract links from each object"
18
+ end
16
19
  def self.unified
17
20
  <<-USAGE
18
21
  Show your App.net timeline, aka the Unified Stream.
@@ -495,6 +498,20 @@ module Ayadn
495
498
  \n\n
496
499
  USAGE
497
500
  end
501
+ def self.delete_m
502
+ <<-USAGE
503
+ Delete a message (private message or message in a channel).
504
+
505
+ Usage:
506
+
507
+ ayadn delete_m 42666 3365251
508
+
509
+ ayadn -DM 42666 3365251
510
+
511
+ ayadn -DM my_channel_alias 3365251
512
+ \n\n
513
+ USAGE
514
+ end
498
515
  def self.unfollow
499
516
  <<-USAGE
500
517
  Unfollow a user.
@@ -911,6 +928,8 @@ module Ayadn
911
928
  <<-USAGE
912
929
  Adds a mention, hashtag or client to your blacklist.
913
930
 
931
+ You don't have to respect the case as all data is recorded downcase.
932
+
914
933
  Usage:
915
934
 
916
935
  ayadn blacklist add mention @shmuck
@@ -929,6 +948,8 @@ module Ayadn
929
948
  <<-USAGE
930
949
  Removes a mention, hashtag or client from your blacklist.
931
950
 
951
+ You don't have to respect the case as all data is recorded downcase.
952
+
932
953
  Usage:
933
954
 
934
955
  ayadn blacklist remove mention @shmuck
@@ -953,6 +974,18 @@ module Ayadn
953
974
  \n\n
954
975
  USAGE
955
976
  end
977
+ def self.blacklist_convert
978
+ <<-USAGE
979
+ Convert your current blacklist database to the new format. Useful if you used the blacklist command prior to Ayadn 10.0.13.
980
+
981
+ Usage:
982
+
983
+ ayadn blacklist convert
984
+
985
+ ayadn -K convert
986
+ \n\n
987
+ USAGE
988
+ end
956
989
  def self.blacklist_list
957
990
  <<-USAGE
958
991
  Lists the content of your blacklist.
@@ -185,6 +185,10 @@ module Ayadn
185
185
  "#{@posts_url}#{post_id}?access_token=#{Settings.user_token}"
186
186
  end
187
187
 
188
+ def delete_message(channel_id, message_id)
189
+ "#{@channels_url}/#{channel_id}/messages/#{message_id}?access_token=#{Settings.user_token}"
190
+ end
191
+
188
192
  def follow(username)
189
193
  "#{@users_url}#{username}/follow?access_token=#{Settings.user_token}"
190
194
  end
data/lib/ayadn/errors.rb CHANGED
@@ -11,7 +11,7 @@ module Ayadn
11
11
  Logs.rec.debug "STACK: #{caller}"
12
12
  Logs.rec.error "--END--"
13
13
  puts "\n(error logged in #{Settings.config[:paths][:log]}/ayadn.log)\n".color(:blue)
14
- raise error
14
+ #raise error
15
15
  exit
16
16
  end
17
17
  def self.error(status)
data/lib/ayadn/scroll.rb CHANGED
@@ -7,44 +7,28 @@ module Ayadn
7
7
  @view = view
8
8
  end
9
9
 
10
- def global(options)
11
- options = check_raw(options)
12
- loop do
13
- begin
14
- stream = @api.get_global(options)
15
- if Databases.has_new?(stream, 'global')
16
- show(stream, options)
17
- end
18
- unless stream['meta']['max_id'].nil?
19
- Databases.save_max_id(stream)
20
- options = options_hash(stream)
21
- end
22
- sleep Settings.options[:scroll][:timer]
23
- rescue Interrupt
24
- canceled
25
- rescue => e
26
- raise e
27
- end
10
+ def method_missing(meth, options)
11
+ case meth.to_s
12
+ when 'trending', 'photos', 'checkins', 'replies', 'global', 'unified'
13
+ scroll_it(meth.to_s, options)
14
+ else
15
+ super
28
16
  end
29
17
  end
30
18
 
31
- def unified(options)
19
+ def scroll_it(target, options)
32
20
  options = check_raw(options)
21
+ orig_target = target
33
22
  loop do
34
23
  begin
35
- stream = @api.get_unified(options)
36
- if Databases.has_new?(stream, 'unified')
37
- show(stream, options)
38
- end
39
- unless stream['meta']['max_id'].nil? #check if there isn't lost posts
40
- Databases.save_max_id(stream)
41
- options = options_hash(stream)
42
- end
43
- sleep Settings.options[:scroll][:timer]
24
+ stream = get(target, options)
25
+ target = "explore:#{target}" if explore?(target)
26
+ show_if_new(stream, options, target)
27
+ target = orig_target if target =~ /explore/
28
+ options = save_then_return(stream, options)
29
+ pause
44
30
  rescue Interrupt
45
31
  canceled
46
- rescue => e
47
- raise e
48
32
  end
49
33
  end
50
34
  end
@@ -56,18 +40,11 @@ module Ayadn
56
40
  loop do
57
41
  begin
58
42
  stream = @api.get_mentions(username, options)
59
- if Databases.has_new?(stream, "mentions:#{id}")
60
- show(stream, options)
61
- end
62
- unless stream['meta']['max_id'].nil?
63
- Databases.save_max_id(stream)
64
- options = options_hash(stream)
65
- end
66
- sleep Settings.options[:scroll][:timer]
43
+ show_if_new(stream, options, "mentions:#{id}")
44
+ options = save_then_return(stream, options)
45
+ pause
67
46
  rescue Interrupt
68
47
  canceled
69
- rescue => e
70
- raise e
71
48
  end
72
49
  end
73
50
  end
@@ -79,18 +56,11 @@ module Ayadn
79
56
  loop do
80
57
  begin
81
58
  stream = @api.get_posts(username, options)
82
- if Databases.has_new?(stream, "posts:#{id}")
83
- show(stream, options)
84
- end
85
- unless stream['meta']['max_id'].nil?
86
- Databases.save_max_id(stream)
87
- options = options_hash(stream)
88
- end
89
- sleep Settings.options[:scroll][:timer]
59
+ show_if_new(stream, options, "posts:#{id}")
60
+ options = save_then_return(stream, options)
61
+ pause
90
62
  rescue Interrupt
91
63
  canceled
92
- rescue => e
93
- raise e
94
64
  end
95
65
  end
96
66
  end
@@ -100,128 +70,72 @@ module Ayadn
100
70
  loop do
101
71
  begin
102
72
  stream = @api.get_convo(post_id, options)
103
- if Databases.has_new?(stream, "replies:#{post_id}")
104
- show(stream, options)
105
- end
106
- unless stream['meta']['max_id'].nil?
107
- Databases.save_max_id(stream)
108
- options = options_hash(stream)
109
- end
110
- sleep Settings.options[:scroll][:timer]
73
+ show_if_new(stream, options, "replies:#{post_id}")
74
+ options = save_then_return(stream, options)
75
+ pause
111
76
  rescue Interrupt
112
77
  canceled
113
- rescue => e
114
- raise e
115
78
  end
116
79
  end
117
80
  end
118
81
 
119
- def conversations(options)
82
+ def messages(channel_id, options)
120
83
  options = check_raw(options)
121
84
  loop do
122
85
  begin
123
- stream = @api.get_conversations(options)
124
- if Databases.has_new?(stream, 'explore:replies')
125
- show(stream, options)
126
- end
127
- unless stream['meta']['max_id'].nil?
128
- Databases.save_max_id(stream)
129
- options = options_hash(stream)
130
- end
131
- sleep Settings.options[:scroll][:timer]
86
+ stream = @api.get_messages(channel_id, options)
87
+ show_if_new(stream, options, "channel:#{channel_id}")
88
+ options = save_then_return(stream, options)
89
+ pause
132
90
  rescue Interrupt
133
91
  canceled
134
- rescue => e
135
- raise e
136
92
  end
137
93
  end
138
94
  end
139
95
 
140
- def trending(options)
141
- options = check_raw(options)
142
- loop do
143
- begin
144
- stream = @api.get_trending(options)
145
- if Databases.has_new?(stream, 'explore:trending')
146
- show(stream, options)
147
- end
148
- unless stream['meta']['max_id'].nil?
149
- Databases.save_max_id(stream)
150
- options = options_hash(stream)
151
- end
152
- sleep Settings.options[:scroll][:timer]
153
- rescue Interrupt
154
- canceled
155
- rescue => e
156
- raise e
157
- end
96
+ private
97
+
98
+ def get(target, options)
99
+ case target
100
+ when 'global'
101
+ @api.get_global(options)
102
+ when 'unified'
103
+ @api.get_unified(options)
104
+ when 'trending'
105
+ @api.get_trending(options)
106
+ when 'photos'
107
+ @api.get_photos(options)
108
+ when 'checkins'
109
+ @api.get_checkins(options)
110
+ when 'replies'
111
+ @api.get_conversations(options)
158
112
  end
159
113
  end
160
114
 
161
- def checkins(options)
162
- options = check_raw(options)
163
- loop do
164
- begin
165
- stream = @api.get_checkins(options)
166
- if Databases.has_new?(stream, 'explore:checkins')
167
- show(stream, options)
168
- end
169
- unless stream['meta']['max_id'].nil?
170
- Databases.save_max_id(stream)
171
- options = options_hash(stream)
172
- end
173
- sleep Settings.options[:scroll][:timer]
174
- rescue Interrupt
175
- canceled
176
- rescue => e
177
- raise e
178
- end
115
+ def explore?(target)
116
+ case target
117
+ when 'trending', 'photos', 'checkins', 'replies'
118
+ true
119
+ else
120
+ false
179
121
  end
180
122
  end
181
123
 
182
- def photos(options)
183
- options = check_raw(options)
184
- loop do
185
- begin
186
- stream = @api.get_photos(options)
187
- if Databases.has_new?(stream, 'explore:photos')
188
- show(stream, options)
189
- end
190
- unless stream['meta']['max_id'].nil?
191
- Databases.save_max_id(stream)
192
- options = options_hash(stream)
193
- end
194
- sleep Settings.options[:scroll][:timer]
195
- rescue Interrupt
196
- canceled
197
- rescue => e
198
- raise e
199
- end
200
- end
124
+ def pause
125
+ sleep Settings.options[:scroll][:timer]
201
126
  end
202
127
 
203
- def messages(channel_id, options)
204
- options = check_raw(options)
205
- loop do
206
- begin
207
- stream = @api.get_messages(channel_id, options)
208
- if Databases.has_new?(stream, "channel:#{channel_id}")
209
- show(stream, options)
210
- end
211
- unless stream['meta']['max_id'].nil?
212
- Databases.save_max_id(stream)
213
- options = options_hash(stream)
214
- end
215
- sleep Settings.options[:scroll][:timer]
216
- rescue Interrupt
217
- canceled
218
- rescue => e
219
- raise e
220
- end
221
- end
128
+ def show_if_new(stream, options, target)
129
+ show(stream, options) if Databases.has_new?(stream, target)
222
130
  end
223
131
 
224
- private
132
+ def save_then_return(stream, options)
133
+ unless stream['meta']['max_id'].nil?
134
+ Databases.save_max_id(stream)
135
+ return options_hash(stream)
136
+ end
137
+ options
138
+ end
225
139
 
226
140
  def check_raw(options)
227
141
  if options[:raw]