mij-discord 1.0.5 → 1.0.6

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.
@@ -4,37 +4,37 @@ module MijDiscord::Core::API::User
4
4
  class << self
5
5
  # Get user data
6
6
  # https://discordapp.com/developers/docs/resources/user#get-user
7
- def resolve(token, user_id)
7
+ def resolve(auth, user_id)
8
8
  MijDiscord::Core::API.request(
9
9
  :users_uid,
10
10
  nil,
11
11
  :get,
12
12
  "#{MijDiscord::Core::API::APIBASE_URL}/users/#{user_id}",
13
- Authorization: token
13
+ Authorization: auth
14
14
  )
15
15
  end
16
16
 
17
17
  # Get profile data
18
18
  # https://discordapp.com/developers/docs/resources/user#get-current-user
19
- def profile(token)
19
+ def profile(auth)
20
20
  MijDiscord::Core::API.request(
21
21
  :users_me,
22
22
  nil,
23
23
  :get,
24
24
  "#{MijDiscord::Core::API::APIBASE_URL}/users/@me",
25
- Authorization: token
25
+ Authorization: auth
26
26
  )
27
27
  end
28
28
 
29
29
  # Change the current bot's nickname on a server
30
- def change_own_nickname(token, server_id, nick, reason = nil)
30
+ def change_own_nickname(auth, server_id, nick, reason = nil)
31
31
  MijDiscord::Core::API.request(
32
32
  :guilds_sid_members_me_nick,
33
33
  server_id, # This is technically a guild endpoint
34
34
  :patch,
35
35
  "#{MijDiscord::Core::API::APIBASE_URL}/guilds/#{server_id}/members/@me/nick",
36
36
  { nick: nick }.to_json,
37
- Authorization: token,
37
+ Authorization: auth,
38
38
  content_type: :json,
39
39
  'X-Audit-Log-Reason': reason
40
40
  )
@@ -42,97 +42,96 @@ module MijDiscord::Core::API::User
42
42
 
43
43
  # Update user data
44
44
  # https://discordapp.com/developers/docs/resources/user#modify-current-user
45
- def update_profile(token, username, avatar)
45
+ def update_profile(auth, username, avatar)
46
46
  MijDiscord::Core::API.request(
47
47
  :users_me,
48
48
  nil,
49
49
  :patch,
50
50
  "#{MijDiscord::Core::API::APIBASE_URL}/users/@me",
51
51
  { avatar: avatar, username: username }.delete_if {|_,v| v.nil? }.to_json,
52
- Authorization: token,
52
+ Authorization: auth,
53
53
  content_type: :json
54
54
  )
55
55
  end
56
56
 
57
57
  # Get the servers a user is connected to
58
58
  # https://discordapp.com/developers/docs/resources/user#get-current-user-guilds
59
- def servers(token)
59
+ def servers(auth)
60
60
  MijDiscord::Core::API.request(
61
61
  :users_me_guilds,
62
62
  nil,
63
63
  :get,
64
64
  "#{MijDiscord::Core::API::APIBASE_URL}/users/@me/guilds",
65
- Authorization: token
65
+ Authorization: auth
66
66
  )
67
67
  end
68
68
 
69
69
  # Leave a server
70
70
  # https://discordapp.com/developers/docs/resources/user#leave-guild
71
- def leave_server(token, server_id)
71
+ def leave_server(auth, server_id)
72
72
  MijDiscord::Core::API.request(
73
73
  :users_me_guilds_sid,
74
74
  nil,
75
75
  :delete,
76
76
  "#{MijDiscord::Core::API::APIBASE_URL}/users/@me/guilds/#{server_id}",
77
- Authorization: token
77
+ Authorization: auth
78
78
  )
79
79
  end
80
80
 
81
81
  # Get the DMs for the current user
82
82
  # https://discordapp.com/developers/docs/resources/user#get-user-dms
83
- def user_dms(token)
83
+ def user_dms(auth)
84
84
  MijDiscord::Core::API.request(
85
85
  :users_me_channels,
86
86
  nil,
87
87
  :get,
88
88
  "#{MijDiscord::Core::API::APIBASE_URL}/users/@me/channels",
89
- Authorization: token
89
+ Authorization: auth
90
90
  )
