discorb 0.9.5 → 0.9.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 39902a57677adf3ce903678e58060ee04da318617ba81611546772131c9d1696
4
- data.tar.gz: 6f0f17d2230a19b79f6330cda2d567f704f8ffe44ca59e8938cc0ec0f32dfb35
3
+ metadata.gz: 82c013d06e2f831b3d0bac635ca13eeea99fe5b248a04e4879bb5f0a17374b90
4
+ data.tar.gz: bf9d0ea7d1f84696d03e705edbcf8e78ee80b87ab393a06b6d7c5abee6d7fcb5
5
5
  SHA512:
6
- metadata.gz: 453b9228e5afca3d9b206b54aa3f34f97b3a4c6d6ade46034fe3d0fd8620c1069d0288fa672bc20cdcce2816405f925d92a9fcf6012bc73d5a09fdb4bc7c0335
7
- data.tar.gz: 11920dcfc13754975686abe69504af19f81331fa684fd5d51aa1065ff426300dfa90ef373c626a84f1c3533e511dd0f35641126f020c1838bc7262538d6fa505
6
+ metadata.gz: '08088483e41f563e1458cef68132c6f0d98c9ff2d99f319ff80dbd4d242b0248567b0e4114d48bd07fcf942179b76ac480217b2bfb82da7a9d957ace5b1ef83c'
7
+ data.tar.gz: 95995caa4ca9ac2d8a6388660afcf10e0928b59347fb4fc5656324fd0917bf80506c6ceb42545b76196ab988e3d3ad62d9449a15cfa57acad85c02e42cbc9294
data/Changelog.md CHANGED
@@ -257,4 +257,10 @@ end
257
257
 
258
258
  - Fix: Fix editing message
259
259
  - Add: Add `required` in slash command argument
260
- - Add: Add `default` in slash command argument
260
+ - Add: Add `default` in slash command argument
261
+
262
+ ## 0.9.6
263
+
264
+ - Add: Add `Messageable#send_message` as alias of `Messageable#post`
265
+ - Fix: Fix interaction responding with updating message
266
+ - Fix: Fix `MessageComponentInteraction#message`
@@ -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.9.5"
7
+ VERSION = "0.9.6"
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
 
@@ -36,6 +36,34 @@ module Discorb
36
36
  )
37
37
  end
38
38
  end
39
+
40
+ #
41
+ # Convert components to a hash.
42
+ #
43
+ # @param [Array<Discorb::Component>, Array<Array<Discorb::Component>>] components Components.
44
+ #
45
+ # @return [Array<Hash>] Hash data.
46
+ #
47
+ def to_payload(components)
48
+ tmp_components = []
49
+ tmp_row = []
50
+ components.each do |c|
51
+ case c
52
+ when Array
53
+ tmp_components << tmp_row
54
+ tmp_row = []
55
+ tmp_components << c
56
+ when SelectMenu
57
+ tmp_components << tmp_row
58
+ tmp_row = []
59
+ tmp_components << [c]
60
+ else
61
+ tmp_row << c
62
+ end
63
+ end
64
+ tmp_components << tmp_row
65
+ return tmp_components.filter { |c| c.length.positive? }.map { |c| { type: 1, components: c.map(&:to_hash) } }
66
+ end
39
67
  end
40
68
  end
41
69
 
@@ -255,7 +255,7 @@ module Discorb
255
255
  def defer_update(ephemeral: false)
256
256
  Async do
257
257
  @client.http.post("/interactions/#{@id}/#{@token}/callback", {
258
- type: 7,
258
+ type: 6,
259
259
  data: {
260
260
  flags: (ephemeral ? 1 << 6 : 0),
261
261
  },
@@ -310,7 +310,7 @@ module Discorb
310
310
  payload[:components] = tmp_components.filter { |c| c.length.positive? }.map { |c| { type: 1, components: c.map(&:to_hash) } }
311
311
  end
312
312
  payload[:flags] = (ephemeral ? 1 << 6 : 0)
313
- @client.http.post("/interactions/#{@id}/#{@token}/callback", { type: 6, data: payload }).wait
313
+ @client.http.post("/interactions/#{@id}/#{@token}/callback", { type: 7, data: payload }).wait
314
314
  end
315
315
  end
316
316
  end
@@ -460,6 +460,8 @@ module Discorb
460
460
  include Interaction::UpdateResponse
461
461
  # @return [String] The content of the response.
462
462
  attr_reader :custom_id
463
+ # @return [Discorb::Message] The target message.
464
+ attr_reader :message
463
465
 
464
466
  @interaction_type = 3
465
467
  @interaction_name = :message_component
@@ -37,26 +37,7 @@ module Discorb
37
37
  payload[:allowed_mentions] =
38
38
  allowed_mentions ? allowed_mentions.to_hash(@client.allowed_mentions) : @client.allowed_mentions.to_hash
39
39
  payload[:message_reference] = reference.to_reference if reference
40
- if components
41
- tmp_components = []
42
- tmp_row = []
43
- components.each do |c|
44
- case c
45
- when Array
46
- tmp_components << tmp_row
47
- tmp_row = []
48
- tmp_components << c
49
- when SelectMenu
50
- tmp_components << tmp_row
51
- tmp_row = []
52
- tmp_components << [c]
53
- else
54
- tmp_row << c
55
- end
56
- end
57
- tmp_components << tmp_row
58
- payload[:components] = tmp_components.filter { |c| c.length.positive? }.map { |c| { type: 1, components: c.map(&:to_hash) } }
59
- end
40
+ payload[:components] = Component.to_payload(components) if components
60
41
  files = [file] if file
61
42
  if files
62
43
  seperator, payload = HTTP.multipart(payload, files)
@@ -69,6 +50,8 @@ module Discorb
69
50
  end
70
51
  end
71
52
 
53
+ alias send_message post
54
+
72
55
  #
73
56
  # Edit a message.
74
57
  # @macro async
@@ -95,27 +78,8 @@ module Discorb
95
78
  payload[:embeds] = tmp_embed.map(&:to_hash) if tmp_embed
96
79
  payload[:allowed_mentions] =
97
80
  allowed_mentions ? allowed_mentions.to_hash(@client.allowed_mentions) : @client.allowed_mentions.to_hash
98
- if components
99
- tmp_components = []
100
- tmp_row = []
101
- components.each do |c|
102
- case c
103
- when Array
104
- tmp_components << tmp_row
105
- tmp_row = []
106
- tmp_components << c
107
- when SelectMenu
108
- tmp_components << tmp_row
109
- tmp_row = []
110
- tmp_components << [c]
111
- else
112
- tmp_row << c
113
- end
114
- end
115
- tmp_components << tmp_row
116
- payload[:flags] = (supress ? 1 << 2 : 0) unless supress.nil?
117
- payload[:components] = tmp_components.filter { |c| c.length.positive? }.map { |c| { type: 1, components: c.map(&:to_hash) } }
118
- end
81
+ payload[:components] = Component.to_payload(components) if components
82
+ payload[:flags] = (supress ? 1 << 2 : 0) unless supress.nil?
119
83
  @client.http.patch("/channels/#{channel_id.wait}/messages/#{message_id}", payload).wait
120
84
  end
121
85
  end
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.9.5
4
+ version: 0.9.6
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-28 00:00:00.000000000 Z
11
+ date: 2021-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async