Primer commit del sistema separado falta mejorar mucho
This commit is contained in:
3
vendor/discord/interactions/.gitignore
vendored
Executable file
3
vendor/discord/interactions/.gitignore
vendored
Executable file
@@ -0,0 +1,3 @@
|
||||
composer.phar
|
||||
composer.lock
|
||||
vendor
|
||||
46
vendor/discord/interactions/README.md
vendored
Executable file
46
vendor/discord/interactions/README.md
vendored
Executable file
@@ -0,0 +1,46 @@
|
||||
discord-interactions-php
|
||||
---
|
||||
|
||||
Types and helper functions that may come in handy when you implement a Discord Interactions webhook.
|
||||
|
||||
# Installation
|
||||
|
||||
Install from [packagist](https://packagist.org/packages/discord/interactions):
|
||||
|
||||
```
|
||||
composer require discord/interactions
|
||||
```
|
||||
|
||||
Validating request signatures requires the [`simplito/elliptic-php`](https://github.com/simplito/elliptic-php) package to be installed, which requires the `php-gmp` extension to be enabled:
|
||||
|
||||
```
|
||||
composer require simplito/elliptic-php
|
||||
```
|
||||
|
||||
# Usage
|
||||
|
||||
Use `InteractionType` and `InteractionResponseType` to interpret and respond to webhooks.
|
||||
|
||||
Use `InteractionResponseFlags` to make your response special.
|
||||
|
||||
Use `verifyKey` to check a request signature. Note you must install the `simplito/elliptic-php` package first. For example:
|
||||
|
||||
```php
|
||||
use Discord\Interaction;
|
||||
use Discord\InteractionResponseType;
|
||||
|
||||
$CLIENT_PUBLIC_KEY = getenv('CLIENT_PUBLIC_KEY');
|
||||
|
||||
$signature = $_SERVER['HTTP_X_SIGNATURE_ED25519'];
|
||||
$timestamp = $_SERVER['HTTP_X_SIGNATURE_TIMESTAMP'];
|
||||
$postData = file_get_contents('php://input');
|
||||
|
||||
if (Interaction::verifyKey($postData, $signature, $timestamp, $CLIENT_PUBLIC_KEY)) {
|
||||
echo json_encode(array(
|
||||
'type' => InteractionResponseType::PONG
|
||||
));
|
||||
} else {
|
||||
http_response_code(401);
|
||||
echo "Not verified";
|
||||
}
|
||||
```
|
||||
28
vendor/discord/interactions/composer.json
vendored
Executable file
28
vendor/discord/interactions/composer.json
vendored
Executable file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "discord/interactions",
|
||||
"description": "Utils for implementing the Discord Interactions API",
|
||||
"type": "library",
|
||||
"require-dev": {
|
||||
"simplito/elliptic-php": "^1.0"
|
||||
},
|
||||
"archive": {
|
||||
"exclude": ["!README.md", "!composer.json", "examples", "vendor"]
|
||||
},
|
||||
"license": "MIT",
|
||||
"keywords": ["discord"],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Ian Webster",
|
||||
"email": "ianw_php@ianww.com"
|
||||
}
|
||||
],
|
||||
"autoload": {
|
||||
"psr-4": {"Discord\\": "discord"}
|
||||
},
|
||||
"suggest": {
|
||||
"simplito/elliptic-php": "Required to validate interaction signatures."
|
||||
},
|
||||
"conflict": {
|
||||
"simplito/elliptic-php": "<1.0,>=1.1"
|
||||
}
|
||||
}
|
||||
19
vendor/discord/interactions/discord/Interaction.php
vendored
Executable file
19
vendor/discord/interactions/discord/Interaction.php
vendored
Executable file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Discord;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
class Interaction {
|
||||
public static function verifyKey($rawBody, $signature, $timestamp, $client_public_key) {
|
||||
if (! class_exists('\Elliptic\EdDSA')) {
|
||||
throw new RuntimeException('The `simplito/elliptic-php` package is required to validate interactions.');
|
||||
}
|
||||
|
||||
$ec = new \Elliptic\EdDSA('ed25519');
|
||||
$key = $ec->keyFromPublic($client_public_key, 'hex');
|
||||
|
||||
$message = array_merge(unpack('C*', $timestamp), unpack('C*', $rawBody));
|
||||
return $key->verify($message, $signature) == TRUE;
|
||||
}
|
||||
}
|
||||
8
vendor/discord/interactions/discord/InteractionResponseFlags.php
vendored
Executable file
8
vendor/discord/interactions/discord/InteractionResponseFlags.php
vendored
Executable file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Discord;
|
||||
|
||||
abstract class InteractionResponseFlags {
|
||||
const EPHEMERAL = 1 << 6;
|
||||
}
|
||||
|
||||
14
vendor/discord/interactions/discord/InteractionResponseType.php
vendored
Executable file
14
vendor/discord/interactions/discord/InteractionResponseType.php
vendored
Executable file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Discord;
|
||||
|
||||
abstract class InteractionResponseType {
|
||||
const PONG = 1;
|
||||
const CHANNEL_MESSAGE_WITH_SOURCE = 4;
|
||||
const DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE = 5;
|
||||
const DEFERRED_UPDATE_MESSAGE = 6;
|
||||
const UPDATE_MESSAGE = 7;
|
||||
const APPLICATION_COMMAND_AUTOCOMPLETE_RESULT = 8;
|
||||
const MODAL = 9;
|
||||
}
|
||||
|
||||
12
vendor/discord/interactions/discord/InteractionType.php
vendored
Executable file
12
vendor/discord/interactions/discord/InteractionType.php
vendored
Executable file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Discord;
|
||||
|
||||
abstract class InteractionType {
|
||||
const PING = 1;
|
||||
const APPLICATION_COMMAND = 2;
|
||||
const MESSAGE_COMPONENT = 3;
|
||||
const APPLICATION_COMMAND_AUTOCOMPLETE = 4;
|
||||
const MODAL_SUBMIT = 5;
|
||||
}
|
||||
|
||||
20
vendor/discord/interactions/examples/simple_example.php
vendored
Executable file
20
vendor/discord/interactions/examples/simple_example.php
vendored
Executable file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../DiscordInteraction.php';
|
||||
|
||||
use Discord\Interaction;
|
||||
use Discord\InteractionResponseType;
|
||||
|
||||
$CLIENT_PUBLIC_KEY = getenv('CLIENT_PUBLIC_KEY');
|
||||
|
||||
$signature = $_SERVER['HTTP_X_SIGNATURE_ED25519'];
|
||||
$timestamp = $_SERVER['HTTP_X_SIGNATURE_TIMESTAMP'];
|
||||
$postData = file_get_contents('php://input');
|
||||
|
||||
if (Interaction::verifyKey($postData, $signature, $timestamp, $CLIENT_PUBLIC_KEY)) {
|
||||
echo json_encode(array(
|
||||
'type' => InteractionResponseType::PONG
|
||||
));
|
||||
} else {
|
||||
http_response_code(401);
|
||||
echo "Not verified";
|
||||
}
|
||||
Reference in New Issue
Block a user