Skip to content

Commit

Permalink
Merge pull request #180 from HanashiDev/next
Browse files Browse the repository at this point in the history
Next
  • Loading branch information
Hanashi authored Nov 12, 2023
2 parents cee2464 + 3481da4 commit b53a33d
Show file tree
Hide file tree
Showing 31 changed files with 96 additions and 88 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codestyle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Set up node.js
uses: actions/setup-node@v3
with:
node-version: "16"
node-version: "18"
cache: "npm"
- run: npm install
- name: Run prettier
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18

- name: Create package
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/typescript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Set up node.js
uses: actions/setup-node@v3
with:
node-version: "16"
node-version: "18"
cache: "npm"
- run: npm install
- run: npx tsc --noEmit
Expand All @@ -29,7 +29,7 @@ jobs:
- name: Set up node.js
uses: actions/setup-node@v3
with:
node-version: "16"
node-version: "18"
cache: "npm"
- run: npm install
- run: npx eslint .
6 changes: 3 additions & 3 deletions files/lib/acp/form/DiscordBotAddForm.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected function createForm()
$requestData = $this->form->getRequestData();
$botToken = $requestData['botToken'];

if ($this->formAction == 'edit' && empty($botToken)) {
if ($this->formAction == 'edit' && $botToken === '') {
$botToken = $this->formObject->botToken;
}

Expand All @@ -94,10 +94,10 @@ protected function createForm()
));
}

if (!empty($guild['body']['name'])) {
if (isset($guild['body']['name']) && $guild['body']['name'] !== '') {
$this->guildName = $guild['body']['name'];
}
if (!empty($guild['body']['icon'])) {
if (isset($guild['body']['icon']) && $guild['body']['icon'] !== '') {
$this->guildIcon = $guild['body']['icon'];
}
})),
Expand Down
4 changes: 2 additions & 2 deletions files/lib/acp/form/DiscordBotAddManagerForm.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ protected function createFormStep1()

