Skip to content

Commit

Permalink
fix: update Discord domain (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
owenvoke authored Nov 2, 2020
1 parent 32d5714 commit 7e4e28f
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/laravel-notification-channels/discord/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/laravel-notification-channels/discord/?branch=master)
[![Total Downloads](https://img.shields.io/packagist/dt/laravel-notification-channels/discord.svg?style=flat-square)](https://packagist.org/packages/laravel-notification-channels/discord)

This package makes it easy to send notifications using the [Discord bot API](https://discordapp.com/developers/docs/intro) with Laravel.
This package makes it easy to send notifications using the [Discord bot API](https://discord.com/developers/docs/intro) with Laravel.

## Contents

Expand Down Expand Up @@ -46,7 +46,7 @@ Next, you must load the service provider:

### Setting up your Discord bot

1. [Create a Discord application.](https://discordapp.com/developers/applications/me/create)
1. [Create a Discord application.](https://discord.com/developers/applications)
2. Click the `Create a Bot User` button on your Discord application.
3. Paste your bot's API token, found under `App Bot User`, in your `services.php` config file:

Expand Down Expand Up @@ -107,7 +107,7 @@ class Guild extends Eloquent
> }
> ```
>
> Please take note that the `getPrivateChannel` method only accepts [Discord's snowflake IDs](https://discordapp.com/developers/docs/reference#snowflakes). There is no API route provided by Discord to lookup a user's ID by their name and tag, and the process for copying and pasting a user ID can be confusing to some users. Because of this, it is recommended to add the option for users to connect their Discord account to their account within your application either by logging in with Discord or linking it to their pre-existing account.
> Please take note that the `getPrivateChannel` method only accepts [Discord's snowflake IDs](https://discord.com/developers/docs/reference#snowflakes). There is no API route provided by Discord to lookup a user's ID by their name and tag, and the process for copying and pasting a user ID can be confusing to some users. Because of this, it is recommended to add the option for users to connect their Discord account to their account within your application either by logging in with Discord or linking it to their pre-existing account.
You may now tell Laravel to send notifications to Discord channels in the `via` method:
Expand Down Expand Up @@ -142,8 +142,8 @@ class GameChallengeNotification extends Notification
### Available Message methods

* `body(string)`: Set the content of the message. ([Supports basic markdown](https://support.discordapp.com/hc/en-us/articles/210298617-Markdown-Text-101-Chat-Formatting-Bold-Italic-Underline-))
* `embed(array)`: Set the embedded content. ([View embed structure](https://discordapp.com/developers/docs/resources/channel#embed-object))
* `body(string)`: Set the content of the message. ([Supports basic markdown](https://support.discord.com/hc/en-us/articles/210298617-Markdown-Text-101-Chat-Formatting-Bold-Italic-Underline-))
* `embed(array)`: Set the embedded content. ([View embed structure](https://discord.com/developers/docs/resources/channel#embed-object))

## Changelog

Expand Down
6 changes: 3 additions & 3 deletions src/Commands/SetupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function handle()
if (! $this->confirm('Is the bot already added to your server?')) {
$clientId = $this->ask('What is your Discord app client ID?');

$this->warn('Add the bot to your server by visiting this link: https://discordapp.com/oauth2/authorize?&client_id='.$clientId.'&scope=bot&permissions=0');
$this->warn('Add the bot to your server by visiting this link: https://discord.com/oauth2/authorize?&client_id='.$clientId.'&scope=bot&permissions=0');

if (! $this->confirm('Continue?', true)) {
return -1;
Expand All @@ -81,7 +81,7 @@ public function handle()

// Discord requires all bots to connect via a websocket connection and
// identify at least once before any API requests over HTTP are allowed.
// https://discordapp.com/developers/docs/topics/gateway#gateway-identify
// https://discord.com/developers/docs/topics/gateway#gateway-identify
$client->send(json_encode([
'op' => 2,
'd' => [
Expand Down Expand Up @@ -128,7 +128,7 @@ public function getGateway()
$gateway = $this->gateway;

try {
$response = $this->guzzle->get('https://discordapp.com/api/gateway');
$response = $this->guzzle->get('https://discord.com/api/gateway');

$gateway = Arr::get(json_decode($response->getBody(), true), 'url', $gateway);
} catch (Exception $e) {
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/CouldNotSendNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static function serviceRespondedWithAnHttpError(ResponseInterface $respon
*
* @return static
*/
public static function serviceRespondedWithAnApiError(array $response, $code, $exception)
public static function serviceRespondedWithAnApiError(array $response, $code, $exception = null)
{
return new static("Discord responded with an API error: {$response['code']}: {$response['message']}", $code);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/DiscordChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ public function it_can_send_a_notification()
$http = Mockery::mock(HttpClient::class);
$http->shouldReceive('request')
->once()
->with('POST', 'https://discordapp.com/api/channels/0123456789/messages', [
->with('POST', 'https://discord.com/api/channels/0123456789/messages', [
'headers' => [
'Authorization' => 'Bot super-secret',
],
'json' => ['content' => 'Hello, Discord!', 'embed' => [
'title' => 'Object Title',
'url' => 'https://discordapp.com',
'url' => 'https://discord.com',
]],
])
->andReturn(new Response(200));
Expand Down Expand Up @@ -69,7 +69,7 @@ public function toDiscord()
->body('Hello, Discord!')
->embed([
'title' => 'Object Title',
'url' => 'https://discordapp.com',
'url' => 'https://discord.com',
]);
}
}
10 changes: 5 additions & 5 deletions tests/DiscordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function it_can_get_a_private_channel_for_a_user()
$http = Mockery::mock(HttpClient::class);
$http->shouldReceive('request')
->once()
->with('POST', 'https://discordapp.com/api/users/@me/channels', [
->with('POST', 'https://discord.com/api/users/@me/channels', [
'headers' => [
'Authorization' => 'Bot super-secret',
],
Expand All @@ -41,7 +41,7 @@ public function it_throws_an_exception_when_it_receives_an_http_error()
$http = Mockery::mock(HttpClient::class);
$http->shouldReceive('request')
->once()
->with('POST', 'https://discordapp.com/api/channels/some-channel-id/messages', [
->with('POST', 'https://discord.com/api/channels/some-channel-id/messages', [
'headers' => [
'Authorization' => 'Bot super-secret',
],
Expand All @@ -63,7 +63,7 @@ public function it_throws_an_exception_when_it_could_not_talk_to_discord()
$http = Mockery::mock(HttpClient::class);
$http->shouldReceive('request')
->once()
->with('POST', 'https://discordapp.com/api/channels/some-channel-id/messages', [
->with('POST', 'https://discord.com/api/channels/some-channel-id/messages', [
'headers' => [
'Authorization' => 'Bot super-secret',
],
Expand All @@ -85,7 +85,7 @@ public function it_wraps_and_rethrows_a_caught_exception()
$http = Mockery::mock(HttpClient::class);
$http->shouldReceive('request')
->once()
->with('POST', 'https://discordapp.com/api/channels/some-channel-id/messages', [
->with('POST', 'https://discord.com/api/channels/some-channel-id/messages', [
'headers' => [
'Authorization' => 'Bot super-secret',
],
Expand All @@ -107,7 +107,7 @@ public function it_throws_an_exception_if_the_api_responds_with_an_error()
$http = Mockery::mock(HttpClient::class);
$http->shouldReceive('request')
->once()
->with('POST', 'https://discordapp.com/api/channels/some-channel-id/messages', [
->with('POST', 'https://discord.com/api/channels/some-channel-id/messages', [
'headers' => [
'Authorization' => 'Bot super-secret',
],
Expand Down
8 changes: 4 additions & 4 deletions tests/SetupCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function it_tells_the_user_to_connect_the_bot_to_their_discord_server()

$command->shouldReceive('confirm')->with('Is the bot already added to your server?')->once()->andReturn(false);
$command->shouldReceive('ask')->with('What is your Discord app client ID?')->once()->andReturn('my-client-id');
$command->shouldReceive('warn')->with('Add the bot to your server by visiting this link: https://discordapp.com/oauth2/authorize?&client_id=my-client-id&scope=bot&permissions=0');
$command->shouldReceive('warn')->with('Add the bot to your server by visiting this link: https://discord.com/oauth2/authorize?&client_id=my-client-id&scope=bot&permissions=0');
$command->shouldReceive('confirm')->with('Continue?', true)->once()->andReturn(false);

$this->app[Kernel::class]->registerCommand($command);
Expand All @@ -59,7 +59,7 @@ public function it_fetches_the_websocket_gateway_url()
{
$http = Mockery::mock(HttpClient::class);

$http->shouldReceive('get')->with('https://discordapp.com/api/gateway')->once()->andReturn(new Response(200, [], json_encode(['url' => 'wss://test-gateway.discord.gg'])));
$http->shouldReceive('get')->with('https://discord.com/api/gateway')->once()->andReturn(new Response(200, [], json_encode(['url' => 'wss://test-gateway.discord.gg'])));

$command = new SetupCommand($http, 'my-token');

Expand All @@ -73,7 +73,7 @@ public function it_returns_a_default_websocket_gateway_url()
{
$http = Mockery::mock(HttpClient::class);

$http->shouldReceive('get')->with('https://discordapp.com/api/gateway')->once()->andThrow(new RequestException('Not found', Mockery::mock(Request::class), new Response(404, [], json_encode(['message' => 'Not found']))));
$http->shouldReceive('get')->with('https://discord.com/api/gateway')->once()->andThrow(new RequestException('Not found', Mockery::mock(Request::class), new Response(404, [], json_encode(['message' => 'Not found']))));

$command = Mockery::mock(SetupCommand::class.'[warn]', [$http, 'my-token']);

Expand Down Expand Up @@ -136,7 +136,7 @@ public function it_notifies_the_user_of_a_failed_identification_attempt()

$command->shouldReceive('confirm')->with('Is the bot already added to your server?')->once()->andReturn(false);
$command->shouldReceive('ask')->with('What is your Discord app client ID?')->once()->andReturn('my-client-id');
$command->shouldReceive('warn')->with('Add the bot to your server by visiting this link: https://discordapp.com/oauth2/authorize?&client_id=my-client-id&scope=bot&permissions=0');
$command->shouldReceive('warn')->with('Add the bot to your server by visiting this link: https://discord.com/oauth2/authorize?&client_id=my-client-id&scope=bot&permissions=0');
$command->shouldReceive('confirm')->with('Continue?', true)->once()->andReturn(true);
$command->shouldReceive('warn')->with("Attempting to identify the bot with Discord's websocket gateway...")->once();
$command->shouldReceive('getGateway')->once()->andReturn('wss://gateway.discord.gg');
Expand Down

0 comments on commit 7e4e28f

Please sign in to comment.