Skip to content

Commit

Permalink
Improve docs (#1015) build docs
Browse files Browse the repository at this point in the history
* update workflow php version build docs

* update readme.md

* comment spacing

* Update README.md

* curly bracket inheritdoc

* change @see self:: to Class::

* return self

* correct return type hinting static and self and $this

* phpdoc description

* another description fix

* more description

* ran php cs fixer

* update README.md
  • Loading branch information
SQKo authored Dec 13, 2022
1 parent e7e0ee5 commit 589f147
Show file tree
Hide file tree
Showing 174 changed files with 726 additions and 652 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.0'
extensions: iconv
tools: phive
- name: Install phpDocumentor
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ jobs:
strategy:
matrix:
php:
- '8.2'
- '8.1'
- '8.0'
- '7.4'
steps:
- name: Checkout code
uses: actions/checkout@v2
Expand Down
61 changes: 29 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,67 +1,60 @@
DiscordPHP
====
[![Latest Stable Version](https://poser.pugx.org/team-reflex/discord-php/v)](https://packagist.org/packages/team-reflex/discord-php) [![Total Downloads](https://poser.pugx.org/team-reflex/discord-php/downloads)](https://packagist.org/packages/team-reflex/discord-php) [![PHP Version Require](https://poser.pugx.org/team-reflex/discord-php/require/php)](https://packagist.org/packages/team-reflex/discord-php)
[![Latest Stable Version](https://poser.pugx.org/team-reflex/discord-php/v)](https://packagist.org/packages/team-reflex/discord-php) [![Latest Unstable Version](http://poser.pugx.org/team-reflex/discord-php/v/unstable)](https://packagist.org/packages/team-reflex/discord-php) [![Total Downloads](https://poser.pugx.org/team-reflex/discord-php/downloads)](https://packagist.org/packages/team-reflex/discord-php) [![PHP Version Require](https://poser.pugx.org/team-reflex/discord-php/require/php)](https://packagist.org/packages/team-reflex/discord-php)

[![PHP Discorders](https://discord.com/api/guilds/115233111977099271/widget.png?style=banner1)](https://discord.gg/dphp)

A wrapper for the official [Discord](https://discordapp.com) REST, gateway and voice APIs. Documentation is [available here](http://discord-php.github.io/DiscordPHP), albeit limited at the moment, as well as a class reference. Feel free to ask questions in the Discord server above.

For testing and stability it would be greatly appreciated if you were able to add our test bot to your server. We don't store any data - the bot simply idles and does not interact with anyone and is used to test stability with large numbers of guilds. You can invite the bot [here.](https://discord.com/oauth2/authorize?client_id=157746770539970560&scope=bot)

## CacheInterface (experimental)
> Warning: This branch contains an experimental feature, do not use this in production! Create issues or join our Discord for feedback and discussions.
See [the wiki page for more information](https://github.com/discord-php/DiscordPHP/wiki/Cache-Interface) on how to set it up

## Before you start

Before you start using this Library, you **need** to know how PHP works, you need to know the language and you need to know how Event Loops and Promises work. This is a fundamental requirement before you start. Without this knowledge, you will only suffer.
## Cache Interface (experimental)
> **Warning**
> This branch contains an experimental feature, do not use it in production! See [the wiki page for more information](https://github.com/discord-php/DiscordPHP/wiki/Cache-Interface) on how to set it up.
## FAQ

1. Can I run DiscordPHP on a webserver (e.g. Apache, nginx)?
- No, DiscordPHP will only run in CLI. If you want to have an interface for your bot you can integrate [react/http](https://github.com/ReactPHP/http) with your bot and run it through CLI.
2. PHP is running out of memory?
- Try increase your memory limit using `ini_set('memory_limit', '-1');`.
- Try unlimit your PHP memory using `ini_set('memory_limit', '-1');`.

## Getting Started

Before you start using this Library, you **need** to know how PHP works, you need to know how Event Loops and Promises work. This is a fundamental requirement before you start. Without this knowledge, you will only suffer.

### Requirements

- PHP 8.0
- x86 (32-bit) PHP requires [`ext-gmp` extension](https://www.php.net/manual/en/book.gmp.php) enabled.
- Composer
- `ext-json`
- `ext-zlib`
- [PHP 8.0](https://php.net) or higher (latest version recommended)
- x86 (32-bit) PHP requires [`ext-gmp`](https://www.php.net/manual/en/book.gmp.php) enabled.
- [`ext-json`](https://www.php.net/manual/en/book.json.php)
- [`ext-zlib`](https://www.php.net/manual/en/book.zlib.php)

### Windows and SSL
#### Recommended Extensions

Unfortunately PHP on Windows does not have access to the Windows Certificate Store. This is an issue because TLS gets used and as such certificate verification gets applied (turning this off is **not** an option).
- One of [`ext-uv`](https://github.com/amphp/ext-uv) (recommended), `ext-libev` or `ext-event` for a faster, and more performant event loop.
- [`ext-mbstring`](https://www.php.net/manual/en/book.mbstring.php) if handling non-latin characters.

You will notice this issue by your script exiting immediately after one loop turn without any errors. Unfortunately there is for some reason no error or exception.
#### Voice Requirements

As such users of this library need to download a [Certificate Authority extract](https://curl.haxx.se/docs/caextract.html) from the cURL website.<br>
The path to the caextract must be set in the [`php.ini`](https://secure.php.net/manual/en/openssl.configuration.php) for `openssl.cafile`.
- 64-bit PHP
- [`ext-sodium`](https://www.php.net/manual/en/book.sodium.php)
- [FFmpeg](https://ffmpeg.org/)

#### Recommended Extensions
### Windows and SSL

- The latest PHP version.
- One of `ext-uv` (recommended), `ext-libev` or `ext-event` for a faster, and more performant event loop.
- `ext-mbstring` if handling non-english characters.
- `ext-gmp` if using 32-bit PHP.
Unfortunately PHP on Windows does not have access to the Windows Certificate Store. This is an issue because TLS gets used and as such certificate verification gets applied (turning this off is **not** an option).

#### Voice Requirements
You will notice this issue by your script exiting immediately after one loop turn without any errors.

- 64-bit Linux or Darwin based OS.
- If you are running on Windows, you must be using PHP 8.0.
- `ext-sodium`
- FFmpeg
As such users of this library need to download a [Certificate Authority extract](https://curl.haxx.se/docs/caextract.html) from the cURL website.<br>
The path to the caextract must be set in the [`php.ini`](https://secure.php.net/manual/en/openssl.configuration.php) for `openssl.cafile`.

### Installing DiscordPHP

DiscordPHP is installed using [Composer](https://getcomposer.org).

1. Run `composer require team-reflex/discord-php`. This will install the latest release.
1. Run `composer require team-reflex/discord-php`. This will install the latest stable release.
- If you would like, you can also install the development branch by running `composer require team-reflex/discord-php dev-master`.
2. Include the Composer autoload file at the top of your main file:
- `include __DIR__.'/vendor/autoload.php';`
Expand All @@ -76,10 +69,13 @@ include __DIR__.'/vendor/autoload.php';

use Discord\Discord;
use Discord\Parts\Channel\Message;
use Discord\WebSockets\Intents;
use Discord\WebSockets\Event;

$discord = new Discord([
'token' => 'bot-token',
'intents' => Intents::getDefaultIntents()
// | Intents::MESSAGE_CONTENT, // Note: MESSAGE_CONTENT is privileged, see https://dis.gd/mcfaq
]);

$discord->on('ready', function (Discord $discord) {
Expand All @@ -88,6 +84,7 @@ $discord->on('ready', function (Discord $discord) {
// Listen for messages.
$discord->on(Event::MESSAGE_CREATE, function (Message $message, Discord $discord) {
echo "{$message->author->username}: {$message->content}", PHP_EOL;
// Note: MESSAGE_CONTENT intent must be enabled to get the content if the bot is not mentioned/DMed.
});
});

Expand All @@ -98,7 +95,7 @@ See [examples folder](examples) for more.

## Documentation

Documentation can be found [here](//discord-php.github.io/DiscordPHP/guide). Raw documentation can be found in-line in the code. Community contributed tutorials can be found on the [wiki](//github.com/discord-php/DiscordPHP/wiki).
Documentation for the latest version can be found [here](//discord-php.github.io/DiscordPHP/guide). Community contributed tutorials can be found on the [wiki](//github.com/discord-php/DiscordPHP/wiki).

## Contributing

Expand Down
24 changes: 12 additions & 12 deletions src/Discord/Builders/CommandAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ trait CommandAttributes
*
* @throws \InvalidArgumentException `$type` is not 1-3.
*
* @return self
* @return $this
*/
public function setType(int $type): self
{
Expand All @@ -65,7 +65,7 @@ public function setType(int $type): self
* @throws \LengthException `$name` is not 1-32 characters long.
* @throws \DomainException `$name` contains invalid characters.
*
* @return self
* @return $this
*/
public function setName(string $name): self
{
Expand Down Expand Up @@ -94,7 +94,7 @@ public function setName(string $name): self
* @throws \LengthException `$name` is not 1-32 characters long.
* @throws \DomainException `$name` contains invalid characters.
*
* @return self
* @return $this
*/
public function setNameLocalization(string $locale, ?string $name): self
{
Expand Down Expand Up @@ -125,7 +125,7 @@ public function setNameLocalization(string $locale, ?string $name): self
*
* @throws \LengthException `$description` is not 1-100 characters long.
*
* @return self
* @return $this
*/
public function setDescription(string $description): self
{
Expand All @@ -149,7 +149,7 @@ public function setDescription(string $description): self
*
* @throws \LengthException `$description` is not 1-100 characters long.
*
* @return self
* @return $this
*/
public function setDescriptionLocalization(string $locale, ?string $description): self
{
Expand All @@ -171,7 +171,7 @@ public function setDescriptionLocalization(string $locale, ?string $description)
*
* @param ?bool $permission Default permission of the command
*
* @return self
* @return $this
*/
public function setDefaultPermission(?bool $permission): self
{
Expand All @@ -185,7 +185,7 @@ public function setDefaultPermission(?bool $permission): self
*
* @param string|int $permissions Default member permission bits of the command.
*
* @return self
* @return $this
*/
public function setDefaultMemberPermissions($permissions): self
{
Expand All @@ -199,7 +199,7 @@ public function setDefaultMemberPermissions($permissions): self
*
* @param bool $permission DM permission of the command.
*
* @return self
* @return $this
*/
public function setDmPermission(bool $permission): self
{
Expand All @@ -213,7 +213,7 @@ public function setDmPermission(bool $permission): self
*
* @param bool $restricted Age restriction of the command.
*
* @return self
* @return $this
*/
public function setNsfw(bool $restricted): self
{
Expand All @@ -230,7 +230,7 @@ public function setNsfw(bool $restricted): self
* @throws \DomainException Command type is not CHAT_INPUT (1).
* @throws \OverflowException Command exceeds maximum 25 options.
*
* @return self
* @return $this
*/
public function addOption(Option $option): self
{
Expand All @@ -256,7 +256,7 @@ public function addOption(Option $option): self
*
* @throws \DomainException Command type is not CHAT_INPUT (1).
*
* @return self
* @return $this
*/
public function removeOption(Option $option): self
{
Expand All @@ -274,7 +274,7 @@ public function removeOption(Option $option): self
/**
* Clear all options from the command.
*
* @return self
* @return $this
*/
public function clearOptions(): self
{
Expand Down
4 changes: 2 additions & 2 deletions src/Discord/Builders/CommandBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class CommandBuilder implements JsonSerializable
/**
* Creates a new command builder.
*
* @return self
* @return static
*/
public static function new(): self
{
Expand Down Expand Up @@ -111,7 +111,7 @@ public function toArray(): array
}

/**
* @inheritDoc
* {@inheritDoc}
*/
public function jsonSerialize(): array
{
Expand Down
11 changes: 6 additions & 5 deletions src/Discord/Builders/Components/ActionRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
namespace Discord\Builders\Components;

/**
* An Action Row is a non-interactive container component for other types of components.
* An Action Row is a non-interactive container component for other types of
* components.
* It has a type: 1 and a sub-array of components of other types.
*
* @link https://discord.com/developers/docs/interactions/message-components#action-rows
Expand Down Expand Up @@ -46,7 +47,7 @@ public static function new(): self
* @throws \InvalidArgumentException
* @throws \OverflowException
*
* @return self
* @return $this
*/
public function addComponent(Component $component): self
{
Expand All @@ -72,7 +73,7 @@ public function addComponent(Component $component): self
*
* @param Component $component Component to remove.
*
* @return self
* @return $this
*/
public function removeComponent(Component $component): self
{
Expand All @@ -86,7 +87,7 @@ public function removeComponent(Component $component): self
/**
* Removes all components from the action row.
*
* @return self
* @return $this
*/
public function clearComponents(): self
{
Expand All @@ -106,7 +107,7 @@ public function getComponents(): array
}

/**
* @inheritDoc
* {@inheritDoc}
*/
public function jsonSerialize(): array
{
Expand Down
Loading

0 comments on commit 589f147

Please sign in to comment.