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

Complexity

Conditions 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
dl 0
loc 10
rs 9.9332
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' => 'ping',
15
                'aliases' => array(),
16
                'group' => 'utils',
17
                'description' => 'Sends a ping and measures the latency between command message and ping message. It will also display websocket ping.',
18
                'guildOnly' => false,
19
                'throttling' => array(
20
                    'usages' => 5,
21
                    'duration' => 10
22
                ),
23
                'guarded' => true
24
            ));
25
        }
26
        
27
        function run(\CharlotteDunois\Livia\Commands\Context $context, \ArrayObject $args, bool $fromPattern) {
28
            return $context->say('Pinging...')->then(function ($msg) use ($context) {
29
                $time = \CharlotteDunois\Yasmin\Utils\Snowflake::deconstruct($msg->id)->timestamp - \CharlotteDunois\Yasmin\Utils\Snowflake::deconstruct($context->message->id)->timestamp;
30
                
31
                $ping = $this->client->getPing();
32
                if(!\is_int($ping)) {
33
                    $ping = 0;
34
                }
35
                
36
                return $msg->edit($context->message->author.' Pong! The message round-trip took '.\ceil(($time * 1000)).'ms. The WS heartbeat is '.$ping.'ms.');
37
            });
38
        }
39
    });
40
};
41