Module: Discorb::Interaction::SourceResponder
- Included in:
- CommandInteraction, MessageComponentInteraction, ModalInteraction
- Defined in:
- lib/discorb/interaction/response.rb
Overview
A module for response with source.
Defined Under Namespace
Classes: CallbackMessage
Instance Method Summary collapse
-
#defer_source(ephemeral: false) -> Async::Task<void>
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::SourceResponder::CallbackMessage, Discorb::Webhook::Message
Response with
CHANNEL_MESSAGE_WITH_SOURCE
(4
).
Instance Method Details
#defer_source(ephemeral: false) -> Async::Task<void>
Response with DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE
(5
).
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/discorb/interaction/response.rb', line 21 def defer_source(ephemeral: false) Async do @client.http.request( Route.new( "/interactions/#{@id}/#{@token}/callback", "//interactions/:interaction_id/:token/callback", :post ), { 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::SourceResponder::CallbackMessage, Discorb::Webhook::Message
Response with CHANNEL_MESSAGE_WITH_SOURCE
(4
).
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/discorb/interaction/response.rb', line 55 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 payload[:embeds] = ( || []).map { |e| e&.to_hash }.filter { _1 } payload[:allowed_mentions] = allowed_mentions&.to_hash(@client.allowed_mentions) || @client.allowed_mentions.to_hash payload[:components] = Component.to_payload(components) if components payload[:flags] = (ephemeral ? 1 << 6 : 0) ret = if @responded _resp, data = @client.http.request( Route.new("/webhooks/#{@application_id}/#{@token}", "//webhooks/:webhook_id/:token", :post), payload ).wait webhook = Webhook::URLWebhook.new("/webhooks/#{@application_id}/#{@token}") Webhook::Message.new(webhook, data, @client) elsif @defered @client.http.request( Route.new("/webhooks/#{@application_id}/#{@token}/messages/@original", "//webhooks/:webhook_id/:token/messages/@original", :patch), payload ).wait CallbackMessage.new(@client, payload, @application_id, @token) else @client.http.request( Route.new("/interactions/#{@id}/#{@token}/callback", "//interactions/:interaction_id/:token/callback", :post), { type: 4, data: payload } ).wait CallbackMessage.new(@client, payload, @application_id, @token) end @responded = true ret end end |