Skip to content

Commit 8e0f7e1

Browse files
committed
githubupdated promise handling tweak
1 parent 9da2ee8 commit 8e0f7e1

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/Civ13/HttpServiceManager.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -309,18 +309,18 @@ function (ServerRequestInterface $request, string $endpoint, bool $whitelisted):
309309
if (! $channel = $this->discord->getChannel($this->civ13->channel_ids['staff_bot'])) return HttpResponse::plaintext('Discord Channel Not Found')->withStatus(HttpResponse::STATUS_INTERNAL_SERVER_ERROR);
310310
$promise = $this->civ13->sendMessage($channel, 'Updating code from GitHub... (1/3)');
311311
OSFunctions::execInBackground('git pull');
312-
$this->civ13->loop->addTimer(5, function () use ($promise, $channel) {
313-
$promise = $promise->then(function (Message $message) use ($channel) {
314-
$promise = $message->edit(MessageBuilder::new()->setContent('Forcefully moving the HEAD back to origin/main... (2/3)'));
315-
$promise->then(fn(Message $message) => $this->civ13->restart_message = $message);
312+
$this->civ13->loop->addTimer(5, fn() =>
313+
$promise->then(function (Message $message) use ($channel) {
314+
$message->edit(MessageBuilder::new()->setContent('Forcefully moving the HEAD back to origin/main... (2/3)'))->then(fn(Message $message) => $this->civ13->restart_message = $message);
316315
OSFunctions::execInBackground('git reset --hard origin/main');
317316
if (isset($this->civ13->timers['restart_pending']) && $this->civ13->timers['restart_pending'] instanceof TimerInterface) $this->civ13->loop->cancelTimer($this->civ13->timers['restart_pending']);
318-
$this->civ13->timers['restart_pending'] = $this->civ13->loop->addTimer(300, function () use ($channel) {
319-
if (isset($this->civ13->restart_message) && $this->civ13->restart_message instanceof Message) $this->civ13->restart_message->edit(MessageBuilder::new()->setContent('Restarting... (3/3)'))->then(fn() => $this->civ13->restart());
320-
else $this->civ13->sendMessage($channel, 'Restarting... (3/3)')->then(fn() => $this->civ13->restart());
321-
});
322-
});
323-
});
317+
$this->civ13->timers['restart_pending'] = $this->civ13->loop->addTimer(300, fn() =>
318+
(isset($this->civ13->restart_message) && $this->civ13->restart_message instanceof Message)
319+
? $this->civ13->restart_message->edit(MessageBuilder::new()->setContent('Restarting... (3/3)'))->then(fn() => $this->civ13->restart())
320+
: $this->civ13->sendMessage($channel, 'Restarting... (3/3)')->then(fn() => $this->civ13->restart())
321+
);
322+
})
323+
);
324324
return new HttpResponse(HttpResponse::STATUS_OK);
325325
})
326326
->offsetSet('/cancelupdaterestart',

0 commit comments

Comments
 (0)