discordrb-webhooks 3.5.0 → 3.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: ac23678014708b3612c2b64182fc560e28fffaff546fe32068b6c80f92241a49
4
- data.tar.gz: 1af3c1de510f8262df3074bbcb28af659ad233c0447feab33709ccafbb99bf9b
3
+ metadata.gz: 64adff3c11dc30cbe5688e48d2dad1b827fc6ef225cfce9d767e21082f3a0469
4
+ data.tar.gz: 11bc596b4feb9d4805ab73c313dc918a346ffde62db136fb544231b42f91014a
5
5
  SHA512:
6
- metadata.gz: eb90480b721262fe38147e7f117ebd102ab05f9dc5435ef4fdf2263c0c4bb9b0886077f10ebb8f4b73db57e8cd751bad1e97f90917c5c3f4ad9b6714fd92212b
7
- data.tar.gz: '0678b594744221149421bb72ed219ee9b916aca0e2ad58f4f7002fc94627d3d9aed6bcbaaca73cf8116eed7a0b7a5a5dd3f0c8a71cf5183a256d6af6471fe61d'
6
+ metadata.gz: 5742b179ad21db8f23f73b55da2a6739cf6a7c16b63a3368a83f01c4e7b59c7e72ca26aa17b5f8beceb1aca1a72e6b9431d8d5da158625ef4c199a7ded04e53a
7
+ data.tar.gz: 75516b95f3346a5774ddd5e0067613acad2b83bf055b55e4296c14c03b45202d3a9b0113409fab37e8d78f67e7f9df5becaba878b713cfd49bef05889359180e
@@ -22,6 +22,7 @@ module Discordrb::Webhooks
22
22
  # @param builder [Builder, nil] The builder to start out with, or nil if one should be created anew.
23
23
  # @param wait [true, false] Whether Discord should wait for the message to be successfully received by clients, or
24
24
  # whether it should return immediately after sending the message.
25
+ # @param thread_id [String, Integer, nil] The thread_id of the thread if a thread should be targeted for the webhook execution
25
26
  # @yield [builder] Gives the builder to the block to add additional steps, or to do the entire building process.
26
27
  # @yieldparam builder [Builder] The builder given as a parameter which is used as the initial step to start from.
27
28
  # @example Execute the webhook with an already existing builder
@@ -38,7 +39,7 @@ module Discordrb::Webhooks
38
39
  # end
39
40
  # end
40
41
  # @return [RestClient::Response] the response returned by Discord.
41
- def execute(builder = nil, wait = false, components = nil)
42
+ def execute(builder = nil, wait = false, components = nil, thread_id: nil)
42
43
  raise TypeError, 'builder needs to be nil or like a Discordrb::Webhooks::Builder!' unless
43
44
  (builder.respond_to?(:file) && builder.respond_to?(:to_multipart_hash)) || builder.respond_to?(:to_json_hash) || builder.nil?
44
45
 
@@ -50,9 +51,9 @@ module Discordrb::Webhooks
50
51
  components ||= view
51
52
 
52
53
  if builder.file
53
- post_multipart(builder, components, wait)
54
+ post_multipart(builder, components, wait, thread_id)
54
55
  else
55
- post_json(builder, components, wait)
56
+ post_json(builder, components, wait, thread_id)
56
57
  end
57
58
  end
58
59
 
@@ -79,6 +80,7 @@ module Discordrb::Webhooks
79
80
  # @param content [String] The message content.
80
81
  # @param embeds [Array<Embed, Hash>]
81
82
  # @param allowed_mentions [Hash]
83
+ # @param thread_id [String, Integer, nil] The id of the thread in which the message resides
82
84
  # @return [RestClient::Response] the response returned by Discord.
83
85
  # @example Edit message content
84
86
  # client.edit_message(message_id, content: 'goodbye world!')
@@ -89,13 +91,17 @@ module Discordrb::Webhooks
89
91
  # end
90
92
  # end
91
93
  # @note Not all builder options are available when editing.
92
- def edit_message(message_id, builder: nil, content: nil, embeds: nil, allowed_mentions: nil)
94
+ def edit_message(message_id, builder: nil, content: nil, embeds: nil, allowed_mentions: nil, thread_id: nil)
93
95
  builder ||= Builder.new
94
96
 
95
97
  yield builder if block_given?
96
98
 
