Module: Discorb::Interaction::SourceResponse
- Included in:
- CommandInteraction, MessageComponentInteraction
- Defined in:
- lib/discorb/interaction.rb
Overview
A module for response with source.
Defined Under Namespace
Classes: CallbackMessage
Instance Method Summary collapse
-
#defer_source(ephemeral: false) -> Object
Response with
DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE
(5
). -
#post(content = nil, tts: false, embed: nil, embeds: nil, allowed_mentions: nil, components: nil, ephemeral: false) -> Discorb::Interaction::SourceResponse::CallbackMessage, Discorb::Webhook::Message
Response with
CHANNEL_MESSAGE_WITH_SOURCE
(4
).
Instance Method Details
#defer_source(ephemeral: false) -> Object
Note:
This is an asynchronous method, it will return a Async::Task
object. Use Async::Task#wait
to get the result.
Note:
This method calls HTTP request.
Response with DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE
(5
).
108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/discorb/interaction.rb', line 108 def defer_source(ephemeral: false) Async do @client.http.post("/interactions/#{@id}/#{@token}/callback", { type: 5, data: { flags: (ephemeral ? 1 << 6 : 0), }, }).wait @defered = true end end |
#post(content = nil, tts: false, embed: nil, embeds: nil, allowed_mentions: nil, components: nil, ephemeral: false) -> Discorb::Interaction::SourceResponse::CallbackMessage, Discorb::Webhook::Message
Note:
This is an asynchronous method, it will return a Async::Task
object. Use Async::Task#wait
to get the result.
Note:
This method calls HTTP request.
Response with CHANNEL_MESSAGE_WITH_SOURCE
(4
).
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/discorb/interaction.rb', line 136 def post(content = nil, tts: false, embed: nil, embeds: nil, allowed_mentions: nil, components: nil, ephemeral: false) Async do payload = {} payload[:content] = content if content payload[:tts] = tts = if [] elsif end payload[:embeds] = .map(&:to_hash) if payload[:allowed_mentions] = allowed_mentions ? allowed_mentions.to_hash(@client.allowed_mentions) : @client.allowed_mentions.to_hash if components tmp_components = [] tmp_row = [] components.each do |c| case c when Array tmp_components << tmp_row tmp_row = [] tmp_components << c when SelectMenu tmp_components << tmp_row tmp_row = [] tmp_components << [c] else tmp_row << c end end tmp_components << tmp_row payload[:components] = tmp_components.filter { |c| c.length.positive? }.map { |c| { type: 1, components: c.map(&:to_hash) } } end payload[:flags] = (ephemeral ? 1 << 6 : 0) ret = if @responded _resp, data = @client.http.post("/webhooks/#{@application_id}/#{@token}", payload).wait webhook = Webhook::URLWebhook.new("/webhooks/#{@application_id}/#{@token}", data) Webhook::Message.new(data, webhook, @client) elsif @defered @client.http.patch("/webhooks/#{@application_id}/#{@token}/messages/@original", payload).wait CallbackMessage.new(@client, payload, @application_id, @token) else @client.http.post("/interactions/#{@id}/#{@token}/callback", { type: 4, data: payload }).wait CallbackMessage.new(@client, payload, @application_id, @token) end @responded = true ret end end |