discorb 0.16.0 → 0.17.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitattributes +1 -0
- data/.github/workflows/build_main.yml +2 -2
- data/.github/workflows/build_version.yml +1 -1
- data/.github/workflows/codeql-analysis.yml +1 -1
- data/.github/workflows/lint-push.yml +3 -5
- data/.github/workflows/lint.yml +1 -1
- data/.github/workflows/spec.yml +30 -0
- data/.lefthook/commit-msg/validator.rb +5 -0
- data/.rspec +2 -0
- data/.rspec_parallel +2 -0
- data/.rubocop.yml +43 -6
- data/Changelog.md +14 -1
- data/Gemfile +14 -8
- data/Rakefile +41 -26
- data/bin/console +3 -3
- data/docs/Examples.md +1 -1
- data/docs/application_command.md +138 -46
- data/docs/cli/irb.md +2 -2
- data/docs/cli/new.md +14 -9
- data/docs/cli/run.md +7 -11
- data/docs/cli.md +17 -10
- data/docs/events.md +209 -211
- data/docs/extension.md +1 -2
- data/docs/faq.md +0 -1
- data/docs/tutorial.md +12 -12
- data/docs/voice_events.md +106 -106
- data/examples/commands/message.rb +63 -0
- data/examples/commands/permission.rb +18 -0
- data/examples/commands/slash.rb +44 -0
- data/examples/commands/user.rb +51 -0
- data/examples/components/authorization_button.rb +2 -2
- data/examples/components/select_menu.rb +2 -2
- data/examples/extension/main.rb +1 -1
- data/examples/extension/message_expander.rb +5 -2
- data/examples/simple/eval.rb +2 -2
- data/examples/simple/ping_pong.rb +1 -1
- data/examples/simple/rolepanel.rb +1 -1
- data/examples/simple/shard.rb +1 -1
- data/examples/simple/wait_for_message.rb +1 -1
- data/exe/discorb +31 -16
- data/lefthook.yml +45 -0
- data/lib/discorb/allowed_mentions.rb +1 -0
- data/lib/discorb/app_command/command.rb +127 -65
- data/lib/discorb/app_command/common.rb +25 -0
- data/lib/discorb/app_command/handler.rb +115 -33
- data/lib/discorb/app_command.rb +2 -1
- data/lib/discorb/application.rb +1 -0
- data/lib/discorb/asset.rb +1 -2
- data/lib/discorb/attachment.rb +1 -1
- data/lib/discorb/audit_logs.rb +11 -8
- data/lib/discorb/channel/base.rb +108 -0
- data/lib/discorb/channel/category.rb +32 -0
- data/lib/discorb/channel/container.rb +44 -0
- data/lib/discorb/channel/dm.rb +28 -0
- data/lib/discorb/channel/guild.rb +245 -0
- data/lib/discorb/channel/stage.rb +140 -0
- data/lib/discorb/channel/text.rb +345 -0
- data/lib/discorb/channel/thread.rb +321 -0
- data/lib/discorb/channel/voice.rb +79 -0
- data/lib/discorb/channel.rb +2 -1165
- data/lib/discorb/client.rb +38 -26
- data/lib/discorb/common.rb +2 -1
- data/lib/discorb/components/button.rb +2 -1
- data/lib/discorb/components/select_menu.rb +4 -2
- data/lib/discorb/components/text_input.rb +12 -2
- data/lib/discorb/components.rb +1 -1
- data/lib/discorb/embed.rb +22 -7
- data/lib/discorb/emoji.rb +30 -3
- data/lib/discorb/emoji_table.rb +4969 -3
- data/lib/discorb/event.rb +29 -4
- data/lib/discorb/exe/about.rb +1 -0
- data/lib/discorb/exe/irb.rb +2 -4
- data/lib/discorb/exe/new.rb +90 -23
- data/lib/discorb/exe/run.rb +8 -22
- data/lib/discorb/exe/setup.rb +25 -12
- data/lib/discorb/exe/show.rb +4 -3
- data/lib/discorb/extend.rb +1 -0
- data/lib/discorb/extension.rb +6 -3
- data/lib/discorb/flag.rb +11 -0
- data/lib/discorb/gateway.rb +67 -19
- data/lib/discorb/guild.rb +188 -56
- data/lib/discorb/guild_template.rb +10 -4
- data/lib/discorb/http.rb +16 -9
- data/lib/discorb/integration.rb +4 -1
- data/lib/discorb/intents.rb +1 -1
- data/lib/discorb/interaction/autocomplete.rb +28 -16
- data/lib/discorb/interaction/command.rb +36 -12
- data/lib/discorb/interaction/components.rb +5 -2
- data/lib/discorb/interaction/modal.rb +0 -1
- data/lib/discorb/interaction/response.rb +61 -22
- data/lib/discorb/interaction/root.rb +13 -13
- data/lib/discorb/interaction.rb +1 -0
- data/lib/discorb/invite.rb +5 -2
- data/lib/discorb/member.rb +25 -5
- data/lib/discorb/message.rb +47 -14
- data/lib/discorb/message_meta.rb +1 -0
- data/lib/discorb/modules.rb +56 -14
- data/lib/discorb/presence.rb +2 -2
- data/lib/discorb/rate_limit.rb +7 -2
- data/lib/discorb/reaction.rb +4 -4
- data/lib/discorb/role.rb +19 -4
- data/lib/discorb/shard.rb +1 -1
- data/lib/discorb/sticker.rb +8 -7
- data/lib/discorb/user.rb +2 -1
- data/lib/discorb/utils/colored_puts.rb +1 -0
- data/lib/discorb/voice_state.rb +10 -6
- data/lib/discorb/webhook.rb +36 -24
- data/lib/discorb.rb +5 -3
- data/po/yard.pot +9 -9
- data/sig/discorb.rbs +7232 -7235
- metadata +21 -5
- data/examples/commands/bookmarker.rb +0 -42
- data/examples/commands/hello.rb +0 -10
- data/examples/commands/inspect.rb +0 -25
data/lib/discorb/message.rb
CHANGED
@@ -85,7 +85,9 @@ module Discorb
|
|
85
85
|
# @return [Boolean] Whether the message is pinned.
|
86
86
|
attr_reader :pinned
|
87
87
|
alias pinned? pinned
|
88
|
-
@
|
88
|
+
# @private
|
89
|
+
# @return [{Integer => Symbol}] The mapping of message type.
|
90
|
+
MESSAGE_TYPE = {
|
89
91
|
0 => :default,
|
90
92
|
1 => :recipient_add,
|
91
93
|
2 => :recipient_remove,
|
@@ -257,8 +259,15 @@ module Discorb
|
|
257
259
|
#
|
258
260
|
# @return [Async::Task<void>] The task.
|
259
261
|
#
|
260
|
-
def edit(
|
261
|
-
|
262
|
+
def edit(
|
263
|
+
content = Discorb::Unset,
|
264
|
+
embed: Discorb::Unset,
|
265
|
+
embeds: Discorb::Unset,
|
266
|
+
allowed_mentions: Discorb::Unset,
|
267
|
+
attachments: Discorb::Unset,
|
268
|
+
components: Discorb::Unset,
|
269
|
+
supress: Discorb::Unset
|
270
|
+
)
|
262
271
|
Async do
|
263
272
|
channel.edit_message(@id, content, embed: embed, embeds: embeds, allowed_mentions: allowed_mentions,
|
264
273
|
attachments: attachments, components: components, supress: supress).wait
|
@@ -331,7 +340,10 @@ module Discorb
|
|
331
340
|
#
|
332
341
|
def add_reaction(emoji)
|
333
342
|
Async do
|
334
|
-
@client.http.request(
|
343
|
+
@client.http.request(
|
344
|
+
Route.new("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}/@me",
|
345
|
+
"//channels/:channel_id/messages/:message_id/reactions/:emoji/@me", :put), nil
|
346
|
+
).wait
|
335
347
|
end
|
336
348
|
end
|
337
349
|
|
@@ -347,7 +359,11 @@ module Discorb
|
|
347
359
|
#
|
348
360
|
def remove_reaction(emoji)
|
349
361
|
Async do
|
350
|
-
@client.http.request(
|
362
|
+
@client.http.request(
|
363
|
+
Route.new("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}/@me",
|
364
|
+
"//channels/:channel_id/messages/:message_id/reactions/:emoji/@me",
|
365
|
+
:delete)
|
366
|
+
).wait
|
351
367
|
end
|
352
368
|
end
|
353
369
|
|
@@ -364,7 +380,17 @@ module Discorb
|
|
364
380
|
#
|
365
381
|
def remove_reaction_of(emoji, member)
|
366
382
|
Async do
|
367
|
-
@client.http.request(
|
383
|
+
@client.http.request(
|
384
|
+
Route.new(
|
385
|
+
"/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}/#{if member.is_a?(Member)
|
386
|
+
member.id
|
387
|
+
else
|
388
|
+
member
|
389
|
+
end}",
|
390
|
+
"//channels/:channel_id/messages/:message_id/reactions/:emoji/:user_id",
|
391
|
+
:delete
|
392
|
+
)
|
393
|
+
).wait
|
368
394
|
end
|
369
395
|
end
|
370
396
|
|
@@ -386,7 +412,13 @@ module Discorb
|
|
386
412
|
after = 0
|
387
413
|
users = []
|
388
414
|
loop do
|
389
|
-
_resp, data = @client.http.request(
|
415
|
+
_resp, data = @client.http.request(
|
416
|
+
Route.new(
|
417
|
+
"/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}?limit=100&after=#{after}",
|
418
|
+
"//channels/:channel_id/messages/:message_id/reactions/:emoji",
|
419
|
+
:get
|
420
|
+
)
|
421
|
+
).wait
|
390
422
|
break if data.empty?
|
391
423
|
|
392
424
|
users += data.map { |r| guild&.members&.[](r[:id]) || @client.users[r[:id]] || User.new(@client, r) }
|
@@ -397,7 +429,13 @@ module Discorb
|
|
397
429
|
end
|
398
430
|
next users
|
399
431
|
else
|
400
|
-
_resp, data = @client.http.request(
|
432
|
+
_resp, data = @client.http.request(
|
433
|
+
Route.new(
|
434
|
+
"/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}?limit=#{limit}&after=#{after}",
|
435
|
+
"//channels/:channel_id/messages/:message_id/reactions/:emoji",
|
436
|
+
:get
|
437
|
+
)
|
438
|
+
).wait
|
401
439
|
next data.map { |r| guild&.members&.[](r[:id]) || @client.users[r[:id]] || User.new(@client, r) }
|
402
440
|
end
|
403
441
|
end
|
@@ -487,7 +525,7 @@ module Discorb
|
|
487
525
|
@embeds = data[:embeds] ? data[:embeds].map { |e| Embed.from_hash(e) } : []
|
488
526
|
@reactions = data[:reactions] ? data[:reactions].map { |r| Reaction.new(self, r) } : []
|
489
527
|
@pinned = data[:pinned]
|
490
|
-
@type =
|
528
|
+
@type = MESSAGE_TYPE[data[:type]]
|
491
529
|
@activity = data[:activity] && Activity.new(data[:activity])
|
492
530
|
@application_id = data[:application_id]
|
493
531
|
@message_reference = data[:message_reference] && Reference.from_hash(data[:message_reference])
|
@@ -500,10 +538,5 @@ module Discorb
|
|
500
538
|
@data.update(data)
|
501
539
|
@deleted = false
|
502
540
|
end
|
503
|
-
|
504
|
-
class << self
|
505
|
-
# @private
|
506
|
-
attr_reader :message_type
|
507
|
-
end
|
508
541
|
end
|
509
542
|
end
|
data/lib/discorb/message_meta.rb
CHANGED
data/lib/discorb/modules.rb
CHANGED
@@ -21,8 +21,17 @@ module Discorb
|
|
21
21
|
#
|
22
22
|
# @return [Async::Task<Discorb::Message>] The message sent.
|
23
23
|
#
|
24
|
-
def post(
|
25
|
-
|
24
|
+
def post(
|
25
|
+
content = nil,
|
26
|
+
tts: false,
|
27
|
+
embed: nil,
|
28
|
+
embeds: nil,
|
29
|
+
allowed_mentions: nil,
|
30
|
+
reference: nil,
|
31
|
+
components: nil,
|
32
|
+
attachment: nil,
|
33
|
+
attachments: nil
|
34
|
+
)
|
26
35
|
Async do
|
27
36
|
payload = {}
|
28
37
|
payload[:content] = content if content
|
@@ -47,7 +56,10 @@ module Discorb
|
|
47
56
|
}
|
48
57
|
end
|
49
58
|
|
50
|
-
_resp, data = @client.http.multipart_request(
|
59
|
+
_resp, data = @client.http.multipart_request(
|
60
|
+
Route.new("/channels/#{channel_id.wait}/messages", "//channels/:channel_id/messages",
|
61
|
+
:post), payload, attachments
|
62
|
+
).wait
|
51
63
|
Message.new(@client, data.merge({ guild_id: @guild_id.to_s }))
|
52
64
|
end
|
53
65
|
end
|
@@ -70,8 +82,16 @@ module Discorb
|
|
70
82
|
#
|
71
83
|
# @return [Async::Task<void>] The task.
|
72
84
|
#
|
73
|
-
def edit_message(
|
74
|
-
|
85
|
+
def edit_message(
|
86
|
+
message_id,
|
87
|
+
content = Discorb::Unset,
|
88
|
+
embed: Discorb::Unset,
|
89
|
+
embeds: Discorb::Unset,
|
90
|
+
allowed_mentions: Discorb::Unset,
|
91
|
+
attachments: Discorb::Unset,
|
92
|
+
components: Discorb::Unset,
|
93
|
+
supress: Discorb::Unset
|
94
|
+
)
|
75
95
|
Async do
|
76
96
|
payload = {}
|
77
97
|
payload[:content] = content if content != Discorb::Unset
|
@@ -81,8 +101,11 @@ module Discorb
|
|
81
101
|
embeds
|
82
102
|
end
|
83
103
|
payload[:embeds] = tmp_embed.map(&:to_hash) if tmp_embed
|
84
|
-
payload[:allowed_mentions] =
|
85
|
-
|
104
|
+
payload[:allowed_mentions] = if allowed_mentions == Discorb::Unset
|
105
|
+
@client.allowed_mentions.to_hash
|
106
|
+
else
|
107
|
+
allowed_mentions.to_hash(@client.allowed_mentions)
|
108
|
+
end
|
86
109
|
payload[:components] = Component.to_payload(components) if components != Discorb::Unset
|
87
110
|
payload[:flags] = (supress ? 1 << 2 : 0) if supress != Discorb::Unset
|
88
111
|
if attachments != Discorb::Unset
|
@@ -95,7 +118,8 @@ module Discorb
|
|
95
118
|
end
|
96
119
|
end
|
97
120
|
@client.http.multipart_request(
|
98
|
-
Route.new("/channels/#{channel_id.wait}/messages/#{message_id}",
|
121
|
+
Route.new("/channels/#{channel_id.wait}/messages/#{message_id}",
|
122
|
+
"//channels/:channel_id/messages/:message_id", :patch),
|
99
123
|
payload,
|
100
124
|
attachments == Discorb::Unset ? [] : attachments
|
101
125
|
).wait
|
@@ -113,7 +137,12 @@ module Discorb
|
|
113
137
|
#
|
114
138
|
def delete_message!(message_id, reason: nil)
|
115
139
|
Async do
|
116
|
-
@client.http.request(
|
140
|
+
@client.http.request(
|
141
|
+
Route.new(
|
142
|
+
"/channels/#{channel_id.wait}/messages/#{message_id}", "//channels/:channel_id/messages/:message_id",
|
143
|
+
:delete
|
144
|
+
), {}, audit_log_reason: reason,
|
145
|
+
).wait
|
117
146
|
end
|
118
147
|
end
|
119
148
|
|
@@ -130,7 +159,8 @@ module Discorb
|
|
130
159
|
#
|
131
160
|
def fetch_message(id)
|
132
161
|
Async do
|
133
|
-
_resp, data = @client.http.request(Route.new("/channels/#{channel_id.wait}/messages/#{id}",
|
162
|
+
_resp, data = @client.http.request(Route.new("/channels/#{channel_id.wait}/messages/#{id}",
|
163
|
+
"//channels/:channel_id/messages/:message_id", :get)).wait
|
134
164
|
Message.new(@client, data.merge({ guild_id: @guild_id.to_s }))
|
135
165
|
end
|
136
166
|
end
|
@@ -154,7 +184,12 @@ module Discorb
|
|
154
184
|
after: Discorb::Utils.try(around, :id),
|
155
185
|
around: Discorb::Utils.try(before, :id),
|
156
186
|
}.filter { |_k, v| !v.nil? }.to_h
|
157
|
-
_resp, messages = @client.http.request(
|
187
|
+
_resp, messages = @client.http.request(
|
188
|
+
Route.new(
|
189
|
+
"/channels/#{channel_id.wait}/messages?#{URI.encode_www_form(params)}", "//channels/:channel_id/messages",
|
190
|
+
:get
|
191
|
+
)
|
192
|
+
).wait
|
158
193
|
messages.map { |m| Message.new(@client, m.merge({ guild_id: @guild_id.to_s })) }
|
159
194
|
end
|
160
195
|
end
|
@@ -167,7 +202,8 @@ module Discorb
|
|
167
202
|
#
|
168
203
|
def fetch_pins
|
169
204
|
Async do
|
170
|
-
_resp, data = @client.http.request(Route.new("/channels/#{channel_id.wait}/pins",
|
205
|
+
_resp, data = @client.http.request(Route.new("/channels/#{channel_id.wait}/pins",
|
206
|
+
"//channels/:channel_id/pins", :get)).wait
|
171
207
|
data.map { |pin| Message.new(@client, pin) }
|
172
208
|
end
|
173
209
|
end
|
@@ -183,7 +219,10 @@ module Discorb
|
|
183
219
|
#
|
184
220
|
def pin_message(message, reason: nil)
|
185
221
|
Async do
|
186
|
-
@client.http.request(
|
222
|
+
@client.http.request(
|
223
|
+
Route.new("/channels/#{channel_id.wait}/pins/#{message.id}", "//channels/:channel_id/pins/:message_id",
|
224
|
+
:put), {}, audit_log_reason: reason,
|
225
|
+
).wait
|
187
226
|
end
|
188
227
|
end
|
189
228
|
|
@@ -198,7 +237,10 @@ module Discorb
|
|
198
237
|
#
|
199
238
|
def unpin_message(message, reason: nil)
|
200
239
|
Async do
|
201
|
-
@client.http.request(
|
240
|
+
@client.http.request(
|
241
|
+
Route.new("/channels/#{channel_id.wait}/pins/#{message.id}", "//channels/:channel_id/pins/:message_id",
|
242
|
+
:delete), {}, audit_log_reason: reason,
|
243
|
+
).wait
|
202
244
|
end
|
203
245
|
end
|
204
246
|
|
data/lib/discorb/presence.rb
CHANGED
@@ -113,8 +113,8 @@ module Discorb
|
|
113
113
|
@details = data[:details]
|
114
114
|
@state = data[:state]
|
115
115
|
@emoji = if data[:emoji]
|
116
|
-
|
117
|
-
|
116
|
+
data[:emoji][:id].nil? ? UnicodeEmoji.new(data[:emoji][:name]) : PartialEmoji.new(data[:emoji])
|
117
|
+
end
|
118
118
|
@party = data[:party] && Party.new(data[:party])
|
119
119
|
@assets = data[:assets] && Asset.new(data[:assets])
|
120
120
|
@instance = data[:instance]
|
data/lib/discorb/rate_limit.rb
CHANGED
@@ -48,7 +48,8 @@ module Discorb
|
|
48
48
|
return if (bucket[:remaining]).positive?
|
49
49
|
|
50
50
|
time = bucket[:reset_at] - Time.now.to_f
|
51
|
-
@client.logger.info("rate limit for #{path.identifier} with #{path.major_param} reached,
|
51
|
+
@client.logger.info("rate limit for #{path.identifier} with #{path.major_param} reached, " \
|
52
|
+
"waiting #{time.round(4)} seconds")
|
52
53
|
sleep(time)
|
53
54
|
end
|
54
55
|
|
@@ -59,8 +60,12 @@ module Discorb
|
|
59
60
|
# @param [Net::HTTPResponse] resp The response.
|
60
61
|
#
|
61
62
|
def save(path, resp)
|
62
|
-
|
63
|
+
if resp["X-Ratelimit-Global"] == "true"
|
64
|
+
@global = Time.now.to_f + JSON.parse(resp.body,
|
65
|
+
symbolize_names: true)[:retry_after]
|
66
|
+
end
|
63
67
|
return unless resp["X-RateLimit-Remaining"]
|
68
|
+
|
64
69
|
@path_ratelimit_hash[path.identifier] = resp["X-Ratelimit-Bucket"]
|
65
70
|
@path_ratelimit_bucket[resp["X-Ratelimit-Bucket"] + path.major_param] = {
|
66
71
|
remaining: resp["X-RateLimit-Remaining"].to_i,
|
data/lib/discorb/reaction.rb
CHANGED
@@ -45,10 +45,10 @@ module Discorb
|
|
45
45
|
@count = data[:count]
|
46
46
|
@me = data[:me]
|
47
47
|
@emoji = if data[:emoji][:id].nil?
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
48
|
+
UnicodeEmoji.new(data[:emoji][:name])
|
49
|
+
else
|
50
|
+
PartialEmoji.new(data[:emoji])
|
51
|
+
end
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
data/lib/discorb/role.rb
CHANGED
@@ -106,7 +106,8 @@ module Discorb
|
|
106
106
|
#
|
107
107
|
def move(position, reason: nil)
|
108
108
|
Async do
|
109
|
-
@client.http.request(Route.new("/guilds/#{@guild.id}/roles", "//guilds/:guild_id/roles", :patch),
|
109
|
+
@client.http.request(Route.new("/guilds/#{@guild.id}/roles", "//guilds/:guild_id/roles", :patch),
|
110
|
+
{ id: @id, position: position }, audit_log_reason: reason).wait
|
110
111
|
end
|
111
112
|
end
|
112
113
|
|
@@ -125,7 +126,15 @@ module Discorb
|
|
125
126
|
#
|
126
127
|
# @return [Async::Task<void>] The task.
|
127
128
|
#
|
128
|
-
def edit(
|
129
|
+
def edit(
|
130
|
+
name: Discorb::Unset,
|
131
|
+
position: Discorb::Unset,
|
132
|
+
color: Discorb::Unset,
|
133
|
+
hoist: Discorb::Unset,
|
134
|
+
mentionable: Discorb::Unset,
|
135
|
+
icon: Discorb::Unset,
|
136
|
+
reason: nil
|
137
|
+
)
|
129
138
|
Async do
|
130
139
|
payload = {}
|
131
140
|
payload[:name] = name if name != Discorb::Unset
|
@@ -140,7 +149,10 @@ module Discorb
|
|
140
149
|
payload[:unicode_emoji] = icon.to_s
|
141
150
|
end
|
142
151
|
end
|
143
|
-
@client.http.request(
|
152
|
+
@client.http.request(
|
153
|
+
Route.new("/guilds/#{@guild.id}/roles/#{@id}", "//guilds/:guild_id/roles/:role_id",
|
154
|
+
:patch), payload, audit_log_reason: reason,
|
155
|
+
).wait
|
144
156
|
end
|
145
157
|
end
|
146
158
|
|
@@ -155,7 +167,10 @@ module Discorb
|
|
155
167
|
#
|
156
168
|
def delete!(reason: nil)
|
157
169
|
Async do
|
158
|
-
@client.http.request(
|
170
|
+
@client.http.request(
|
171
|
+
Route.new("/guilds/#{@guild.id}/roles/#{@id}", "//guilds/:guild_id/roles/:role_id",
|
172
|
+
:delete), {}, audit_log_reason: reason,
|
173
|
+
).wait
|
159
174
|
end
|
160
175
|
end
|
161
176
|
|
data/lib/discorb/shard.rb
CHANGED
@@ -41,7 +41,7 @@ module Discorb
|
|
41
41
|
Thread.current.thread_variable_set("shard", self)
|
42
42
|
if @index.positive?
|
43
43
|
Thread.stop
|
44
|
-
sleep 5
|
44
|
+
sleep 5 # Somehow discord disconnects the shard without a little sleep.
|
45
45
|
end
|
46
46
|
client.send(:main_loop, id)
|
47
47
|
end
|
data/lib/discorb/sticker.rb
CHANGED
@@ -85,7 +85,10 @@ module Discorb
|
|
85
85
|
payload[:name] = name unless name == Discorb::Unset
|
86
86
|
payload[:description] = description unless description == Discorb::Unset
|
87
87
|
payload[:tags] = tag.name unless tag == Discorb::Unset
|
88
|
-
@client.http.request(
|
88
|
+
@client.http.request(
|
89
|
+
Route.new("/guilds/#{@guild_id}/stickers/#{@id}", "//guilds/:guild_id/stickers/:sticker_id",
|
90
|
+
:patch), payload, audit_log_reason: reason
|
91
|
+
).wait
|
89
92
|
end
|
90
93
|
end
|
91
94
|
|
@@ -99,7 +102,10 @@ module Discorb
|
|
99
102
|
#
|
100
103
|
def delete!(reason: nil)
|
101
104
|
Async do
|
102
|
-
@client.http.request(
|
105
|
+
@client.http.request(
|
106
|
+
Route.new("/guilds/#{@guild_id}/stickers/#{@id}", "//guilds/:guild_id/stickers/:sticker_id",
|
107
|
+
:delete), {}, audit_log_reason: reason
|
108
|
+
).wait
|
103
109
|
end
|
104
110
|
end
|
105
111
|
|
@@ -161,10 +167,5 @@ module Discorb
|
|
161
167
|
@user = data[:user] && (@client.users[data[:user][:id]] || User.new(@client, data[:user]))
|
162
168
|
end
|
163
169
|
end
|
164
|
-
|
165
|
-
class << self
|
166
|
-
# @private
|
167
|
-
attr_reader :sticker_type, :sticker_format
|
168
|
-
end
|
169
170
|
end
|
170
171
|
end
|
data/lib/discorb/user.rb
CHANGED
@@ -95,7 +95,8 @@ module Discorb
|
|
95
95
|
Async do
|
96
96
|
next @dm_channel_id if @dm_channel_id
|
97
97
|
|
98
|
-
_resp, dm_channel = @client.http.request(Route.new("/users/@me/channels", "//users/@me/channels", :post),
|
98
|
+
_resp, dm_channel = @client.http.request(Route.new("/users/@me/channels", "//users/@me/channels", :post),
|
99
|
+
{ recipient_id: @id }).wait
|
99
100
|
@dm_channel_id = dm_channel[:id]
|
100
101
|
@dm_channel_id
|
101
102
|
end
|
data/lib/discorb/voice_state.rb
CHANGED
@@ -95,10 +95,10 @@ module Discorb
|
|
95
95
|
@user_id = data[:user_id]
|
96
96
|
unless guild.nil?
|
97
97
|
@member = if data.key?(:member)
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
98
|
+
guild.members[data[:user_id]] || Member.new(@client, @guild_id, data[:member][:user], data[:member])
|
99
|
+
else
|
100
|
+
guild.members[data[:user_id]]
|
101
|
+
end
|
102
102
|
end
|
103
103
|
@session_id = data[:session_id]
|
104
104
|
@deaf = data[:deaf]
|
@@ -197,7 +197,8 @@ module Discorb
|
|
197
197
|
payload[:topic] = topic if topic != Discorb::Unset
|
198
198
|
payload[:privacy_level] = PRIVACY_LEVEL.key(privacy_level) if privacy_level != Discorb::Unset
|
199
199
|
@client.http.request(
|
200
|
-
Route.new("/stage-instances/#{@channel_id}", "//stage-instances/:channel_id",
|
200
|
+
Route.new("/stage-instances/#{@channel_id}", "//stage-instances/:channel_id",
|
201
|
+
:patch), payload, audit_log_reason: reason,
|
201
202
|
).wait
|
202
203
|
self
|
203
204
|
end
|
@@ -214,7 +215,10 @@ module Discorb
|
|
214
215
|
#
|
215
216
|
def delete!(reason: nil)
|
216
217
|
Async do
|
217
|
-
@client.http.request(
|
218
|
+
@client.http.request(
|
219
|
+
Route.new("/stage-instances/#{@channel_id}", "//stage-instances/:stage_instance_id",
|
220
|
+
:delete), {}, audit_log_reason: reason
|
221
|
+
).wait
|
218
222
|
self
|
219
223
|
end
|
220
224
|
end
|
data/lib/discorb/webhook.rb
CHANGED
@@ -66,22 +66,23 @@ module Discorb
|
|
66
66
|
# @return [Async::Task<nil>] If `wait` is false.
|
67
67
|
#
|
68
68
|
def post(content = nil, tts: false, embed: nil, embeds: nil, allowed_mentions: nil,
|
69
|
-
|
69
|
+
file: nil, files: nil, username: nil, avatar_url: Discorb::Unset, wait: true)
|
70
70
|
Async do
|
71
71
|
payload = {}
|
72
72
|
payload[:content] = content if content
|
73
73
|
payload[:tts] = tts
|
74
74
|
tmp_embed = if embed
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
75
|
+
[embed]
|
76
|
+
elsif embeds
|
77
|
+
embeds
|
78
|
+
end
|
79
79
|
payload[:embeds] = tmp_embed.map(&:to_hash) if tmp_embed
|
80
80
|
payload[:allowed_mentions] = allowed_mentions&.to_hash
|
81
81
|
payload[:username] = username if username
|
82
82
|
payload[:avatar_url] = avatar_url if avatar_url != Discorb::Unset
|
83
83
|
files = [file]
|
84
|
-
_resp, data = @http.multipart_request(Route.new("#{url}?wait=#{wait}", "//webhooks/:webhook_id/:token", :post),
|
84
|
+
_resp, data = @http.multipart_request(Route.new("#{url}?wait=#{wait}", "//webhooks/:webhook_id/:token", :post),
|
85
|
+
files, payload, headers: headers).wait
|
85
86
|
data && Webhook::Message.new(self, data)
|
86
87
|
end
|
87
88
|
end
|
@@ -157,7 +158,10 @@ module Discorb
|
|
157
158
|
payload[:attachments] = attachments.map(&:to_hash) if attachments != Discorb::Unset
|
158
159
|
payload[:allowed_mentions] = allowed_mentions if allowed_mentions != Discorb::Unset
|
159
160
|
files = [file] if file != Discorb::Unset
|
160
|
-
_resp, data = @http.multipart_request(
|
161
|
+
_resp, data = @http.multipart_request(
|
162
|
+
Route.new("#{url}/messages/#{Utils.try(message, :id)}", "//webhooks/:webhook_id/:token/messages/:message_id",
|
163
|
+
:patch), payload, files
|
164
|
+
).wait
|
161
165
|
message.send(:_set_data, data)
|
162
166
|
message
|
163
167
|
end
|
@@ -173,9 +177,9 @@ module Discorb
|
|
173
177
|
def delete_message!(message)
|
174
178
|
Async do
|
175
179
|
@http.request(Route.new(
|
176
|
-
|
177
|
-
|
178
|
-
|
180
|
+
"#{url}/messages/#{Utils.try(message, :id)}",
|
181
|
+
"//webhooks/:webhook_id/:token/messages/:message_id", :delete
|
182
|
+
)).wait
|
179
183
|
message
|
180
184
|
end
|
181
185
|
end
|
@@ -447,25 +451,33 @@ module Discorb
|
|
447
451
|
# @return [Discorb::Webhook::URLWebhook] The URLWebhook.
|
448
452
|
#
|
449
453
|
def new(url)
|
450
|
-
if self
|
451
|
-
return super(*url) if url.is_a?(Array)
|
452
|
-
|
453
|
-
return super
|
454
|
-
end
|
455
|
-
if url.is_a?(String)
|
454
|
+
if self == Webhook
|
456
455
|
URLWebhook.new(url)
|
457
456
|
else
|
458
|
-
|
459
|
-
when 1
|
460
|
-
IncomingWebhook
|
461
|
-
when 2
|
462
|
-
FollowerWebhook
|
463
|
-
when 3
|
464
|
-
ApplicationWebhook
|
465
|
-
end.new(url)
|
457
|
+
super
|
466
458
|
end
|
467
459
|
end
|
468
460
|
|
461
|
+
#
|
462
|
+
# Creates Webhook with discord data.
|
463
|
+
# @private
|
464
|
+
#
|
465
|
+
# @param [Discorb::Client] client The client.
|
466
|
+
# @param [Hash] data The data of the webhook.
|
467
|
+
#
|
468
|
+
# @return [Discorb::Webhook] The Webhook.
|
469
|
+
#
|
470
|
+
def from_data(client, data)
|
471
|
+
case data[:type]
|
472
|
+
when 1
|
473
|
+
IncomingWebhook
|
474
|
+
when 2
|
475
|
+
FollowerWebhook
|
476
|
+
when 3
|
477
|
+
ApplicationWebhook
|
478
|
+
end.new(client, data)
|
479
|
+
end
|
480
|
+
|
469
481
|
def from_url(url)
|
470
482
|
URLWebhook.new(url)
|
471
483
|
end
|
data/lib/discorb.rb
CHANGED
@@ -9,7 +9,8 @@ module Discorb
|
|
9
9
|
# @private
|
10
10
|
#
|
11
11
|
# @!macro [new] async
|
12
|
-
# @note This is an asynchronous method, it will return a `Async::Task` object.
|
12
|
+
# @note This is an asynchronous method, it will return a `Async::Task` object.
|
13
|
+
# Use `Async::Task#wait` to get the result.
|
13
14
|
#
|
14
15
|
# @!macro [new] client_cache
|
15
16
|
# @note This method returns an object from client cache. it will return `nil` if the object is not in cache.
|
@@ -19,7 +20,8 @@ module Discorb
|
|
19
20
|
# @note You must enable `GUILD_MEMBERS` intent to use this method.
|
20
21
|
#
|
21
22
|
# @!macro edit
|
22
|
-
# @note The arguments of this method are defaultly set to `Discorb::Unset`.
|
23
|
+
# @note The arguments of this method are defaultly set to `Discorb::Unset`.
|
24
|
+
# Specify value to set the value, if not don't specify or specify `Discorb::Unset`.
|
23
25
|
#
|
24
26
|
# @!macro http
|
25
27
|
# @note This method calls HTTP request.
|
@@ -42,7 +44,7 @@ module Discorb
|
|
42
44
|
end
|
43
45
|
|
44
46
|
require_order = %w[common flag dictionary error rate_limit http intents emoji_table modules] +
|
45
|
-
%w[message_meta allowed_mentions] +
|
47
|
+
%w[channel/container message_meta allowed_mentions] +
|
46
48
|
%w[user member guild emoji channel embed message] +
|
47
49
|
%w[application audit_logs color components event event_handler] +
|
48
50
|
%w[attachment guild_template image integration interaction invite permission] +
|