99
+ query = URI.encode_www_form({ thread_id: }.compact)
97
100
  data = builder.to_json_hash.merge({ content: content, embeds: embeds, allowed_mentions: allowed_mentions }.compact)
98
- RestClient.patch("#{@url}/messages/#{message_id}", data.compact.to_json, content_type: :json)
101
+ RestClient.patch(
102
+ "#{@url}/messages/#{message_id}#{(query.empty? ? '' : "?#{query}")}",
103
+ data.compact.to_json, content_type: :json
104
+ )
99
105
  end
100
106
 
101
107
  # Delete a message created by this webhook.
@@ -117,18 +123,21 @@ module Discordrb::Webhooks
117
123
  end
118
124
  end
119
125
 
120
- def post_json(builder, components, wait)
126
+ def post_json(builder, components, wait, thread_id)
127
+ query = URI.encode_www_form({ wait:, thread_id: }.compact)
121
128
  data = builder.to_json_hash.merge({ components: components.to_a })
122
- RestClient.post(@url + (wait ? '?wait=true' : ''), data.to_json, content_type: :json)
129
+ RestClient.post(@url + (query.empty? ? '' : "?#{query}"), data.to_json, content_type: :json)
123
130
  end
124
131
 
125
- def post_multipart(builder, components, wait)
126
- data = builder.to_multipart_hash.merge({ components: components.to_a })
127
- RestClient.post(@url + (wait ? '?wait=true' : ''), data)
132
+ def post_multipart(builder, components, wait, thread_id)
133
+ query = URI.encode_www_form({ wait:, thread_id: }.compact)
134
+ data = builder.to_multipart_hash
135
+ data[:components] = components.to_a if components&.to_a&.any?
136
+ RestClient.post(@url + (query.empty? ? '' : "?#{query}"), data.compact)
128
137
  end
129
138
 
130
139
  def generate_url(id, token)
131
- "https://discord.com/api/v8/webhooks/#{id}/#{token}"
140
+ "https://discord.com/api/v9/webhooks/#{id}/#{token}"
132
141
  end
133
142
  end
134
143
  end
@@ -4,6 +4,6 @@
4
4
  module Discordrb
5
5
  module Webhooks
6
6
  # The current version of discordrb-webhooks.
7
- VERSION = '3.5.0'
7
+ VERSION = '3.7.1'
8
8
  end
9
9
  end
@@ -49,7 +49,7 @@ class Discordrb::Webhooks::View
49
49
  when Integer, String
50
50
  emoji.to_i.positive? ? { id: emoji } : { name: emoji }
51
51
  else
52
- emoji.to_h
52
+ emoji&.to_h
53
53
  end
54
54
 
55
55
  @components << { type: COMPONENT_TYPES[:button], label: label, emoji: emoji, style: style, custom_id: custom_id, disabled: disabled, url: url }
@@ -149,7 +149,7 @@ class Discordrb::Webhooks::View
149
149
  when Integer, String
150
150
  emoji.to_i.positive? ? { id: emoji } : { name: emoji }
151
151
  else
152
- emoji.to_h
152
+ emoji&.to_h
153
153
  end
154
154
 
155
155
  @options << { label: label, value: value, description: description, emoji: emoji, default: default }
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: discordrb-webhooks
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.5.0
4
+ version: 3.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - meew0
8
8
  - swarley
9
- autorequire:
10
9
  bindir: exe
11
10
  cert_chain: []
12
- date: 2023-07-05 00:00:00.000000000 Z
11
+ date: 1980-01-02 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rest-client
@@ -44,7 +43,6 @@ licenses:
44
43
  - MIT
45
44
  metadata:
46
45
  rubygems_mfa_required: 'true'
47
- post_install_message:
48
46
  rdoc_options: []
49
47
  require_paths:
50
48
  - lib
@@ -52,15 +50,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
52
50
  requirements:
53
51
  - - ">="
54
52
  - !ruby/object:Gem::Version
55
- version: '2.7'
53
+ version: '3.2'
56
54
  required_rubygems_version: !ruby/object:Gem::Requirement
57
55
  requirements:
58
56
  - - ">="
59
57
  - !ruby/object:Gem::Version
60
58
  version: '0'
61
59
  requirements: []
62
- rubygems_version: 3.3.3
63
- signing_key:
60
+ rubygems_version: 3.6.9
64
61
  specification_version: 4
65
62
  summary: Webhook client for discordrb
66
63
  test_files: []