discorb 0.0.1 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +14 -2
- data/Gemfile.lock +5 -5
- data/README.md +1 -1
- data/discorb.gemspec +7 -5
- data/lib/discorb/channel.rb +32 -32
- data/lib/discorb/client.rb +8 -8
- data/lib/discorb/common.rb +4 -1
- data/lib/discorb/emoji.rb +2 -2
- data/lib/discorb/gateway.rb +4 -2
- data/lib/discorb/guild.rb +37 -37
- 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 +65 -18
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)
|
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
|
|
@@ -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
|
|