discordrb 1.4.1 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of discordrb might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ad6998ddf964b9fbb9898312e7d41d503a207bff
4
- data.tar.gz: c2bfb298aacd612fee0800f8f1ff434fc0cfe90c
3
+ metadata.gz: 5d1542d6ad0666eb828fb415023c62059b0d29a7
4
+ data.tar.gz: 3f4ba2868eea476ecc4195f0ce025fe8322aea9b
5
5
  SHA512:
6
- metadata.gz: cfcf66d6d21815e39b66b9dfdc1508abfd2f22e11e0d435073aa9d7de45dec0dcef62fb6a50f1921d28ddadd3e8e5c4972364e70a65813bb2284859f305b685d
7
- data.tar.gz: f43645f7d126eda651ee82027eb829b7b66e6661b4fe81a6283d81b7935bcb7305e66a7d7614c03af4355a5b6e6b05f71396aae1c720f949a1c36fd20a2c4311
6
+ metadata.gz: 667bff54430e689507d9983e62e1288ebea7854edc82d43724f3d0fac9cf37f108ff8c2682ad1bf82341ff02d68149aa7510ad4261e343cf9e4957b418b12481
7
+ data.tar.gz: ca0d56615189e67ef450c26ca16f997bd3b37f33e30348832ddbd0ea949b8c077296a0deea7706d3153d1c7a278bc5eb9e6002ac81684fd7a0a5cf7955e59072
data/lib/discordrb/api.rb CHANGED
@@ -8,9 +8,37 @@ module Discordrb::API
8
8
 
9
9
  module_function
10
10
 
11
+ # Generate a user agent identifying this requester as discordrb.
12
+ def user_agent
13
+ libraries = [
14
+ # rest-client
15
+ "rest-client/#{RestClient::VERSION}",
16
+
17
+ # ruby
18
+ "#{RUBY_ENGINE}/#{RUBY_VERSION}p#{RUBY_PATCHLEVEL}",
19
+
20
+ # discordrb
21
+ "discordrb/#{Discordrb::VERSION}"
22
+ ]
23
+
24
+ # Required by Discord devs
25
+ required = "DiscordBot (https://github.com/meew0/discordrb, v#{Discordrb::VERSION})"
26
+ "#{libraries.join(' ')} #{required}"
27
+ end
28
+
29
+ # Make an API request. Utility function to implement message queueing
30
+ # in the future
31
+ def request(type, *attributes)
32
+ # Add a custom user agent
33
+ attributes.last[:user_agent] = user_agent if attributes.last.is_a? Hash
34
+ puts attributes.last[:user_agent]
35
+ RestClient.send(type, *attributes)
36
+ end
37
+
11
38
  # Ban a user from a server and delete their messages from the last message_days days
12
39
  def ban_user(token, server_id, user_id, message_days)
