Small fix

This commit is contained in:
Daniil Gentili 2017-05-16 21:08:46 +01:00
parent 915a0cd180
commit 3c30bbf39c
2 changed files with 8 additions and 7 deletions

13
bot.php
View File

@ -12,24 +12,25 @@ If not, see <http://www.gnu.org/licenses/>.
*/
require 'vendor/autoload.php';
$settings = [];
// $token="Uncomment and put your Token here";
$settings = ["app_info" => ["api_id" => 6, "api_hash" => "eb06d4abfb49dc3eeb1aeb98ae0f581e"]];
try {
$MadelineProto = \danog\MadelineProto\Serialization::deserialize('bot.madeline');
} catch (\danog\MadelineProto\Exception $e) {
if (isset($token)) {
if (file_exists('token.php')) {
require_once 'token.php';
$MadelineProto = new \danog\MadelineProto\API($settings);
$authorization = $MadelineProto->bot_login($token);
\danog\MadelineProto\Logger::log([$authorization], \danog\MadelineProto\Logger::NOTICE);
} else {
echo 'token does not exist';
echo 'token.php does not exist';
die;
}
}
$offset = 0;
while (true) {
$updates = $MadelineProto->API->get_updates(['offset' => $offset, 'limit' => 50, 'timeout' => 0]); // Just like in the bot API, you can specify an offset, a limit and a timeout
\danog\MadelineProto\Logger::log([$updates]);
//\danog\MadelineProto\Logger::log([$updates]);
foreach ($updates as $update) {
$offset = $update['update_id'] + 1; // Just like in the bot API, the offset must be set to the last update_id
switch ($update['update']['_']) {
@ -43,7 +44,7 @@ while (true) {
$res = var_export($update, true);
}
try {
$MadelineProto->messages->sendMessage(['peer' => $update['update']['message']['to_id'], 'message' => $res, 'reply_to_msg_id' => $update['update']['message']['id'], 'entities' => [['_' => 'messageEntityPre', 'offset' => 0, 'length' => strlen($res), 'language' => 'json']]]);
$MadelineProto->messages->sendMessage(['peer' => $update['update']['_'] === 'updateNewMessage' ? $update['update']['message']['from_id'] : $update['update']['message']['to_id'], 'message' => $res, 'reply_to_msg_id' => $update['update']['message']['id'], 'entities' => [['_' => 'messageEntityPre', 'offset' => 0, 'length' => strlen($res), 'language' => 'json']]]);
} catch (\danog\MadelineProto\RPCErrorException $e) {
$MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => $e->getCode().': '.$e->getMessage().PHP_EOL.$e->getTraceAsString()]);
}

View File

@ -22,7 +22,7 @@ class RPCErrorException extends \Exception
case 'RPC_CALL_FAIL': $message = 'Telegram is having internal issues, please try again later.'; break;
case 'CHANNEL_PRIVATE':$message = "You haven't joined this channel/supergroup"; break;
case 'FLOOD_WAIT_666':$message = 'Spooky af m8'; break;
case 'USER_IS_BOT':
case 'USER_IS_BOT':$message = "Bots can't send messages to themselves"; break;
case 'BOT_METHOD_INVALID':$message = 'This method cannot be run by a bot'; break;
case 'PHONE_CODE_EXPIRED': $message = 'The phone code you provided has expired, this may happen if it was sent to any chat on telegram (if the code is sent through a telegram chat (not the official account) to avoid it append or prepend to the code some chars)'; break;
case 'USERNAME_INVALID': $message = 'The provided username is not valid'; break;