discorb 0.7.0 → 0.7.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 13326863238ba4e79e873947fe579da1027bfcfe7f6baed1bd9d0c74806e31a1
4
- data.tar.gz: c43a370b95eec06dcfa2ce0f627c8b9e14421464848c7170690ddc9527aff589
3
+ metadata.gz: 6b163ab1659df50cb3b66467a2a70077af84df29c378c339a1a6eb26a45a32b6
4
+ data.tar.gz: ab25ec2928e9030532e099caa3857ab4852ab3b79d4f9f558f10716e50ebc339
5
5
  SHA512:
6
- metadata.gz: bf804c54e218696a9ba5464af5e8c6d4d25132ac573413d0453502872e2dcc55ec49bfb4c571d05df4d489a49cef894ca139091e74fb41fb0d5f36c2786e5cdf
7
- data.tar.gz: 8fb94771a4ea9730962f084d40439383b412caa97674aa9d6edb38d01ebd10fb14ecc54a9bac24a067768bbe5866d18ddd6366449ba84355324af70839fce135
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
@@ -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.0"
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
 
@@ -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
- payload = {}
130
- payload[:content] = content if content
131
- payload[:tts] = tts
132
- tmp_embed = if embed
133
- [embed]
134
- elsif embeds
135
- embeds
136
- end
137
- payload[:embeds] = tmp_embed.map(&:to_hash) if tmp_embed
138
- payload[:allowed_mentions] = allowed_mentions ? allowed_mentions.to_hash(@client.allowed_mentions) : @client.allowed_mentions.to_hash
139
- if components
140
- tmp_components = []
141
- tmp_row = []
142
- components.each do |c|
143
- case c
144
- when Array
145
- tmp_components << tmp_row
146
- tmp_row = []
147
- tmp_components << c
148
- when SelectMenu
149
- tmp_components << tmp_row
150
- tmp_row = []
151
- tmp_components << [c]
152
- else
153
- tmp_row << c
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
- tmp_components << tmp_row
157
- payload[:components] = tmp_components.filter { |c| c.length.positive? }.map { |c| { type: 1, components: c.map(&:to_hash) } }
158
- end
159
- payload[:flags] = (ephemeral ? 1 << 6 : 0)
160
- if @responded
161
- @client.http.post("/webhooks/#{@id}/#{@token}", { type: 4, data: payload }).wait
162
- elsif @defered
163
- @client.http.post("/interactions/#{@id}/#{@token}/@original/edit", { type: 4, data: payload }).wait
164
- else
165
- @client.http.post("/interactions/#{@id}/#{@token}/callback", { type: 4, data: payload }).wait
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
- payload = {}
204
- payload[:content] = content if content
205
- payload[:tts] = tts
206
- tmp_embed = if embed
207
- [embed]
208
- elsif embeds
209
- embeds
210
- end
211
- payload[:embeds] = tmp_embed.map(&:to_hash) if tmp_embed
212
- payload[:allowed_mentions] = allowed_mentions ? allowed_mentions.to_hash(@client.allowed_mentions) : @client.allowed_mentions.to_hash
213
- if components
214
- tmp_components = []
215
- tmp_row = []
216
- components.each do |c|
217
- case c
218
- when Array
219
- tmp_components << tmp_row
220
- tmp_row = []
221
- tmp_components << c
222
- when SelectMenu
223
- tmp_components << tmp_row
224
- tmp_row = []
225
- tmp_components << [c]
226
- else
227
- tmp_row << c
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
- tmp_components << tmp_row
231
- payload[:components] = tmp_components.filter { |c| c.length.positive? }.map { |c| { type: 1, components: c.map(&:to_hash) } }
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.0
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-20 00:00:00.000000000 Z
11
+ date: 2021-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async