Skip to content

Commit

Permalink
add rebuild worker
Browse files Browse the repository at this point in the history
  • Loading branch information
Hanashi committed Oct 2, 2024
1 parent 5d3621b commit 401db32
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
9 changes: 9 additions & 0 deletions files/lib/bootstrap/dev.hanashi.wsc.discord-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace wcf\system\worker;

use Override;
use wcf\data\discord\bot\DiscordBotEditor;
use wcf\data\discord\bot\DiscordBotList;
use wcf\data\file\FileEditor;

final class DiscordWebhookAvatarRebuildDataWorker extends AbstractRebuildDataWorker
{
/**
* @inheritDoc
*/
protected $objectListClassName = DiscordBotList::class;

#[Override]
public function execute()
{
parent::execute();

if (!\count($this->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');
}
}
4 changes: 4 additions & 0 deletions language/de.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@
<category name="wcf.acp.discordBotSelectOptionType">
<item name="wcf.acp.discordBotSelectOptionType.noBot"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Du hast{else}Sie haben{/if} noch keinen Discord-Bot angelegt. Dies {if LANGUAGE_USE_INFORMAL_VARIANT}kannst du{else}können Sie{/if} unter <a href="{link controller="DiscordBotAddManager"}{/link}">Discord-Bot</a> erledigen.]]></item>
</category>
<category name="wcf.acp.rebuildData">
<item name="wcf.acp.rebuildData.wcf_system_worker_DiscordWebhookAvatarRebuildDataWorker"><![CDATA[Discord-Webhook-Avatar aktualisieren]]></item>
<item name="wcf.acp.rebuildData.wcf_system_worker_DiscordWebhookAvatarRebuildDataWorker.description"><![CDATA[Aktualisiert Avatare für Discord-Webhook.]]></item>
</category>
</import>
<delete>
<item name="wcf.acp.discordBotAddManager.useOAuth2.description"/>
Expand Down
4 changes: 4 additions & 0 deletions language/en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ Go the <a href="https://discord.com/developers/applications" class="externalURL"
<category name="wcf.acp.discordBotSelectOptionType">
<item name="wcf.acp.discordBotSelectOptionType.noBot"><![CDATA[You haven't created a discord bot yet. You can do this under <a href="{link controller="DiscordBotAddManager"}{/link}">Discord bot</a>.]]></item>
</category>
<category name="wcf.acp.rebuildData">
<item name="wcf.acp.rebuildData.wcf_system_worker_DiscordWebhookAvatarRebuildDataWorker"><![CDATA[Update discord webhook avatar]]></item>
<item name="wcf.acp.rebuildData.wcf_system_worker_DiscordWebhookAvatarRebuildDataWorker.description"><![CDATA[Updates avatars for discord webhook.]]></item>
</category>
</import>
<delete>
<item name="wcf.acp.discordBotAddManager.useOAuth2.description"/>
Expand Down

0 comments on commit 401db32

Please sign in to comment.