Skip to content

Commit 3e13385

Browse files
Cody Scottfreekmurze
authored andcommitted
Add Discord channel
1 parent 77737de commit 3e13385

20 files changed

+830
-2
lines changed

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
; This file is for unifying the coding style for different editors and IDEs.
2+
; More information at http://editorconfig.org
3+
4+
root = true
5+
6+
[*]
7+
charset = utf-8
8+
indent_size = 4
9+
indent_style = space
10+
end_of_line = lf
11+
insert_final_newline = true
12+
trim_trailing_whitespace = true
13+
14+
[*.md]
15+
trim_trailing_whitespace = false

.gitattributes

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Path-based git attributes
2+
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html
3+
4+
# Ignore all test and documentation with "export-ignore".
5+
/.gitattributes export-ignore
6+
/.gitignore export-ignore
7+
/.travis.yml export-ignore
8+
/phpunit.xml.dist export-ignore
9+
/.scrutinizer.yml export-ignore
10+
/tests export-ignore

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/vendor
2+
build
3+
composer.phar
4+
composer.lock

.scrutinizer.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
filter:
2+
excluded_paths: [tests/*]
3+
4+
checks:
5+
php:
6+
remove_extra_empty_lines: true
7+
remove_php_closing_tag: true
8+
remove_trailing_whitespace: true
9+
fix_use_statements:
10+
remove_unused: true
11+
preserve_multiple: false
12+
preserve_blanklines: true
13+
order_alphabetically: true
14+
fix_php_opening_tag: true
15+
fix_linefeed: true
16+
fix_line_ending: true
17+
fix_identation_4spaces: true
18+
fix_doc_comments: true
19+
20+
tools:
21+
external_code_coverage: true

.styleci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
preset: laravel
2+
3+
linting: true

.travis.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
language: php
2+
3+
php:
4+
- 5.6
5+
- 7.0
6+
- 7.1
7+
8+
env:
9+
matrix:
10+
- COMPOSER_FLAGS="--prefer-lowest"
11+
- COMPOSER_FLAGS=""
12+
13+
before_script:
14+
- travis_retry composer self-update
15+
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-source
16+
17+
script:
18+
- phpunit --coverage-text --coverage-clover=coverage.clover
19+
20+
after_script:
21+
- wget https://scrutinizer-ci.com/ocular.phar
22+
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Changelog
2+
3+
All Notable changes to `discord` will be documented in this file
4+
5+
## 1.0.0 - 201X-XX-XX
6+
7+
- initial release

CONTRIBUTING.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Contributing
2+
3+
Contributions are **welcome** and will be fully **credited**.
4+
5+
Please read and understand the contribution guide before creating an issue or pull request.
6+
7+
## Etiquette
8+
9+
This project is open source, and as such, the maintainers give their free time to build and maintain the source code
10+
held within. They make the code freely available in the hope that it will be of use to other developers. It would be
11+
extremely unfair for them to suffer abuse or anger for their hard work.
12+
13+
Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the
14+
world that developers are civilized and selfless people.
15+
16+
It's the duty of the maintainer to ensure that all submissions to the project are of sufficient
17+
quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used.
18+
19+
## Viability
20+
21+
When requesting or submitting new features, first consider whether it might be useful to others. Open
22+
source projects are used by many developers, who may have entirely different needs to your own. Think about
23+
whether or not your feature is likely to be used by other users of the project.
24+
25+
## Procedure
26+
27+
Before filing an issue:
28+
29+
- Attempt to replicate the problem, to ensure that it wasn't a coincidental incident.
30+
- Check to make sure your feature suggestion isn't already present within the project.
31+
- Check the pull requests tab to ensure that the bug doesn't have a fix in progress.
32+
- Check the pull requests tab to ensure that the feature isn't already in progress.
33+
34+
Before submitting a pull request:
35+
36+
- Check the codebase to ensure that your feature doesn't already exist.
37+
- Check the pull requests to ensure that another person hasn't already submitted the feature or fix.
38+
39+
## Requirements
40+
41+
If the project maintainer has any additional requirements, you will find them listed here.
42+
43+
- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer).
44+
45+
- **Add tests!** - Your patch won't be accepted if it doesn't have tests.
46+
47+
- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
48+
49+
- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option.
50+
51+
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
52+
53+
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.
54+
55+
**Happy coding**!

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# The MIT License (MIT)
2+
3+
Copyright (c) Cody Scott <[email protected]>
4+
5+
> Permission is hereby granted, free of charge, to any person obtaining a copy
6+
> of this software and associated documentation files (the "Software"), to deal
7+
> in the Software without restriction, including without limitation the rights
8+
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
> copies of the Software, and to permit persons to whom the Software is
10+
> furnished to do so, subject to the following conditions:
11+
>
12+
> The above copyright notice and this permission notice shall be included in
13+
> all copies or substantial portions of the Software.
14+
>
15+
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
> THE SOFTWARE.

README.md

Lines changed: 163 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,163 @@
1-
# new-channels
2-
Submit pull requests here for new notification channels
1+
# Discord notification channel for Laravel 5.3 [WIP]
2+
3+
[![Latest Version on Packagist](https://img.shields.io/packagist/v/laravel-notification-channels/discord.svg?style=flat-square)](https://packagist.org/packages/laravel-notification-channels/discord)
4+
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
5+
[![Build Status](https://img.shields.io/travis/laravel-notification-channels/discord/master.svg?style=flat-square)](https://travis-ci.org/laravel-notification-channels/discord)
6+
[![StyleCI](https://styleci.io/repos/:style_ci_id/shield)](https://styleci.io/repos/:style_ci_id)
7+
[![SensioLabsInsight](https://img.shields.io/sensiolabs/i/:sensio_labs_id.svg?style=flat-square)](https://insight.sensiolabs.com/projects/:sensio_labs_id)
8+
[![Quality Score](https://img.shields.io/scrutinizer/g/laravel-notification-channels/discord.svg?style=flat-square)](https://scrutinizer-ci.com/g/laravel-notification-channels/discord)
9+
[![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)
10+
[![Total Downloads](https://img.shields.io/packagist/dt/laravel-notification-channels/discord.svg?style=flat-square)](https://packagist.org/packages/laravel-notification-channels/discord)
11+
12+
This package makes it easy to send notifications using the [Discord bot API](https://discordapp.com/developers/docs/intro) with Laravel 5.3.
13+
14+
## Contents
15+
16+
- [Installation](#installation)
17+
- [Setting up your Discord bot](#setting-up-your-discord-bot)
18+
- [Usage](#usage)
19+
- [Available Message methods](#available-message-methods)
20+
- [Changelog](#changelog)
21+
- [Testing](#testing)
22+
- [Security](#security)
23+
- [Contributing](#contributing)
24+
- [Credits](#credits)
25+
- [License](#license)
26+
27+
28+
## Installation
29+
30+
You can install the package via composer:
31+
32+
`composer require laravel-notification-channels/discord`
33+
34+
Next, you must load the service provider:
35+
36+
```php
37+
// config/app.php
38+
'providers' => [
39+
// ...
40+
NotificationChannels\Discord\DiscordServiceProvider::class,
41+
]
42+
```
43+
44+
### Setting up your Discord bot
45+
46+
1. [Create a Discord application.](https://discordapp.com/developers/applications/me/create)
47+
2. Click the `Create a Bot User` button on your Discord application.
48+
3. Paste your bot's API token, found under `App Bot User`, in your `services.php` config file:
49+
50+
```php
51+
// config/services.php
52+
'discord' => [
53+
'token' => 'YOUR_API_TOKEN',
54+
],
55+
```
56+
57+
4. Add the bot to your server and identify it by running the artisan command:
58+
59+
```shell
60+
php artisan discord:setup
61+
```
62+
63+
## Usage
64+
65+
In every model you wish to be notifiable via Discord, you must add a channel ID property to that model accessible through a `routeNotificationForDiscord` method:
66+
67+
```php
68+
class Guild extends Eloquent
69+
{
70+
use Notifiable;
71+
72+
public function routeNotificationForPushover()
73+
{
74+
return $this->discord_channel;
75+
}
76+
}
77+
```
78+
79+
> **NOTE**: Discord handles direct messages as though they are a regular channel. If you wish to allow users to receive direct messages from your bot, you will need to create a private channel with that user.
80+
> An example workflow may look like the following:
81+
>
82+
> 1. Your `users` table has two discord columns: `discord_user` and `discord_channel`
83+
> 2. When a user updates their Discord user ID (`discord_user`), generate and save a channel ID (`discord_channel`)
84+
> 3. Return the user's `discord_channel` in the `routeNotificationForDiscord` method on the User model
85+
>
86+
> You can generate direct message channels by using the `getPrivateChannel` method in `NotificationChannels\Discord\Discord`:
87+
>
88+
> ```php
89+
> use NotificationChannels\Discord\Discord;
90+
> // ...
91+
>
92+
> class UserDiscordSettingsController
93+
> {
94+
> public function store(Request $request)
95+
> {
96+
> $user = $request->input('discord_user');
97+
> $channel = app(Discord::class)->getPrivateChannel($user);
98+
>
99+
> Auth::user()->update([
100+
> 'discord_user' => $user,
101+
> 'discord_channel' => $channel,
102+
> ]);
103+
> }
104+
> }
105+
> ```
106+
107+
You may now tell Laravel to send notifications to Discord channels in the `via` method:
108+
109+
```php
110+
class GameChallengeNotification extends Notification
111+
{
112+
public $channelger;
113+
114+
public $game;
115+
116+
public function __construct(Guild $challenger, Game $game)
117+
{
118+
$this->challenger = $challenger;
119+
$this->game = $game;
120+
}
121+
public function via($notifiable)
122+
{
123+
return [DiscordChannel::class];
124+
}
125+
126+
public function toDiscord($notifiable)
127+
{
128+
return (new DiscordMessage)
129+
->body("You have been challenged to a game of *{$this->game->name}* by **{$this->channelger->name}**!");
130+
}
131+
}
132+
```
133+
134+
### Available Message methods
135+
136+
* `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-))
137+
138+
## Changelog
139+
140+
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
141+
142+
## Testing
143+
144+
``` bash
145+
$ composer test
146+
```
147+
148+
## Security
149+
150+
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
151+
152+
## Contributing
153+
154+
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
155+
156+
## Credits
157+
158+
- [Cody Scott](https://github.com/cs475x)
159+
- [All Contributors](../../contributors)
160+
161+
## License
162+
163+
The MIT License (MIT). Please see [LICENSE](LICENSE.md) for more information.

0 commit comments

Comments
 (0)