Completed
Push — master ( a00622...08b3e1 )
by Martin
14:53
created

helpers.php ➔ reply()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 8
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 11
rs 9.4285
1
<?php
2
declare(strict_types=1);
3
4
use Spires\Core\Core;
5
use Spires\Irc\Client;
6
use Spires\Plugins\Message\Outbound\Message;
7
use Spires\Plugins\SystemMessage\Outbound\SystemMessage;
8
use Spires\Plugins\Message\Inbound\Message as InboundMessage;
9
10
function core(string $abstract = null, array $parameters = [])
11
{
12
    if (is_null($abstract)) {
13
        return Core::getInstance();
14
    }
15
16
    return Core::getInstance()->make($abstract, $parameters);
17
}
18
19
function send_command(string $command, string $params)
20
{
21
    core(Client::class)->write((string) new SystemMessage($command, $params));
22
}
23
24
function send_to(array $targets, string $text)
25
{
26
    core(Client::class)->write((string) new Message($targets, $text));
27
}
28
29
function reply(string $text)
30
{
31
    $myNick = core(Client::class)->user()->nickname();
32
    $senderNick = core(InboundMessage::class)->nickname();
33
    $targets = core(InboundMessage::class)->targets();
34
    $targets = array_map(function ($target) use ($myNick, $senderNick) {
35
        return $target === $myNick ? $senderNick : $target;
36
    }, $targets);
37
38
    send_to($targets, $text);
39
}
40