91
91
  end
92
92
 
93
93
  # Create a DM to another user
94
94
  # https://discordapp.com/developers/docs/resources/user#create-dm
95
- def create_pm(token, recipient_id)
95
+ def create_pm(auth, recipient_id)
96
96
  MijDiscord::Core::API.request(
97
97
  :users_me_channels,
98
98
  nil,
99
99
  :post,
100
100
  "#{MijDiscord::Core::API::APIBASE_URL}/users/@me/channels",
101
101
  { recipient_id: recipient_id }.to_json,
102
- Authorization: token,
102
+ Authorization: auth,
103
103
  content_type: :json
104
104
  )
105
105
  end
106
106
 
107
107
  # Get information about a user's connections
108
108
  # https://discordapp.com/developers/docs/resources/user#get-users-connections
109
- def connections(token)
109
+ def connections(auth)
110
110
  MijDiscord::Core::API.request(
111
111
  :users_me_connections,
112
112
  nil,
113
113
  :get,
114
114
  "#{MijDiscord::Core::API::APIBASE_URL}/users/@me/connections",
115
- Authorization: token
115
+ Authorization: auth
116
116
  )
117
117
  end
118
118
 
119
119
  # Change user status setting
120
- def change_status_setting(token, status)
120
+ def change_status_setting(auth, status)
121
121
  MijDiscord::Core::API.request(
122
122
  :users_me_settings,
123
123
  nil,
124
124
  :patch,
125
125
  "#{MijDiscord::Core::API::APIBASE_URL}/users/@me/settings",
126
126
  { status: status }.to_json,
127
- Authorization: token,
127
+ Authorization: auth,
128
128
  content_type: :json
129
129
  )
130
130
  end
131
131
 
132
132
  # Returns one of the "default" discord avatars from the CDN given a discriminator
133
133
  def default_avatar(discrim = 0)
134
- index = discrim.to_i % 5
135
- "#{MijDiscord::Core::API::CDN_URL}/embed/avatars/#{index}.png"
134
+ "#{MijDiscord::Core::API::CDN_URL}/embed/avatars/#{discrim.to_i % 5}.png"
136
135
  end
137
136
 
138
137
  # Make an avatar URL from the user and avatar IDs
@@ -106,8 +106,8 @@ module MijDiscord::Core
106
106
 
107
107
  attr_accessor :check_heartbeat_acks
108
108
 
109
- def initialize(bot, token, shard_key = nil)
110
- @bot, @token, @shard_key = bot, token, shard_key
109
+ def initialize(bot, auth, shard_key = nil)
110
+ @bot, @auth, @shard_key = bot, auth, shard_key
111
111
 
112
112
  @ws_success = false
113
113
  @getc_mutex = Mutex.new
@@ -278,11 +278,11 @@ module MijDiscord::Core
278
278
  '$referring_domain': '',
279
279
  }
280
280
 
281
- send_identify(@token, props, true, LARGE_THRESHOLD, @shard_key)
281
+ send_identify(@auth, props, true, LARGE_THRESHOLD, @shard_key)
282
282
  end
283
283
 
284
284
  def send_resume_self
285
- send_resume(@token, @session.session_id, @session.sequence)
285
+ send_resume(@auth, @session.session_id, @session.sequence)
286
286
  end
287
287
 
288
288
  def setup_heartbeat(interval)
@@ -331,7 +331,7 @@ module MijDiscord::Core
331
331
  end
332
332
 
333
333
  def get_gateway_url
334
- response = API.gateway(@token)
334
+ response = API.gateway(@auth)
335
335
  raw_url = JSON.parse(response)['url']
336
336
  raw_url << '/' unless raw_url.end_with? '/'
337
337
  "#{raw_url}?encoding=json&v=#{GATEWAY_VERSION}"
@@ -30,9 +30,5 @@ module MijDiscord::Data
30
30
  return nil if @icon_id.nil?
31
31
  MijDiscord::Core::API.app_icon_url(@id, @icon_id, format)
