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

Merge branch 'danog:v8' into new-updates

This commit is contained in:
AhJ 2023-10-26 21:08:26 +03:30 committed by GitHub
commit 076f5aad26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 93 additions and 25 deletions

View File

@ -58,7 +58,7 @@
"webmozart/assert": "^1.11",
"bacon/bacon-qr-code": "^2.0",
"nikic/php-parser": "^4.16",
"revolt/event-loop": "^1.0.3"
"revolt/event-loop": "^1.0.4"
},
"require-dev": {
"phpdocumentor/reflection-docblock": "dev-master",

2
docs

@ -1 +1 @@
Subproject commit 326dc6dee0cc0303db36c4bd5e74a241f8f9ad57
Subproject commit 9738df4639cb8901b6a897f3c1a53db6683caadf

View File

@ -30,6 +30,7 @@ use danog\MadelineProto\EventHandler\Filter\FilterText;
use danog\MadelineProto\EventHandler\Filter\FilterTextCaseInsensitive;
use danog\MadelineProto\EventHandler\Message;
use danog\MadelineProto\EventHandler\Message\Service\DialogPhotoChanged;
use danog\MadelineProto\EventHandler\Plugin\RestartPlugin;
use danog\MadelineProto\EventHandler\SimpleFilter\FromAdmin;
use danog\MadelineProto\EventHandler\SimpleFilter\Incoming;
use danog\MadelineProto\EventHandler\SimpleFilter\IsReply;
@ -103,6 +104,17 @@ class MyEventHandler extends SimpleEventHandler
$this->sendMessageToAdmins("The bot was started!");
}
/**
* Returns a set of plugins to activate.
*/
public static function getPlugins(): array
{
return [
// Offers a /restart command to admins that can be used to restart the bot, applying changes.
RestartPlugin::class
];
}
/**
* This cron function will be executed forever, every 60 seconds.
*/

View File

@ -9,6 +9,7 @@
use danog\MadelineProto\EventHandler\Attributes\Handler;
use danog\MadelineProto\EventHandler\Message;
use danog\MadelineProto\EventHandler\Plugin\RestartPlugin;
use danog\MadelineProto\EventHandler\SimpleFilter\Incoming;
use danog\MadelineProto\SimpleEventHandler;
@ -36,6 +37,17 @@ class MyEventHandler extends SimpleEventHandler
return [self::ADMIN];
}
/**
* Returns a set of plugins to activate.
*/
public static function getPlugins(): array
{
return [
// Offers a /restart command to admins that can be used to restart the bot, applying changes.
RestartPlugin::class
];
}
/**
* Handle incoming updates from users, chats and channels.
*/

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="dev-master@1b12255fb19da5c25413fb0071ab3d1f006bb67b">
<files psalm-version="dev-master@75fcfe3540e378856b49cf60c8d9cfb1cdc434f2">
<file src="src/API.php">
<ArgumentTypeCoercion>
<code>$settings</code>
@ -209,11 +209,8 @@
</file>
<file src="src/Db/Driver/Mysql.php">
<ArgumentTypeCoercion>
<code>$config</code>
<code>$config</code>
<code><![CDATA[$config->withDatabase(null)]]></code>
<code><![CDATA[$settings->getIdleTimeout()]]></code>
<code><![CDATA[$settings->getMaxConnections()]]></code>
</ArgumentTypeCoercion>
<PossiblyNullArrayAccess>
<code><![CDATA[$connection->query("SHOW VARIABLES LIKE 'max_connections'")->fetchRow()['Value']]]></code>
@ -1347,6 +1344,10 @@
<code>\is_int($dc_id)</code>
<code><![CDATA[isset($this->datacenter)]]></code>
</RedundantConditionGivenDocblockType>
<UndefinedFunction>
<code>memprof_dump_pprof($file)</code>
<code>memprof_enabled()</code>
</UndefinedFunction>
<UndefinedThisPropertyFetch>
<code><![CDATA[$this->full_chats]]></code>
</UndefinedThisPropertyFetch>
@ -1386,11 +1387,6 @@
<code><![CDATA[$this->new_outgoing]]></code>
</PossiblyNullArrayOffset>
</file>
<file src="src/MTProtoSession/AuthKeyHandler.php">
<PossiblyUndefinedMethod>
<code>expires</code>
</PossiblyUndefinedMethod>
</file>
<file src="src/MTProtoSession/CallHandler.php">
<MissingClosureReturnType>
<code><![CDATA[fn (WrappedFuture $f) => $f->await()]]></code>

View File

@ -4,6 +4,8 @@
resolveFromConfigFile="true"
findUnusedCode="false"
findUnusedBaselineEntry="false"
ignoreInternalFunctionFalseReturn="true"
ignoreInternalFunctionNullReturn="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"

View File

