discorb 0.0.4 → 0.0.8
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 +4 -3
- data/discorb.gemspec +3 -3
- data/docs/events.md +50 -54
- data/docs/voice_events.md +32 -32
- data/examples/components/authorization_button.rb +2 -2
- data/examples/components/select_menu.rb +2 -2
- data/examples/extension/message_expander.rb +1 -1
- data/examples/simple/eval.rb +2 -2
- data/examples/simple/ping_pong.rb +1 -1
- data/examples/simple/rolepanel.rb +3 -3
- data/examples/simple/wait_for_message.rb +1 -1
- data/lib/discorb/channel.rb +36 -32
- data/lib/discorb/client.rb +11 -11
- data/lib/discorb/common.rb +1 -1
- data/lib/discorb/emoji.rb +2 -2
- data/lib/discorb/gateway.rb +10 -8
- 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 +11 -11
- data/lib/discorb/modules.rb +7 -7
- 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 +11 -13
- data/lib/discorb.rb +1 -1
- metadata +6 -6
@@ -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
@@ -239,7 +239,7 @@ module Discorb
|
|
239
239
|
# @param (see #post)
|
240
240
|
# @return [Discorb::Message] The message.
|
241
241
|
def reply(*args, **kwargs)
|
242
|
-
Async do
|
242
|
+
Async do
|
243
243
|
channel.post(*args, reference: self, **kwargs).wait
|
244
244
|
end
|
245
245
|
end
|
@@ -250,7 +250,7 @@ module Discorb
|
|
250
250
|
# @macro http
|
251
251
|
#
|
252
252
|
def publish
|
253
|
-
Async do
|
253
|
+
Async do
|
254
254
|
channel.post("/channels/#{@channel_id}/messages/#{@id}/crosspost", nil).wait
|
255
255
|
end
|
256
256
|
end
|
@@ -263,8 +263,8 @@ module Discorb
|
|
263
263
|
# @param [Discorb::Emoji] emoji The emoji to react with.
|
264
264
|
#
|
265
265
|
def add_reaction(emoji)
|
266
|
-
Async do
|
267
|
-
@client.
|
266
|
+
Async do
|
267
|
+
@client.http.put("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}/@me", nil).wait
|
268
268
|
end
|
269
269
|
end
|
270
270
|
|
@@ -278,8 +278,8 @@ module Discorb
|
|
278
278
|
# @param [Discorb::Emoji] emoji The emoji to remove.
|
279
279
|
#
|
280
280
|
def remove_reaction(emoji)
|
281
|
-
Async do
|
282
|
-
@client.
|
281
|
+
Async do
|
282
|
+
@client.http.delete("/channels/#{@channel_id}/messages/#{@id}/reactions/#{emoji.to_uri}/@me").wait
|
283
283
|
end
|
284
284
|
end
|
285
285
|
|
@@ -294,8 +294,8 @@ module Discorb
|
|
294
294
|
# @param [Discorb::Member] member The member to remove the reaction from.
|
295
295
|
#
|
296
296
|
def remove_reaction_of(emoji, member)
|
297
|
-
Async do
|
298
|
-
@client.
|
297
|
+
Async do
|
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
|
|
@@ -313,12 +313,12 @@ module Discorb
|
|
313
313
|
# @return [Array<Discorb::User>] The users.
|
314
314
|
#
|
315
315
|
def fetch_reacted_users(emoji, limit: nil, after: 0)
|
316
|
-
Async do
|
316
|
+
Async do
|
317
317
|
if limit.nil? || !limit.positive?
|
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
|
data/lib/discorb/modules.rb
CHANGED
@@ -22,7 +22,7 @@ module Discorb
|
|
22
22
|
#
|
23
23
|
def post(content = nil, tts: false, embed: nil, embeds: nil, allowed_mentions: nil,
|
24
24
|
reference: nil, components: nil, file: nil, files: nil)
|
25
|
-
Async do
|
25
|
+
Async do
|
26
26
|
payload = {}
|
27
27
|
payload[:content] = content if content
|
28
28
|
payload[:tts] = tts
|
@@ -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
|
@@ -64,7 +62,7 @@ module Discorb
|
|
64
62
|
#
|
65
63
|
def post(content = nil, tts: false, embed: nil, embeds: nil, allowed_mentions: nil,
|
66
64
|
file: nil, files: nil, username: nil, avatar_url: :unset, wait: true)
|
67
|
-
Async do
|
65
|
+
Async do
|
68
66
|
payload = {}
|
69
67
|
payload[:content] = content if content
|
70
68
|
payload[:tts] = tts
|
@@ -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
|
@@ -104,12 +102,12 @@ module Discorb
|
|
104
102
|
# @param [Discorb::GuildChannel] channel The new channel of the webhook.
|
105
103
|
#
|
106
104
|
def edit(name: :unset, avatar: :unset, channel: :unset)
|
107
|
-
Async do
|
105
|
+
Async do
|
108
106
|
payload = {}
|
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
|
|
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,7 +1,7 @@
|
|
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.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sevenc-nanashi
|
@@ -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:
|