Primer commit del sistema separado falta mejorar mucho

This commit is contained in:
nickpons666
2025-12-30 01:18:46 -06:00
commit 1679c73e52
2384 changed files with 472342 additions and 0 deletions

3
vendor/discord/interactions/.gitignore vendored Executable file
View File

@@ -0,0 +1,3 @@
composer.phar
composer.lock
vendor

46
vendor/discord/interactions/README.md vendored Executable file
View 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
View 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"
}
}

View 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;
}
}

View File

@@ -0,0 +1,8 @@
<?php
namespace Discord;
abstract class InteractionResponseFlags {
const EPHEMERAL = 1 << 6;
}

View 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;
}

View 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;
}

View 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";
}