@ -51,7 +51,7 @@ final class API extends AbstractAPI
*
* @var string
*/
public const RELEASE = '8.0.0-beta153';
public const RELEASE = '8.0.0-beta157';
/**
* We're not logged in.
*

View File

@ -48,7 +48,9 @@ final class Progress extends Update implements JsonSerializable
public readonly int $failCount,
) {
parent::__construct($API);
$this->percent = $pendingCount ? (int) (($successCount+$failCount)*100/$pendingCount) : 0;
$this->percent = $status === Status::FINISHED
? 100
: ($pendingCount ? (int) (($successCount+$failCount)*100/$pendingCount) : 0);
}
public function __toString(): string
{

View File

@ -411,7 +411,7 @@ final class Connection
$arguments['peer'] = 'me';
}
}
if (\is_array($arguments['media']) && isset($arguments['media']['_'])) {
if (isset($arguments['media']) && \is_array($arguments['media']) && isset($arguments['media']['_'])) {
$this->API->processMedia($arguments['media'], $arguments['cancellation'] ?? null);
if ($arguments['media']['_'] === 'inputMediaUploadedPhoto'
&& (
@ -529,6 +529,7 @@ final class Connection
'reply_to_msg_id' => $arguments['reply_to_msg_id'],
'top_msg_id' => $arguments['top_msg_id'] ?? null
];
unset($arguments['reply_to_msg_id'], $arguments['top_msg_id']);
}
}
/**

View File

@ -0,0 +1,34 @@
<?php declare(strict_types=1);
/**
* This file is part of MadelineProto.
* MadelineProto is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* MadelineProto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
* You should have received a copy of the GNU General Public License along with MadelineProto.
* If not, see <http://www.gnu.org/licenses/>.
*
* @author Daniil Gentili <daniil@daniil.it>
* @copyright 2016-2023 Daniil Gentili <daniil@daniil.it>
* @license https://opensource.org/licenses/AGPL-3.0 AGPLv3
* @link https://docs.madelineproto.xyz MadelineProto documentation
*/
namespace danog\MadelineProto\EventHandler\Plugin;
use danog\MadelineProto\EventHandler\Filter\FilterCommand;
use danog\MadelineProto\EventHandler\Message;
use danog\MadelineProto\EventHandler\SimpleFilter\FromAdmin;
use danog\MadelineProto\EventHandler\SimpleFilter\Incoming;
use danog\MadelineProto\PluginEventHandler;
/**
* Plugin that offers a /restart command to admins that can be used to restart the bot, applying changes.
*/
final class RestartPlugin extends PluginEventHandler {
#[FilterCommand('restart')]
public function cmd(Incoming&Message&FromAdmin $_): void
{
$this->restart();
}
}

View File

@ -370,6 +370,7 @@ trait AuthKeyHandler
$this->API->logger('Diffie Hellman key exchange processed successfully!', Logger::VERBOSE);
$key = $expires_in < 0 ? new PermAuthKey() : new TempAuthKey();
if ($expires_in >= 0) {
\assert($key instanceof TempAuthKey);
$key->expires(time() + $expires_in);
}
$key->setServerSalt(substr($new_nonce, 0, 8) ^ substr($server_nonce, 0, 8));

View File

