-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvariable_functions.php
More file actions
55 lines (47 loc) · 1.87 KB
/
variable_functions.php
File metadata and controls
55 lines (47 loc) · 1.87 KB
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
46
47
48
49
50
51
52
53
54
55
<?php
declare(strict_types=1);
/*
* This file is a part of the Civilizationbot project.
*
* Copyright (c) 2021-present Valithor Obsidion <valithor@civ13.org>
*
* This file is subject to the MIT license that is bundled
* with this source code in the LICENSE.md file.
*/
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, 5 | Game/Playing, Streaming, Listening, Watching, Custom Status, Competing
]);
$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
{
//
};*/