diff --git a/CHANGELOG.md b/CHANGELOG.md
index c8fbd366a..fbf1a3047 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,7 @@ Fixes:
- Improved the `markdownEscape` function!
- Translated even more MadelineProto UI elements!
- Now the same static analysis rules are applied for both plugins and simple event handlers.
+- Made some fixes to simple filters.
---
diff --git a/README.md b/README.md
index 043f1e812..6f2e47a5c 100644
--- a/README.md
+++ b/README.md
@@ -495,7 +495,7 @@ Want to add your own open-source project to this list? [Click here!](https://doc
* Get diffie-hellman configuration: getDhConfig
* Get download info of file: getDownloadInfo
* Get download info of the propic of a user: getPropicInfo
- * Get download link of media file: getDownloadLink
+ * Get download link of media file: getDownloadLink
* Get event handler (or plugin instance): getEventHandler
* Get extension from file location: getExtensionFromLocation
* Get extension from mime type: getExtensionFromMime
@@ -617,6 +617,7 @@ Want to add your own open-source project to this list? [Click here!](https://doc
* Install a theme: account.installTheme
* Install/uninstall wallpaper: account.saveWallPaper
* Installs a previously uploaded photo as a profile photo: photos.updateProfilePhoto
+ * Internal endpoint used by the download server: processDownloadServerPing
* Internal use: help.editUserInfo
* Invite a set of users to a group call: phone.inviteToGroupCall
* Invite users to a channel/supergroup: channels.inviteToChannel
diff --git a/examples/bot.php b/examples/bot.php
index a9d42def2..7818b4c48 100755
--- a/examples/bot.php
+++ b/examples/bot.php
@@ -30,7 +30,6 @@ use danog\MadelineProto\EventHandler\Filter\FilterText;
use danog\MadelineProto\EventHandler\Message;
use danog\MadelineProto\EventHandler\SimpleFilter\FromAdmin;
use danog\MadelineProto\EventHandler\SimpleFilter\Incoming;
-use danog\MadelineProto\EventHandler\SimpleFilter\IsReply;
use danog\MadelineProto\Logger;
use danog\MadelineProto\Settings;
use danog\MadelineProto\Settings\Database\Mysql;
@@ -184,8 +183,12 @@ class MyEventHandler extends SimpleEventHandler
* Gets a download link for any file up to 4GB!
*/
#[FilterCommand('dl')]
- public function downloadLink(Incoming&Message&IsReply $message): void
+ public function downloadLink(Incoming&Message $message): void
{
+ if (!$message->replyToMsgId) {
+ $message->reply("This command must reply to a media message!");
+ return;
+ }
$message = $message->getReply();
if (!$message instanceof Message || !$message->media) {
$message->reply("This command must reply to a media message!");
diff --git a/src/InternalDoc.php b/src/InternalDoc.php
index 150715793..89d1b09a6 100644
--- a/src/InternalDoc.php
+++ b/src/InternalDoc.php
@@ -1355,6 +1355,13 @@ abstract class InternalDoc
{
return \danog\MadelineProto\Tools::posmod($a, $b);
}
+ /**
+ * Internal endpoint used by the download server.
+ */
+ public function processDownloadServerPing(string $path, string $payload): void
+ {
+ $this->wrapper->getAPI()->processDownloadServerPing($path, $payload);
+ }
/**
* Initiates QR code login.
*
diff --git a/src/Ipc/Runner/RunnerAbstract.php b/src/Ipc/Runner/RunnerAbstract.php
index 2ce33d98c..daf8bbd83 100644
--- a/src/Ipc/Runner/RunnerAbstract.php
+++ b/src/Ipc/Runner/RunnerAbstract.php
@@ -6,9 +6,6 @@ namespace danog\MadelineProto\Ipc\Runner;
use Phar;
-use const MADELINE_PHAR;
-use const MADELINE_PHP;
-
/**
* @internal
*/
diff --git a/src/MTProtoTools/FileServer.php b/src/MTProtoTools/FileServer.php
index 212174fae..026a95a8d 100644
--- a/src/MTProtoTools/FileServer.php
+++ b/src/MTProtoTools/FileServer.php
@@ -45,7 +45,8 @@ trait FileServer
public static function downloadServer(string $session): void
{
if (isset($_GET['c'])) {
- self::$checkedScripts[$_GET['c']] = $_GET['i'];
+ $API = new API($session);
+ $API->processDownloadServerPing($_GET['c'], $_GET['i']);
die;
}
if (!isset($_GET['f'])) {
@@ -61,6 +62,14 @@ trait FileServer
);
}
+ /**
+ * Internal endpoint used by the download server.
+ */
+ public function processDownloadServerPing(string $path, string $payload): void
+ {
+ self::$checkedScripts[$path] = $payload;
+ }
+
/**
* Get download link of media file.
*/
@@ -104,17 +113,17 @@ trait FileServer
}
private static array $checkedAutoload = [];
- private const DOWNLOAD_SCRIPT = 'getSessionName();
- if (\defined(MADELINE_PHP)) {
- $autoloadPath = MADELINE_PHP;
- } elseif (\defined(MADELINE_PHAR)) {
- $autoloadPath = MADELINE_PHAR;
+ if (\defined('MADELINE_PHP')) {
+ $autoloadPath = \MADELINE_PHP;
+ } elseif (\defined('MADELINE_PHAR')) {
+ $autoloadPath = \MADELINE_PHAR;
} else {
$paths = [
\dirname(__DIR__, 4).'/autoload.php',
@@ -139,7 +148,7 @@ trait FileServer
return self::$checkedAutoload[$autoloadPath];
}
$downloadScript = \sprintf(self::DOWNLOAD_SCRIPT, \var_export($autoloadPath, true));
- $f = $s.DIRECTORY_SEPARATOR.\hash('sha256', $autoloadPath);
+ $f = $s.DIRECTORY_SEPARATOR.'dl.php';
$recreate = true;
if (exists($f)) {
$recreate = read($f) !== $downloadScript;
@@ -177,10 +186,16 @@ trait FileServer
if (isset(self::$checkedScripts[$scriptUrl])) {
return;
}
- $i = \random_int(PHP_INT_MIN, PHP_INT_MAX);
- $this->fileGetContents($scriptUrl.'?'.\http_build_query(['c' => $scriptUrl, 'i' => $i]));
- if (!isset(self::$checkedScripts[$scriptUrl]) || self::$checkedScripts[$scriptUrl] !== $i) {
- throw new AssertionError("$scriptUrl is not a valid download script!");
+ $i = (string) \random_int(PHP_INT_MIN, PHP_INT_MAX);
+ $scriptUrl = $scriptUrl.'?'.\http_build_query(['c' => $scriptUrl, 'i' => $i]);
+ $this->logger->logger("Checking $scriptUrl...");
+ $this->fileGetContents($scriptUrl);
+ if (!isset(self::$checkedScripts[$scriptUrl])) {
+ throw new AssertionError("$scriptUrl is not a valid download script, the check array wasn't populated!");
+ }
+ if (self::$checkedScripts[$scriptUrl] !== $i) {
+ $v = self::$checkedScripts[$scriptUrl];
+ throw new AssertionError("$scriptUrl is not a valid download script, the check array contains {$v} instead of $i!");
}
} finally {
$lock->release();