From 401db328ccd808c01f21a34f3a2a608854f69ef8 Mon Sep 17 00:00:00 2001 From: Peter Lohse Date: Thu, 3 Oct 2024 00:09:29 +0200 Subject: [PATCH] add rebuild worker --- .../bootstrap/dev.hanashi.wsc.discord-api.php | 9 +++ ...rdWebhookAvatarRebuildDataWorker.class.php | 57 +++++++++++++++++++ language/de.xml | 4 ++ language/en.xml | 4 ++ 4 files changed, 74 insertions(+) create mode 100644 files/lib/system/worker/DiscordWebhookAvatarRebuildDataWorker.class.php diff --git a/files/lib/bootstrap/dev.hanashi.wsc.discord-api.php b/files/lib/bootstrap/dev.hanashi.wsc.discord-api.php index 8bad4df..725d164 100644 --- a/files/lib/bootstrap/dev.hanashi.wsc.discord-api.php +++ b/files/lib/bootstrap/dev.hanashi.wsc.discord-api.php @@ -5,11 +5,13 @@ use wcf\acp\page\DiscordWebhookListPage; use wcf\event\acp\dashboard\box\PHPExtensionCollecting; use wcf\event\acp\menu\item\ItemCollecting; +use wcf\event\worker\RebuildWorkerCollecting; use wcf\system\event\EventHandler; use wcf\system\menu\acp\AcpMenuItem; use wcf\system\request\LinkHandler; use wcf\system\style\FontAwesomeIcon; use wcf\system\WCF; +use wcf\system\worker\DiscordWebhookAvatarRebuildDataWorker; return static function (): void { EventHandler::getInstance()->register(ItemCollecting::class, static function (ItemCollecting $event) { @@ -68,4 +70,11 @@ static function (PHPExtensionCollecting $event) { $event->register('sodium'); } ); + + EventHandler::getInstance()->register( + RebuildWorkerCollecting::class, + static function (RebuildWorkerCollecting $event) { + $event->register(DiscordWebhookAvatarRebuildDataWorker::class, 0); + } + ); }; diff --git a/files/lib/system/worker/DiscordWebhookAvatarRebuildDataWorker.class.php b/files/lib/system/worker/DiscordWebhookAvatarRebuildDataWorker.class.php new file mode 100644 index 0000000..027a228 --- /dev/null +++ b/files/lib/system/worker/DiscordWebhookAvatarRebuildDataWorker.class.php @@ -0,0 +1,57 @@ +objectList)) { + return; + } + + foreach ($this->objectList as $bot) { + $avatarFile = \sprintf('%simages/discord_webhook/%s.png', WCF_DIR, $bot->botID); + if (!\file_exists($avatarFile)) { + continue; + } + + $editor = new DiscordBotEditor($bot); + + $file = FileEditor::createFromExistingFile( + $avatarFile, + $bot->botID . '.png', + 'dev.hanashi.wsc.discord.webhook.avatar' + ); + + if ($file === null) { + continue; + } + + $editor->update([ + 'webhookIconID' => $file->fileID, + ]); + } + } + + #[Override] + protected function initObjectList() + { + parent::initObjectList(); + + $this->objectList->getConditionBuilder()->add('webhookIconID IS NULL'); + } +} diff --git a/language/de.xml b/language/de.xml index b385e6d..a38b40e 100644 --- a/language/de.xml +++ b/language/de.xml @@ -117,6 +117,10 @@ Discord-Bot erledigen.]]> + + + + diff --git a/language/en.xml b/language/en.xml index 0cef2dd..3d618e2 100644 --- a/language/en.xml +++ b/language/en.xml @@ -117,6 +117,10 @@ Go the Discord bot.]]> + + + +