32
32
  end
33
-
34
- def inspect
35
- %(<Application id=#{@id} name="#{@name}">)
36
- end
37
33
  end
38
34
  end
@@ -152,7 +152,7 @@ module MijDiscord::Data
152
152
 
153
153
  def set_options(reason = nil, name: nil, topic: nil, nsfw: nil,
154
154
  parent: nil, position: nil, bitrate: nil, user_limit: nil, overwrites: nil)
155
- response = MijDiscord::Core::API::Channel.update(@bot.token, @id,
155
+ response = MijDiscord::Core::API::Channel.update(@bot.auth, @id,
156
156
  name, topic, nsfw,parent&.to_id, position, bitrate, user_limit, overwrites, reason)
157
157
  @server.cache.put_channel(JSON.parse(response), update: true)
158
158
  end
@@ -174,7 +174,7 @@ module MijDiscord::Data
174
174
  object = Overwrite.new(object, allow: allow_bits, deny: deny_bits)
175
175
  end
176
176
 
177
- MijDiscord::Core::API::Channel.update_permission(@bot.token, @id,
177
+ MijDiscord::Core::API::Channel.update_permission(@bot.auth, @id,
178
178
  object.id, object.allow.bits, object.deny.bits, object.type, reason)
179
179
  nil
180
180
  end
@@ -185,7 +185,7 @@ module MijDiscord::Data
185
185
 
186
186
  def delete_overwrite(object, reason = nil)
187
187
  raise ArgumentError, 'Invalid overwrite target' unless object.respond_to?(:to_id)
188
- MijDiscord::Core::API::Channel.delete_permission(@bot.token, @id,
188
+ MijDiscord::Core::API::Channel.delete_permission(@bot.auth, @id,
189
189
  object.to_id, reason)
190
190
  nil
191
191
  end
@@ -201,13 +201,9 @@ module MijDiscord::Data
201
201
  alias_method :sync_permission_overwrites, :sync_overwrites
202
202
 
203
203
  def delete(reason = nil)
204
- MijDiscord::Core::API::Channel.delete(@bot.token, @id, reason)
204
+ MijDiscord::Core::API::Channel.delete(@bot.auth, @id, reason)
205
205
  @server.cache.remove_channel(@id)
206
206
  end
207
-
208
- def inspect
209
- %(<Channel id=#{@id} server=#{@server.id} name="#{@name}" type=#{@type}>)
210
- end
211
207
  end
212
208
 
213
209
  class TextChannel < Channel
@@ -301,7 +297,7 @@ module MijDiscord::Data
301
297
  def send_message(text: '', embed: nil, tts: false)
302
298
  raise MijDiscord::Core::Errors::MessageTooLong if text.length > 2000
303
299
 
304
- response = MijDiscord::Core::API::Channel.create_message(@bot.token, @id,
300
+ response = MijDiscord::Core::API::Channel.create_message(@bot.auth, @id,
305
301
  text, tts, embed&.to_h)
306
302
  @cache.put_message(JSON.parse(response))
307
303
  end
@@ -309,12 +305,12 @@ module MijDiscord::Data
309
305
  def send_file(file, caption: '', tts: false)
310
306
  raise MijDiscord::Core::Errors::MessageTooLong if caption.length > 2000
311
307
 
312
- response = MijDiscord::Core::API::Channel.upload_file(@bot.token, @id, file, caption, tts)
308
+ response = MijDiscord::Core::API::Channel.upload_file(@bot.auth, @id, file, caption, tts)
313
309
  @cache.put_message(JSON.parse(response))
314
310
  end
315
311
 
316
312
  def delete_message(message)
317
- MijDiscord::Core::API::Channel.delete_message(@bot.token, @id, message.to_id)
313
+ MijDiscord::Core::API::Channel.delete_message(@bot.auth, @id, message.to_id)
318
314
  @cache.remove_message(message)
319
315
  end
320
316
 
@@ -323,7 +319,7 @@ module MijDiscord::Data
323
319
  end
324
320
 
325
321
  def message_history(amount, before: nil, after: nil, around: nil)
326
- response = MijDiscord::Core::API::Channel.messages(@bot.token, @id,
322
+ response = MijDiscord::Core::API::Channel.messages(@bot.auth, @id,
327
323
  amount, before&.to_id, after&.to_id, around&.to_id)
328
324
  JSON.parse(response).map {|m| Message.new(m, @bot) }
329
325
  end
@@ -331,7 +327,7 @@ module MijDiscord::Data
331
327
  alias_method :history, :message_history
332
328
 
333
329
  def pinned_messages
334
- response = MijDiscord::Core::API::Channel.pinned_messages(@bot.token, @id)
330
+ response = MijDiscord::Core::API::Channel.pinned_messages(@bot.auth, @id)
335
331
  JSON.parse(response).map {|m| Message.new(m, @bot) }
336
332
  end
337
333
 
@@ -342,18 +338,18 @@ module MijDiscord::Data
342
338
  min_snowflake = IDObject.synthesize(two_weeks)
343
339
  ids = messages.map(&:to_id).delete_if {|m| m < min_snowflake }
344
340
 
345
- MijDiscord::Core::API::Channel.bulk_delete_messages(@bot.token, @id, ids)
341
+ MijDiscord::Core::API::Channel.bulk_delete_messages(@bot.auth, @id, ids)
346
342
  ids.each {|m| @cache.remove_message(m) }
347
343
  nil
348
344
  end
349
345
 
350
346
  def invites
351
- response = MijDiscord::Core::API::Channel.invites(@bot.token, @id)
347
+ response = MijDiscord::Core::API::Channel.invites(@bot.auth, @id)
352
348
  JSON.parse(response).map {|x| Invite.new(x, @bot) }
353
349
  end
354
350
 
355
351
  def make_invite(reason = nil, max_age: 0, max_uses: 0, temporary: false, unique: false)
356
- response = MijDiscord::Core::API::Channel.create_invite(@bot.token, @id,
352
+ response = MijDiscord::Core::API::Channel.create_invite(@bot.auth, @id,
357
353
  max_age, max_uses, temporary, unique, reason)
358
354
  Invite.new(JSON.parse(response), @bot)
359
355
  end
@@ -361,7 +357,7 @@ module MijDiscord::Data
361
357
  alias_method :invite, :make_invite
362
358
 
363
359
  def start_typing
364
- MijDiscord::Core::API::Channel.start_typing(@bot.token, @id)
360
+ MijDiscord::Core::API::Channel.start_typing(@bot.auth, @id)
365
361
  nil
366
362
  end
367
363
 
@@ -369,7 +365,7 @@ module MijDiscord::Data
369
365
  raise 'Attempted to create group channel on a non-pm channel' unless pm?
370
366
 
371
367
  ids = users.map(&:to_id)
372
- response = MijDiscord::Core::API::Channel.create_group(@bot.token, @id, ids.shift)
368
+ response = MijDiscord::Core::API::Channel.create_group(@bot.auth, @id, ids.shift)
373
369
  channel = @bot.cache.put_channel(JSON.parse(response))
374
370
  channel.add_group_users(ids)
375
371
 
@@ -380,7 +376,7 @@ module MijDiscord::Data
380
376
  raise 'Attempted to add a user to a non-group channel' unless group?
381
377
 
382
378
  users.each do |u|
383
- MijDiscord::Core::API::Channel.add_group_user(@bot.token, @id, u.to_id)
379
+ MijDiscord::Core::API::Channel.add_group_user(@bot.auth, @id, u.to_id)
384
380
  end
385
381
  nil
386
382
  end
@@ -389,7 +385,7 @@ module MijDiscord::Data
389
385
  raise 'Attempted to remove a user to a non-group channel' unless group?
390
386
 
391
387
  users.each do |u|
392
- MijDiscord::Core::API::Channel.remove_group_user(@bot.token, @id, u.to_id)
388
+ MijDiscord::Core::API::Channel.remove_group_user(@bot.auth, @id, u.to_id)
393
389
  end
394
390
  nil
395
391
  end
@@ -397,7 +393,7 @@ module MijDiscord::Data
397
393
  def leave_group
398
394
  raise 'Attempoted to leave a non-group channel' unless group?
399
395
 
400
- MijDiscord::Core::API::Channel.leave_group(@bot.token, @id)
396
+ MijDiscord::Core::API::Channel.leave_group(@bot.auth, @id)
401
397
  nil
402
398
  end
403
399
  end
@@ -35,10 +35,6 @@ module MijDiscord::Data
35
35
  def icon_url(format = :png)
36
36
  MijDiscord::Core::API.emoji_icon_url(@id, format)
37
37
  end
38
-
39
- def inspect
40
- %(<Emoji id=#{@id} name=#{@name}>)
41
- end
42
38
  end
43
39
 
44
40
  class Reaction
@@ -71,7 +71,7 @@ module MijDiscord::Data
71
71
  alias_method :eql?, :==
72
72
 
73
73
  def delete(reason = nil)
74
- MijDiscord::Core::API::Invite.delete(@bot.token, @code, reason)
74
+ MijDiscord::Core::API::Invite.delete(@bot.auth, @code, reason)
75
75
  end
76
76
 
77
77
  alias_method :revoke, :delete
@@ -79,9 +79,5 @@ module MijDiscord::Data
79
79
  def invite_url
80
80
  "https://discord.gg/#{@code}"
81
81
  end
82
-
83
- def inspect
84
- %(<Invite code=#{@code} uses=#{@max_uses} temporary=#{@temporary} revoked=#{@revoked}>)
85
- end
86
82
  end
87
83
  end
@@ -74,7 +74,7 @@ module MijDiscord::Data
74
74
 
75
75
  def set_roles(roles, reason = nil)
76
76
  roles = roles.map(&:to_id)
77
- MijDiscord::Core::API::Server.update_member(@bot.token, @server.id, @user.id, reason, roles: roles)
77
+ MijDiscord::Core::API::Server.update_member(@bot.auth, @server.id, @user.id, reason, roles: roles)
78
78
  end
79
79
 
80
80
  def modify_roles(add, remove, reason = nil)
@@ -88,7 +88,7 @@ module MijDiscord::Data
88
88
  modify_roles(role, [], reason)
89
89
  else
90
90
  role = role.to_id
91
- MijDiscord::Core::API::Server.add_member_role(@bot.token, @server.id, @user.id, role, reason)
91
+ MijDiscord::Core::API::Server.add_member_role(@bot.auth, @server.id, @user.id, role, reason)
92
92
  end
93
93
  end
94
94
 
@@ -97,7 +97,7 @@ module MijDiscord::Data
97
97
  modify_roles([], role, reason)
98
98
  else
99
99
  role = role.to_id
100
- MijDiscord::Core::API::Server.remove_member_role(@bot.token, @server.id, @user.id, role, reason)
100
+ MijDiscord::Core::API::Server.remove_member_role(@bot.auth, @server.id, @user.id, role, reason)
101
101
  end
102
102
  end
103
103
 
@@ -123,9 +123,9 @@ module MijDiscord::Data
123
123
  nick ||= ''
124
124
 
125
125
  if @user.current_bot?
126
- MijDiscord::Core::API::User.change_own_nickname(@bot.token, @server.id, nick, reason)
126
+ MijDiscord::Core::API::User.change_own_nickname(@bot.auth, @server.id, nick, reason)
127
127
  else
128
- MijDiscord::Core::API::Server.update_member(@bot.token, @server.id, @user.id, reason, nick: nick)
128
+ MijDiscord::Core::API::Server.update_member(@bot.auth, @server.id, @user.id, reason, nick: nick)
129
129
  end
130
130
  end
131
131
 
@@ -135,10 +135,6 @@ module MijDiscord::Data
135
135
  nickname.empty? ? username : nickname
136
136
  end
137
137
 
138
- def inspect
139
- %(<Member user=#{@user.inspect} server=#{@server.id}>)
140
- end
141
-
142
138
  private
143
139
 
144
140
  def voice_state_attribute(key)
@@ -166,9 +162,5 @@ module MijDiscord::Data
166
162
  @voice_channel, @server, @roles = nil, nil, []
167
163
  @nickname, @joined_at = '', @channel.creation_time
168
164
  end
169
-
170
- def inspect
171
- %(<Recipient user=#{@user.inspect} channel=#{@channel.inspect}>)
172
- end
173
165
  end
174
166
  end
@@ -114,18 +114,18 @@ module MijDiscord::Data
114
114
  end
115
115
 
116
116
  def edit(text: '', embed: nil)
117
- response = MijDiscord::Core::API::Channel.edit_message(@bot.token, @channel.id, @id,
117
+ response = MijDiscord::Core::API::Channel.edit_message(@bot.auth, @channel.id, @id,
118
118
  text, [], embed&.to_h)
119
119
  @channel.cache.put_message(JSON.parse(response), update: true)
120
120
  end
121
121
 
122
122
  def pin
123
- MijDiscord::Core::API::Channel.pin_message(@bot.token, @channel.id, @id)
123
+ MijDiscord::Core::API::Channel.pin_message(@bot.auth, @channel.id, @id)
124
124
  nil
125
125
  end
126
126
 
127
127
  def unpin
128
- MijDiscord::Core::API::Channel.unpin_message(@bot.token, @channel.id, @id)
128
+ MijDiscord::Core::API::Channel.unpin_message(@bot.auth, @channel.id, @id)
129
129
  nil
130
130
  end
131
131
 
@@ -139,7 +139,7 @@ module MijDiscord::Data
139
139
 
140
140
  def create_reaction(reaction)
141
141
  emoji = reaction.respond_to?(:reaction) ? reaction.reaction : reaction
142
- MijDiscord::Core::API::Channel.create_reaction(@bot.token, @channel.id, @id, emoji)
142
+ MijDiscord::Core::API::Channel.create_reaction(@bot.auth, @channel.id, @id, emoji)
143
143
  nil
144
144
  end
145
145
 
@@ -147,33 +147,29 @@ module MijDiscord::Data
147
147
 
148
148
  def reacted_with(reaction)
149
149
  emoji = reaction.respond_to?(:reaction) ? reaction.reaction : reaction
150
- response = MijDiscord::Core::API::Channel.get_reactions(@bot.token, @channel.id, @id, emoji)
150
+ response = MijDiscord::Core::API::Channel.get_reactions(@bot.auth, @channel.id, @id, emoji)
151
151
  JSON.parse(response).map {|x| @bot.cache.put_user(x) }
152
152
  end
153
153
 
154
154
  def delete_reaction(reaction, user: nil)
155
155
  emoji = reaction.respond_to?(:reaction) ? reaction.reaction : reaction
156
156
  if user.nil?
157
- MijDiscord::Core::API::Channel.delete_own_reaction(@bot.token, @channel.id, @id, emoji)
157
+ MijDiscord::Core::API::Channel.delete_own_reaction(@bot.auth, @channel.id, @id, emoji)
158
158
  else
159
- MijDiscord::Core::API::Channel.delete_user_reaction(@bot.token, @channel.id, @id, emoji, user.to_id)
159
+ MijDiscord::Core::API::Channel.delete_user_reaction(@bot.auth, @channel.id, @id, emoji, user.to_id)
160
160
  end
161
161
  nil
162
162
  end
163
163
 
164
164
  def clear_reactions
165
- MijDiscord::Core::API::Channel.delete_all_reactions(@bot.token, @channel.id, @id)
165
+ MijDiscord::Core::API::Channel.delete_all_reactions(@bot.auth, @channel.id, @id)
166
166
  nil
167
167
  end
168
168
 
169
169
  def delete
170
- MijDiscord::Core::API::Channel.delete_message(@bot.token, @channel.id, @id)
170
+ MijDiscord::Core::API::Channel.delete_message(@bot.auth, @channel.id, @id)
171
171
  nil
172
172
  end
173
-
174
- def inspect
175
- %(<Message id=#{@id} timestamp=#{@timestamp} content="#{@content}" author=#{@author.inspect} channel=#{@channel.inspect}>)
176
- end
177
173
  end
178
174
 
179
175
  class Attachment