13
- RestClient.put(
40
+ request(
41
+ :put,
14
42
  "#{APIBASE}/guilds/#{server_id}/bans/#{user_id}?delete-message-days=#{message_days}",
15
43
  Authorization: token
16
44
  )
@@ -18,7 +46,8 @@ module Discordrb::API
18
46
 
19
47
  # Unban a user from a server
20
48
  def unban_user(token, server_id, user_id)
21
- RestClient.delete(
49
+ request(
50
+ :delete,
22
51
  "#{APIBASE}/guilds/#{server_id}/bans/#{user_id}",
23
52
  Authorization: token
24
53
  )
@@ -26,7 +55,8 @@ module Discordrb::API
26
55
 
27
56
  # Kick a user from a server
28
57
  def kick_user(token, server_id, user_id)
29
- RestClient.delete(
58
+ request(
59
+ :delete,
30
60
  "#{APIBASE}/guilds/#{server_id}/members/#{user_id}",
31
61
  Authorization: token
32
62
  )
@@ -34,7 +64,8 @@ module Discordrb::API
34
64
 
35
65
  # Get a server's banned users
36
66
  def bans(token, server_id)
37
- RestClient.get(
67
+ request(
68
+ :get,
38
69
  "#{APIBASE}/guilds/#{server_id}/bans",
39
70
  Authorization: token
40
71
  )
@@ -42,7 +73,8 @@ module Discordrb::API
42
73
 
43
74
  # Login to the server
44
75
  def login(email, password)
45
- RestClient.post(
76
+ request(
77
+ :post,
46
78
  "#{APIBASE}/auth/login",
47
79
  email: email,
48
80
  password: password
@@ -51,7 +83,8 @@ module Discordrb::API
51
83
 
52
84
  # Logout from the server
53
85
  def logout(token)
54
- RestClient.post(
86
+ request(
87
+ :post,
55
88
  "#{APIBASE}/auth/logout",
56
89
  nil,
57
90
  Authorization: token
@@ -60,7 +93,8 @@ module Discordrb::API
60
93
 
61
94
  # Create a server
62
95
  def create_server(token, name, region = :london)
63
- RestClient.post(
96
+ request(
97
+ :post,
64
98
  "#{APIBASE}/guilds",
65
99
  { 'name' => name, 'region' => region.to_s }.to_json,
66
100
  Authorization: token,
@@ -70,7 +104,8 @@ module Discordrb::API
70
104
 
71
105
  # Update a server
72
106
  def update_server(token, server_id, name, region, icon, afk_channel_id, afk_timeout)
73
- RestClient.patch(
107
+ request(
108
+ :patch,
74
109
  "#{APIBASE}/guilds/#{server_id}",
75
110
  { 'name' => name, 'region' => region, 'icon' => icon, 'afk_channel_id' => afk_channel_id, 'afk_timeout' => afk_timeout }.to_json,
76
111
  Authorization: token,
@@ -80,7 +115,8 @@ module Discordrb::API
80
115
 
81
116
  # Delete a server
82
117
  def delete_server(token, server_id)
83
- RestClient.delete(
118
+ request(
119
+ :delete,
84
120
  "#{APIBASE}/guilds/#{server_id}",
85
121
  Authorization: token
86
122
  )
@@ -88,7 +124,8 @@ module Discordrb::API
88
124
 
89
125
  # Leave a server
90
126
  def leave_server(server_id)
91
- RestClient.delete(
127
+ request(
128
+ :delete,
92
129
  "#{APIBASE}/guilds/#{server_id}",
93
130
  Authorization: token
94
131
  )
@@ -96,7 +133,8 @@ module Discordrb::API
96
133
 
97
134
  # Get a channel's data
98
135
  def channel(token, channel_id)
99
- RestClient.get(
136
+ request(
137
+ :get,
100
138
  "#{APIBASE}/channels/#{channel_id}",
101
139
  Authorization: token
102
140
  )
@@ -104,7 +142,8 @@ module Discordrb::API
104
142
 
105
143
  # Create a channel
106
144
  def create_channel(token, server_id, name, type)
107
- RestClient.post(
145
+ request(
146
+ :post,
108
147
  "#{APIBASE}/guilds/#{server_id}/channels",
109
148
  { 'name' => name, 'type' => type }.to_json,
110
149
  Authorization: token,
@@ -114,7 +153,8 @@ module Discordrb::API
114
153
 
115
154
  # Update a channel's data
116
155
  def update_channel(token, channel_id, name, topic, position = 0)
117
- RestClient.patch(
156
+ request(
157
+ :patch,
118
158
  "#{APIBASE}/channels/#{channel_id}",
119
159
  { 'name' => name, 'position' => position, 'topic' => topic }.to_json,
120
160
  Authorization: token,
@@ -124,7 +164,8 @@ module Discordrb::API
124
164
 
125
165
  # Delete a channel
126
166
  def delete_channel(token, channel_id)
127
- RestClient.delete(
167
+ request(
168
+ :delete,
128
169
  "#{APIBASE}/channels/#{channel_id}",
129
170
  Authorization: token
130
171
  )
@@ -132,7 +173,8 @@ module Discordrb::API
132
173
 
133
174
  # Join a server using an invite
134
175
  def join_server(token, invite_code)
135
- RestClient.post(
176
+ request(
177
+ :post,
136
178
  "#{APIBASE}/invite/#{invite_code}",
137
179
  nil,
138
180
  Authorization: token
@@ -141,7 +183,8 @@ module Discordrb::API
141
183
 
142
184
  # Resolve an invite
143
185
  def resolve_invite(token, invite_code)
144
- RestClient.get(
186
+ request(
187
+ :get,
145
188
  "#{APIBASE}/invite/#{invite_code}",
146
189
  Authorization: token
147
190
  )
@@ -149,7 +192,8 @@ module Discordrb::API
149
192
 
150
193
  # Create a private channel
151
194
  def create_private(token, bot_user_id, user_id)
152
- RestClient.post(
195
+ request(
196
+ :post,
153
197
  "#{APIBASE}/users/#{bot_user_id}/channels",
154
198
  { 'recipient_id' => user_id }.to_json,
155
199
  Authorization: token,
@@ -159,7 +203,8 @@ module Discordrb::API
159
203
 
160
204
  # Create an instant invite from a server or a channel id
161
205
  def create_invite(token, channel_id, max_age = 0, max_uses = 0, temporary = false, xkcd = false)
162
- RestClient.post(
206
+ request(
207
+ :post,
163
208
  "#{APIBASE}/channels/#{channel_id}/invites",
164
209
  { 'max_age' => max_age, 'max_uses' => max_uses, 'temporary' => temporary, 'xkcdpass' => xkcd }.to_json,
165
210
  Authorization: token,
@@ -169,7 +214,8 @@ module Discordrb::API
169
214
 
170
215
  # Delete an invite by code
171
216
  def delete_invite(token, code)
172
- RestClient.delete(
217
+ request(
218
+ :delete,
173
219
  "#{APIBASE}/invites/#{code}",
174
220
  Authorization: token
175
221
  )
@@ -177,7 +223,8 @@ module Discordrb::API
177
223
 
178
224
  # Send a message to a channel
179
225
  def send_message(token, channel_id, message, mentions = [], tts = false)
180
- RestClient.post(
226
+ request(
227
+ :post,
181
228
  "#{APIBASE}/channels/#{channel_id}/messages",
182
229
  { 'content' => message, 'mentions' => mentions, tts => tts }.to_json,
183
230
  Authorization: token,
@@ -187,7 +234,8 @@ module Discordrb::API
187
234
 
188
235
  # Delete a message
189
236
  def delete_message(token, channel_id, message_id)
190
- RestClient.delete(
237
+ request(
238
+ :delete,
191
239
  "#{APIBASE}/channels/#{channel_id}/messages/#{message_id}",
192
240
  Authorization: token
193
241
  )
@@ -195,7 +243,8 @@ module Discordrb::API
195
243
 
196
244
  # Edit a message
197
245
  def edit_message(token, channel_id, message_id, message, mentions = [])
198
- RestClient.patch(
246
+ request(
247
+ :patch,
199
248
  "#{APIBASE}/channels/#{channel_id}/messages/#{message_id}",
200
249
  { 'content' => message, 'mentions' => mentions }.to_json,
201
250
  Authorization: token,
@@ -207,7 +256,8 @@ module Discordrb::API
207
256
  # The last acknowledged message will be sent in the ready packet,
208
257
  # so this is an easy way to catch up on messages
209
258
  def acknowledge_message(token, channel_id, message_id)
210
- RestClient.post(
259
+ request(
260
+ :post,
211
261
  "#{APIBASE}/channels/#{channel_id}/messages/#{message_id}/ack",
212
262
  nil,
213
263
  Authorization: token
@@ -216,7 +266,8 @@ module Discordrb::API
216
266
 
217
267
  # Send a file as a message to a channel
218
268
  def send_file(token, channel_id, file)
219
- RestClient.post(
269
+ request(
270
+ :post,
220
271
  "#{APIBASE}/channels/#{channel_id}/messages",
221
272
  { file: file },
222
273
  Authorization: token
@@ -225,7 +276,8 @@ module Discordrb::API
225
276
 
226
277
  # Create a role (parameters such as name and colour will have to be set by update_role afterwards)
227
278
  def create_role(token, server_id)
228
- RestClient.post(
279
+ request(
280
+ :post,
229
281
  "#{APIBASE}/guilds/#{server_id}/roles",
230
282
  nil,
231
283
  Authorization: token
@@ -237,7 +289,8 @@ module Discordrb::API
237
289
  # sending TTS messages, embedding links, sending files, reading the history, mentioning everybody,
238
290
  # connecting to voice, speaking and voice activity (push-to-talk isn't mandatory)
239
291
  def update_role(token, server_id, role_id, name, colour, hoist = false, packed_permissions = 36_953_089)
240
- RestClient.patch(
292
+ request(
293
+ :patch,
241
294
  "#{APIBASE}/guilds/#{server_id}/roles/#{role_id}",
242
295
  { 'color' => colour, 'name' => name, 'hoist' => hoist, 'permissions' => packed_permissions }.to_json,
243
296
  Authorization: token,
@@ -247,7 +300,8 @@ module Discordrb::API
247
300
 
248
301
  # Delete a role
249
302
  def delete_role(token, server_id, role_id)
250
- RestClient.delete(
303
+ request(
304
+ :delete,
251
305
  "#{APIBASE}/guilds/#{server_id}/roles/#{role_id}",
252
306
  Authorization: token
253
307
  )
@@ -255,7 +309,8 @@ module Discordrb::API
255
309
 
256
310
  # Update a user's roles
257
311
  def update_user_roles(token, server_id, user_id, roles)
258
- RestClient.patch(
312
+ request(
313
+ :patch,
259
314
  "#{APIBASE}/guilds/#{server_id}/members/#{user_id}",
260
315
  { 'roles' => roles }.to_json,
261
316
  Authorization: token,
@@ -265,7 +320,8 @@ module Discordrb::API
265
320
 
266
321
  # Update a user's permission overrides in a channel
267
322
  def update_user_overrides(token, channel_id, user_id, allow, deny)
268
- RestClient.put(
323
+ request(
324
+ :put,
269
325
  "#{APIBASE}/channels/#{channel_id}/permissions/#{user_id}",
270
326
  { 'type' => 'member', 'id' => user_id, 'allow' => allow, 'deny' => deny }.to_json,
271
327
  Authorization: token,
@@ -275,7 +331,8 @@ module Discordrb::API
275
331
 
276
332
  # Update a role's permission overrides in a channel
277
333
  def update_role_overrides(token, channel_id, role_id, allow, deny)
278
- RestClient.put(
334
+ request(
335
+ :put,
279
336
  "#{APIBASE}/channels/#{channel_id}/permissions/#{role_id}",
280
337
  { 'type' => 'role', 'id' => role_id, 'allow' => allow, 'deny' => deny }.to_json,
281
338
  Authorization: token,
@@ -285,7 +342,8 @@ module Discordrb::API
285
342
 
286
343
  # Get the gateway to be used
287
344
  def gateway(token)
288
- RestClient.get(
345
+ request(
346
+ :get,
289
347
  "#{APIBASE}/gateway",
290
348
  Authorization: token
291
349
  )
@@ -293,7 +351,8 @@ module Discordrb::API
293
351
 
294
352
  # Start typing (needs to be resent every 5 seconds to keep up the typing)
295
353
  def start_typing(token, channel_id)
296
- RestClient.post(
354
+ request(
355
+ :post,
297
356
  "#{APIBASE}/channels/#{channel_id}/typing",
298
357
  nil,
299
358
  Authorization: token
@@ -302,7 +361,8 @@ module Discordrb::API
302
361
 
303
362
  # Get user data
304
363
  def user(token, user_id)
305
- RestClient.get(
364
+ request(
365
+ :get,
306
366
  "#{APIBASE}/users/#{user_id}",
307
367
  Authorization: token
308
368
  )
@@ -310,7 +370,8 @@ module Discordrb::API
310
370
 
311
371
  # Update user data
312
372
  def update_user(token, email, password, new_username, avatar, new_password = nil)
313
- RestClient.patch(
373
+ request(
374
+ :patch,
314
375
  "#{APIBASE}/users/@me",
315
376
  { 'avatar' => avatar, 'email' => email, 'new_password' => new_password, 'password' => password, 'username' => new_username }.to_json,
316
377
  Authorization: token,
@@ -320,7 +381,8 @@ module Discordrb::API
320
381
 
321
382
  # Get a list of messages from a channel's history
322
383
  def channel_log(token, channel_id, amount, before = nil, after = nil)
323
- RestClient.get(
384
+ request(
385
+ :get,
324
386
  "#{APIBASE}/channels/#{channel_id}/messages?limit=#{amount}#{"&before=#{before}" if before}#{"&after=#{after}" if after}",
325
387
  Authorization: token
326
388
  )
data/lib/discordrb/bot.rb CHANGED
@@ -726,6 +726,7 @@ module Discordrb
726
726
 
727
727
  # Apparently we get a 400 if the password or username is incorrect. In that case, tell the user
728
728
  debug("Are you sure you're using the correct username and password?") if e.class == RestClient::BadRequest
729
+ log_exception(e)
729
730
  raise $ERROR_INFO
730
731
  end
731
732
  end
@@ -1,4 +1,4 @@
1
1
  # Discordrb and all its functionality, in this case only the version.
2
2
  module Discordrb
3
- VERSION = '1.4.1'
3
+ VERSION = '1.4.2'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: discordrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - meew0
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-12-07 00:00:00.000000000 Z
11
+ date: 2015-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faye-websocket