@ -109,7 +109,7 @@ trait CallHandler
{
$cancellation = $args['cancellation'] ?? null;
$cancellation?->throwIfRequested();
if (isset($args['id']) && is_array($args['id']) && isset($args['id']['_']) && isset($args['id']['dc_id']) && ($args['id']['_'] === 'inputBotInlineMessageID' || $args['id']['_'] === 'inputBotInlineMessageID64') && $this->datacenter != $args['id']['dc_id']) {
if (isset($args['id']) && \is_array($args['id']) && isset($args['id']['_']) && isset($args['id']['dc_id']) && ($args['id']['_'] === 'inputBotInlineMessageID' || $args['id']['_'] === 'inputBotInlineMessageID64') && $this->datacenter != $args['id']['dc_id']) {
return $this->API->methodCallAsyncWrite($method, $args, $args['id']['dc_id']);
}
$file = \in_array($method, ['upload.saveFilePart', 'upload.saveBigFilePart', 'upload.getFile', 'upload.getCdnFile'], true);

View File

@ -1100,7 +1100,6 @@ trait Files
$cdn = false;
$params[0]['previous_promise'] = true;
$start = microtime(true);
$old_dc = null;
$size = $this->downloadPart($messageMedia, $cdn, $datacenter, $old_dc, $ige, $cb, $initParam = array_shift($params), $callable, $seekable, $cancellation);
if ($initParam['part_end_at'] - $initParam['part_start_at'] !== $size) {
// Premature end for undefined length files
@ -1203,7 +1202,6 @@ trait Files
$messageMedia['file_token'] = $res['file_token'];
$messageMedia['cdn_key'] = $res['encryption_key'];
$messageMedia['cdn_iv'] = $res['encryption_iv'];
$old_dc = $datacenter;
$datacenter = ($this->isTestMode() ? 10_000 : 0) + $res['dc_id'];
if (!$this->datacenter->has($datacenter)) {
$this->config['expires'] = -1;
@ -1216,7 +1214,7 @@ trait Files
$this->config['expires'] = 0;
$this->getConfig();
try {
$this->addCdnHashes($messageMedia['file_token'], $this->methodCallAsyncRead('upload.reuploadCdnFile', ['file_token' => $messageMedia['file_token'], 'request_token' => $res['request_token'], 'cancellation' => $cancellation], $datacenter));
$this->addCdnHashes($messageMedia['file_token'], $this->methodCallAsyncRead('upload.reuploadCdnFile', ['file_token' => $messageMedia['file_token'], 'request_token' => $res['request_token'], 'cancellation' => $cancellation], $this->authorized_dc));
} catch (RPCErrorException $e) {
switch ($e->rpc) {
case 'FILE_TOKEN_INVALID':
@ -1250,7 +1248,7 @@ trait Files
if (isset($messageMedia['cdn_key'])) {
$ivec = substr($messageMedia['cdn_iv'], 0, 12).pack('N', $offset['offset'] >> 4);
$res['bytes'] = Crypt::ctrEncrypt($res['bytes'], $messageMedia['cdn_key'], $ivec);
$this->checkCdnHash($messageMedia['file_token'], $offset['offset'], $res['bytes'], $old_dc, $cancellation);
$this->checkCdnHash($messageMedia['file_token'], $offset['offset'], $res['bytes'], $cancellation);
}
if (isset($messageMedia['key'])) {
$res['bytes'] = $ige->decrypt($res['bytes']);
@ -1281,11 +1279,11 @@ trait Files
$this->cdn_hashes[$file][$hash['offset']] = ['limit' => $hash['limit'], 'hash' => (string) $hash['hash']];
}
}
private function checkCdnHash(string $file, int $offset, string $data, int &$datacenter, ?Cancellation $cancellation): void
private function checkCdnHash(string $file, int $offset, string $data, ?Cancellation $cancellation): void
{
while (\strlen($data)) {
if (!isset($this->cdn_hashes[$file][$offset])) {
$this->addCdnHashes($file, $this->methodCallAsyncRead('upload.getCdnFileHashes', ['file_token' => $file, 'offset' => $offset, 'cancellation' => $cancellation], $datacenter));
$this->addCdnHashes($file, $this->methodCallAsyncRead('upload.getCdnFileHashes', ['file_token' => $file, 'offset' => $offset, 'cancellation' => $cancellation], $this->authorized_dc));
}
if (!isset($this->cdn_hashes[$file][$offset])) {
throw new Exception('Could not fetch CDN hashes for offset '.$offset);

View File

@ -32,11 +32,15 @@ abstract class SqlAbstract extends DriverDatabaseAbstract
/**
* Maximum connection limit.
*
* @var positive-int
*/
protected int $maxConnections = 100;
/**
* Idle timeout.
*
* @var positive-int
*/
protected int $idleTimeout = 60;
@ -47,6 +51,8 @@ abstract class SqlAbstract extends DriverDatabaseAbstract
/**
* Get maximum connection limit.
*
* @return positive-int
*/
public function getMaxConnections(): int
{
@ -56,7 +62,7 @@ abstract class SqlAbstract extends DriverDatabaseAbstract
/**
* Set maximum connection limit.
*
* @param int $maxConnections Maximum connection limit.
* @param positive-int $maxConnections Maximum connection limit.
*/
public function setMaxConnections(int $maxConnections): static
{
@ -67,6 +73,8 @@ abstract class SqlAbstract extends DriverDatabaseAbstract
/**
* Get idle timeout.
*
* @return positive-int
*/
public function getIdleTimeout(): int
{
@ -76,7 +84,7 @@ abstract class SqlAbstract extends DriverDatabaseAbstract
/**
* Set idle timeout.
*
* @param int $idleTimeout Idle timeout.
* @param positive-int $idleTimeout Idle timeout.
*/
public function setIdleTimeout(int $idleTimeout): static
{

View File

@ -11,7 +11,7 @@ if ping -c 1 192.168.69.206; then
fi
has_x86=0
for f in 192.168.1.30 192.168.69.236 192.168.69.207; do
for f in 192.168.1.30 192.168.69.236 192.168.69.207 192.168.69.130; do
if ping -c 1 $f; then
docker buildx create --append --name wp --driver remote tcp://$f:1234
has_x86=1

View File

@ -16,7 +16,9 @@ mv MadelineProtoDocs-master/ docs
git submodule init schemas
git submodule update schemas
export COMPOSER_PROCESS_TIMEOUT=10000
composer update
composer build
if [ "$(git diff)" != "" ]; then echo "Please run composer build!"; exit 1; fi
if [ "$(git diff)" != "" ]; then echo "Please run composer build!"; exit 1; fi