Further simplification of code snippets.

parent beae90ee
......@@ -162,7 +162,8 @@ class Message extends Entity
if (strpos($text, '/') !== 0) {
return null;
}
$no_EOL = strtok($text, PHP_EOL);
$no_EOL = strtok($text, PHP_EOL);
$no_space = strtok($text, ' ');
//try to understand which separator \n or space divide /command from text
......@@ -176,30 +177,28 @@ class Message extends Entity
*/
public function getCommand()
{
$command = $this->getProperty('command');
if (!empty($command)) {
if ($command = $this->getProperty('command')) {
return $command;
}
$full_command = $this->getFullCommand();
if (strpos($full_command, '/') !== 0) {
return false;
}
$full_command = substr($full_command, 1);
//check if command is follow by botname
//check if command is followed by bot username
$split_cmd = explode('@', $full_command);
if (isset($split_cmd[1])) {
//command is followed by name check if is addressed to me
if (strtolower($split_cmd[1]) === strtolower($this->getBotUsername())) {
return $split_cmd[0];
}
} else {
if (!isset($split_cmd[1])) {
//command is not followed by name
return $full_command;
}
if (strtolower($split_cmd[1]) === strtolower($this->getBotUsername())) {
//command is addressed to me
return $split_cmd[0];
}
return false;
}
......
......@@ -24,25 +24,15 @@ class StickerSet extends Entity
/**
* List of all set stickers
*
* This method overrides the default getStickers method and returns a nice array
* This method overrides the default getStickers method
* and returns a nice array of Sticker objects.
*
* @return Sticker[]
* @return null|Sticker[]
*/
public function getStickers()
{
$all_stickers = [];
$these_stickers = $this->getProperty('stickers')
if (!$these_stickers) {
return [];
}
foreach ($these_stickers as $stickers) {
$new_stickers = [];
foreach ($stickers as $sticker) {
$new_stickers[] = new Sticker($sticker);
}
$all_stickers[] = $new_stickers;
}
$pretty_array = $this->makePrettyObjectArray(Sticker::class, 'stickers');
return $all_stickers;
return empty($pretty_array) ? null : $pretty_array;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment