Completed
Push — master ( e135cc...194ff8 )
by Dan
07:03 queued 04:54
created

StatusPlugin   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 40
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 1
A yabotStatus() 0 5 1
A yabotShutdown() 0 5 1
A yabotReconnect() 0 5 1
1
<?php
2
namespace Nopolabs\Yabot\Plugin;
3
4
use Nopolabs\Yabot\Message\Message;
5
use Nopolabs\Yabot\Yabot;
6
use Psr\Log\LoggerInterface;
7
8
class StatusPlugin implements PluginInterface
9
{
10
    use PluginTrait;
11
12
    private $yabot;
13
14
    public function __construct(Yabot $yabot, LoggerInterface $logger = null)
15
    {
16
        $this->setLog($logger);
17
        $this->yabot = $yabot;
18
19
        $this->setConfig([
20
            'help' => '<prefix> status',
21
            'prefix' => PluginManager::AUTHED_USER_PREFIX,
22
            'matchers' => [
23
                'yabotStatus' => "/^status\\b/",
24
                'yabotShutdown' => "/^shutdown\\b/",
25
                'yabotReconnect' => "/^reconnect\\b/",
26
            ],
27
        ]);
28
    }
29
30
    public function yabotStatus(Message $msg)
31
    {
32
        $msg->reply($this->yabot->getStatus());
33
        $msg->setHandled(true);
34
    }
35
36
    public function yabotShutdown(Message $msg)
37
    {
38
        $this->yabot->shutDown();
39
        $msg->setHandled(true);
40
    }
41
42
    public function yabotReconnect(Message $msg)
43
    {
44
        $this->yabot->reconnect();
45
        $msg->setHandled(true);
46
    }
47
}