-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvariable_functions.php
45 lines (41 loc) · 1.73 KB
/
variable_functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php declare(strict_types=1);
/*
* This file is a part of the Civ13 project.
*
* Copyright (c) 2022-present Valithor Obsidion <[email protected]>
*/
use Civ13\Civ13;
use Civ13\Exceptions\FileNotFoundException;
use Discord\Parts\User\Activity;
use React\Promise\PromiseInterface;
use function React\Promise\reject;
use function React\Promise\resolve;
$status_changer_random = function (Civ13 $civ13): PromiseInterface
{ // on ready
if (! $civ13::status) {
unset($civ13->timers['status_changer_timer']);
$civ13->logger->warning($err = 'status is not defined');
return reject(new \LogicException($err));
}
if (! $status_array = file($civ13::status, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)) {
unset($civ13->timers['status_changer_timer']);
$civ13->logger->warning($err = 'unable to open file `' . $civ13::status . '`');
return reject(new FileNotFoundException($err));
}
list($status, $type, $state) = explode('; ', $status_array[array_rand($status_array)]);
if (! $status) return reject(new \Exception('status must not be empty'));
$activity = new Activity($civ13->discord, [ // Discord status
'name' => $status,
'type' => (int) $type, // 0, 1, 2, 3, 4 | Game/Playing, Streaming, Listening, Watching, Custom Status
]);
$civ13->statusChanger($activity, $state);
return resolve(null);
};
$status_changer_timer = function (Civ13 $civ13) use ($status_changer_random): void
{ // on ready
if (! isset($civ13->timers['status_changer_timer'])) $civ13->timers['status_changer_timer'] = $civ13->discord->getLoop()->addPeriodicTimer(120, fn() => $status_changer_random($civ13));
};
/*$on_ready = function (Civ13 $civ13): void
{
//
};*/