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\Commands\SystemCommand; |
14
|
|
|
use Longman\TelegramBot\Conversation; |
15
|
|
|
use Longman\TelegramBot\Entities\ServerResponse; |
16
|
|
|
use Longman\TelegramBot\Exception\TelegramException; |
17
|
|
|
use Longman\TelegramBot\Request; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Generic message command |
21
|
|
|
*/ |
22
|
|
|
class GenericmessageCommand extends SystemCommand |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
protected $name = 'genericmessage'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
protected $description = 'Handle generic message'; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
protected $version = '1.1.0'; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var bool |
41
|
|
|
*/ |
42
|
|
|
protected $need_mysql = true; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Execution if MySQL is required but not available |
46
|
|
|
* |
47
|
|
|
* @return ServerResponse |
48
|
|
|
*/ |
49
|
|
|
public function executeNoDb() |
50
|
|
|
{ |
51
|
|
|
//Do nothing |
52
|
|
|
return Request::emptyResponse(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Execute command |
57
|
|
|
* |
58
|
|
|
* @return ServerResponse |
59
|
|
|
* @throws TelegramException |
60
|
|
|
*/ |
61
|
|
|
public function execute() |
62
|
|
|
{ |
63
|
|
|
//If a conversation is busy, execute the conversation command after handling the message |
64
|
|
|
$conversation = new Conversation( |
65
|
|
|
$this->getMessage()->getFrom()->getId(), |
66
|
|
|
$this->getMessage()->getChat()->getId() |
67
|
|
|
); |
68
|
|
|
|
69
|
|
|
//Fetch conversation command if it exists and execute it |
70
|
|
|
if ($conversation->exists() && ($command = $conversation->getCommand())) { |
71
|
|
|
return $this->getTelegram()->executeCommand($command); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
// Try to execute any deprecated system commands. |
75
|
|
|
if ($deprecated_system_command_response = $this->executeDeprecatedSystemCommand()) { |
76
|
|
|
return $deprecated_system_command_response; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
return Request::emptyResponse(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
|
83
|
|
|
public function executeDeprecatedSystemCommand() |
84
|
|
|
{ |
85
|
|
|
$telegram = $this->getTelegram(); |
86
|
|
|
$update = $this->getUpdate(); |
87
|
|
|
$message = $this->getMessage(); |
88
|
|
|
|
89
|
|
|
// List of service messages previously handled internally. |
90
|
|
|
$service_messages = [ |
91
|
|
|
'editedmessage' => [$update, 'getEditedMessage'], |
92
|
|
|
'channelpost' => [$update, 'getChannelPost'], |
93
|
|
|
'editedchannelpost' => [$update, 'getEditedChannelPost'], |
94
|
|
|
'newchatmembers' => [$message, 'getNewChatMembers'], |
95
|
|
|
'leftchatmember' => [$message, 'getLeftChatMember'], |
96
|
|
|
'newchattitle' => [$message, 'getNewChatTitle'], |
97
|
|
|
'newchatphoto' => [$message, 'getNewChatPhoto'], |
98
|
|
|
'deletechatphoto' => [$message, 'getDeleteChatPhoto'], |
99
|
|
|
'groupchatcreated' => [$message, 'getGroupChatCreated'], |
100
|
|
|
'supergroupchatcreated' => [$message, 'getSupergroupChatCreated'], |
101
|
|
|
'channelchatcreated' => [$message, 'getChannelChatCreated'], |
102
|
|
|
'migratefromchatid' => [$message, 'getMigrateFromChatId'], |
103
|
|
|
'migratetochatid' => [$message, 'getMigrateToChatId'], |
104
|
|
|
'pinnedmessage' => [$message, 'getPinnedMessage'], |
105
|
|
|
'successfulpayment' => [$message, 'getSuccessfulPayment'], |
106
|
|
|
]; |
107
|
|
|
|
108
|
|
|
foreach ($service_messages as $command => $service_message_getter) { |
109
|
|
|
// Let's check if this message is a service message. |
110
|
|
|
if ($service_message_getter() === null) { |
111
|
|
|
continue; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
// Make sure the command exists, otherwise GenericCommand would be executed instead! |
115
|
|
|
if ($telegram->getCommandObject($command) === null) { |
116
|
|
|
break; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
return $telegram->executeCommand($command); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
return null; |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|