1 | <?php |
||
11 | class MessageUtility extends AbstractUtility |
||
12 | { |
||
13 | /** |
||
14 | * Remove the mentioned bot username from the message. |
||
15 | * |
||
16 | * @param $message |
||
17 | * |
||
18 | * @throws \Exception |
||
19 | * |
||
20 | * @return string |
||
21 | */ |
||
22 | 10 | public function removeMentionedBot(string $message): string |
|
28 | |||
29 | /** |
||
30 | * Check if the bot user id is mentioned in the message. |
||
31 | * |
||
32 | * @param $message |
||
33 | * |
||
34 | * @throws \Exception |
||
35 | * |
||
36 | * @return bool |
||
37 | */ |
||
38 | 2 | public function isBotMentioned(string $message): bool |
|
44 | |||
45 | /** |
||
46 | * Return command name in the message. |
||
47 | * |
||
48 | * @param string $message |
||
49 | * |
||
50 | * @throws \Exception |
||
51 | * |
||
52 | * @return null|string |
||
53 | */ |
||
54 | 9 | public function extractCommandName(string $message) |
|
72 | |||
73 | /** |
||
74 | * Return command details in the message. |
||
75 | * |
||
76 | * @param string $message |
||
77 | * |
||
78 | * @throws \Exception |
||
79 | * |
||
80 | * @return \Botonomous\Command|null |
||
81 | */ |
||
82 | 1 | public function extractCommandDetails(string $message) |
|
90 | |||
91 | /** |
||
92 | * @param $triggerWord |
||
93 | * @param $message |
||
94 | * |
||
95 | * @return string |
||
96 | */ |
||
97 | 4 | public function removeTriggerWord(string $message, string $triggerWord) |
|
103 | |||
104 | /** |
||
105 | * @param $userId |
||
106 | * @param string $userName |
||
107 | * |
||
108 | * @throws \Exception |
||
109 | * |
||
110 | * @return string |
||
111 | */ |
||
112 | 13 | public function linkToUser(string $userId, string $userName = '') |
|
124 | |||
125 | /** |
||
126 | * @throws \Exception |
||
127 | * |
||
128 | * @return string |
||
129 | */ |
||
130 | 12 | private function getUserLink(): string |
|
134 | |||
135 | /** |
||
136 | * @param array $keywords |
||
137 | * @param $message |
||
138 | * |
||
139 | * @return array |
||
140 | */ |
||
141 | 6 | public function keywordPos(array $keywords, string $message): array |
|
159 | |||
160 | /** |
||
161 | * @param array $keywords |
||
162 | * @param $message |
||
163 | * |
||
164 | * @return array|void |
||
165 | */ |
||
166 | 5 | public function keywordCount(array $keywords, string $message) |
|
180 | |||
181 | /** |
||
182 | * @param array $tokensPositions |
||
183 | * @param $newPosition |
||
184 | * |
||
185 | * @return bool |
||
186 | */ |
||
187 | 4 | private function isPositionTaken(array $tokensPositions, int $newPosition) |
|
202 | |||
203 | /** |
||
204 | * @param $newPosition |
||
205 | * @param $positions |
||
206 | * @param $tokenLength |
||
207 | * |
||
208 | * @return bool |
||
209 | */ |
||
210 | 4 | private function isPositionIn(int $newPosition, array $positions, int $tokenLength) |
|
220 | } |
||
221 |