discorb 0.0.3 → 0.0.7
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 +14 -2
- data/Gemfile.lock +1 -1
- data/README.md +3 -2
- data/discorb.gemspec +3 -3
- data/lib/discorb/channel.rb +36 -32
- data/lib/discorb/client.rb +8 -8
- data/lib/discorb/common.rb +1 -1
- data/lib/discorb/emoji.rb +2 -2
- data/lib/discorb/gateway.rb +6 -4
- data/lib/discorb/guild.rb +38 -38
- data/lib/discorb/guild_template.rb +3 -3
- data/lib/discorb/{internet.rb → http.rb} +2 -2
- data/lib/discorb/integration.rb +1 -1
- data/lib/discorb/interaction.rb +6 -6
- data/lib/discorb/invite.rb +1 -1
- data/lib/discorb/member.rb +3 -3
- data/lib/discorb/message.rb +7 -7
- data/lib/discorb/modules.rb +6 -6
- data/lib/discorb/role.rb +3 -3
- data/lib/discorb/sticker.rb +2 -2
- data/lib/discorb/user.rb +2 -2
- data/lib/discorb/voice_state.rb +2 -2
- data/lib/discorb/webhook.rb +10 -11
- data/lib/discorb.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 066cdc59fc560a9d91badf19ac7628de7e7d7bf112b6a054ea68e697c7c738f2
|
4
|
+
data.tar.gz: 29558ecd466f3048aa3a7abac2b64bd526fee442cf7f84e49288e29422f0edc6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8ff733e1fc0caefcfb902584b6a9c2826f0bf1e4372e44cd1cd7a66c32da9a460e7c2b69e26a63812f4d15a2f94b49548496f589b56903c75233045bc4aa66d
|
7
|
+
data.tar.gz: cec8a40047b30df81c0c8e84f17e1d2aa73ad69204420811ec51427682595060b6632c81eadcef6e4435f831179f2b57f22fd9dc6a01dd8929dc1c56b7e0eddc
|
data/Changelog.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
## v0.0.1
|
3
|
+
## v0.0.1
|
4
4
|
|
5
|
-
- Initial release
|
5
|
+
- Initial release
|
6
|
+
|
7
|
+
## v0.0.2
|
8
|
+
|
9
|
+
- Fix: Fix rubygems description
|
10
|
+
|
11
|
+
## v0.0.3
|
12
|
+
|
13
|
+
- Fix: Fix no dependencies
|
14
|
+
|
15
|
+
## v0.0.4
|
16
|
+
|
17
|
+
- Fix: Fix NoMethodError by webhook message
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# discorb
|
2
2
|
[](https://rubydoc.info/gems/discorb)
|
3
3
|
[](https://rubygems.org/gems/discorb)
|
4
|
-
[](https://rubygems.org/gems/discorb)
|
4
|
+
[](https://rubygems.org/gems/discorb)
|
5
|
+
[](https://discord.gg/hCP6zq8Vpj)
|
5
6
|
|
6
7
|
discorb is a Discord API wrapper for Ruby.
|
7
8
|
|
@@ -46,7 +47,7 @@ client.run(ENV["DISCORD_BOT_TOKEN"])
|
|
46
47
|
|
47
48
|
## Contributing
|
48
49
|
|
49
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
50
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/discorb-lib/discorb.
|
50
51
|
|
51
52
|
## License
|
52
53
|
|
data/discorb.gemspec
CHANGED
@@ -9,15 +9,15 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.email = ["sevenc-nanashi@sevenbot.jp"]
|
10
10
|
|
11
11
|
spec.summary = "discorb is a Discord API wrapper for Ruby."
|
12
|
-
spec.homepage = "https://github.com/
|
12
|
+
spec.homepage = "https://github.com/discorb-lib/discorb"
|
13
13
|
spec.license = "MIT"
|
14
14
|
spec.required_ruby_version = Gem::Requirement.new(">= 3.0.0")
|
15
15
|
|
16
16
|
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
17
17
|
|
18
18
|
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
-
spec.metadata["source_code_uri"] = "https://github.com/
|
20
|
-
spec.metadata["changelog_uri"] = "https://github.com/
|
19
|
+
spec.metadata["source_code_uri"] = "https://github.com/discorb-lib/discorb"
|
20
|
+
spec.metadata["changelog_uri"] = "https://github.com/discorb-lib/discorb/blob/main/Changelog.md"
|
21
21
|
|
22
22
|
# Specify which files should be added to the gem when it is released.
|
23
23
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
data/lib/discorb/channel.rb
CHANGED
@@ -175,7 +175,7 @@ module Discorb
|
|
175
175
|
#
|
176
176
|
def delete!(reason: nil)
|
177
177
|
Async do
|
178
|
-
@client.
|
178
|
+
@client.http.delete(base_url.wait.to_s, audit_log_reason: reason).wait
|
179
179
|
@deleted = true
|
180
180
|
self
|
181
181
|
end
|
@@ -203,7 +203,7 @@ module Discorb
|
|
203
203
|
}
|
204
204
|
payload[:lock_permissions] = lock_permissions
|
205
205
|
payload[:parent_id] = parent&.id if parent != :unset
|
206
|
-
@client.
|
206
|
+
@client.http.patch("/guilds/#{@guild_id}/channels", payload, audit_log_reason: reason).wait
|
207
207
|
end
|
208
208
|
end
|
209
209
|
|
@@ -295,7 +295,7 @@ module Discorb
|
|
295
295
|
default_auto_archive_duration ||= archive_in
|
296
296
|
payload[:default_auto_archive_duration] = default_auto_archive_duration if default_auto_archive_duration != :unset
|
297
297
|
|
298
|
-
@client.
|
298
|
+
@client.http.patch("/channels/#{@id}", payload, audit_log_reason: reason).wait
|
299
299
|
self
|
300
300
|
end
|
301
301
|
end
|
@@ -317,7 +317,7 @@ module Discorb
|
|
317
317
|
payload = {}
|
318
318
|
payload[:name] = name
|
319
319
|
payload[:avatar] = avatar.to_s if avatar
|
320
|
-
_resp, data = @client.
|
320
|
+
_resp, data = @client.http.post("/channels/#{@id}/webhooks", payload).wait
|
321
321
|
Webhook.new([@client, data])
|
322
322
|
end
|
323
323
|
end
|
@@ -331,7 +331,7 @@ module Discorb
|
|
331
331
|
#
|
332
332
|
def fetch_webhooks
|
333
333
|
Async do
|
334
|
-
_resp, data = @client.
|
334
|
+
_resp, data = @client.http.get("/channels/#{@id}/webhooks").wait
|
335
335
|
data.map { |webhook| Webhook.new([@client, webhook]) }
|
336
336
|
end
|
337
337
|
end
|
@@ -358,7 +358,7 @@ module Discorb
|
|
358
358
|
|
359
359
|
message_ids = messages.map { |m| Discorb::Utils.try(m, :id).to_s }
|
360
360
|
|
361
|
-
@client.
|
361
|
+
@client.http.post("/channels/#{@id}/messages/bulk-delete", { messages: message_ids }).wait
|
362
362
|
end
|
363
363
|
end
|
364
364
|
|
@@ -387,7 +387,7 @@ module Discorb
|
|
387
387
|
deny: deny_value,
|
388
388
|
type: target.is_a?(Member) ? 1 : 0,
|
389
389
|
}
|
390
|
-
@client.
|
390
|
+
@client.http.put("/channels/#{@id}/permissions/#{target.id}", payload, audit_log_reason: reason).wait
|
391
391
|
end
|
392
392
|
end
|
393
393
|
|
@@ -406,7 +406,7 @@ module Discorb
|
|
406
406
|
#
|
407
407
|
def delete_permissions(target, reason: nil)
|
408
408
|
Async do
|
409
|
-
@client.
|
409
|
+
@client.http.delete("/channels/#{@id}/permissions/#{target.id}", audit_log_reason: reason).wait
|
410
410
|
end
|
411
411
|
end
|
412
412
|
|
@@ -423,7 +423,7 @@ module Discorb
|
|
423
423
|
#
|
424
424
|
def fetch_invites
|
425
425
|
Async do
|
426
|
-
_resp, data = @client.
|
426
|
+
_resp, data = @client.http.get("/channels/#{@id}/invites").wait
|
427
427
|
data.map { |invite| Invite.new(@client, invite) }
|
428
428
|
end
|
429
429
|
end
|
@@ -444,7 +444,7 @@ module Discorb
|
|
444
444
|
#
|
445
445
|
def create_invite(max_age: nil, max_uses: nil, temporary: false, unique: false, reason: nil)
|
446
446
|
Async do
|
447
|
-
_resp, data = @client.
|
447
|
+
_resp, data = @client.http.post("/channels/#{@id}/invites", {
|
448
448
|
max_age: max_age,
|
449
449
|
max_uses: max_uses,
|
450
450
|
temporary: temporary,
|
@@ -464,7 +464,7 @@ module Discorb
|
|
464
464
|
#
|
465
465
|
def follow_from(target, reason: nil)
|
466
466
|
Async do
|
467
|
-
@client.
|
467
|
+
@client.http.post("/channels/#{target.id}/followers", { webhook_channel_id: @id }, audit_log_reason: reason).wait
|
468
468
|
end
|
469
469
|
end
|
470
470
|
|
@@ -478,7 +478,7 @@ module Discorb
|
|
478
478
|
#
|
479
479
|
def follow_to(target, reason: nil)
|
480
480
|
Async do
|
481
|
-
@client.
|
481
|
+
@client.http.post("/channels/#{@id}/followers", { webhook_channel_id: target.id }, audit_log_reason: reason).wait
|
482
482
|
end
|
483
483
|
end
|
484
484
|
|
@@ -491,7 +491,7 @@ module Discorb
|
|
491
491
|
#
|
492
492
|
def fetch_pins
|
493
493
|
Async do
|
494
|
-
_resp, data = @client.
|
494
|
+
_resp, data = @client.http.get("/channels/#{@id}/pins").wait
|
495
495
|
data.map { |pin| Message.new(@client, pin) }
|
496
496
|
end
|
497
497
|
end
|
@@ -506,7 +506,7 @@ module Discorb
|
|
506
506
|
#
|
507
507
|
def pin_message(message, reason: nil)
|
508
508
|
Async do
|
509
|
-
@client.
|
509
|
+
@client.http.put("/channels/#{@id}/pins/#{message.id}", {}, audit_log_reason: reason).wait
|
510
510
|
end
|
511
511
|
end
|
512
512
|
|
@@ -520,7 +520,7 @@ module Discorb
|
|
520
520
|
#
|
521
521
|
def unpin_message(message, reason: nil)
|
522
522
|
Async do
|
523
|
-
@client.
|
523
|
+
@client.http.delete("/channels/#{@id}/pins/#{message.id}", {}, audit_log_reason: reason).wait
|
524
524
|
end
|
525
525
|
end
|
526
526
|
|
@@ -540,12 +540,12 @@ module Discorb
|
|
540
540
|
def start_thread(name, message: nil, auto_archive_duration: 1440, public: true, reason: nil)
|
541
541
|
Async do
|
542
542
|
_resp, data = if message.nil?
|
543
|
-
@client.
|
543
|
+
@client.http.post("/channels/#{@id}/threads", {
|
544
544
|
name: name, auto_archive_duration: auto_archive_duration, type: public ? 11 : 10,
|
545
545
|
},
|
546
|
-
|
546
|
+
audit_log_reason: reason).wait
|
547
547
|
else
|
548
|
-
@client.
|
548
|
+
@client.http.post("/channels/#{@id}/messages/#{Utils.try(message, :id)}/threads", {
|
549
549
|
name: name, auto_archive_duration: auto_archive_duration,
|
550
550
|
}, audit_log_reason: reason).wait
|
551
551
|
end
|
@@ -564,7 +564,7 @@ module Discorb
|
|
564
564
|
#
|
565
565
|
def fetch_archived_public_threads
|
566
566
|
Async do
|
567
|
-
_resp, data = @client.
|
567
|
+
_resp, data = @client.http.get("/channels/#{@id}/threads/archived/public").wait
|
568
568
|
data.map { |thread| Channel.make_channel(@client, thread) }
|
569
569
|
end
|
570
570
|
end
|
@@ -578,7 +578,7 @@ module Discorb
|
|
578
578
|
#
|
579
579
|
def fetch_archived_private_threads
|
580
580
|
Async do
|
581
|
-
_resp, data = @client.
|
581
|
+
_resp, data = @client.http.get("/channels/#{@id}/threads/archived/private").wait
|
582
582
|
data.map { |thread| Channel.make_channel(@client, thread) }
|
583
583
|
end
|
584
584
|
end
|
@@ -599,7 +599,7 @@ module Discorb
|
|
599
599
|
before = 0
|
600
600
|
threads = []
|
601
601
|
loop do
|
602
|
-
_resp, data = @client.
|
602
|
+
_resp, data = @client.http.get("/channels/#{@id}/users/@me/threads/archived/private?before=#{before}").wait
|
603
603
|
threads += data[:threads].map { |thread| Channel.make_channel(@client, thread) }
|
604
604
|
before = data[:threads][-1][:id]
|
605
605
|
|
@@ -607,7 +607,7 @@ module Discorb
|
|
607
607
|
end
|
608
608
|
threads
|
609
609
|
else
|
610
|
-
_resp, data = @client.
|
610
|
+
_resp, data = @client.http.get("/channels/#{@id}/users/@me/threads/archived/private?limit=#{limit}&before=#{before}").wait
|
611
611
|
data.map { |thread| Channel.make_channel(@client, thread) }
|
612
612
|
end
|
613
613
|
end
|
@@ -670,7 +670,7 @@ module Discorb
|
|
670
670
|
payload[:user_limit] = user_limit if user_limit != :unset
|
671
671
|
payload[:rtc_region] = rtc_region if rtc_region != :unset
|
672
672
|
|
673
|
-
@client.
|
673
|
+
@client.http.patch("/channels/#{@id}", payload, audit_log_reason: reason).wait
|
674
674
|
self
|
675
675
|
end
|
676
676
|
end
|
@@ -734,7 +734,7 @@ module Discorb
|
|
734
734
|
payload[:position] = position if position != :unset
|
735
735
|
payload[:bitrate] = bitrate if bitrate != :unset
|
736
736
|
payload[:rtc_region] = rtc_region if rtc_region != :unset
|
737
|
-
@client.
|
737
|
+
@client.http.patch("/channels/#{@id}", payload, audit_log_reason: reason).wait
|
738
738
|
self
|
739
739
|
end
|
740
740
|
end
|
@@ -754,7 +754,7 @@ module Discorb
|
|
754
754
|
#
|
755
755
|
def start(topic, public: false, reason: nil)
|
756
756
|
Async do
|
757
|
-
_resp, data = @client.
|
757
|
+
_resp, data = @client.http.post("/stage-instances", { channel_id: @id, topic: topic, public: public ? 2 : 1 }, audit_log_reason: reason).wait
|
758
758
|
StageInstance.new(@client, data)
|
759
759
|
end
|
760
760
|
end
|
@@ -769,7 +769,7 @@ module Discorb
|
|
769
769
|
#
|
770
770
|
def fetch_stage_instance
|
771
771
|
Async do
|
772
|
-
_resp, data = @client.
|
772
|
+
_resp, data = @client.http.get("/stage-instances/#{@id}").wait
|
773
773
|
rescue Discorb::NotFoundError
|
774
774
|
nil
|
775
775
|
else
|
@@ -865,7 +865,7 @@ module Discorb
|
|
865
865
|
auto_archive_duration ||= archive_in
|
866
866
|
payload[:auto_archive_duration] = auto_archive_duration if auto_archive_duration != :unset
|
867
867
|
payload[:locked] = locked if locked != :unset
|
868
|
-
@client.
|
868
|
+
@client.http.patch("/channels/#{@id}", payload, audit_log_reason: reason).wait
|
869
869
|
self
|
870
870
|
end
|
871
871
|
end
|
@@ -947,9 +947,9 @@ module Discorb
|
|
947
947
|
def add_member(member = :me)
|
948
948
|
Async do
|
949
949
|
if member == :me
|
950
|
-
@client.
|
950
|
+
@client.http.post("/channels/#{@id}/thread-members/@me").wait
|
951
951
|
else
|
952
|
-
@client.
|
952
|
+
@client.http.post("/channels/#{@id}/thread-members/#{Utils.try(member, :id)}").wait
|
953
953
|
end
|
954
954
|
end
|
955
955
|
end
|
@@ -959,9 +959,9 @@ module Discorb
|
|
959
959
|
def remove_member(member = :me)
|
960
960
|
Async do
|
961
961
|
if member == :me
|
962
|
-
@client.
|
962
|
+
@client.http.delete("/channels/#{@id}/thread-members/@me").wait
|
963
963
|
else
|
964
|
-
@client.
|
964
|
+
@client.http.delete("/channels/#{@id}/thread-members/#{Utils.try(member, :id)}").wait
|
965
965
|
end
|
966
966
|
end
|
967
967
|
end
|
@@ -970,11 +970,15 @@ module Discorb
|
|
970
970
|
|
971
971
|
def fetch_members
|
972
972
|
Async do
|
973
|
-
_resp, data = @client.
|
973
|
+
_resp, data = @client.http.get("/channels/#{@id}/thread-members").wait
|
974
974
|
data.map { |d| @members[d[:id]] = Member.new(@client, d) }
|
975
975
|
end
|
976
976
|
end
|
977
977
|
|
978
|
+
class News < ThreadChannel
|
979
|
+
@channel_type = 10
|
980
|
+
end
|
981
|
+
|
978
982
|
class Public < ThreadChannel
|
979
983
|
@channel_type = 11
|
980
984
|
end
|
data/lib/discorb/client.rb
CHANGED
@@ -16,8 +16,8 @@ module Discorb
|
|
16
16
|
# @return [Discorb::Application] The application that the client is using.
|
17
17
|
# @return [nil] If never fetched application by {#fetch_application}.
|
18
18
|
attr_reader :application
|
19
|
-
# @return [Discorb::
|
20
|
-
attr_reader :
|
19
|
+
# @return [Discorb::HTTP] The http client.
|
20
|
+
attr_reader :http
|
21
21
|
# @return [Integer] The heartbeat interval.
|
22
22
|
attr_reader :heartbeat_interval
|
23
23
|
# @return [Integer] The API version of the Discord gateway.
|
@@ -187,7 +187,7 @@ module Discorb
|
|
187
187
|
#
|
188
188
|
def fetch_user(id)
|
189
189
|
Async do
|
190
|
-
_resp, data =
|
190
|
+
_resp, data = http.get("/users/#{id}").wait
|
191
191
|
User.new(self, data)
|
192
192
|
end
|
193
193
|
end
|
@@ -205,7 +205,7 @@ module Discorb
|
|
205
205
|
#
|
206
206
|
def fetch_channel(id)
|
207
207
|
Async do
|
208
|
-
_resp, data =
|
208
|
+
_resp, data = http.get("/channels/#{id}").wait
|
209
209
|
Channel.make_channel(self, data)
|
210
210
|
end
|
211
211
|
end
|
@@ -223,7 +223,7 @@ module Discorb
|
|
223
223
|
#
|
224
224
|
def fetch_guild(id)
|
225
225
|
Async do
|
226
|
-
_resp, data =
|
226
|
+
_resp, data = http.get("/guilds/#{id}").wait
|
227
227
|
Guild.new(self, data, false)
|
228
228
|
end
|
229
229
|
end
|
@@ -241,7 +241,7 @@ module Discorb
|
|
241
241
|
#
|
242
242
|
def fetch_invite(code, with_count: false, with_expiration: false)
|
243
243
|
Async do
|
244
|
-
_resp, data =
|
244
|
+
_resp, data = http.get("/invites/#{code}?with_count=#{with_count}&with_expiration=#{with_expiration}").wait
|
245
245
|
Invite.new(self, data, false)
|
246
246
|
end
|
247
247
|
end
|
@@ -260,7 +260,7 @@ module Discorb
|
|
260
260
|
Async do
|
261
261
|
next @application if @application && !force
|
262
262
|
|
263
|
-
_resp, data =
|
263
|
+
_resp, data = http.get("/oauth2/applications/@me").wait
|
264
264
|
@application = Application.new(self, data)
|
265
265
|
@application
|
266
266
|
end
|
@@ -275,7 +275,7 @@ module Discorb
|
|
275
275
|
#
|
276
276
|
def fetch_nitro_sticker_packs
|
277
277
|
Async do
|
278
|
-
_resp, data =
|
278
|
+
_resp, data = http.get("/stickers-packs").wait
|
279
279
|
data.map { |pack| Sticker::Pack.new(self, pack) }
|
280
280
|
end
|
281
281
|
end
|
data/lib/discorb/common.rb
CHANGED
@@ -4,7 +4,7 @@ module Discorb
|
|
4
4
|
# @return [String] The API base URL.
|
5
5
|
API_BASE_URL = "https://discord.com/api/v9"
|
6
6
|
# @return [String] The version of discorb.
|
7
|
-
VERSION = "0.0.
|
7
|
+
VERSION = "0.0.7"
|
8
8
|
# @return [String] The user agent for the bot.
|
9
9
|
USER_AGENT = "DiscordBot (https://github.com/discorb-lib/discorb #{VERSION}) Ruby/#{RUBY_VERSION}"
|
10
10
|
|
data/lib/discorb/emoji.rb
CHANGED
@@ -86,7 +86,7 @@ module Discorb
|
|
86
86
|
payload = {}
|
87
87
|
payload[:name] = name if name != :unset
|
88
88
|
payload[:roles] = roles.map { |r| Discorb::Utils.try(r, :id) } if roles != :unset
|
89
|
-
@client.
|
89
|
+
@client.http.patch("/guilds/#{@guild.id}/emojis/#{@id}", payload, audit_log_reason: reason)
|
90
90
|
self
|
91
91
|
end
|
92
92
|
end
|
@@ -104,7 +104,7 @@ module Discorb
|
|
104
104
|
#
|
105
105
|
def delete!(reason: nil)
|
106
106
|
Async do
|
107
|
-
@client.
|
107
|
+
@client.http.delete("/guilds/#{@guild.id}/emojis/#{@id}", audit_log_reason: reason).wait
|
108
108
|
@available = false
|
109
109
|
self
|
110
110
|
end
|
data/lib/discorb/gateway.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "async/http"
|
4
|
+
|
3
5
|
module Discorb
|
4
6
|
#
|
5
7
|
# A module to handle gateway.
|
@@ -454,9 +456,9 @@ module Discorb
|
|
454
456
|
def connect_gateway(first)
|
455
457
|
@log.info "Connecting to gateway."
|
456
458
|
Async do |_task|
|
457
|
-
@
|
459
|
+
@http = HTTP.new(self) if first
|
458
460
|
@first = first
|
459
|
-
_, gateway_response = @
|
461
|
+
_, gateway_response = @http.get("/gateway").wait
|
460
462
|
gateway_url = gateway_response[:url]
|
461
463
|
endpoint = Async::HTTP::Endpoint.parse("#{gateway_url}?v=9&encoding=json",
|
462
464
|
alpn_protocols: Async::HTTP::Protocol::HTTP11.names)
|
@@ -710,14 +712,14 @@ module Discorb
|
|
710
712
|
dispatch(:member_add, nm)
|
711
713
|
when "GUILD_MEMBER_UPDATE"
|
712
714
|
return @log.warn "Unknown guild id #{data[:guild_id]}, ignoring" unless (guild = @guilds[data[:guild_id]])
|
713
|
-
return @log.warn "Unknown member id #{data[:id]}, ignoring" unless (nm = guild.members[data[:id]])
|
715
|
+
return @log.warn "Unknown member id #{data[:user][:id]}, ignoring" unless (nm = guild.members[data[:user][:id]])
|
714
716
|
|
715
717
|
old = Member.new(self, data[:guild_id], data[:user], data.update({ no_cache: true }))
|
716
718
|
nm.send(:_set_data, data[:user], data)
|
717
719
|
dispatch(:member_update, old, nm)
|
718
720
|
when "GUILD_MEMBER_REMOVE"
|
719
721
|
return @log.warn "Unknown guild id #{data[:guild_id]}, ignoring" unless (guild = @guilds[data[:guild_id]])
|
720
|
-
return @log.warn "Unknown member id #{data[:id]}, ignoring" unless (member = guild.members.delete(data[:id]))
|
722
|
+
return @log.warn "Unknown member id #{data[:user][:id]}, ignoring" unless (member = guild.members.delete(data[:user][:id]))
|
721
723
|
|
722
724
|
dispatch(:member_remove, member)
|
723
725
|
when "GUILD_BAN_ADD"
|
data/lib/discorb/guild.rb
CHANGED
@@ -164,7 +164,7 @@ module Discorb
|
|
164
164
|
#
|
165
165
|
def leave!
|
166
166
|
Async do
|
167
|
-
@client.
|
167
|
+
@client.http.delete("/users/@me/guilds/#{@id}").wait
|
168
168
|
@client.guilds.delete(@id)
|
169
169
|
end
|
170
170
|
end
|
@@ -179,7 +179,7 @@ module Discorb
|
|
179
179
|
#
|
180
180
|
def fetch_emoji_list
|
181
181
|
Async do
|
182
|
-
_resp, data = @client.
|
182
|
+
_resp, data = @client.http.get("/guilds/#{@id}/emojis").wait
|
183
183
|
@emojis = Dictionary.new
|
184
184
|
ids = @emojis.map(&:id).map(&:to_s)
|
185
185
|
data.map do |e|
|
@@ -204,7 +204,7 @@ module Discorb
|
|
204
204
|
# @return [Discorb::CustomEmoji] The emoji with the given id.
|
205
205
|
#
|
206
206
|
def fetch_emoji(id)
|
207
|
-
_resp, data = @client.
|
207
|
+
_resp, data = @client.http.get("/guilds/#{@id}/emojis/#{id}").wait
|
208
208
|
@emojis[e[:id]] = CustomEmoji.new(@client, self, data)
|
209
209
|
end
|
210
210
|
|
@@ -220,7 +220,7 @@ module Discorb
|
|
220
220
|
# @return [Discorb::CustomEmoji] The created emoji.
|
221
221
|
#
|
222
222
|
def create_emoji(name, image, roles: [])
|
223
|
-
_resp, data = @client.
|
223
|
+
_resp, data = @client.http.post(
|
224
224
|
"/guilds/#{@id}/emojis",
|
225
225
|
{
|
226
226
|
name: name,
|
@@ -240,7 +240,7 @@ module Discorb
|
|
240
240
|
#
|
241
241
|
def fetch_webhooks
|
242
242
|
Async do
|
243
|
-
_resp, data = @client.
|
243
|
+
_resp, data = @client.http.get("/guilds/#{@id}/webhooks").wait
|
244
244
|
data.map { |webhook| Webhook.new([@client, webhook]) }
|
245
245
|
end
|
246
246
|
end
|
@@ -254,7 +254,7 @@ module Discorb
|
|
254
254
|
#
|
255
255
|
def fetch_audit_log
|
256
256
|
Async do
|
257
|
-
_resp, data = @client.
|
257
|
+
_resp, data = @client.http.get("/guilds/#{@id}/audit-logs").wait
|
258
258
|
AuditLog.new(@client, data, self)
|
259
259
|
end
|
260
260
|
end
|
@@ -268,7 +268,7 @@ module Discorb
|
|
268
268
|
#
|
269
269
|
def fetch_channels
|
270
270
|
Async do
|
271
|
-
_resp, data = @client.
|
271
|
+
_resp, data = @client.http.get("/guilds/#{@id}/channels").wait
|
272
272
|
data.map { |c| Channel.make_channel(@client, c) }
|
273
273
|
end
|
274
274
|
end
|
@@ -312,7 +312,7 @@ module Discorb
|
|
312
312
|
end
|
313
313
|
end
|
314
314
|
payload[:parent_id] = parent.id if parent
|
315
|
-
_resp, data = @client.
|
315
|
+
_resp, data = @client.http.post(
|
316
316
|
"/guilds/#{@id}/channels", payload, audit_log_reason: reason,
|
317
317
|
).wait
|
318
318
|
payload[:parent_id] = parent&.id
|
@@ -355,7 +355,7 @@ module Discorb
|
|
355
355
|
end
|
356
356
|
end
|
357
357
|
payload[:parent_id] = parent.id if parent
|
358
|
-
_resp, data = @client.
|
358
|
+
_resp, data = @client.http.post(
|
359
359
|
"/guilds/#{@id}/channels", payload, audit_log_reason: reason,
|
360
360
|
).wait
|
361
361
|
payload[:parent_id] = parent&.id
|
@@ -391,7 +391,7 @@ module Discorb
|
|
391
391
|
end
|
392
392
|
end
|
393
393
|
payload[:parent_id] = parent&.id
|
394
|
-
_resp, data = @client.
|
394
|
+
_resp, data = @client.http.post(
|
395
395
|
"/guilds/#{@id}/channels", payload, audit_log_reason: reason,
|
396
396
|
).wait
|
397
397
|
Channel.make_channel(@client, data)
|
@@ -431,7 +431,7 @@ module Discorb
|
|
431
431
|
end
|
432
432
|
end
|
433
433
|
payload[:parent_id] = parent&.id
|
434
|
-
_resp, data = @client.
|
434
|
+
_resp, data = @client.http.post(
|
435
435
|
"/guilds/#{@id}/channels", payload, audit_log_reason: reason,
|
436
436
|
).wait
|
437
437
|
Channel.make_channel(@client, data)
|
@@ -477,7 +477,7 @@ module Discorb
|
|
477
477
|
end
|
478
478
|
payload[:nsfw] = nsfw unless nsfw.nil?
|
479
479
|
payload[:parent_id] = parent&.id
|
480
|
-
_resp, data = @client.
|
480
|
+
_resp, data = @client.http.post(
|
481
481
|
"/guilds/#{@id}/channels", payload, audit_log_reason: reason,
|
482
482
|
).wait
|
483
483
|
Channel.make_channel(@client, data)
|
@@ -493,7 +493,7 @@ module Discorb
|
|
493
493
|
#
|
494
494
|
def fetch_active_threads
|
495
495
|
Async do
|
496
|
-
_resp, data = @client.
|
496
|
+
_resp, data = @client.http.get("/guilds/#{@id}/threads/active").wait
|
497
497
|
data[:threads].map { |t| Channel.make_thread(@client, t) }
|
498
498
|
end
|
499
499
|
end
|
@@ -511,7 +511,7 @@ module Discorb
|
|
511
511
|
#
|
512
512
|
def fetch_member(id)
|
513
513
|
Async do
|
514
|
-
_resp, data = @client.
|
514
|
+
_resp, data = @client.http.get("/guilds/#{@id}/members/#{id}").wait
|
515
515
|
rescue Discorb::NotFoundError
|
516
516
|
nil
|
517
517
|
else
|
@@ -531,7 +531,7 @@ module Discorb
|
|
531
531
|
#
|
532
532
|
def fetch_members_named(name, limit: 1)
|
533
533
|
Async do
|
534
|
-
_resp, data = @client.
|
534
|
+
_resp, data = @client.http.get("/guilds/#{@id}/members/search?#{URI.encode_www_form({ query: name, limit: limit })}").wait
|
535
535
|
data.map { |d| Member.new(@client, @id, d[:user], d) }
|
536
536
|
end
|
537
537
|
end
|
@@ -558,7 +558,7 @@ module Discorb
|
|
558
558
|
#
|
559
559
|
def edit_nickname(nickname, reason: nil)
|
560
560
|
Async do
|
561
|
-
@client.
|
561
|
+
@client.http.patch("/guilds/#{@id}/members/@me/nick", { nick: nickname }, audit_log_reason: reason).wait
|
562
562
|
end
|
563
563
|
end
|
564
564
|
|
@@ -576,7 +576,7 @@ module Discorb
|
|
576
576
|
#
|
577
577
|
def kick_member(member, reason: nil)
|
578
578
|
Async do
|
579
|
-
@client.
|
579
|
+
@client.http.delete("/guilds/#{@id}/members/#{member.id}", audit_log_reason: reason).wait
|
580
580
|
end
|
581
581
|
end
|
582
582
|
|
@@ -589,7 +589,7 @@ module Discorb
|
|
589
589
|
#
|
590
590
|
def fetch_bans
|
591
591
|
Async do
|
592
|
-
_resp, data = @client.
|
592
|
+
_resp, data = @client.http.get("/guilds/#{@id}/bans").wait
|
593
593
|
data.map { |d| Ban.new(@client, self, d) }
|
594
594
|
end
|
595
595
|
end
|
@@ -606,7 +606,7 @@ module Discorb
|
|
606
606
|
#
|
607
607
|
def fetch_ban(user)
|
608
608
|
Async do
|
609
|
-
_resp, data = @client.
|
609
|
+
_resp, data = @client.http.get("/guilds/#{@id}/bans/#{user.id}").wait
|
610
610
|
rescue Discorb::NotFoundError
|
611
611
|
nil
|
612
612
|
else
|
@@ -642,7 +642,7 @@ module Discorb
|
|
642
642
|
#
|
643
643
|
def ban_member(member, delete_message_days: 0, reason: nil)
|
644
644
|
Async do
|
645
|
-
_resp, data = @client.
|
645
|
+
_resp, data = @client.http.post(
|
646
646
|
"/guilds/#{@id}/bans", { user: member.id, delete_message_days: delete_message_days }, audit_log_reason: reason,
|
647
647
|
).wait
|
648
648
|
Ban.new(@client, self, data)
|
@@ -659,7 +659,7 @@ module Discorb
|
|
659
659
|
#
|
660
660
|
def unban_user(user, reason: nil)
|
661
661
|
Async do
|
662
|
-
@client.
|
662
|
+
@client.http.delete("/guilds/#{@id}/bans/#{user.id}", audit_log_reason: reason).wait
|
663
663
|
end
|
664
664
|
end
|
665
665
|
|
@@ -672,7 +672,7 @@ module Discorb
|
|
672
672
|
#
|
673
673
|
def fetch_roles
|
674
674
|
Async do
|
675
|
-
_resp, data = @client.
|
675
|
+
_resp, data = @client.http.get("/guilds/#{@id}/roles").wait
|
676
676
|
data.map { |d| Role.new(@client, self, d) }
|
677
677
|
end
|
678
678
|
end
|
@@ -697,7 +697,7 @@ module Discorb
|
|
697
697
|
payload[:color] = color.to_i if color
|
698
698
|
payload[:hoist] = hoist if hoist
|
699
699
|
payload[:mentionable] = mentionable if mentionable
|
700
|
-
_resp, data = @client.
|
700
|
+
_resp, data = @client.http.post(
|
701
701
|
"/guilds/#{@id}/roles", payload, audit_log_reason: reason,
|
702
702
|
).wait
|
703
703
|
Role.new(@client, self, data)
|
@@ -721,7 +721,7 @@ module Discorb
|
|
721
721
|
include_roles: @id.to_s,
|
722
722
|
}
|
723
723
|
param[:include_roles] = roles.map(&:id).map(&:to_s).join(";") if roles.any?
|
724
|
-
_resp, data = @client.
|
724
|
+
_resp, data = @client.http.get("/guilds/#{@id}/prune?#{URI.encode_www_form(params)}").wait
|
725
725
|
data[:pruned]
|
726
726
|
end
|
727
727
|
end
|
@@ -739,7 +739,7 @@ module Discorb
|
|
739
739
|
#
|
740
740
|
def prune(days = 7, roles: [], reason: nil)
|
741
741
|
Async do
|
742
|
-
_resp, data = @client.
|
742
|
+
_resp, data = @client.http.post(
|
743
743
|
"/guilds/#{@id}/prune", { days: days, roles: roles.map(&:id) }, audit_log_reason: reason,
|
744
744
|
).wait
|
745
745
|
data[:pruned]
|
@@ -755,7 +755,7 @@ module Discorb
|
|
755
755
|
#
|
756
756
|
def fetch_voice_regions
|
757
757
|
Async do
|
758
|
-
_resp, data = @client.
|
758
|
+
_resp, data = @client.http.get("/guilds/#{@id}/voice").wait
|
759
759
|
data.map { |d| VoiceRegion.new(@client, d) }
|
760
760
|
end
|
761
761
|
end
|
@@ -769,7 +769,7 @@ module Discorb
|
|
769
769
|
#
|
770
770
|
def fetch_invites
|
771
771
|
Async do
|
772
|
-
_resp, data = @client.
|
772
|
+
_resp, data = @client.http.get("/guilds/#{@id}/invites").wait
|
773
773
|
data.map { |d| Invite.new(@client, d) }
|
774
774
|
end
|
775
775
|
end
|
@@ -783,7 +783,7 @@ module Discorb
|
|
783
783
|
#
|
784
784
|
def fetch_integrations
|
785
785
|
Async do
|
786
|
-
_resp, data = @client.
|
786
|
+
_resp, data = @client.http.get("/guilds/#{@id}/integrations").wait
|
787
787
|
data.map { |d| Integration.new(@client, d) }
|
788
788
|
end
|
789
789
|
end
|
@@ -797,7 +797,7 @@ module Discorb
|
|
797
797
|
#
|
798
798
|
def fetch_widget
|
799
799
|
Async do
|
800
|
-
_resp, data = @client.
|
800
|
+
_resp, data = @client.http.get("/guilds/#{@id}/widget").wait
|
801
801
|
Widget.new(@client, @id, data)
|
802
802
|
end
|
803
803
|
end
|
@@ -811,7 +811,7 @@ module Discorb
|
|
811
811
|
#
|
812
812
|
def fetch_vanity_invite
|
813
813
|
Async do
|
814
|
-
_resp, data = @client.
|
814
|
+
_resp, data = @client.http.get("/guilds/#{@id}/vanity-url").wait
|
815
815
|
VanityInvite.new(@client, self, data)
|
816
816
|
end
|
817
817
|
end
|
@@ -825,7 +825,7 @@ module Discorb
|
|
825
825
|
#
|
826
826
|
def fetch_welcome_screen
|
827
827
|
Async do
|
828
|
-
_resp, data = @client.
|
828
|
+
_resp, data = @client.http.get("/guilds/#{@id}/welcome-screen").wait
|
829
829
|
WelcomeScreen.new(@client, self, data)
|
830
830
|
end
|
831
831
|
end
|
@@ -839,7 +839,7 @@ module Discorb
|
|
839
839
|
#
|
840
840
|
def fetch_stickers
|
841
841
|
Async do
|
842
|
-
_resp, data = @client.
|
842
|
+
_resp, data = @client.http.get("/guilds/#{@id}/stickers").wait
|
843
843
|
data.map { |d| Sticker::GuildSticker.new(@client, d) }
|
844
844
|
end
|
845
845
|
end
|
@@ -856,7 +856,7 @@ module Discorb
|
|
856
856
|
#
|
857
857
|
def fetch_sticker(id)
|
858
858
|
Async do
|
859
|
-
_resp, data = @client.
|
859
|
+
_resp, data = @client.http.get("/guilds/#{@id}/stickers/#{id}").wait
|
860
860
|
rescue Discorb::NotFoundError
|
861
861
|
nil
|
862
862
|
else
|
@@ -873,7 +873,7 @@ module Discorb
|
|
873
873
|
#
|
874
874
|
def fetch_templates
|
875
875
|
Async do
|
876
|
-
_resp, data = @client.
|
876
|
+
_resp, data = @client.http.get("/guilds/#{@id}/templates").wait
|
877
877
|
data.map { |d| GuildTemplate.new(@client, d) }
|
878
878
|
end
|
879
879
|
end
|
@@ -901,7 +901,7 @@ module Discorb
|
|
901
901
|
#
|
902
902
|
def create_template(name, description = nil, reason: nil)
|
903
903
|
Async do
|
904
|
-
_resp, data = @client.
|
904
|
+
_resp, data = @client.http.post(
|
905
905
|
"/guilds/#{@id}/templates", { name: name, description: description }, audit_log_reason: reason,
|
906
906
|
).wait
|
907
907
|
GuildTemplate.new(@client, data)
|
@@ -982,7 +982,7 @@ module Discorb
|
|
982
982
|
payload = {}
|
983
983
|
payload[:enabled] = enabled unless enabled.nil?
|
984
984
|
payload[:channel_id] = channel.id if channel_id
|
985
|
-
@client.
|
985
|
+
@client.http.patch("/guilds/#{@guild_id}/widget", payload, audit_log_reason: reason).wait
|
986
986
|
end
|
987
987
|
end
|
988
988
|
|
@@ -1059,7 +1059,7 @@ module Discorb
|
|
1059
1059
|
@members = Discorb::Dictionary.new
|
1060
1060
|
data[:members].each do |m|
|
1061
1061
|
Member.new(@client, @id, m[:user], m)
|
1062
|
-
end
|
1062
|
+
end if data[:members]
|
1063
1063
|
@splash = data[:splash] && Asset.new(self, data[:splash], path: "splashes/#{@id}")
|
1064
1064
|
@discovery_splash = data[:discovery_splash] && Asset.new(self, data[:discovery_splash], path: "discovery-splashes/#{@id}")
|
1065
1065
|
@owner_id = data[:owner_id]
|
@@ -1236,7 +1236,7 @@ module Discorb
|
|
1236
1236
|
payload[:enabled] = enabled unless enabled == :unset
|
1237
1237
|
payload[:welcome_channels] = channels.map(&:to_hash) unless channels == :unset
|
1238
1238
|
payload[:description] = description unless description == :unset
|
1239
|
-
@client.
|
1239
|
+
@client.http.patch("/guilds/#{@guild.id}/welcome-screen", payload, audit_log_reason: reason).wait
|
1240
1240
|
end
|
1241
1241
|
end
|
1242
1242
|
end
|
@@ -57,7 +57,7 @@ module Discorb
|
|
57
57
|
payload = {}
|
58
58
|
payload[:name] = name if name
|
59
59
|
payload[:description] = description if description != :unset
|
60
|
-
@client.
|
60
|
+
@client.http.patch("/guilds/#{@source_guild_id}/templates/#{@code}", payload).wait
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
@@ -70,7 +70,7 @@ module Discorb
|
|
70
70
|
#
|
71
71
|
def update
|
72
72
|
Async do
|
73
|
-
_resp, data = @client.
|
73
|
+
_resp, data = @client.http.put("/guilds/#{@source_guild_id}/templates/#{@code}").wait
|
74
74
|
_set_data(data)
|
75
75
|
end
|
76
76
|
end
|
@@ -82,7 +82,7 @@ module Discorb
|
|
82
82
|
#
|
83
83
|
def delete!
|
84
84
|
Async do
|
85
|
-
@client.
|
85
|
+
@client.http.delete("/guilds/#{@source_guild_id}/templates/#{@code}").wait
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
data/lib/discorb/integration.rb
CHANGED
data/lib/discorb/interaction.rb
CHANGED
@@ -99,7 +99,7 @@ module Discorb
|
|
99
99
|
#
|
100
100
|
def defer_source(hide: false)
|
101
101
|
Async do
|
102
|
-
@client.
|
102
|
+
@client.http.post("/interactions/#{@id}/#{@token}/callback", {
|
103
103
|
type: 5,
|
104
104
|
data: {
|
105
105
|
flags: (hide ? 1 << 6 : 0),
|
@@ -153,11 +153,11 @@ module Discorb
|
|
153
153
|
end
|
154
154
|
payload[:flags] = (hide ? 1 << 6 : 0)
|
155
155
|
if @responded
|
156
|
-
@client.
|
156
|
+
@client.http.post("/webhooks/#{@id}/#{@token}", { type: 4, data: payload }).wait
|
157
157
|
elsif @defered
|
158
|
-
@client.
|
158
|
+
@client.http.post("/interactions/#{@id}/#{@token}/@original/edit", { type: 4, data: payload }).wait
|
159
159
|
else
|
160
|
-
@client.
|
160
|
+
@client.http.post("/interactions/#{@id}/#{@token}/callback", { type: 4, data: payload }).wait
|
161
161
|
end
|
162
162
|
@responded = true
|
163
163
|
end
|
@@ -174,7 +174,7 @@ module Discorb
|
|
174
174
|
#
|
175
175
|
def defer_update(hide: false)
|
176
176
|
Async do
|
177
|
-
@client.
|
177
|
+
@client.http.post("/interactions/#{@id}/#{@token}/callback", {
|
178
178
|
type: 7,
|
179
179
|
data: {
|
180
180
|
flags: (hide ? 1 << 6 : 0),
|
@@ -226,7 +226,7 @@ module Discorb
|
|
226
226
|
payload[:components] = tmp_components.filter { |c| c.length.positive? }.map { |c| { type: 1, components: c.map(&:to_hash) } }
|
227
227
|
end
|
228
228
|
payload[:flags] = (hide ? 1 << 6 : 0)
|
229
|
-
@client.
|
229
|
+
@client.http.post("/interactions/#{@id}/#{@token}/callback", { type: 6, data: payload }).wait
|
230
230
|
end
|
231
231
|
end
|
232
232
|
|
data/lib/discorb/invite.rb
CHANGED
data/lib/discorb/member.rb
CHANGED
@@ -140,7 +140,7 @@ module Discorb
|
|
140
140
|
#
|
141
141
|
def add_role(role, reason: nil)
|
142
142
|
Async do
|
143
|
-
@client.
|
143
|
+
@client.http.put("/guilds/#{@guild_id}/members/#{@id}/roles/#{role.is_a?(Role) ? role.id : role}", nil, audit_log_reason: reason).wait
|
144
144
|
end
|
145
145
|
end
|
146
146
|
|
@@ -154,7 +154,7 @@ module Discorb
|
|
154
154
|
#
|
155
155
|
def remove_role(role, reason: nil)
|
156
156
|
Async do
|
157
|
-
@client.
|
157
|
+
@client.http.delete("/guilds/#{@guild_id}/members/#{@id}/roles/#{role.is_a?(Role) ? role.id : role}", audit_log_reason: reason).wait
|
158
158
|
end
|
159
159
|
end
|
160
160
|
|
@@ -179,7 +179,7 @@ module Discorb
|
|
179
179
|
payload[:mute] = mute if mute != :unset
|
180
180
|
payload[:deaf] = deaf if deaf != :unset
|
181
181
|
payload[:channel_id] = channel&.id if channel != :unset
|
182
|
-
@client.
|
182
|
+
@client.http.patch("/guilds/#{@guild_id}/members/#{@id}", payload, audit_log_reason: reason).wait
|
183
183
|
end
|
184
184
|
end
|
185
185
|
|
data/lib/discorb/message.rb
CHANGED
@@ -264,7 +264,7 @@ module Discorb
|
|
264
264
|
#
|
265
265
|
def add_reaction(emoji)
|
266
266
|
Async do |_task|
|
267
|
-
@client.
|
267
|
+
@client.http.put("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}/@me", nil).wait
|
268
268
|
end
|
269
269
|
end
|
270
270
|
|
@@ -279,7 +279,7 @@ module Discorb
|
|
279
279
|
#
|
280
280
|
def remove_reaction(emoji)
|
281
281
|
Async do |_task|
|
282
|
-
@client.
|
282
|
+
@client.http.delete("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}/@me").wait
|
283
283
|
end
|
284
284
|
end
|
285
285
|
|
@@ -295,7 +295,7 @@ module Discorb
|
|
295
295
|
#
|
296
296
|
def remove_reaction_of(emoji, member)
|
297
297
|
Async do |_task|
|
298
|
-
@client.
|
298
|
+
@client.http.delete("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}/#{member.is_a?(Member) ? member.id : member}").wait
|
299
299
|
end
|
300
300
|
end
|
301
301
|
|
@@ -318,7 +318,7 @@ module Discorb
|
|
318
318
|
after = 0
|
319
319
|
users = []
|
320
320
|
loop do
|
321
|
-
_resp, data = @client.
|
321
|
+
_resp, data = @client.http.get("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}?limit=100&after=#{after}").wait
|
322
322
|
break if data.empty?
|
323
323
|
|
324
324
|
users += data.map { |r| guild&.members&.[](r[:id]) || @client.users[r[:id]] || User.new(@client, r) }
|
@@ -329,7 +329,7 @@ module Discorb
|
|
329
329
|
end
|
330
330
|
next users
|
331
331
|
else
|
332
|
-
_resp, data = @client.
|
332
|
+
_resp, data = @client.http.get("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}?limit=#{limit}&after=#{after}").wait
|
333
333
|
next data.map { |r| guild&.members&.[](r[:id]) || @client.users[r[:id]] || User.new(@client, r) }
|
334
334
|
end
|
335
335
|
end
|
@@ -490,9 +490,9 @@ module Discorb
|
|
490
490
|
@guild_id = nil
|
491
491
|
end
|
492
492
|
|
493
|
-
if data[:
|
493
|
+
if data[:member].nil? && data[:webhook_id]
|
494
494
|
@webhook_id = Snowflake.new(data[:webhook_id])
|
495
|
-
|
495
|
+
@author = Webhook::Message::Author.new(data[:author])
|
496
496
|
elsif data[:guild_id].nil? || data[:guild_id].empty?
|
497
497
|
@author = @client.users[data[:author][:id]] || User.new(@client, data[:author])
|
498
498
|
else
|
data/lib/discorb/modules.rb
CHANGED
@@ -57,11 +57,11 @@ module Discorb
|
|
57
57
|
end
|
58
58
|
files = [file] if file
|
59
59
|
if files
|
60
|
-
headers, payload =
|
60
|
+
headers, payload = HTTP.multipart(payload, files)
|
61
61
|
else
|
62
62
|
headers = {}
|
63
63
|
end
|
64
|
-
_resp, data = @client.
|
64
|
+
_resp, data = @client.http.post("#{base_url.wait}/messages", payload, headers: headers).wait
|
65
65
|
Message.new(@client, data.merge({ guild_id: @guild_id.to_s }))
|
66
66
|
end
|
67
67
|
end
|
@@ -76,7 +76,7 @@ module Discorb
|
|
76
76
|
#
|
77
77
|
def fetch_message(id)
|
78
78
|
Async do
|
79
|
-
_resp, data = @client.
|
79
|
+
_resp, data = @client.http.get("#{base_url.wait}/messages/#{id}").wait
|
80
80
|
Message.new(@client, data.merge({ guild_id: @guild_id.to_s }))
|
81
81
|
end
|
82
82
|
end
|
@@ -99,7 +99,7 @@ module Discorb
|
|
99
99
|
after: Discorb::Utils.try(around, :id),
|
100
100
|
around: Discorb::Utils.try(before, :id),
|
101
101
|
}.filter { |_k, v| !v.nil? }.to_h
|
102
|
-
_resp, messages = @client.
|
102
|
+
_resp, messages = @client.http.get("#{base_url.wait}/messages?#{URI.encode_www_form(params)}").wait
|
103
103
|
messages.map { |m| Message.new(@client, m.merge({ guild_id: @guild_id.to_s })) }
|
104
104
|
end
|
105
105
|
end
|
@@ -122,7 +122,7 @@ module Discorb
|
|
122
122
|
if block_given?
|
123
123
|
begin
|
124
124
|
post_task = task.async do
|
125
|
-
@client.
|
125
|
+
@client.http.post("/channels/#{@id}/typing", {})
|
126
126
|
sleep(5)
|
127
127
|
end
|
128
128
|
yield
|
@@ -130,7 +130,7 @@ module Discorb
|
|
130
130
|
post_task.stop
|
131
131
|
end
|
132
132
|
else
|
133
|
-
@client.
|
133
|
+
@client.http.post("/channels/#{@id}/typing", {})
|
134
134
|
end
|
135
135
|
end
|
136
136
|
end
|
data/lib/discorb/role.rb
CHANGED
@@ -88,7 +88,7 @@ module Discorb
|
|
88
88
|
#
|
89
89
|
def move(position, reason: nil)
|
90
90
|
Async do
|
91
|
-
@client.
|
91
|
+
@client.http.patch("/guilds/#{@guild_id}/roles", { id: @id, position: position }, reason: reason).wait
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
@@ -113,7 +113,7 @@ module Discorb
|
|
113
113
|
payload[:color] = color.to_i if color != :unset
|
114
114
|
payload[:hoist] = hoist if hoist != :unset
|
115
115
|
payload[:mentionable] = mentionable if mentionable != :unset
|
116
|
-
@client.
|
116
|
+
@client.http.patch("/guilds/#{@guild_id}/roles/#{@id}", payload, reason: reason).wait
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
@@ -126,7 +126,7 @@ module Discorb
|
|
126
126
|
#
|
127
127
|
def delete!(reason: nil)
|
128
128
|
Async do
|
129
|
-
@client.
|
129
|
+
@client.http.delete("/guilds/#{@guild_id}/roles/#{@id}", reason: reason).wait
|
130
130
|
end
|
131
131
|
end
|
132
132
|
|
data/lib/discorb/sticker.rb
CHANGED
@@ -73,7 +73,7 @@ module Discorb
|
|
73
73
|
payload[:name] = name unless name == :unset
|
74
74
|
payload[:description] = description unless description == :unset
|
75
75
|
payload[:tags] = tag.name unless tag == :unset
|
76
|
-
@client.
|
76
|
+
@client.http.patch("/guilds/#{@guild_id}/stickers/#{@id}", payload, audit_log_reason: reason).wait
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
@@ -88,7 +88,7 @@ module Discorb
|
|
88
88
|
#
|
89
89
|
def delete!(reason: nil)
|
90
90
|
Async do
|
91
|
-
@client.
|
91
|
+
@client.http.delete("/guilds/#{@guild_id}/stickers/#{@id}", audit_log_reason: reason).wait
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
data/lib/discorb/user.rb
CHANGED
@@ -74,7 +74,7 @@ module Discorb
|
|
74
74
|
Async do
|
75
75
|
next @dm_channel_id if @dm_channel_id
|
76
76
|
|
77
|
-
dm_channel = @client.
|
77
|
+
dm_channel = @client.http.post("/users/#{@id}/channels", { recipient_id: @client.user.id }).wait
|
78
78
|
@dm_channel_id = dm_channel[:id]
|
79
79
|
"/channels/#{@dm_channel_id}"
|
80
80
|
end
|
@@ -155,7 +155,7 @@ module Discorb
|
|
155
155
|
else
|
156
156
|
payload[:avatar] = avatar.to_s
|
157
157
|
end
|
158
|
-
@client.
|
158
|
+
@client.http.patch("/users/@me", payload).wait
|
159
159
|
self
|
160
160
|
end
|
161
161
|
end
|
data/lib/discorb/voice_state.rb
CHANGED
@@ -179,7 +179,7 @@ module Discorb
|
|
179
179
|
payload = {}
|
180
180
|
payload[:topic] = topic if topic != :unset
|
181
181
|
payload[:privacy_level] = self.class.privacy_level.key(privacy_level) if privacy_level != :unset
|
182
|
-
@client.
|
182
|
+
@client.http.edit("/stage-instances/#{@channel_id}", payload, audit_log_reason: reason).wait
|
183
183
|
self
|
184
184
|
end
|
185
185
|
end
|
@@ -193,7 +193,7 @@ module Discorb
|
|
193
193
|
#
|
194
194
|
def delete!(reason: nil)
|
195
195
|
Async do
|
196
|
-
@client.
|
196
|
+
@client.http.delete("/stage-instances/#{@channel_id}", reason: reason).wait
|
197
197
|
self
|
198
198
|
end
|
199
199
|
end
|
data/lib/discorb/webhook.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "async/http/internet"
|
4
|
-
|
5
3
|
module Discorb
|
6
4
|
#
|
7
5
|
# Represents a webhook.
|
@@ -36,7 +34,7 @@ module Discorb
|
|
36
34
|
@token = ""
|
37
35
|
@application_id = data[:application_id]
|
38
36
|
@client = client
|
39
|
-
@
|
37
|
+
@http = Discorb::HTTP.new(client)
|
40
38
|
end
|
41
39
|
|
42
40
|
def inspect
|
@@ -79,13 +77,13 @@ module Discorb
|
|
79
77
|
payload[:avatar_url] = avatar_url if avatar_url != :unset
|
80
78
|
files = [file] if file
|
81
79
|
if files
|
82
|
-
headers, payload =
|
80
|
+
headers, payload = HTTP.multipart(payload, files)
|
83
81
|
else
|
84
82
|
headers = {
|
85
83
|
"Content-Type" => "application/json",
|
86
84
|
}
|
87
85
|
end
|
88
|
-
_resp, data = @
|
86
|
+
_resp, data = @http.post("#{url}?wait=#{wait}", payload, headers: headers).wait
|
89
87
|
|
90
88
|
data && Webhook::Message.new(self, data)
|
91
89
|
end
|
@@ -109,7 +107,7 @@ module Discorb
|
|
109
107
|
payload[:name] = name if name != :unset
|
110
108
|
payload[:avatar] = avatar if avatar != :unset
|
111
109
|
payload[:channel_id] = Utils.try(channel, :id) if channel != :unset
|
112
|
-
@
|
110
|
+
@http.patch(url.to_s, payload).wait
|
113
111
|
end
|
114
112
|
end
|
115
113
|
|
@@ -122,7 +120,7 @@ module Discorb
|
|
122
120
|
#
|
123
121
|
def delete!
|
124
122
|
Async do
|
125
|
-
@
|
123
|
+
@http.delete(url).wait
|
126
124
|
self
|
127
125
|
end
|
128
126
|
end
|
@@ -165,9 +163,9 @@ module Discorb
|
|
165
163
|
"Content-Type" => "application/json",
|
166
164
|
}
|
167
165
|
else
|
168
|
-
headers, payload =
|
166
|
+
headers, payload = HTTP.multipart(payload, files)
|
169
167
|
end
|
170
|
-
_resp, data = @
|
168
|
+
_resp, data = @http.patch("#{url}/messages/#{Utils.try(message, :id)}", payload, headers: headers).wait
|
171
169
|
message.send(:_set_data, data)
|
172
170
|
message
|
173
171
|
end
|
@@ -180,7 +178,7 @@ module Discorb
|
|
180
178
|
#
|
181
179
|
def delete_message!(message)
|
182
180
|
Async do
|
183
|
-
@
|
181
|
+
@http.delete("#{url}/messages/#{Utils.try(message, :id)}").wait
|
184
182
|
message
|
185
183
|
end
|
186
184
|
end
|
@@ -200,7 +198,7 @@ module Discorb
|
|
200
198
|
def initialize(url)
|
201
199
|
@url = url
|
202
200
|
@token = ""
|
203
|
-
@
|
201
|
+
@http = Discorb::HTTP.new(self)
|
204
202
|
end
|
205
203
|
end
|
206
204
|
|
@@ -362,6 +360,7 @@ module Discorb
|
|
362
360
|
# @return [Boolean] Whether the author is a bot.
|
363
361
|
# @note This will be always `true`.
|
364
362
|
attr_reader :bot
|
363
|
+
alias bot? bot
|
365
364
|
# @return [Discorb::Snowflake] The ID of the author.
|
366
365
|
attr_reader :id
|
367
366
|
# @return [String] The name of the author.
|
data/lib/discorb.rb
CHANGED
@@ -39,7 +39,7 @@ module Discorb
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
require_order = %w[common flag dictionary error
|
42
|
+
require_order = %w[common flag dictionary error http intents emoji_table modules] +
|
43
43
|
%w[user member guild emoji channel embed message] +
|
44
44
|
%w[application audit_logs color components event extension] +
|
45
45
|
%w[file guild_template image integration interaction invite log permission] +
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: discorb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sevenc-nanashi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-08-
|
11
|
+
date: 2021-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async
|
@@ -118,11 +118,11 @@ files:
|
|
118
118
|
- lib/discorb/gateway_requests.rb
|
119
119
|
- lib/discorb/guild.rb
|
120
120
|
- lib/discorb/guild_template.rb
|
121
|
+
- lib/discorb/http.rb
|
121
122
|
- lib/discorb/image.rb
|
122
123
|
- lib/discorb/integration.rb
|
123
124
|
- lib/discorb/intents.rb
|
124
125
|
- lib/discorb/interaction.rb
|
125
|
-
- lib/discorb/internet.rb
|
126
126
|
- lib/discorb/invite.rb
|
127
127
|
- lib/discorb/log.rb
|
128
128
|
- lib/discorb/member.rb
|
@@ -137,14 +137,14 @@ files:
|
|
137
137
|
- lib/discorb/utils.rb
|
138
138
|
- lib/discorb/voice_state.rb
|
139
139
|
- lib/discorb/webhook.rb
|
140
|
-
homepage: https://github.com/
|
140
|
+
homepage: https://github.com/discorb-lib/discorb
|
141
141
|
licenses:
|
142
142
|
- MIT
|
143
143
|
metadata:
|
144
144
|
allowed_push_host: https://rubygems.org
|
145
|
-
homepage_uri: https://github.com/
|
146
|
-
source_code_uri: https://github.com/
|
147
|
-
changelog_uri: https://github.com/
|
145
|
+
homepage_uri: https://github.com/discorb-lib/discorb
|
146
|
+
source_code_uri: https://github.com/discorb-lib/discorb
|
147
|
+
changelog_uri: https://github.com/discorb-lib/discorb/blob/main/Changelog.md
|
148
148
|
post_install_message:
|
149
149
|
rdoc_options: []
|
150
150
|
require_paths:
|