|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Livia |
|
4
|
|
|
* Copyright 2017-2019 Charlotte Dunois, All Rights Reserved |
|
5
|
|
|
* |
|
6
|
|
|
* Website: https://charuru.moe |
|
7
|
|
|
* License: https://github.com/CharlotteDunois/Livia/blob/master/LICENSE |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
return function ($client) { |
|
11
|
|
|
return (new class($client) extends \CharlotteDunois\Livia\Commands\Command { |
|
12
|
|
|
function __construct(\CharlotteDunois\Livia\Client $client) { |
|
13
|
|
|
parent::__construct($client, array( |
|
14
|
|
|
'name' => 'load', |
|
15
|
|
|
'aliases' => array('load-command'), |
|
16
|
|
|
'group' => 'commands', |
|
17
|
|
|
'description' => 'Loads a new command.', |
|
18
|
|
|
'details' => 'The argument must be full name of the command in the format of `group:name`. Only the bot owner may use this command.', |
|
19
|
|
|
'examples' => array('enable utils'), |
|
20
|
|
|
'guildOnly' => false, |
|
21
|
|
|
'ownerOnly' => true, |
|
22
|
|
|
'args' => array( |
|
23
|
|
|
array( |
|
24
|
|
|
'key' => 'command', |
|
25
|
|
|
'prompt' => 'Which command would you like to load?', |
|
26
|
|
|
'validate' => function ($value) { |
|
27
|
|
|
$value = \explode(':', $value); |
|
28
|
|
|
if(\count($value) !== 2) { |
|
29
|
|
|
return false; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
if(\count($this->client->registry->findCommands($value[1])) > 0) { |
|
33
|
|
|
return 'That command is already registered.'; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
try { |
|
37
|
|
|
$this->client->registry->resolveCommandPath($value[0], $value[1]); |
|
38
|
|
|
return true; |
|
39
|
|
|
} catch (\InvalidArgumentException $e) { |
|
40
|
|
|
return false; |
|
41
|
|
|
} |
|
42
|
|
|
}, |
|
43
|
|
|
'parse' => function ($value) { |
|
44
|
|
|
return $value; |
|
45
|
|
|
} |
|
46
|
|
|
) |
|
47
|
|
|
), |
|
48
|
|
|
'guarded' => true |
|
49
|
|
|
)); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
function run(\CharlotteDunois\Livia\Commands\Context $context, \ArrayObject $args, bool $fromPattern) { |
|
53
|
|
|
$this->client->registry->registerCommand($args['command']); |
|
54
|
|
|
return $context->reply('Loaded the command `'.$args['command'].'`.'); |
|
55
|
|
|
} |
|
56
|
|
|
}); |
|
57
|
|
|
}; |
|
58
|
|
|
|