mirror of
https://github.com/danog/MadelineProto.git
synced 2024-11-26 19:04:40 +01:00
Fixes
This commit is contained in:
parent
cc740b73f2
commit
9c3c52ce23
14
CHANGELOG.md
14
CHANGELOG.md
@ -1,3 +1,17 @@
|
||||
MadelineProto was updated (8.0.0-beta114)!
|
||||
|
||||
Features:
|
||||
- Added `DialogMessagePinned` service message with a `getPinnedMessage()` method.
|
||||
|
||||
Fixes:
|
||||
- Fixed simple filters with service messages.
|
||||
- Fixed IDE typehinting for `getEventHandler`
|
||||
- Fixed startAndLoopMulti
|
||||
- Tweaked the default drop timeout on media DCs to avoid timeout errors on slow networks
|
||||
- Now the admin list only contains user report peers.
|
||||
|
||||
---
|
||||
|
||||
MadelineProto was updated (8.0.0-beta101)!
|
||||
|
||||
After introducing [plugins »](https://docs.madelineproto.xyz/docs/PLUGINS.html), [bound methods »](https://docs.madelineproto.xyz/docs/UPDATES.html#bound-methods), [filters »](https://docs.madelineproto.xyz/docs/FILTERS.html), [a built-in cron system »](https://docs.madelineproto.xyz/docs/UPDATES.html#cron), [IPC support for the event handler »](https://docs.madelineproto.xyz/docs/UPDATES.html#persisting-data-and-ipc) and [automatic static analysis for event handler code »](https://docs.madelineproto.xyz/docs/UPDATES.html#automatic-static-analysis) in beta100, beta101 brings some bugfixes and the `getDownloadLink` function!
|
||||
|
@ -28,6 +28,8 @@ use danog\MadelineProto\EventHandler\Filter\FilterCommand;
|
||||
use danog\MadelineProto\EventHandler\Filter\FilterRegex;
|
||||
use danog\MadelineProto\EventHandler\Filter\FilterText;
|
||||
use danog\MadelineProto\EventHandler\Message;
|
||||
use danog\MadelineProto\EventHandler\Message\Service\DialogMessagePinned;
|
||||
use danog\MadelineProto\EventHandler\Message\Service\DialogPhotoChanged;
|
||||
use danog\MadelineProto\EventHandler\SimpleFilter\FromAdmin;
|
||||
use danog\MadelineProto\EventHandler\SimpleFilter\Incoming;
|
||||
use danog\MadelineProto\Logger;
|
||||
@ -180,6 +182,20 @@ class MyEventHandler extends SimpleEventHandler
|
||||
$message->reply('hello');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called when the dialog photo of a chat or channel changes.
|
||||
*/
|
||||
#[Handler]
|
||||
public function logPhotoChanged(Incoming&DialogPhotoChanged $message): void
|
||||
{
|
||||
if ($message->photo) {
|
||||
$message->reply("Nice :D");
|
||||
} else {
|
||||
$message->reply("Aww, why did you delete the group photo? :(");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a download link for any file up to 4GB!
|
||||
*/
|
||||
|
@ -76,12 +76,7 @@ class MyEventHandler extends EventHandler
|
||||
}
|
||||
|
||||
$MadelineProtos = [];
|
||||
foreach ([
|
||||
'session1.madeline' => 'Bot Login',
|
||||
'session2.madeline' => 'Userbot login',
|
||||
'session3.madeline' => 'Userbot login (2)',
|
||||
] as $session => $message) {
|
||||
Logger::log($message, Logger::WARNING);
|
||||
foreach (['session1.madeline', 'session2.madeline', 'session3.madeline'] as $session => $message) {
|
||||
$MadelineProtos []= new API($session);
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ use danog\MadelineProto\Tools;
|
||||
use const PHP_EOL;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @internal This garbage code needs to be thrown away completely and rewritten from scratch.
|
||||
*/
|
||||
trait Constructors
|
||||
{
|
||||
|
@ -35,7 +35,7 @@ use ReflectionMethod;
|
||||
use const PHP_EOL;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @internal This garbage code needs to be thrown away completely and rewritten from scratch.
|
||||
*/
|
||||
trait Methods
|
||||
{
|
||||
@ -185,7 +185,7 @@ trait Methods
|
||||
}
|
||||
$type_or_bare_type = \ctype_upper(Tools::end(\explode('.', $param[$type_or_subtype]))[0]) || \in_array($param[$type_or_subtype], ['!X', 'X', 'bytes', 'true', 'false', 'double', 'string', 'Bool', 'int', 'long', 'int128', 'int256', 'int512', 'int53'], true) ? 'types' : 'constructors';
|
||||
if (isset($this->tdDescriptions['methods'][$method])) {
|
||||
$table .= '|'.self::markdownEscape($param['name']).'|'.(isset($param['subtype']) ? 'Array of ' : '').'['.self::markdownEscape($human_ptype).'](/API_docs/'.$type_or_bare_type.'/'.$ptype.'.md) | '.$this->tdDescriptions['methods'][$method]['params'][$param['name']].' | '.(isset($param['pow']) || $param['type'] === 'int' || ($id = $this->TL->getConstructors($this->td)->findByPredicate(\lcfirst($param['type']).'Empty')) && $id['type'] === $param['type'] || ($id = $this->TL->getConstructors($this->td)->findByPredicate('input'.$param['type'].'Empty')) && $id['type'] === $param['type'] ? 'Optional' : 'Yes').'|';
|
||||
$table .= '|'.self::markdownEscape($param['name']).'|'.(isset($param['subtype']) ? 'Array of ' : '').'['.self::markdownEscape($human_ptype).'](/API_docs/'.$type_or_bare_type.'/'.$ptype.'.md) | '.$this->tdDescriptions['methods'][$method]['params'][$param['name']].' | '.(isset($param['pow']) || $param['type'] === 'int' || $param['type'] === 'double' || ($id = $this->TL->getConstructors($this->td)->findByPredicate(\lcfirst($param['type']).'Empty')) && $id['type'] === $param['type'] || ($id = $this->TL->getConstructors($this->td)->findByPredicate('input'.$param['type'].'Empty')) && $id['type'] === $param['type'] ? 'Optional' : 'Yes').'|';
|
||||
} else {
|
||||
$table .= '|'.self::markdownEscape($param['name']).'|'.(isset($param['subtype']) ? 'Array of ' : '').'['.self::markdownEscape($human_ptype).'](/API_docs/'.$type_or_bare_type.'/'.$ptype.'.md) | '.(isset($param['pow']) || ($param['type'] === 'long' && $param['name'] === 'hash')|| ($id = $this->TL->getConstructors($this->td)->findByPredicate(\lcfirst($param['type']).'Empty')) && $id['type'] === $param['type'] || ($id = $this->TL->getConstructors($this->td)->findByPredicate('input'.$param['type'].'Empty')) && $id['type'] === $param['type'] ? 'Optional' : 'Yes').'|';
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ abstract class AbstractMessage extends Update implements SimpleFilters
|
||||
$this->silent = $rawMessage['silent'];
|
||||
$this->ttlPeriod = $rawMessage['ttl_period'] ?? null;
|
||||
|
||||
if (isset($rawMessage['reply_to'])) {
|
||||
if (isset($rawMessage['reply_to']) && $rawMessage['reply_to']['_'] === 'messageReplyHeader') {
|
||||
$replyTo = $rawMessage['reply_to'];
|
||||
$this->replyToScheduled = $replyTo['reply_to_scheduled'];
|
||||
if ($replyTo['forum_topic']) {
|
||||
@ -119,7 +119,7 @@ abstract class AbstractMessage extends Update implements SimpleFilters
|
||||
API::isSupergroup($this->chatId) ? 'channels.getMessages' : 'messages.getMessages',
|
||||
[
|
||||
'channel' => $this->chatId,
|
||||
'id' => [$this->replyToMsgId]
|
||||
'id' => [['_' => 'inputMessageReplyTo', 'id' => $this->id]]
|
||||
]
|
||||
)['messages'][0]);
|
||||
}
|
||||
|
@ -91,7 +91,16 @@ abstract class Filter
|
||||
HasSticker::class => new FilterSticker,
|
||||
HasVideo::class => new FilterVideo,
|
||||
HasVoice::class => new FilterVoice,
|
||||
default => throw new AssertionError("Unknown type ".$type->getName())
|
||||
default => is_subclass_of($type->getName(), Update::class)
|
||||
? new class($type->getName()) extends Filter {
|
||||
public function __construct(private readonly string $class)
|
||||
{
|
||||
}
|
||||
public function apply(Update $update): bool {
|
||||
return $update instanceof $this->class;
|
||||
}
|
||||
}
|
||||
: throw new AssertionError("Unknown type ".$type->getName())
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -104,6 +104,9 @@ trait AckHandler
|
||||
$unencrypted = !$this->shared->hasTempAuthKey();
|
||||
$notBound = !$this->shared->isBound();
|
||||
$pfsNotBound = $pfs && $notBound;
|
||||
if ($this->datacenter < 0) {
|
||||
$dropTimeout *= 10;
|
||||
}
|
||||
$result = [];
|
||||
/** @var MTProtoOutgoingMessage $message */
|
||||
foreach ($this->new_outgoing as $message_id => $message) {
|
||||
|
@ -335,7 +335,10 @@ trait AuthKeyHandler
|
||||
* ***********************************************************************
|
||||
* Generate auth_key
|
||||
*/
|
||||
$this->logger->logger('Generating authorization key...', Logger::VERBOSE);
|
||||
$this->logger->logger(
|
||||
extension_loaded('gmp') ? 'Generating authorization key...' : 'Generating authorization key (install gmp to speed up this process)...',
|
||||
Logger::VERBOSE
|
||||
);
|
||||
$auth_key = $g_a->powMod($b, $dh_prime);
|
||||
$auth_key_str = $auth_key->toBytes();
|
||||
$auth_key_sha = \sha1($auth_key_str, true);
|
||||
|
@ -151,9 +151,6 @@ trait CallHandler
|
||||
)));
|
||||
}
|
||||
$args = $this->API->botAPIToMTProto($args);
|
||||
if (isset($args['ping_id']) && \is_int($args['ping_id'])) {
|
||||
$args['ping_id'] = Tools::packSignedLong($args['ping_id']);
|
||||
}
|
||||
}
|
||||
$methodInfo = $this->API->getTL()->getMethods()->findByMethod($method);
|
||||
if (!$methodInfo) {
|
||||
|
@ -27,6 +27,7 @@ use Amp\Http\Client\Response;
|
||||
use Amp\TimeoutCancellation;
|
||||
use Amp\TimeoutException;
|
||||
use danog\MadelineProto\API;
|
||||
use danog\MadelineProto\EventHandler\AbstractMessage;
|
||||
use danog\MadelineProto\EventHandler\Message;
|
||||
use danog\MadelineProto\EventHandler\Message\ChannelMessage;
|
||||
use danog\MadelineProto\EventHandler\Message\GroupMessage;
|
||||
@ -34,6 +35,7 @@ use danog\MadelineProto\EventHandler\Message\PrivateMessage;
|
||||
use danog\MadelineProto\EventHandler\Message\Service\DialogCreated;
|
||||
use danog\MadelineProto\EventHandler\Message\Service\DialogMemberLeft;
|
||||
use danog\MadelineProto\EventHandler\Message\Service\DialogMembersJoined;
|
||||
use danog\MadelineProto\EventHandler\Message\Service\DialogMessagePinned;
|
||||
use danog\MadelineProto\EventHandler\Message\Service\DialogPhotoChanged;
|
||||
use danog\MadelineProto\EventHandler\Message\Service\DialogTitleChanged;
|
||||
use danog\MadelineProto\EventHandler\Update;
|
||||
@ -338,7 +340,7 @@ trait UpdateHandler
|
||||
/**
|
||||
* Wrap a Message constructor into an abstract Message object.
|
||||
*/
|
||||
public function wrapMessage(array $message): ?Message
|
||||
public function wrapMessage(array $message): ?AbstractMessage
|
||||
{
|
||||
if ($message['_'] === 'messageEmpty') {
|
||||
return null;
|
||||
@ -386,6 +388,11 @@ trait UpdateHandler
|
||||
$info,
|
||||
$message['action']['user_id']
|
||||
),
|
||||
'messageActionPinMessage' => new DialogMessagePinned(
|
||||
$this,
|
||||
$message,
|
||||
$info,
|
||||
),
|
||||
default => null
|
||||
};
|
||||
}
|
||||
|
@ -141,7 +141,11 @@ trait Events
|
||||
/**
|
||||
* Get event handler (or plugin instance).
|
||||
*
|
||||
* @param ?class-string<PluginEventHandler> $class
|
||||
* @template T as EventHandler
|
||||
*
|
||||
* @param class-string<T>|null $class
|
||||
*
|
||||
* @return T|EventHandlerProxy|__PHP_Incomplete_Class|null
|
||||
*/
|
||||
public function getEventHandler(?string $class = null): EventHandler|EventHandlerProxy|__PHP_Incomplete_Class|null
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user