Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 21 additions & 22 deletions src/Entities/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,15 @@ public function getEntities()
public function getFullCommand()
{
$text = $this->getProperty('text');
if (strpos($text, '/') === 0) {
$no_EOL = strtok($text, PHP_EOL);
$no_space = strtok($text, ' ');

//try to understand which separator \n or space divide /command from text
return strlen($no_space) < strlen($no_EOL) ? $no_space : $no_EOL;
if (strpos($text, '/') !== 0) {
return null;
}

return null;
$no_EOL = strtok($text, PHP_EOL);
$no_space = strtok($text, ' ');

//try to understand which separator \n or space divide /command from text
return strlen($no_space) < strlen($no_EOL) ? $no_space : $no_EOL;
}

/**
Expand All @@ -177,27 +177,26 @@ public function getFullCommand()
*/
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);

if (strpos($full_command, '/') === 0) {
$full_command = substr($full_command, 1);
//check if command is followed by bot username
$split_cmd = explode('@', $full_command);
if (!isset($split_cmd[1])) {
//command is not followed by name
return $full_command;
}

//check if command is follow by botname
$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 {
//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;
Expand Down
19 changes: 5 additions & 14 deletions src/Entities/StickerSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +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 = [];
$pretty_array = $this->makePrettyObjectArray(Sticker::class, 'stickers');

if ($these_stickers = $this->getProperty('stickers')) {
foreach ($these_stickers as $stickers) {
$new_stickers = [];
foreach ($stickers as $sticker) {
$new_stickers[] = new Sticker($sticker);
}
$all_stickers[] = $new_stickers;
}
}

return $all_stickers;
return empty($pretty_array) ? null : $pretty_array;
}
}