$discord = new DiscordApi(0, $botToken);
$bot = $discord->getCurrentUser();
if (empty($bot['body']['id'])) {
if (!isset($bot['body']['id'])) {
$formField->addValidationError(new FormFieldValidationError(
'invalidBotToken',
'wcf.acp.discordBotAddManager.botToken.invalid'
Expand Down Expand Up @@ -195,7 +195,7 @@ function (SingleSelectionFormField $formField) {
$requestData = $this->form->getRequestData();
$discord = new DiscordApi($guildID, $requestData['botToken']);
$guild = $discord->getGuild();
if (empty($guild['body']['id'])) {
if (!isset($guild['body']['id'])) {
$formField->addValidationError(new FormFieldValidationError(
'invalidGuild',
'wcf.acp.discordBotAddManager.guildID.invalid'
Expand Down
6 changes: 3 additions & 3 deletions files/lib/action/AbstractDiscordInteractionAction.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function execute()
try {
$serverRequest = ServerRequest::fromGlobals();
$body = (string)$serverRequest->getBody();
if (empty($body)) {
if ($body === '') {
throw new BadMethodCallException('body is empty');
}
$data = [];
Expand All @@ -34,7 +34,7 @@ public function execute()
}

$publicKeys = $this->getPublicKeys();
if (empty($publicKeys)) {
if ($publicKeys === []) {
throw new UnexpectedValueException('public key is empty');
}

Expand All @@ -49,7 +49,7 @@ public function execute()
throw new OutOfBoundsException('invalid request signature');
}

if (empty($data['type'])) {
if (!isset($data['type'])) {
throw new BadMethodCallException('type is empty');
}

Expand Down
2 changes: 1 addition & 1 deletion files/lib/action/DiscordInteractionAction.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use wcf\system\discord\event\ModalCommandReceived;
use wcf\system\event\EventHandler;

class DiscordInteractionAction extends AbstractDiscordInteractionAction
final class DiscordInteractionAction extends AbstractDiscordInteractionAction
{
public function handleApplicationCommand(array $data)
{
Expand Down
2 changes: 1 addition & 1 deletion files/lib/data/discord/bot/DiscordBot.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* @property-read string|null $publicKey
* @property-read int $botTime
*/
class DiscordBot extends DatabaseObject
final class DiscordBot extends DatabaseObject
{
/**
* @inheritDoc
Expand Down
12 changes: 6 additions & 6 deletions files/lib/data/discord/bot/DiscordBotAction.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @method DiscordBotEditor[] getObjects()
* @method DiscordBotEditor getSingleObject()
*/
class DiscordBotAction extends AbstractDatabaseObjectAction
final class DiscordBotAction extends AbstractDatabaseObjectAction
{
/**
* @inheritDoc
Expand Down Expand Up @@ -56,18 +56,18 @@ public function create()
*/
public function update()
{
if (isset($this->parameters['data']['botToken']) && empty($this->parameters['data']['botToken'])) {
if (isset($this->parameters['data']['botToken']) && $this->parameters['data']['botToken'] === '') {
unset($this->parameters['data']['botToken']);
}
if (isset($this->parameters['data']['clientSecret']) && empty($this->parameters['data']['clientSecret'])) {
if (isset($this->parameters['data']['clientSecret']) && $this->parameters['data']['clientSecret'] === '') {
unset($this->parameters['data']['clientSecret']);
}

parent::update();

foreach ($this->getObjects() as $object) {
if (isset($this->parameters['webhookIcon']) && \is_array($this->parameters['webhookIcon'])) {
if (empty($this->parameters['webhookIcon'])) {
if ($this->parameters['webhookIcon'] === '') {
$filename = \sprintf('%simages/discord_webhook/%s.png', WCF_DIR, $object->botID);
if (\file_exists($filename)) {
\unlink($filename);
Expand Down Expand Up @@ -120,7 +120,7 @@ protected function processWebhookIcon(int $botID)
*/
public function validateGetBotToken()
{
if (\is_array($this->permissionsGetBotToken) && !empty($this->permissionsGetBotToken)) {
if (\is_array($this->permissionsGetBotToken) && $this->permissionsGetBotToken !== []) {
WCF::getSession()->checkPermissions($this->permissionsGetBotToken);
} else {
throw new PermissionDeniedException();
Expand All @@ -134,7 +134,7 @@ public function validateGetBotToken()
*/
public function getBotToken()
{
if (empty($this->parameters['data']['botID'])) {
if (!isset($this->parameters['data']['botID'])) {
throw new AJAXException('invalid bot id');
}
$botID = $this->parameters['data']['botID'];
Expand Down
2 changes: 1 addition & 1 deletion files/lib/data/discord/bot/DiscordBotEditor.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* @method DiscordBot getDecoratedObject()
* @mixin DiscordBot
*/
class DiscordBotEditor extends DatabaseObjectEditor
final class DiscordBotEditor extends DatabaseObjectEditor
{
/**
* @inheritDoc
Expand Down
2 changes: 1 addition & 1 deletion files/lib/data/discord/bot/DiscordBotList.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
* @method DiscordBot|null search($objectID)
* @property DiscordBot[] $objects
*/
class DiscordBotList extends DatabaseObjectList
final class DiscordBotList extends DatabaseObjectList
{
}
2 changes: 1 addition & 1 deletion files/lib/data/discord/webhook/DiscordWebhook.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* @property-read string $usageBy
* @property-read int $webhookTime
*/
class DiscordWebhook extends DatabaseObject
final class DiscordWebhook extends DatabaseObject
{
/**
* @inheritDoc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @method DiscordWebhookEditor[] getObjects()
* @method DiscordWebhookEditor getSingleObject()
*/
class DiscordWebhookAction extends AbstractDatabaseObjectAction
final class DiscordWebhookAction extends AbstractDatabaseObjectAction
{
/**
* @inheritDoc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* @method DiscordWebhook getDecoratedObject()
* @mixin DiscordWebhook
*/
class DiscordWebhookEditor extends DatabaseObjectEditor
final class DiscordWebhookEditor extends DatabaseObjectEditor
{
/**
* @inheritDoc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
* @method DiscordWebhook|null search($objectID)
* @property DiscordWebhook[] $objects
*/
class DiscordWebhookList extends DatabaseObjectList
final class DiscordWebhookList extends DatabaseObjectList
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @license Freie Lizenz (https://hanashi.dev/freie-lizenz/)
* @package WoltLabSuite\Core\System\Cache\Builder
*/
class DiscordCurrentGuildsCacheBuilder extends AbstractCacheBuilder
final class DiscordCurrentGuildsCacheBuilder extends AbstractCacheBuilder
{
/**
* @inheritDoc
Expand All @@ -24,16 +24,16 @@ class DiscordCurrentGuildsCacheBuilder extends AbstractCacheBuilder
*/
public function rebuild(array $parameters)
{
if (empty($parameters['botToken'])) {
if (!isset($parameters['botToken']) || $parameters['botToken'] === '') {
return [];
}
$discord = new DiscordApi(0, $parameters['botToken']);

$currentUserGuilds = $discord->getCurrentUserGuilds();
if (
!isset($currentUserGuilds['body'])
|| \count($currentUserGuilds['body'])
&& empty($currentUserGuilds['body'][0])
|| !\is_array($currentUserGuilds['body'])
|| $currentUserGuilds['body'] === []
) {
return [];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @license Freie Lizenz (https://hanashi.dev/freie-lizenz/)
* @package WoltLabSuite\Core\System\Cache\Builder
*/
class DiscordGuildChannelCacheBuilder extends AbstractCacheBuilder
final class DiscordGuildChannelCacheBuilder extends AbstractCacheBuilder
{
/**
* @inheritDoc
Expand All @@ -24,7 +24,12 @@ class DiscordGuildChannelCacheBuilder extends AbstractCacheBuilder
*/
public function rebuild(array $parameters)
{
if (empty($parameters['guildID']) || empty($parameters['botToken'])) {
if (
!isset($parameters['guildID'])
|| !isset($parameters['botToken'])
|| $parameters['guildID'] === ''
|| $parameters['botToken'] === ''
) {
return [];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @license Freie Lizenz (https://hanashi.dev/freie-lizenz/)
* @package WoltLabSuite\Core\System\Cache\Runtime
*/
class DiscordBotRuntimeCache extends AbstractRuntimeCache
final class DiscordBotRuntimeCache extends AbstractRuntimeCache
{
/**
* @inheritDoc
Expand Down
8 changes: 4 additions & 4 deletions files/lib/system/cronjob/DiscordApiRefresherCronjob.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* @license Freie Lizenz (https://hanashi.dev/freie-lizenz/)
* @package WoltLabSuite\Core\System\Cronjob
*/
class DiscordApiRefresherCronjob extends AbstractCronjob
final class DiscordApiRefresherCronjob extends AbstractCronjob
{
/**
* @inheritDoc
Expand Down Expand Up @@ -47,7 +47,7 @@ protected function refreshWebhooks()
}

$webhookName = $discordWebhook->webhookName;
if (!empty($webhook['body']['name'])) {
if (isset($webhook['body']['name']) && $webhook['body']['name'] !== '') {
$webhookName = $webhook['body']['name'];
}
$action = new DiscordWebhookAction([$discordWebhook], 'update', [
Expand All @@ -74,10 +74,10 @@ protected function refreshGuilds()

$guildName = $discordBot->guildName;
$guildIcon = $discordBot->guildIcon;
if (!empty($guild['body']['name'])) {
if (isset($guild['body']['name']) && $guild['body']['name'] !== '') {
$guildName = $guild['body']['name'];
}
if (!empty($guild['body']['icon'])) {
if (isset($guild['body']['icon']) && $guild['body']['icon'] !== '') {
$guildIcon = $guild['body']['icon'];
}

Expand Down
Loading

0 comments on commit b53a33d

Please sign in to comment.