Class: Discorb::Webhook Abstract
- Inherits:
-
Object
- Object
- Discorb::Webhook
- Defined in:
- lib/discorb/webhook.rb
Overview
Represents a webhook.
Direct Known Subclasses
ApplicationWebhook, FollowerWebhook, IncomingWebhook, URLWebhook
Defined Under Namespace
Classes: ApplicationWebhook, FollowerWebhook, IncomingWebhook, Message, URLWebhook
Instance Attribute Summary collapse
- #application_id -> Discorb::Snowflake? readonly
-
#avatar -> Discorb::Asset
readonly
The avatar of the webhook.
-
#channel_id -> Discorb::Snowflake
readonly
The ID of the channel this webhook belongs to.
-
#guild_id -> Discorb::Snowflake
readonly
The ID of the guild this webhook belongs to.
-
#name -> String
readonly
The name of the webhook.
-
#token -> String
readonly
The URL of the webhook.
-
#user -> Discorb::User
readonly
The user that created this webhook.
Class Method Summary collapse
- .from_url(url) -> Object
-
.new(url) -> Discorb::Webhook::URLWebhook
Creates URLWebhook.
Instance Method Summary collapse
-
#delete! -> Async::Task<void>
(also: #destroy!)
Deletes the webhook.
-
#delete_message!(message) -> Async::Task<void>
Deletes the webhook's message.
-
#edit(name: Discorb::Unset, avatar: Discorb::Unset, channel: Discorb::Unset) -> Async::Task<void>
(also: #modify)
Edits the webhook.
-
#edit_message(message, content = Discorb::Unset, embed: Discorb::Unset, embeds: Discorb::Unset, file: Discorb::Unset, files: Discorb::Unset, attachments: Discorb::Unset, allowed_mentions: Discorb::Unset) -> Async::Task<void>
Edits the webhook's message.
- #inspect -> Object
-
#post(content = nil, tts: false, embed: nil, embeds: nil, allowed_mentions: nil, attachment: nil, attachments: nil, username: nil, avatar_url: Discorb::Unset, wait: true) -> Discorb::Webhook::Message, Async::Task<nil>
(also: #execute)
Posts a message to the webhook.
Instance Attribute Details
#application_id -> Discorb::Snowflake? (readonly)
21 22 23 |
# File 'lib/discorb/webhook.rb', line 21 def application_id @application_id end |
#avatar -> Discorb::Asset (readonly)
Returns The avatar of the webhook.
18 19 20 |
# File 'lib/discorb/webhook.rb', line 18 def avatar @avatar end |
#channel_id -> Discorb::Snowflake (readonly)
Returns The ID of the channel this webhook belongs to.
14 15 16 |
# File 'lib/discorb/webhook.rb', line 14 def channel_id @channel_id end |
#guild_id -> Discorb::Snowflake (readonly)
Returns The ID of the guild this webhook belongs to.
12 13 14 |
# File 'lib/discorb/webhook.rb', line 12 def guild_id @guild_id end |
#name -> String (readonly)
Returns The name of the webhook.
10 11 12 |
# File 'lib/discorb/webhook.rb', line 10 def name @name end |
#token -> String (readonly)
Returns The URL of the webhook.
23 24 25 |
# File 'lib/discorb/webhook.rb', line 23 def token @token end |
#user -> Discorb::User (readonly)
Returns The user that created this webhook.
16 17 18 |
# File 'lib/discorb/webhook.rb', line 16 def user @user end |
Class Method Details
.from_url(url) -> Object
493 494 495 |
# File 'lib/discorb/webhook.rb', line 493 def from_url(url) URLWebhook.new(url) end |
.new(url) -> Discorb::Webhook::URLWebhook
Creates URLWebhook.
465 466 467 468 469 470 471 |
# File 'lib/discorb/webhook.rb', line 465 def new(url) if self == Webhook URLWebhook.new(url) else super end end |
Instance Method Details
#delete! -> Async::Task<void> Also known as: destroy!
Deletes the webhook.
131 132 133 134 135 136 |
# File 'lib/discorb/webhook.rb', line 131 def delete! Async do @http.request(Route.new(url, "//webhooks/:webhook_id/:token", :delete)).wait self end end |
#delete_message!(message) -> Async::Task<void>
Deletes the webhook's message.
187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/discorb/webhook.rb', line 187 def () Async do @http.request( Route.new( "#{url}/messages/#{Utils.try(, :id)}", "//webhooks/:webhook_id/:token/messages/:message_id", :delete ) ).wait end end |
#edit(name: Discorb::Unset, avatar: Discorb::Unset, channel: Discorb::Unset) -> Async::Task<void> Also known as: modify
The arguments of this method are defaultly set to Discorb::Unset
. Specify value to set the value, if not don't specify or specify Discorb::Unset
.
Edits the webhook.
113 114 115 116 117 118 119 120 121 |
# File 'lib/discorb/webhook.rb', line 113 def edit(name: Discorb::Unset, avatar: Discorb::Unset, channel: Discorb::Unset) Async do payload = {} payload[:name] = name if name != Discorb::Unset payload[:avatar] = avatar if avatar != Discorb::Unset payload[:channel_id] = Utils.try(channel, :id) if channel != Discorb::Unset @http.request(Route.new(url, "//webhooks/:webhook_id/:token", :patch), payload).wait end end |
#edit_message(message, content = Discorb::Unset, embed: Discorb::Unset, embeds: Discorb::Unset, file: Discorb::Unset, files: Discorb::Unset, attachments: Discorb::Unset, allowed_mentions: Discorb::Unset) -> Async::Task<void>
The arguments of this method are defaultly set to Discorb::Unset
. Specify value to set the value, if not don't specify or specify Discorb::Unset
.
Edits the webhook's message.
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/discorb/webhook.rb', line 156 def ( , content = Discorb::Unset, embed: Discorb::Unset, embeds: Discorb::Unset, file: Discorb::Unset, files: Discorb::Unset, attachments: Discorb::Unset, allowed_mentions: Discorb::Unset ) Async do payload = {} payload[:content] = content if content != Discorb::Unset payload[:embeds] = ? [.to_hash] : [] if != Discorb::Unset payload[:embeds] = .map(&:to_hash) if != Discorb::Unset payload[:attachments] = .map(&:to_hash) if != Discorb::Unset payload[:allowed_mentions] = allowed_mentions if allowed_mentions != Discorb::Unset files = [file] if file != Discorb::Unset _resp, data = @http.multipart_request( Route.new("#{url}/messages/#{Utils.try(, :id)}", "//webhooks/:webhook_id/:token/messages/:message_id", :patch), payload, files ).wait .send(:_set_data, data) end end |
#inspect -> Object
46 47 48 |
# File 'lib/discorb/webhook.rb', line 46 def inspect "#<#{self.class} #{@name.inspect} id=#{@id}>" end |
#post(content = nil, tts: false, embed: nil, embeds: nil, allowed_mentions: nil, attachment: nil, attachments: nil, username: nil, avatar_url: Discorb::Unset, wait: true) -> Discorb::Webhook::Message, Async::Task<nil> Also known as: execute
Posts a message to the webhook.
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 97 98 |
# File 'lib/discorb/webhook.rb', line 68 def post( content = nil, tts: false, embed: nil, embeds: nil, allowed_mentions: nil, attachment: nil, attachments: nil, username: nil, avatar_url: Discorb::Unset, wait: true ) 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&.to_hash payload[:username] = username if username payload[:avatar_url] = avatar_url if avatar_url != Discorb::Unset = [] if _resp, data = @http.multipart_request(Route.new("#{url}?wait=#{wait}", "//webhooks/:webhook_id/:token", :post), , payload, headers: headers).wait data && Webhook::Message.new(self, data) end end |