discorb 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +8 -1
- data/lib/discorb/common.rb +1 -1
- data/lib/discorb/interaction.rb +79 -65
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b163ab1659df50cb3b66467a2a70077af84df29c378c339a1a6eb26a45a32b6
|
4
|
+
data.tar.gz: ab25ec2928e9030532e099caa3857ab4852ab3b79d4f9f558f10716e50ebc339
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f43efd7ef3eceddc1d116fd0e6be9655dc1fd489a6d9770411298a3f20f7d4c8f71811679cb865d2ef0baba9929c13b1d29d238b10ba448d440c626274547cce
|
7
|
+
data.tar.gz: e83240f9ce495140613a0777f3c9a5a5a12f35cd8a6c9b39f88f7c080f370af977812d8d7c2fda8acd2a0f62208fd238a101d91998a2e23a12ef18c39373b885
|
data/Changelog.md
CHANGED
@@ -157,6 +157,7 @@
|
|
157
157
|
- Fix: Fix some issues with client without guild intent
|
158
158
|
- Add: Add alias for `#fired_by`
|
159
159
|
- Change!: Change block usage of `ApplicationCommand::Handler#group`
|
160
|
+
|
160
161
|
```ruby
|
161
162
|
# before
|
162
163
|
client.slash_group do
|
@@ -170,4 +171,10 @@ client.slash_group do |group|
|
|
170
171
|
group.slash "help", "Help" do |interaction|
|
171
172
|
# ...
|
172
173
|
end
|
173
|
-
end
|
174
|
+
end
|
175
|
+
|
176
|
+
```
|
177
|
+
|
178
|
+
## 0.7.1
|
179
|
+
|
180
|
+
- Fix: Fix error of responding to interaction
|
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.7.
|
7
|
+
VERSION = "0.7.1"
|
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/interaction.rb
CHANGED
@@ -100,6 +100,9 @@ module Discorb
|
|
100
100
|
#
|
101
101
|
# Response with `DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE`(`5`).
|
102
102
|
#
|
103
|
+
# @macro async
|
104
|
+
# @macro http
|
105
|
+
#
|
103
106
|
# @param [Boolean] ephemeral Whether to make the response ephemeral.
|
104
107
|
#
|
105
108
|
def defer_source(ephemeral: false)
|
@@ -117,6 +120,9 @@ module Discorb
|
|
117
120
|
#
|
118
121
|
# Response with `CHANNEL_MESSAGE_WITH_SOURCE`(`4`).
|
119
122
|
#
|
123
|
+
# @macro async
|
124
|
+
# @macro http
|
125
|
+
#
|
120
126
|
# @param [String] content The content of the response.
|
121
127
|
# @param [Boolean] tts Whether to send the message as text-to-speech.
|
122
128
|
# @param [Discorb::Embed] embed The embed to send.
|
@@ -126,45 +132,48 @@ module Discorb
|
|
126
132
|
# @param [Boolean] ephemeral Whether to make the response ephemeral.
|
127
133
|
#
|
128
134
|
def post(content = nil, tts: false, embed: nil, embeds: nil, allowed_mentions: nil, components: nil, ephemeral: false)
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
embeds
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
135
|
+
Async do
|
136
|
+
payload = {}
|
137
|
+
payload[:content] = content if content
|
138
|
+
payload[:tts] = tts
|
139
|
+
tmp_embed = if embed
|
140
|
+
[embed]
|
141
|
+
elsif embeds
|
142
|
+
embeds
|
143
|
+
end
|
144
|
+
payload[:embeds] = tmp_embed.map(&:to_hash) if tmp_embed
|
145
|
+
payload[:allowed_mentions] = allowed_mentions ? allowed_mentions.to_hash(@client.allowed_mentions) : @client.allowed_mentions.to_hash
|
146
|
+
if components
|
147
|
+
tmp_components = []
|
148
|
+
tmp_row = []
|
149
|
+
components.each do |c|
|
150
|
+
case c
|
151
|
+
when Array
|
152
|
+
tmp_components << tmp_row
|
153
|
+
tmp_row = []
|
154
|
+
tmp_components << c
|
155
|
+
when SelectMenu
|
156
|
+
tmp_components << tmp_row
|
157
|
+
tmp_row = []
|
158
|
+
tmp_components << [c]
|
159
|
+
else
|
160
|
+
tmp_row << c
|
161
|
+
end
|
154
162
|
end
|
163
|
+
tmp_components << tmp_row
|
164
|
+
payload[:components] = tmp_components.filter { |c| c.length.positive? }.map { |c| { type: 1, components: c.map(&:to_hash) } }
|
155
165
|
end
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
@
|
166
|
+
payload[:flags] = (ephemeral ? 1 << 6 : 0)
|
167
|
+
|
168
|
+
if @responded
|
169
|
+
@client.http.post("/webhooks/#{@application_id}/#{@token}", payload).wait
|
170
|
+
elsif @defered
|
171
|
+
@client.http.patch("/webhooks/#{@application_id}/#{@token}/messages/@original", payload).wait
|
172
|
+
else
|
173
|
+
@client.http.post("/interactions/#{@id}/#{@token}/callback", { type: 4, data: payload }).wait
|
174
|
+
end
|
175
|
+
@responded = true
|
166
176
|
end
|
167
|
-
@responded = true
|
168
177
|
end
|
169
178
|
end
|
170
179
|
|
@@ -191,6 +200,9 @@ module Discorb
|
|
191
200
|
#
|
192
201
|
# Response with `UPDATE_MESSAGE`(`7`).
|
193
202
|
#
|
203
|
+
# @macro async
|
204
|
+
# @macro http
|
205
|
+
#
|
194
206
|
# @param [String] content The content of the response.
|
195
207
|
# @param [Boolean] tts Whether to send the message as text-to-speech.
|
196
208
|
# @param [Discorb::Embed] embed The embed to send.
|
@@ -200,38 +212,40 @@ module Discorb
|
|
200
212
|
# @param [Boolean] ephemeral Whether to make the response ephemeral.
|
201
213
|
#
|
202
214
|
def edit(content, tts: false, embed: nil, embeds: nil, allowed_mentions: nil, components: nil, ephemeral: false)
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
embeds
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
215
|
+
Async do
|
216
|
+
payload = {}
|
217
|
+
payload[:content] = content if content
|
218
|
+
payload[:tts] = tts
|
219
|
+
tmp_embed = if embed
|
220
|
+
[embed]
|
221
|
+
elsif embeds
|
222
|
+
embeds
|
223
|
+
end
|
224
|
+
payload[:embeds] = tmp_embed.map(&:to_hash) if tmp_embed
|
225
|
+
payload[:allowed_mentions] = allowed_mentions ? allowed_mentions.to_hash(@client.allowed_mentions) : @client.allowed_mentions.to_hash
|
226
|
+
if components
|
227
|
+
tmp_components = []
|
228
|
+
tmp_row = []
|
229
|
+
components.each do |c|
|
230
|
+
case c
|
231
|
+
when Array
|
232
|
+
tmp_components << tmp_row
|
233
|
+
tmp_row = []
|
234
|
+
tmp_components << c
|
235
|
+
when SelectMenu
|
236
|
+
tmp_components << tmp_row
|
237
|
+
tmp_row = []
|
238
|
+
tmp_components << [c]
|
239
|
+
else
|
240
|
+
tmp_row << c
|
241
|
+
end
|
228
242
|
end
|
243
|
+
tmp_components << tmp_row
|
244
|
+
payload[:components] = tmp_components.filter { |c| c.length.positive? }.map { |c| { type: 1, components: c.map(&:to_hash) } }
|
229
245
|
end
|
230
|
-
|
231
|
-
|
246
|
+
payload[:flags] = (ephemeral ? 1 << 6 : 0)
|
247
|
+
@client.http.post("/interactions/#{@id}/#{@token}/callback", { type: 6, data: payload }).wait
|
232
248
|
end
|
233
|
-
payload[:flags] = (ephemeral ? 1 << 6 : 0)
|
234
|
-
@client.http.post("/interactions/#{@id}/#{@token}/callback", { type: 6, data: payload }).wait
|
235
249
|
end
|
236
250
|
end
|
237
251
|
|
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.7.
|
4
|
+
version: 0.7.1
|
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-09-
|
11
|
+
date: 2021-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async
|