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

StatusPlugin::yabotReconnect()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 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
}