Skip to content

Commit 36087f3

Browse files
DEV: Update Discord webhook domain (discourse#106)
discordapp.com is being deprecated and replaced with discord.com - discord/discord-api-docs#4510
1 parent ddee0c4 commit 36087f3

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
class UpdateDiscordWebhookDomains < ActiveRecord::Migration[6.1]
4+
def up
5+
execute <<~SQL
6+
UPDATE plugin_store_rows psr
7+
SET value = REPLACE(value, 'discordapp.com', 'discord.com')
8+
WHERE psr.plugin_name = 'discourse-chat-integration'
9+
AND psr.key LIKE 'channel:%'
10+
AND psr.type_name = 'JSON'
11+
AND psr.value::json ->> 'provider' = 'discord'
12+
AND psr.value::json ->> 'data' LIKE '%https://discordapp.com/%'
13+
SQL
14+
end
15+
16+
def down
17+
raise ActiveRecord::IrreversibleMigration
18+
end
19+
end

lib/discourse_chat_integration/provider/discord/discord_provider.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ module DiscordProvider
88

99
CHANNEL_PARAMETERS = [
1010
{ key: "name", regex: '^\S+' },
11-
{ key: "webhook_url", regex: '^https:\/\/discord(?:app)?\.com\/api\/webhooks\/', unique: true, hidden: true }
11+
{ key: "webhook_url", regex: '^https:\/\/discord\.com\/api\/webhooks\/', unique: true, hidden: true }
1212
].freeze
1313

1414
def self.send_message(url, message)
15-
http = Net::HTTP.new("discordapp.com", 443)
15+
http = Net::HTTP.new("discord.com", 443)
1616
http.use_ssl = true
1717

1818
uri = URI(url)

spec/lib/discourse_chat_integration/provider/discord/discord_provider_spec.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,24 @@
1010
SiteSetting.chat_integration_discord_enabled = true
1111
end
1212

13-
let(:chan1) { DiscourseChatIntegration::Channel.create!(provider: 'discord', data: { name: "Awesome Channel", webhook_url: 'https://discordapp.com/api/webhooks/1234/abcd' }) }
13+
let(:chan1) { DiscourseChatIntegration::Channel.create!(provider: 'discord', data: { name: "Awesome Channel", webhook_url: 'https://discord.com/api/webhooks/1234/abcd' }) }
1414

1515
it 'sends a webhook request' do
16-
stub1 = stub_request(:post, 'https://discordapp.com/api/webhooks/1234/abcd?wait=true').to_return(status: 200)
16+
stub1 = stub_request(:post, 'https://discord.com/api/webhooks/1234/abcd?wait=true').to_return(status: 200)
1717
described_class.trigger_notification(post, chan1, nil)
1818
expect(stub1).to have_been_requested.once
1919
end
2020

2121
it 'includes the protocol in the avatar URL' do
22-
stub1 = stub_request(:post, 'https://discordapp.com/api/webhooks/1234/abcd?wait=true')
22+
stub1 = stub_request(:post, 'https://discord.com/api/webhooks/1234/abcd?wait=true')
2323
.with(body: hash_including(embeds: [hash_including(author: hash_including(url: /^https?:\/\//))]))
2424
.to_return(status: 200)
2525
described_class.trigger_notification(post, chan1, nil)
2626
expect(stub1).to have_been_requested.once
2727
end
2828

2929
it 'handles errors correctly' do
30-
stub1 = stub_request(:post, "https://discordapp.com/api/webhooks/1234/abcd?wait=true").to_return(status: 400)
30+
stub1 = stub_request(:post, "https://discord.com/api/webhooks/1234/abcd?wait=true").to_return(status: 400)
3131
expect(stub1).to have_been_requested.times(0)
3232
expect { described_class.trigger_notification(post, chan1, nil) }.to raise_exception(::DiscourseChatIntegration::ProviderError)
3333
expect(stub1).to have_been_requested.once

0 commit comments

Comments
 (0)