1
|
|
|
<?php |
2
|
|
|
namespace Sovereign\Command; |
3
|
|
|
|
4
|
|
|
use Sovereign\Service\SystemPluginServiceProvider; |
5
|
|
|
use Sovereign\Sovereign; |
6
|
|
|
use Symfony\Component\Console\Command\Command; |
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
8
|
|
|
use Symfony\Component\Console\Input\InputOption; |
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
10
|
|
|
|
11
|
|
|
class StartCommand extends Command |
12
|
|
|
{ |
13
|
|
|
protected function configure() |
14
|
|
|
{ |
15
|
|
|
$this |
16
|
|
|
->setName('start') |
17
|
|
|
->setDescription('Launch the sovereign bot') |
18
|
|
|
->addOption( |
19
|
|
|
'configFile', |
20
|
|
|
null, |
21
|
|
|
InputOption::VALUE_OPTIONAL, |
22
|
|
|
'The config php file to load', |
23
|
|
|
'config/config.php' |
24
|
|
|
) |
25
|
|
|
; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
29
|
|
|
{ |
30
|
|
|
// Use all the memory |
31
|
|
|
ini_set('memory_limit', '-1'); |
32
|
|
|
gc_enable(); |
33
|
|
|
error_reporting(1); |
34
|
|
|
error_reporting(E_ALL); |
35
|
|
|
define('DISCORDPHP_STARTTIME', microtime(true)); |
36
|
|
|
define('BASEDIR', __DIR__); |
37
|
|
|
define('SOVEREIGN_CONFIG_FILE', realpath('./' . ltrim($input->getOption('configFile'), '/'))); |
38
|
|
|
|
39
|
|
|
// Init the container object |
40
|
|
|
$container = getContainer(); |
41
|
|
|
|
42
|
|
|
// Load the bot into the service container |
43
|
|
|
$container->share('app', Sovereign::class)->withArgument($container); |
44
|
|
|
|
45
|
|
|
try { |
46
|
|
|
// Init the bot |
47
|
|
|
$container->get('log')->addInfo('Sovereign is starting up..'); |
48
|
|
|
$bot = $container->get('app'); |
49
|
|
|
|
50
|
|
|
// Register the default plugins and services, and boot them. |
51
|
|
|
$container->addServiceProvider(SystemPluginServiceProvider::class); |
52
|
|
|
} catch (\Exception $e) { |
53
|
|
|
$container->get('log')->addError('An error occurred: ' . $e->getMessage()); |
54
|
|
|
die(); |
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
// Launch the bot |
58
|
|
|
$bot->run(); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
|
An exit expression should only be used in rare cases. For example, if you write a short command line script.
In most cases however, using an
exit
expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.