mirror of
https://github.com/danog/MadelineProto.git
synced 2024-11-27 02:34:39 +01:00
Apply fixes from StyleCI
This commit is contained in:
parent
884232aec3
commit
f0f8ae56bf
@ -45,7 +45,7 @@ trait PeerHandler
|
||||
case 'channelEmpty':
|
||||
break;
|
||||
case 'channel':
|
||||
$this->chats[(int)('-100'.$chat['id'])] = $chat;
|
||||
$this->chats[(int) ('-100'.$chat['id'])] = $chat;
|
||||
break;
|
||||
default:
|
||||
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 (isset($this->chats[$id])) {
|
||||
return $this->chats[$id];
|
||||
@ -71,16 +72,19 @@ trait PeerHandler
|
||||
}
|
||||
if ($recursive) {
|
||||
$this->resolve_username($id);
|
||||
|
||||
return $this->get_peer($id, false);
|
||||
}
|
||||
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));
|
||||
}
|
||||
|
||||
public function constructor2inputpeer($peer) {
|
||||
public function constructor2inputpeer($peer)
|
||||
{
|
||||
switch ($peer['_']) {
|
||||
case 'user':
|
||||
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)]);
|
||||
if ($res['_'] == 'contacts.resolvedPeer') {
|
||||
$this->add_users($res['users']);
|
||||
$this->add_chats($res['chats']);
|
||||
|
||||
return $res;
|
||||
}
|
||||
throw new \danog\MadelineProto\Exception('resolve_username returned an unexpected constructor: '.var_export($username, true));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -219,7 +219,7 @@ class TL extends \danog\MadelineProto\Tools
|
||||
if ($method == 'messages.forwardMessages') {
|
||||
$serialized .= \danog\PHP\Struct::pack('<i', $this->constructors->find_by_predicate('vector')['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;
|
||||
}
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ $mention = $MadelineProto->API->constructor2inputpeer($mention); // Converts an
|
||||
|
||||
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
|
||||
$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);
|
||||
}
|
||||
|
||||
@ -62,6 +62,6 @@ if (file_exists('token.php')) {
|
||||
}
|
||||
foreach (['@pwrtelegramgroup', '@pwrtelegramgroupita'] as $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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user