-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
files/lib/system/worker/DiscordWebhookAvatarRebuildDataWorker.class.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters