1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-11-30 10:38:59 +01:00

Apply fixes from StyleCI

This commit is contained in:
Daniil Gentili 2016-12-23 20:07:19 +00:00 committed by StyleCI Bot
parent 884232aec3
commit f0f8ae56bf
3 changed files with 14 additions and 9 deletions

View File

@ -45,7 +45,7 @@ trait PeerHandler
case 'channelEmpty': case 'channelEmpty':
break; break;
case 'channel': case 'channel':
$this->chats[(int)('-100'.$chat['id'])] = $chat; $this->chats[(int) ('-100'.$chat['id'])] = $chat;
break; break;
default: default:
throw new \danog\MadelineProto\Exception('Invalid chat provided at key '.$key.': '.var_export($chat, true)); throw new \danog\MadelineProto\Exception('Invalid chat provided at key '.$key.': '.var_export($chat, true));
@ -54,7 +54,8 @@ trait PeerHandler
} }
} }
public function get_peer($id, $recursive = true) { public function get_peer($id, $recursive = true)
{
if (is_numeric($id)) { if (is_numeric($id)) {
if (isset($this->chats[$id])) { if (isset($this->chats[$id])) {
return $this->chats[$id]; return $this->chats[$id];
@ -71,16 +72,19 @@ trait PeerHandler
} }
if ($recursive) { if ($recursive) {
$this->resolve_username($id); $this->resolve_username($id);
return $this->get_peer($id, false); return $this->get_peer($id, false);
} }
throw new \danog\MadelineProto\Exception("Couldn't find peer by provided username ".$id); throw new \danog\MadelineProto\Exception("Couldn't find peer by provided username ".$id);
} }
public function get_input_peer($id) { public function get_input_peer($id)
{
return $this->constructor2inputpeer($this->get_peer($id)); return $this->constructor2inputpeer($this->get_peer($id));
} }
public function constructor2inputpeer($peer) { public function constructor2inputpeer($peer)
{
switch ($peer['_']) { switch ($peer['_']) {
case 'user': case 'user':
return $peer['self'] ? ['_' => 'inputPeerSelf'] : ['_' => 'inputPeerUser', 'user_id' => $peer['id'], 'access_hash' => $peer['access_hash']]; return $peer['self'] ? ['_' => 'inputPeerSelf'] : ['_' => 'inputPeerUser', 'user_id' => $peer['id'], 'access_hash' => $peer['access_hash']];
@ -94,14 +98,15 @@ trait PeerHandler
} }
} }
public function resolve_username($username) { public function resolve_username($username)
{
$res = $this->method_call('contacts.resolveUsername', ['username' => str_replace('@', '', $username)]); $res = $this->method_call('contacts.resolveUsername', ['username' => str_replace('@', '', $username)]);
if ($res['_'] == 'contacts.resolvedPeer') { if ($res['_'] == 'contacts.resolvedPeer') {
$this->add_users($res['users']); $this->add_users($res['users']);
$this->add_chats($res['chats']); $this->add_chats($res['chats']);
return $res; return $res;
} }
throw new \danog\MadelineProto\Exception('resolve_username returned an unexpected constructor: '.var_export($username, true)); throw new \danog\MadelineProto\Exception('resolve_username returned an unexpected constructor: '.var_export($username, true));
} }
} }

View File

@ -219,7 +219,7 @@ class TL extends \danog\MadelineProto\Tools
if ($method == 'messages.forwardMessages') { if ($method == 'messages.forwardMessages') {
$serialized .= \danog\PHP\Struct::pack('<i', $this->constructors->find_by_predicate('vector')['id']); $serialized .= \danog\PHP\Struct::pack('<i', $this->constructors->find_by_predicate('vector')['id']);
$serialized .= \danog\PHP\Struct::pack('<i', count($arguments['id'])); $serialized .= \danog\PHP\Struct::pack('<i', count($arguments['id']));
$serialized .= \phpseclib\Crypt\Random::string(8*count($arguments['id'])); $serialized .= \phpseclib\Crypt\Random::string(8 * count($arguments['id']));
continue 2; continue 2;
} }
} }

View File

@ -49,7 +49,7 @@ $mention = $MadelineProto->API->constructor2inputpeer($mention); // Converts an
foreach (['@pwrtelegramgroup', '@pwrtelegramgroupita'] as $peer) { foreach (['@pwrtelegramgroup', '@pwrtelegramgroupita'] as $peer) {
$peer = $MadelineProto->API->get_input_peer($peer); // Returns directly an inputPeer object, basically does the same thing I've done manually above $peer = $MadelineProto->API->get_input_peer($peer); // Returns directly an inputPeer object, basically does the same thing I've done manually above
$sentMessage = $MadelineProto->messages->sendMessage(['peer' => $peer, 'message' => $message.' & pony', 'entities' => [['_' => 'messageEntityUrl', 'offset' => strlen($message)+1, 'length' => 6, 'url' => $flutter], ['_' => 'inputMessageEntityMentionName', 'offset' => 0, 'length' => strlen($message), 'user_id' => $mention]]]); $sentMessage = $MadelineProto->messages->sendMessage(['peer' => $peer, 'message' => $message.' & pony', 'entities' => [['_' => 'messageEntityUrl', 'offset' => strlen($message) + 1, 'length' => 6, 'url' => $flutter], ['_' => 'inputMessageEntityMentionName', 'offset' => 0, 'length' => strlen($message), 'user_id' => $mention]]]);
var_dump($sentMessage); var_dump($sentMessage);
} }
@ -62,6 +62,6 @@ if (file_exists('token.php')) {
} }
foreach (['@pwrtelegramgroup', '@pwrtelegramgroupita'] as $peer) { foreach (['@pwrtelegramgroup', '@pwrtelegramgroupita'] as $peer) {
$peer = $MadelineProto->API->get_input_peer($peer); $peer = $MadelineProto->API->get_input_peer($peer);
$sentMessage = $MadelineProto->messages->sendMessage(['peer' => $peer, 'message' => $message.' & pony', 'entities' => [['_' => 'messageEntityUrl', 'offset' => strlen($message)+1, 'length' => 6, 'url' => $flutter], ['_' => 'inputMessageEntityMentionName', 'offset' => 0, 'length' => strlen($message), 'user_id' => $mention]]]); $sentMessage = $MadelineProto->messages->sendMessage(['peer' => $peer, 'message' => $message.' & pony', 'entities' => [['_' => 'messageEntityUrl', 'offset' => strlen($message) + 1, 'length' => 6, 'url' => $flutter], ['_' => 'inputMessageEntityMentionName', 'offset' => 0, 'length' => strlen($message), 'user_id' => $mention]]]);
var_dump($sentMessage); var_dump($sentMessage);
} }