Skip to content

Commit

Permalink
Merge pull request #161 from HanashiDev/sensitive-parameter
Browse files Browse the repository at this point in the history
SensitiveParameter eingebaut
  • Loading branch information
Hanashi authored Sep 8, 2023
2 parents bac7209 + 929ef2b commit 43302fd
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ jobs:
fail-fast: false
matrix:
php:
- '8.0'
- '8.1'
- '8.2'
steps:
- name: Set up PHP
uses: shivammathur/setup-php@v2
Expand Down
132 changes: 100 additions & 32 deletions files/lib/system/discord/DiscordApi.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use GuzzleHttp\RequestOptions;
use Laminas\Diactoros\Uri;
use Psr\Http\Message\ResponseInterface;
use SensitiveParameter;
use wcf\data\discord\bot\DiscordBot;
use wcf\system\io\HttpFactory;
use wcf\util\JSON;
Expand Down Expand Up @@ -185,8 +186,12 @@ class DiscordApi
* @param string $botToken Geheimer Schlüssel des Discord-Bots
* @param string $botType Bot-Typ
*/
public function __construct($guildID, $botToken, $botType = 'Bot')
{
public function __construct(
$guildID,
#[SensitiveParameter]
$botToken,
$botType = 'Bot'
) {
$this->guildID = $guildID;
$this->botToken = $botToken;
$this->botType = $botType;
Expand Down Expand Up @@ -433,8 +438,12 @@ public function bulkOverwriteGuildApplicationCommands($applicationID, $guildID)
* @param array $params
* @return array
*/
public function createInteractionResponse($interactionID, $interactionToken, $params)
{
public function createInteractionResponse(
$interactionID,
#[SensitiveParameter]
$interactionToken,
$params
) {
$url = \sprintf('%s/interactions/%s/%s/callback', $this->apiUrl, $interactionID, $interactionToken);

return $this->execute($url, 'POST', $params, 'application/json');
Expand All @@ -447,8 +456,11 @@ public function createInteractionResponse($interactionID, $interactionToken, $pa
* @param string $interactionToken
* @return array
*/
public function getOriginalInteractionResponse($applicationID, $interactionToken)
{
public function getOriginalInteractionResponse(
$applicationID,
#[SensitiveParameter]
$interactionToken
) {
$url = \sprintf('%s/webhooks/%s/%s/messages/@original', $this->apiUrl, $applicationID, $interactionToken);

return $this->execute($url, 'GET');
Expand All @@ -462,8 +474,12 @@ public function getOriginalInteractionResponse($applicationID, $interactionToken
* @param array $params
* @return array
*/
public function editOriginalInteractionResponse($applicationID, $interactionToken, $params)
{
public function editOriginalInteractionResponse(
$applicationID,
#[SensitiveParameter]
$interactionToken,
$params
) {
$url = \sprintf('%s/webhooks/%s/%s/messages/@original', $this->apiUrl, $applicationID, $interactionToken);

return $this->execute($url, 'PATCH', $params, 'application/json');
Expand All @@ -476,8 +492,11 @@ public function editOriginalInteractionResponse($applicationID, $interactionToke
* @param string $interactionToken
* @return array
*/
public function deleteOriginalInteractionResponse($applicationID, $interactionToken)
{
public function deleteOriginalInteractionResponse(
$applicationID,
#[SensitiveParameter]
$interactionToken
) {
$url = \sprintf('%s/webhooks/%s/%s/messages/@original', $this->apiUrl, $applicationID, $interactionToken);

return $this->execute($url, 'DELETE');
Expand All @@ -493,8 +512,12 @@ public function deleteOriginalInteractionResponse($applicationID, $interactionTo
* @param array $params
* @return array
*/
public function createFollowupMessage($applicationID, $interactionToken, $params)
{
public function createFollowupMessage(
$applicationID,
#[SensitiveParameter]
$interactionToken,
$params
) {
$url = \sprintf('%s/webhooks/%s/%s', $this->apiUrl, $applicationID, $interactionToken);

return $this->execute($url, 'POST', $params, 'application/json');
Expand All @@ -509,8 +532,13 @@ public function createFollowupMessage($applicationID, $interactionToken, $params
* @param array $params
* @return array
*/
public function editFollowupMessage($applicationID, $interactionToken, $messageID, $params)
{
public function editFollowupMessage(
$applicationID,
#[SensitiveParameter]
$interactionToken,
$messageID,
$params
) {
$url = \sprintf('%s/webhooks/%s/%s/messages/%s', $this->apiUrl, $applicationID, $interactionToken, $messageID);

return $this->execute($url, 'PATCH', $params, 'application/json');
Expand All @@ -524,8 +552,12 @@ public function editFollowupMessage($applicationID, $interactionToken, $messageI
* @param integer $messageID
* @return array
*/
public function deleteFollowupMessage($applicationID, $interactionToken, $messageID)
{
public function deleteFollowupMessage(
$applicationID,
#[SensitiveParameter]
$interactionToken,
$messageID
) {
$url = \sprintf('%s/webhooks/%s/%s/messages/%s', $this->apiUrl, $applicationID, $interactionToken, $messageID);

return $this->execute($url, 'DELETE');
Expand Down Expand Up @@ -1709,8 +1741,12 @@ public function listGuildMembers($params = [])
* @param array $params Zusätzliche optionale Parameter
* @return array
*/
public function addGuildMember($userID, $accessToken, $params = [])
{
public function addGuildMember(
$userID,
#[SensitiveParameter]
$accessToken,
$params = []
) {
$url = \sprintf('%s/guilds/%s/members/%s', $this->apiUrl, $this->guildID, $userID);
$params = \array_merge([
'access_token' => $accessToken,
Expand Down Expand Up @@ -2866,8 +2902,11 @@ public function getWebhook($webhookID)
* @param string $webhookToken Token des Webhooks
* @return array
*/
public function getWebhookWithToken($webhookID, $webhookToken)
{
public function getWebhookWithToken(
$webhookID,
#[SensitiveParameter]
$webhookToken
) {
$url = \sprintf('%s/webhooks/%s/%s', $this->apiUrl, $webhookID, $webhookToken);

return $this->execute($url);
Expand Down Expand Up @@ -2898,8 +2937,12 @@ public function modifyWebhook($webhookID, $params)
* @param array $params Parameter
* @return array
*/
public function modifyWebhookWithToken($webhookID, $webhookToken, $params)
{
public function modifyWebhookWithToken(
$webhookID,
#[SensitiveParameter]
$webhookToken,
$params
) {
$url = \sprintf('%s/webhooks/%s/%s', $this->apiUrl, $webhookID, $webhookToken);

return $this->execute($url, 'PATCH', $params, 'application/json');
Expand Down Expand Up @@ -2927,8 +2970,11 @@ public function deleteWebhook($webhookID)
* @param string $webhookToken Token des Webhooks
* @return array
*/
public function deleteWebhookWithToken($webhookID, $webhookToken)
{
public function deleteWebhookWithToken(
$webhookID,
#[SensitiveParameter]
$webhookToken
) {
$url = \sprintf('%s/webhooks/%s/%s', $this->apiUrl, $webhookID, $webhookToken);

return $this->execute($url, 'DELETE');
Expand All @@ -2945,8 +2991,14 @@ public function deleteWebhookWithToken($webhookID, $webhookToken)
* does not return an error)
* @return array
*/
public function executeWebhook($webhookID, $webhookToken, $params, $wait = false, $threadID = null)
{
public function executeWebhook(
$webhookID,
#[SensitiveParameter]
$webhookToken,
$params,
$wait = false,
$threadID = null
) {
$url = new Uri(
\sprintf('%s/webhooks/%s/%s', $this->apiUrl, $webhookID, $webhookToken)
);
Expand Down Expand Up @@ -2983,8 +3035,13 @@ public function executeWebhook($webhookID, $webhookToken, $params, $wait = false
* does not return an error)
* @return array
*/
public function executeSlackCompatibleWebhook($webhookID, $webhookToken, $params, $wait = false)
{
public function executeSlackCompatibleWebhook(
$webhookID,
#[SensitiveParameter]
$webhookToken,
$params,
$wait = false
) {
$url = \sprintf('%s/webhooks/%s/%s/slack', $this->apiUrl, $webhookID, $webhookToken);

return $this->execute($url, 'POST', $params, 'application/json');
Expand All @@ -3003,8 +3060,13 @@ public function executeSlackCompatibleWebhook($webhookID, $webhookToken, $params
* does not return an error)
* @return array
*/
public function executeGithubCompatibleWebhook($webhookID, $webhookToken, $params, $wait = false)
{
public function executeGithubCompatibleWebhook(
$webhookID,
#[SensitiveParameter]
$webhookToken,
$params,
$wait = false
) {
$url = \sprintf('%s/webhooks/%s/%s/github', $this->apiUrl, $webhookID, $webhookToken);

return $this->execute($url, 'POST', $params, 'application/json');
Expand Down Expand Up @@ -3051,8 +3113,14 @@ public function oauth2Authorize($clientID, $scope, $redirectUri, $state = null)
* @param string $grantType Grant-Type (authorization_code, refresh_token, client_credentials)
* @return array
*/
public function oauth2Token($clientID, $clientSecret, $code, $redirectUri, $grantType = 'authorization_code')
{
public function oauth2Token(
$clientID,
#[SensitiveParameter]
$clientSecret,
$code,
$redirectUri,
$grantType = 'authorization_code'
) {
$url = \sprintf('%s/oauth2/token', $this->apiUrl);
$params = [
'client_id' => $clientID,
Expand Down

0 comments on commit 43302fd

Please sign in to comment.