disrb 0.1.3 → 0.1.4
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/LICENSE +1 -1
- data/README.md +19 -7
- data/lib/disrb/application_commands.rb +53 -45
- data/lib/disrb/guild.rb +162 -147
- data/lib/disrb/message.rb +87 -66
- data/lib/disrb/user.rb +36 -35
- data/lib/disrb.rb +183 -24
- data/lib/version.rb +5 -0
- metadata +30 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 755465c33626010b7a97992a3afbcee4459e9feae3249870900531ce315ae4f5
|
|
4
|
+
data.tar.gz: dec666a3607d7d21b3a526f6435a291122239ab66ad908d6d3a2626c1fd7ea45
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1120cf0957b7e7ab2c7fdbf011b27816cb9085cb957f8c3eee37813a1a3627a4649adcb2ca001052740fca0fa7db50e6a0731b87d0ad73b46d0771f1b6fad764
|
|
7
|
+
data.tar.gz: d554f6fe8e41c6846d5ed186cc27988e050dc57af37a041203fa5c887414185238dce3c282c88b3c3a14c4e7f3f528eb7c6257b5fdd92e16b167fdd06b86b4df
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
# v0.1.4 (2026-04-05)
|
|
2
|
+
|
|
3
|
+
- Add support for file uploading
|
|
4
|
+
- Fix bug where HTTP handlers would continue executing even after an error
|
|
5
|
+
- Add missing User-Agent header in requests to the HTTP API (it can be changed from the default)
|
|
6
|
+
- Fix bug where functions may run `body` and `status` functions on a nil object
|
|
7
|
+
- Change 200 server limit notice from a warning to an info message in `get_current_user_guilds`
|
|
8
|
+
- Slight modifications in `README.md` and `LICENSE`
|
|
9
|
+
|
|
10
|
+
## Breaking changes
|
|
11
|
+
|
|
12
|
+
- Any project using `DiscordApi`'s `get`, `post`, `delete`, `put` and `patch` functions will not work, as they have been made private (only functions inside the same class can call them), in order to add functionality for customizing the User-Agent header included in requests to the HTTP API.
|
|
13
|
+
|
|
1
14
|
# v0.1.3 (2025-11-15)
|
|
2
15
|
|
|
3
16
|
- Add documentation
|
data/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright (c) 2025-
|
|
1
|
+
Copyright (c) 2025-2026 hoovad
|
|
2
2
|
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
4
|
|
data/README.md
CHANGED
|
@@ -2,16 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
[](LICENSE)
|
|
4
4
|
[](https://rubygems.org/gems/disrb)
|
|
5
|
-

|
|
6
6
|
[](https://github.com/hoovad/discord.rb/actions/workflows/main.yml)
|
|
7
7
|
|
|
8
|
-
[Changelog](CHANGELOG.md) | [Documentation](https://www.rubydoc.info/gems/disrb/) (
|
|
8
|
+
[Changelog](CHANGELOG.md) | [Documentation](https://www.rubydoc.info/gems/disrb/) | [Contributing](CONTRIBUTING.md)
|
|
9
|
+
|
|
10
|
+
> [!IMPORTANT]
|
|
11
|
+
> This is project is still in early development. Expect changes that might break your code at any time. If your code suddenly doesn't work but it did on a previous version, check the [Changelog](CHANGELOG.md) for any breaking changes.
|
|
9
12
|
|
|
10
13
|
W.I.P. Discord API wrapper written in Ruby for fun.
|
|
11
14
|
|
|
12
|
-
|
|
15
|
+
> [!NOTE]
|
|
16
|
+
> This is not a full-featured Discord API handler. This gem lets you interact with the Discord API directly without all the baggage. If you want to make a bot extremely easily, this is not what you are looking for.
|
|
17
|
+
|
|
18
|
+
If you wanted to use this project, but found that something is missing, doesn't work, don't be afraid to open an issue! Read the [Contributing](CONTRIBUTING.md) page.
|
|
19
|
+
|
|
20
|
+
## Demonstration
|
|
21
|
+
|
|
22
|
+
The test.rb file creates two commands "test" and "test2", that return "Hi" and "Hello World!" respectively, sets the bot's current activity to 'Watching if i work', and sets the presence to online since the program was started.
|
|
13
23
|
|
|
14
|
-
!
|
|
24
|
+
> [!NOTE]
|
|
25
|
+
> You will need to fill out the required data in `env.rb.template` and rename it to `env.rb` before running `test.rb`.
|
|
15
26
|
|
|
16
27
|
## How to use this project
|
|
17
28
|
|
|
@@ -19,9 +30,10 @@ The documentation will contain information about the functions implemented in th
|
|
|
19
30
|
|
|
20
31
|
Most functions in this library return a `Faraday::Response` object. Check the [Faraday documentation](https://www.rubydoc.info/github/lostisland/faraday) for info on how to use that object.
|
|
21
32
|
|
|
22
|
-
If you want to get the contents of the response, use the `body` instance method (example: `[Faraday::Response object here].body`). The contents will most likely be JSON. To convert it to a Ruby object, use `JSON.parse([Faraday::Response object here].body)
|
|
33
|
+
If you want to get the contents of the response, use the `body` instance method (example: `[Faraday::Response object here].body`). The contents will most likely be JSON. To convert it to a Ruby object, use `JSON.parse([Faraday::Response object here].body)` (with `require 'json'` of course).
|
|
23
34
|
|
|
24
|
-
|
|
35
|
+
> [!TIP]
|
|
36
|
+
> When reading the documentation, there most likely will be a link to the relevant Discord Developer Documentation page. Please read that page as well, it will contain information that may help you.
|
|
25
37
|
|
|
26
38
|
## Roadmap
|
|
27
39
|
- [x] Indev release (v0.1.0)
|
|
@@ -46,5 +58,5 @@ When reading the documentation, there most likely will be a link to the relevant
|
|
|
46
58
|
- [ ] Voice support
|
|
47
59
|
- [ ] Add parameter validation
|
|
48
60
|
- [ ] Stable release (v1.0.0)
|
|
49
|
-
- [ ]
|
|
61
|
+
- [ ] Return classes instead of `Faraday::Response` objects
|
|
50
62
|
- [ ] Bugfixes, consistency and improvements
|
|
@@ -37,10 +37,11 @@ class DiscordApi
|
|
|
37
37
|
url = "#{@base_url}/applications/#{@application_id}/guilds/#{guild_id}/commands"
|
|
38
38
|
data = JSON.generate(output)
|
|
39
39
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
40
|
-
response =
|
|
41
|
-
return response if response.status == 201 || response.status == 200
|
|
40
|
+
response = post(url, data, headers)
|
|
41
|
+
return response if response.is_a?(Faraday::Response) && (response.status == 201 || response.status == 200)
|
|
42
42
|
|
|
43
|
-
@logger.error("Failed to create guild application command in guild with ID #{guild_id}.
|
|
43
|
+
@logger.error("Failed to create guild application command in guild with ID #{guild_id}." \
|
|
44
|
+
" Response: #{response_error_body(response)}")
|
|
44
45
|
response
|
|
45
46
|
end
|
|
46
47
|
|
|
@@ -112,10 +113,10 @@ class DiscordApi
|
|
|
112
113
|
url = "#{@base_url}/applications/#{@application_id}/commands"
|
|
113
114
|
data = JSON.generate(output)
|
|
114
115
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
115
|
-
response =
|
|
116
|
-
return response if response.status == 201 || response.status == 200
|
|
116
|
+
response = post(url, data, headers)
|
|
117
|
+
return response if response.is_a?(Faraday::Response) && (response.status == 201 || response.status == 200)
|
|
117
118
|
|
|
118
|
-
@logger.error("Failed to create global application command. Response: #{response
|
|
119
|
+
@logger.error("Failed to create global application command. Response: #{response_error_body(response)}")
|
|
119
120
|
response
|
|
120
121
|
end
|
|
121
122
|
|
|
@@ -178,10 +179,11 @@ class DiscordApi
|
|
|
178
179
|
url = "#{@base_url}/applications/#{@application_id}/commands/#{command_id}"
|
|
179
180
|
data = JSON.generate(output)
|
|
180
181
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
181
|
-
response =
|
|
182
|
-
return response if response.status == 200
|
|
182
|
+
response = patch(url, data, headers)
|
|
183
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
183
184
|
|
|
184
|
-
@logger.error("Failed to edit global application command with ID #{command_id}.
|
|
185
|
+
@logger.error("Failed to edit global application command with ID #{command_id}." \
|
|
186
|
+
" Response: #{response_error_body(response)}")
|
|
185
187
|
response
|
|
186
188
|
end
|
|
187
189
|
|
|
@@ -218,10 +220,11 @@ class DiscordApi
|
|
|
218
220
|
url = "#{@base_url}/applications/#{@application_id}/guilds/#{guild_id}/commands/#{command_id}"
|
|
219
221
|
data = JSON.generate(output)
|
|
220
222
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
221
|
-
response =
|
|
222
|
-
return response if response.status == 200
|
|
223
|
+
response = patch(url, data, headers)
|
|
224
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
223
225
|
|
|
224
|
-
@logger.error("Failed to edit guild application command with ID #{command_id}.
|
|
226
|
+
@logger.error("Failed to edit guild application command with ID #{command_id}." \
|
|
227
|
+
" Response: #{response_error_body(response)}")
|
|
225
228
|
response
|
|
226
229
|
end
|
|
227
230
|
|
|
@@ -232,10 +235,11 @@ class DiscordApi
|
|
|
232
235
|
def delete_global_application_command(command_id)
|
|
233
236
|
url = "#{@base_url}/applications/#{@application_id}/commands/#{command_id}"
|
|
234
237
|
headers = { 'Authorization': @authorization_header }
|
|
235
|
-
response =
|
|
236
|
-
return response if response.status == 204
|
|
238
|
+
response = delete(url, headers)
|
|
239
|
+
return response if response.is_a?(Faraday::Response) && response.status == 204
|
|
237
240
|
|
|
238
|
-
@logger.error("Failed to delete global application command with ID #{command_id}.
|
|
241
|
+
@logger.error("Failed to delete global application command with ID #{command_id}." \
|
|
242
|
+
"Response: #{response_error_body(response)}")
|
|
239
243
|
response
|
|
240
244
|
end
|
|
241
245
|
|
|
@@ -247,11 +251,12 @@ class DiscordApi
|
|
|
247
251
|
def delete_guild_application_command(guild_id, command_id)
|
|
248
252
|
url = "#{@base_url}/applications/#{@application_id}/guilds/#{guild_id}/commands/#{command_id}"
|
|
249
253
|
headers = { 'Authorization': @authorization_header }
|
|
250
|
-
response =
|
|
251
|
-
return response if response.status == 204
|
|
254
|
+
response = delete(url, headers)
|
|
255
|
+
return response if response.is_a?(Faraday::Response) && response.status == 204
|
|
252
256
|
|
|
253
257
|
@logger.error("Failed to delete guild application command with ID #{command_id} in guild with ID #{guild_id}. " \
|
|
254
|
-
"Response: #{response
|
|
258
|
+
"Response: #{response_error_body(response)}")
|
|
259
|
+
response
|
|
255
260
|
end
|
|
256
261
|
|
|
257
262
|
# Returns a list of application commands for a guild. Returns 200 OK with an array of command objects.
|
|
@@ -265,10 +270,11 @@ class DiscordApi
|
|
|
265
270
|
query_string = DiscordApi.handle_query_strings(query_string_hash)
|
|
266
271
|
url = "#{@base_url}/applications/#{@application_id}/guilds/#{guild_id}/commands#{query_string}"
|
|
267
272
|
headers = { 'Authorization': @authorization_header }
|
|
268
|
-
response =
|
|
269
|
-
return response if response.status == 200
|
|
273
|
+
response = get(url, headers)
|
|
274
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
270
275
|
|
|
271
|
-
@logger.error("Failed to get guild application commands for guild with ID #{guild_id}.
|
|
276
|
+
@logger.error("Failed to get guild application commands for guild with ID #{guild_id}." \
|
|
277
|
+
" Response: #{response_error_body(response)}")
|
|
272
278
|
response
|
|
273
279
|
end
|
|
274
280
|
|
|
@@ -282,10 +288,10 @@ class DiscordApi
|
|
|
282
288
|
query_string = DiscordApi.handle_query_strings(query_string_hash)
|
|
283
289
|
url = "#{@base_url}/applications/#{@application_id}/commands#{query_string}"
|
|
284
290
|
headers = { 'Authorization': @authorization_header }
|
|
285
|
-
response =
|
|
286
|
-
return response if response.status == 200
|
|
291
|
+
response = get(url, headers)
|
|
292
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
287
293
|
|
|
288
|
-
@logger.error("Failed to get global application commands. Response: #{response
|
|
294
|
+
@logger.error("Failed to get global application commands. Response: #{response_error_body(response)}")
|
|
289
295
|
response
|
|
290
296
|
end
|
|
291
297
|
|
|
@@ -296,10 +302,11 @@ class DiscordApi
|
|
|
296
302
|
def get_global_application_command(command_id)
|
|
297
303
|
url = "#{@base_url}/applications/#{@application_id}/commands/#{command_id}"
|
|
298
304
|
headers = { 'Authorization': @authorization_header }
|
|
299
|
-
response =
|
|
300
|
-
return response if response.status == 200
|
|
305
|
+
response = get(url, headers)
|
|
306
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
301
307
|
|
|
302
|
-
@logger.error("Failed to get global application command with ID #{command_id}.
|
|
308
|
+
@logger.error("Failed to get global application command with ID #{command_id}." \
|
|
309
|
+
" Response: #{response_error_body(response)}")
|
|
303
310
|
response
|
|
304
311
|
end
|
|
305
312
|
|
|
@@ -311,10 +318,11 @@ class DiscordApi
|
|
|
311
318
|
def get_guild_application_command(guild_id, command_id)
|
|
312
319
|
url = "#{@base_url}/applications/#{@application_id}/guilds/#{guild_id}/commands/#{command_id}"
|
|
313
320
|
headers = { 'Authorization': @authorization_header }
|
|
314
|
-
response =
|
|
315
|
-
return response if response.status == 200
|
|
321
|
+
response = get(url, headers)
|
|
322
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
316
323
|
|
|
317
|
-
@logger.error("Failed to get guild application command with ID #{command_id}.
|
|
324
|
+
@logger.error("Failed to get guild application command with ID #{command_id}." \
|
|
325
|
+
" Response: #{response_error_body(response)}")
|
|
318
326
|
response
|
|
319
327
|
end
|
|
320
328
|
|
|
@@ -326,10 +334,10 @@ class DiscordApi
|
|
|
326
334
|
url = "#{@base_url}/applications/#{@application_id}/commands"
|
|
327
335
|
data = JSON.generate(commands)
|
|
328
336
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
329
|
-
response =
|
|
330
|
-
return response if response.status == 200
|
|
337
|
+
response = put(url, data, headers)
|
|
338
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
331
339
|
|
|
332
|
-
@logger.error("Failed to bulk overwrite global application commands. Response: #{response
|
|
340
|
+
@logger.error("Failed to bulk overwrite global application commands. Response: #{response_error_body(response)}")
|
|
333
341
|
response
|
|
334
342
|
end
|
|
335
343
|
|
|
@@ -342,11 +350,11 @@ class DiscordApi
|
|
|
342
350
|
url = "#{@base_url}/applications/#{@application_id}/guilds/#{guild_id}/commands"
|
|
343
351
|
data = JSON.generate(commands)
|
|
344
352
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
345
|
-
response =
|
|
346
|
-
return response if response.status == 200
|
|
353
|
+
response = put(url, data, headers)
|
|
354
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
347
355
|
|
|
348
356
|
@logger.error("Failed to bulk overwrite guild application commands in guild with ID #{guild_id}. " \
|
|
349
|
-
"Response: #{response
|
|
357
|
+
"Response: #{response_error_body(response)}")
|
|
350
358
|
response
|
|
351
359
|
end
|
|
352
360
|
|
|
@@ -357,11 +365,11 @@ class DiscordApi
|
|
|
357
365
|
def get_guild_application_command_permissions(guild_id)
|
|
358
366
|
url = "#{@base_url}/applications/#{@application_id}/guilds/#{guild_id}/commands/permissions"
|
|
359
367
|
headers = { 'Authorization': @authorization_header }
|
|
360
|
-
response =
|
|
361
|
-
return response if response.status == 200
|
|
368
|
+
response = get(url, headers)
|
|
369
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
362
370
|
|
|
363
371
|
@logger.error("Failed to get guild application command permissions for guild with ID #{guild_id}. " \
|
|
364
|
-
"Response: #{response
|
|
372
|
+
"Response: #{response_error_body(response)}")
|
|
365
373
|
response
|
|
366
374
|
end
|
|
367
375
|
|
|
@@ -373,11 +381,11 @@ class DiscordApi
|
|
|
373
381
|
def get_application_command_permissions(guild_id, command_id)
|
|
374
382
|
url = "#{@base_url}/applications/#{@application_id}/guilds/#{guild_id}/commands/#{command_id}/permissions"
|
|
375
383
|
headers = { 'Authorization': @authorization_header }
|
|
376
|
-
response =
|
|
377
|
-
return response if response.status == 200
|
|
384
|
+
response = get(url, headers)
|
|
385
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
378
386
|
|
|
379
387
|
@logger.error("Failed to get appliaction command permissions for command with ID #{command_id} in guild with ID " \
|
|
380
|
-
"#{guild_id}. Response: #{response
|
|
388
|
+
"#{guild_id}. Response: #{response_error_body(response)}")
|
|
381
389
|
response
|
|
382
390
|
end
|
|
383
391
|
|
|
@@ -391,11 +399,11 @@ class DiscordApi
|
|
|
391
399
|
url = "#{@base_url}/applications/#{@application_id}/guilds/#{guild_id}/commands/#{command_id}/permissions"
|
|
392
400
|
data = JSON.generate(permissions)
|
|
393
401
|
headers = { 'Authorization': @authorization_header, 'Content-Type': 'application/json' }
|
|
394
|
-
response =
|
|
395
|
-
return response if response.status == 200
|
|
402
|
+
response = put(url, data, headers)
|
|
403
|
+
return response if response.is_a?(Faraday::Response) && response.status == 200
|
|
396
404
|
|
|
397
405
|
@logger.error("Failed to edit application command permissions for command with ID #{command_id} in guild with ID " \
|
|
398
|
-
"#{guild_id}. Response: #{response
|
|
406
|
+
"#{guild_id}. Response: #{response_error_body(response)}")
|
|
399
407
|
response
|
|
400
408
|
end
|
|
401
409
|
end
|