Module: Discordrb::API::Webhook

Defined in:
lib/discordrb/api/webhook.rb

Overview

API calls for Webhook object

Class Method Summary collapse

Class Method Details

.delete_webhook(token, webhook_id, reason = nil) ⇒ Object



83
84
85
86
87
88
89
90
91
92
# File 'lib/discordrb/api/webhook.rb', line 83

def delete_webhook(token, webhook_id, reason = nil)
  Discordrb::API.request(
    :webhooks_wid,
    webhook_id,
    :delete,
    "#{Discordrb::API.api_base}/webhooks/#{webhook_id}",
    Authorization: token,
    'X-Audit-Log-Reason': reason
  )
end

.token_delete_message(webhook_token, webhook_id, message_id) ⇒ Object

Delete a webhook message via webhook token. discord.com/developers/docs/resources/webhook#delete-webhook-message



132
133
134
135
136
137
138
139
# File 'lib/discordrb/api/webhook.rb', line 132

def token_delete_message(webhook_token, webhook_id, message_id)
  Discordrb::API.request(
    :webhooks_wid_messages,
    webhook_id,
    :delete,
    "#{Discordrb::API.api_base}/webhooks/#{webhook_id}/#{webhook_token}/messages/#{message_id}"
  )
end

.token_delete_webhook(webhook_token, webhook_id, reason = nil) ⇒ Object



96
97
98
99
100
101
102
103
104
# File 'lib/discordrb/api/webhook.rb', line 96

def token_delete_webhook(webhook_token, webhook_id, reason = nil)
  Discordrb::API.request(
    :webhooks_wid,
    webhook_id,
    :delete,
    "#{Discordrb::API.api_base}/webhooks/#{webhook_id}/#{webhook_token}",
    'X-Audit-Log-Reason': reason
  )
end

.token_edit_message(webhook_token, webhook_id, message_id, content = nil, embeds = nil, allowed_mentions = nil, components = nil) ⇒ Object



119
120
121
122
123
124
125
126
127
128
# File 'lib/discordrb/api/webhook.rb', line 119

def token_edit_message(webhook_token, webhook_id, message_id, content = nil, embeds = nil, allowed_mentions = nil, components = nil)
  Discordrb::API.request(
    :webhooks_wid_messages,
    webhook_id,
    :patch,
    "#{Discordrb::API.api_base}/webhooks/#{webhook_id}/#{webhook_token}/messages/#{message_id}",
    { content: content, embeds: embeds, allowed_mentions: allowed_mentions, components: components }.to_json,
    content_type: :json
  )
end

.token_execute_webhook(webhook_token, webhook_id, wait = false, content = nil, username = nil, avatar_url = nil, tts = nil, file = nil, embeds = nil, allowed_mentions = nil, flags = nil, components = nil) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/discordrb/api/webhook.rb', line 32

def token_execute_webhook(webhook_token, webhook_id, wait = false, content = nil, username = nil, avatar_url = nil, tts = nil, file = nil, embeds = nil, allowed_mentions = nil, flags = nil, components = nil)
  body = { content: content, username: username, avatar_url: avatar_url, tts: tts, embeds: embeds&.map(&:to_hash),  allowed_mentions: allowed_mentions, flags: flags, components: components }
  body = if file
           { file: file, payload_json: body.to_json }
         else
           body.to_json
         end

  headers = { content_type: :json } unless file

  Discordrb::API.request(
    :webhooks_wid,
    webhook_id,
    :post,
    "#{Discordrb::API.api_base}/webhooks/#{webhook_id}/#{webhook_token}?wait=#{wait}",
    body,
    headers
  )
end

.token_get_message(webhook_token, webhook_id, message_id) ⇒ Object

Get a message that was created by the webhook corresponding to the provided token. discord.com/developers/docs/resources/webhook#get-webhook-message



108
109
110
111
112
113
114
115
# File 'lib/discordrb/api/webhook.rb', line 108

def token_get_message(webhook_token, webhook_id, message_id)
  Discordrb::API.request(
    :webhooks_wid_messages_mid,
    webhook_id,
    :get,
    "#{Discordrb::API.api_base}/webhooks/#{webhook_id}/#{webhook_token}/messages/#{message_id}"
  )
end

.token_update_webhook(webhook_token, webhook_id, data, reason = nil) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/discordrb/api/webhook.rb', line 69

def token_update_webhook(webhook_token, webhook_id, data, reason = nil)
  Discordrb::API.request(
    :webhooks_wid,
    webhook_id,
    :patch,
    "#{Discordrb::API.api_base}/webhooks/#{webhook_id}/#{webhook_token}",
    data.to_json,
    content_type: :json,
    'X-Audit-Log-Reason': reason
  )
end

.token_webhook(webhook_token, webhook_id) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/discordrb/api/webhook.rb', line 21

def token_webhook(webhook_token, webhook_id)
  Discordrb::API.request(
    :webhooks_wid,
    nil,
    :get,
    "#{Discordrb::API.api_base}/webhooks/#{webhook_id}/#{webhook_token}"
  )
end

.update_webhook(token, webhook_id, data, reason = nil) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/discordrb/api/webhook.rb', line 54

def update_webhook(token, webhook_id, data, reason = nil)
  Discordrb::API.request(
    :webhooks_wid,
    webhook_id,
    :patch,
    "#{Discordrb::API.api_base}/webhooks/#{webhook_id}",
    data.to_json,
    Authorization: token,
    content_type: :json,
    'X-Audit-Log-Reason': reason
  )
end

.webhook(token, webhook_id) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/discordrb/api/webhook.rb', line 9

def webhook(token, webhook_id)
  Discordrb::API.request(
    :webhooks_wid,
    nil,
    :get,
    "#{Discordrb::API.api_base}/webhooks/#{webhook_id}",
    Authorization: token
  )
end