GenericmessageCommand::executeNoDb()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

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 2
nc 1
nop 0
1
<?php
2
/**
3
 * This file is part of the TelegramBot package.
4
 *
5
 * (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Longman\TelegramBot\Commands\SystemCommands;
12
13
use Longman\TelegramBot\Conversation;
14
use Longman\TelegramBot\Request;
15
use Longman\TelegramBot\Commands\SystemCommand;
16
17
/**
18
 * Generic message command
19
 */
20
class GenericmessageCommand extends SystemCommand
21
{
22
    /**
23
     * @var string
24
     */
25
    protected $name = 'Genericmessage';
26
27
    /**
28
     * @var string
29
     */
30
    protected $description = 'Handle generic message';
31
32
    /**
33
     * @var string
34
     */
35
    protected $version = '1.1.0';
36
37
    /**
38
     * @var bool
39
     */
40
    protected $need_mysql = true;
41
42
    /**
43
     * Execution if MySQL is required but not available
44
     *
45
     * @return \Longman\TelegramBot\Entities\ServerResponse
46
     */
47
    public function executeNoDb()
48
    {
49
        //Do nothing
50
        return Request::emptyResponse();
51
    }
52
53
    /**
54
     * Execute command
55
     *
56
     * @return \Longman\TelegramBot\Entities\ServerResponse
57
     * @throws \Longman\TelegramBot\Exception\TelegramException
58
     */
59
    public function execute()
60
    {
61
        //If a conversation is busy, execute the conversation command after handling the message
62
        $conversation = new Conversation(
63
            $this->getMessage()->getFrom()->getId(),
64
            $this->getMessage()->getChat()->getId()
65
        );
66
        //Fetch conversation command if it exists and execute it
67
        if ($conversation->exists() && ($command = $conversation->getCommand())) {
68
            return $this->telegram->executeCommand($command);
69
        }
70
71
        return Request::emptyResponse();
72
    }
73
}
74