mij-discord 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -85,19 +85,13 @@ module MijDiscord::Data
85
85
  alias_method :color=, :set_color
86
86
 
87
87
  def delete(reason = nil)
88
- MijDiscord::Core::API::Server.delete_role(@bot.token, @server.id, @id, reason)
88
+ MijDiscord::Core::API::Server.delete_role(@bot.auth, @server.id, @id, reason)
89
89
  end
90
90
 
91
91
  def set_options(name: nil, color: nil, hoist: nil, mentionable: nil, permissions: nil)
92
- response = MijDiscord::Core::API::Server.update_role(@bot.token, @server.id, @id,
92
+ response = MijDiscord::Core::API::Server.update_role(@bot.auth, @server.id, @id,
93
93
  name, color&.to_i, hoist, mentionable, permissions&.to_i)
94
94
  @server.cache.put_role(JSON.parse(response), update: true)
95
95
  end
96
-
97
- def inspect
98
- %(<Role id=#{@id} name=#{@name} server=#{@server.inspect}>)
99
- end
100
-
101
- private
102
96
  end
103
97
  end
@@ -217,21 +217,21 @@ module MijDiscord::Data
217
217
  end
218
218
 
219
219
  def invites
220
- response = MijDiscord::Core::API::Server.invites(@bot.token, @id)
220
+ response = MijDiscord::Core::API::Server.invites(@bot.auth, @id)
221
221
  JSON.parse(response).map {|x| Invite.new(x, @bot) }
222
222
  end
223
223
 
224
224
  def prune_count(days)
225
225
  raise ArgumentError, 'Days must be between 1 and 30' unless days.between?(1, 30)
226
226
 
227
- response = MijDiscord::Core::API::Server.prune_count(@bot.token, @id, days)
227
+ response = MijDiscord::Core::API::Server.prune_count(@bot.auth, @id, days)
228
228
  JSON.parse(response)['pruned']
229
229
  end
230
230
 
231
231
  def prune(days, reason = nil)
232
232
  raise ArgumentError, 'Days must be between 1 and 30' unless days.between?(1, 30)
233
233
 
234
- response = MijDiscord::Core::API::Server.begin_prune(@bot.token, @id, days, reason)
234
+ response = MijDiscord::Core::API::Server.begin_prune(@bot.auth, @id, days, reason)
235
235
  JSON.parse(response)['pruned']
236
236
  end
237
237
 
@@ -247,55 +247,55 @@ module MijDiscord::Data
247
247
  raise ArgumentError, 'Invalid channel type specified' unless CHANNEL_TYPES.has_key?(type)
248
248
 
249
249
  permissions = permissions.map {|x| x.is_a(Overwrite) ? x.to_hash : x }
250
- response = MijDiscord::Core::API::Server.create_channel(@bot.token, @id,
250
+ response = MijDiscord::Core::API::Server.create_channel(@bot.auth, @id,
251
251
  name, CHANNEL_TYPES[type], bitrate, user_limit, permissions, nsfw, reason)
252
252
  @cache.put_channel(JSON.parse(response))
253
253
  end
254
254
 
255
255
  def create_role(name, reason = nil, color: 0, hoist: false, mentionable: false, permissions: 104_324_161)
256
- response = MijDiscord::Core::API::Server.create_role(@bot.token, @id,
256
+ response = MijDiscord::Core::API::Server.create_role(@bot.auth, @id,
257
257
  name, color.to_i, hoist, mentionable, permissions.to_i, reason)
258
258
  @cache.put_role(JSON.parse(response))
259
259
  end
260
260
 
261
261
  def bans
262
- response = MijDiscord::Core::API::Server.bans(@bot.token, @id)
262
+ response = MijDiscord::Core::API::Server.bans(@bot.auth, @id)
263
263
  JSON.parse(response).map {|x| @bot.cache.put_user(x['user']) }
264
264
  end
265
265
 
266
266
  def ban(user, message_days = 0, reason = nil)
267
- MijDiscord::Core::API::Server.ban_user(@bot.token, @id, user.to_id, message_days, reason)
267
+ MijDiscord::Core::API::Server.ban_user(@bot.auth, @id, user.to_id, message_days, reason)
268
268
  nil
269
269
  end
270
270
 
271
271
  def unban(user, reason = nil)
272
- MijDiscord::Core::API::Server.unban_user(@bot.token, @id, user.to_id, reason)
272
+ MijDiscord::Core::API::Server.unban_user(@bot.auth, @id, user.to_id, reason)
273
273
  nil
274
274
  end
275
275
 
276
276
  def kick(user, reason = nil)
277
- MijDiscord::Core::API::Server.remove_member(@bot.token, @id, user.to_id, reason)
277
+ MijDiscord::Core::API::Server.remove_member(@bot.auth, @id, user.to_id, reason)
278
278
  nil
279
279
  end
280
280
 
281
281
  def leave
282
- MijDiscord::Core::API::User.leave_server(@bot.token, @id)
282
+ MijDiscord::Core::API::User.leave_server(@bot.auth, @id)
283
283
  nil
284
284
  end
285
285
 
286
286
  def delete
287
- MijDiscord::Core::API::Server.delete(@bot.token, @id)
287
+ MijDiscord::Core::API::Server.delete(@bot.auth, @id)
288
288
  nil
289
289
  end
290
290
 
291
291
  def set_owner(user, reason = nil)
292
- MijDiscord::Core::API::Server.transfer_ownership(@bot.token, @id, user.to_id, reason)
292
+ MijDiscord::Core::API::Server.transfer_ownership(@bot.auth, @id, user.to_id, reason)
293
293
  end
294
294
 
295
295
  alias_method :owner=, :set_owner
296
296
 
297
297
  def set_options(reason = nil, name: nil, region: nil, icon: nil, afk_channel: nil, afk_timeout: nil)
298
- response = MijDiscord::Core::API::Server.update(@bot.token, @id,
298
+ response = MijDiscord::Core::API::Server.update(@bot.auth, @id,
299
299
  name, region, icon, afk_channel&.to_id, afk_timeout, reason)
300
300
  @bot.cache.put_server(JSON.parse(response), update: true)
301
301
  end
@@ -310,7 +310,7 @@ module MijDiscord::Data
310
310
  def available_regions
311
311
  return @voice_regions if @voice_regions
312
312
 
313
- response = MijDiscord::Core::API::Server.regions(@bot.token, @id)
313
+ response = MijDiscord::Core::API::Server.regions(@bot.auth, @id)
314
314
  @voice_regions = JSON.parse(response).map {|x| VoiceRegion.new(x) }
315
315
  end
316
316
 
@@ -365,8 +365,59 @@ module MijDiscord::Data
365
365
  MijDiscord::Core::API.widget_url(@id, style)
366
366
  end
367
367
 
368
- def inspect
369
- %(<Server id=#{@id} name="#{@name}" large=#{@large} region=#{@region_id} owner=#{@owner.id}>)
368
+ def search_messages(limit: 25, offset: 0, sort_by: nil, sort_asc: false,
369
+ nsfw: true, around: 2, content: nil, author: nil, channel: nil, mentions: nil,
370
+ author_is: nil, author_not: nil, has: nil, has_not: nil, before: nil, after: nil)
371
+ author = author ? [*author].map(&:to_id) : nil
372
+ channel = channel ? [*channel].map(&:to_id) : nil
373
+ mentions = mentions ? [*mentions].map(&:to_id) : nil
374
+
375
+ has_not = has_not ? [*has_not].map {|x| "-#{x}" } : []
376
+ author_not = author_not ? [*author_not].map {|x| "-#{x}" } : []
377
+
378
+ has = has_not | (has ? [*has].map(&:to_s) : [])
379
+ author_is = author_not | (author_is ? [*author_is].map(&:to_s) : [])
380
+
381
+ before = before ? IDObject.synthesize(before) : nil
382
+ after = after ? IDObject.synthesize(after) : nil
383
+
384
+ options = {
385
+ limit: limit,
386
+ offset: offset,
387
+ sort_by: sort_by,
388
+ sort_order: sort_asc ? 'asc' : 'desc',
389
+ context_size: around,
390
+ include_nsfw: nsfw,
391
+ author_id: author,
392
+ author_type: author_is,
393
+ channel_id: channel,
394
+ mentions: mentions,
395
+ max_id: before,
396
+ min_id: after,
397
+ content: content,
398
+ has: has,
399
+ }.delete_if {|_,v| v.nil? }
400
+
401
+ response = MijDiscord::Core::API::Server.search_messages(@bot.auth, @id, options)
402
+ SearchResults.new(JSON.parse(response), @bot)
403
+ end
404
+ end
405
+
406
+ class SearchResults
407
+ ResultData = Struct.new(:result, :context)
408
+
409
+ attr_reader :total_count
410
+
411
+ attr_reader :messages
412
+
413
+ def initialize(data, bot)
414
+ @total_count = data['total_results']
415
+
416
+ @messages = data['messages'].map do |group|
417
+ context = group.map {|x| Message.new(x, bot) }
418
+ result = context.delete_at(context.length / 2)
419
+ ResultData.new(result, context)
420
+ end
370
421
  end
371
422
  end
372
423
  end
@@ -126,10 +126,6 @@ module MijDiscord::Data
126
126
  return MijDiscord::Core::API::User.default_avatar(@discriminator) unless @avatar_id
127
127
  MijDiscord::Core::API::User.avatar_url(@id, @avatar_id, format)
128
128
  end
129
-
130
- def inspect
131
- %(<User id=#{@id} name="#{@username}" tag=#{@discriminator}>)
132
- end
133
129
  end
134
130
 
135
131
  class Profile < User
@@ -143,7 +139,7 @@ module MijDiscord::Data
143
139
  end
144
140
 
145
141
  def set_username(name)
146
- response = MijDiscord::Core::API::User.update_profile(@bot.token, name, nil)
142
+ response = MijDiscord::Core::API::User.update_profile(@bot.auth, name, nil)
147
143
  update_data(JSON.parse(response))
148
144
  nil
149
145
  end
@@ -163,7 +159,7 @@ module MijDiscord::Data
163
159
  raise ArgumentError, 'Invalid avatar data provided'
164
160
  end
165
161
 
166
- response = MijDiscord::Core::API::User.update_profile(@bot.token, @username, data)
162
+ response = MijDiscord::Core::API::User.update_profile(@bot.auth, @username, data)
167
163
  update_data(JSON.parse(response))
168
164
  nil
169
165
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MijDiscord
4
- VERSION = '1.0.5'
4
+ VERSION = '1.0.6'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mij-discord
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mijyuoon
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-24 00:00:00.000000000 Z
11
+ date: 2017-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client