disable.php$0 ➔ run()   A
last analyzed

Complexity

Conditions 4

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
dl 0
loc 13
rs 9.8333
c 1
b 0
f 0
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' => 'disable',
15
                'aliases' => array('disable-command'),
16
                'group' => 'commands',
17
                'description' => 'Disables a command or command group.',
18
                'details' => 'The argument must be the name/ID (partial or whole) of a command or command group. Only administrators may use this command.',
19
                'examples' => array('disable utils'),
20
                'guildOnly' => false,
21
                'throttling' => array(
22
                    'usages' => 2,
23
                    'duration' => 3
24
                ),
25
                'userPermissions' => array('ADMINISTRATOR'),
26
                'args' => array(
27
                    array(
28
                        'key' => 'commandOrGroup',
29
                        'label' => 'command/group',
30
                        'prompt' => 'Which command or group would you like to disable?',
31
                        'type' => 'command-or-group'
32
                    )
33
                ),
34
                'guarded' => true
35
            ));
36
        }
37
        
38
        function run(\CharlotteDunois\Livia\Commands\Context $context, \ArrayObject $args, bool $fromPattern) {
39
            $type = ($args['commandOrGroup'] instanceof \CharlotteDunois\Livia\Commands\CommandGroup ? 'group' : 'command');
40
            
41
            if(!$args['commandOrGroup']->isEnabledIn($context->message->guild)) {
42
                return $context->reply('The '.$type.' `'.$args['commandOrGroup']->name.'` is already disabled.');
43
            }
44
            
45
            if($args['commandOrGroup']->guarded) {
46
                return $context->reply('The '.$type.' `'.$args['commandOrGroup']->name.'` can not be disabled.');
47
            }
48
            
49
            $args['commandOrGroup']->setEnabledIn($context->message->guild, false);
50
            return $context->reply('Disabled the '.$type.' `'.$args['commandOrGroup']->name.'`.');
51
        }
52
    });
53
};
54