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

Add support for @replies messages

- Add CommentReply class
- Add FilterCommentReply class
- Some changes for chatId ,senderId,messageId (named id here)
This commit is contained in:
Mahdi 2024-06-11 15:09:02 +03:30
parent 3b578f225a
commit 36d1ab7ee5
5 changed files with 65 additions and 6 deletions

View File

@ -93,12 +93,13 @@ abstract class AbstractMessage extends Update implements SimpleFilters
} else {
$secretChat = null;
}
$fromReplies = (($info['User']['username'] ?? '') === 'replies');
$this->out = $rawMessage['out'] ?? false;
$this->id = $rawMessage['id'] ?? $rawMessage['random_id'];
$this->chatId = isset($secretChat) ? $secretChat->chatId : $info['bot_api_id'];
$this->senderId = isset($secretChat) ? $secretChat->otherID : (isset($rawMessage['from_id'])
$this->id = $fromReplies ? $rawMessage['fwd_from']['saved_from_msg_id'] : $rawMessage['id'] ?? $rawMessage['random_id'];
$this->chatId = isset($secretChat) ? $secretChat->chatId : ($fromReplies ? $rawMessage['reply_to']['reply_to_peer_id'] : $info['bot_api_id']);
$this->senderId = isset($secretChat) ? $secretChat->otherID : ($fromReplies ? $this->getClient()->getIdInternal($rawMessage['fwd_from']['from_id']) : (isset($rawMessage['from_id'])
? $this->getClient()->getIdInternal($rawMessage['from_id'])
: $this->chatId);
: $this->chatId));
$this->date = $rawMessage['date'];
$this->mentioned = $rawMessage['mentioned'] ?? false;
$this->silent = $rawMessage['silent'] ?? false;

View File

@ -0,0 +1,33 @@
<?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 Mahdi <mahdi.talaee1379@gmail.com>
* @copyright 2016-2023 Mahdi <mahdi.talaee1379@gmail.com>
* @license https://opensource.org/licenses/AGPL-3.0 AGPLv3
* @link https://docs.madelineproto.xyz MadelineProto documentation
*/
namespace danog\MadelineProto\EventHandler\Filter;
use Attribute;
use danog\MadelineProto\EventHandler\Message\CommentReply;
use danog\MadelineProto\EventHandler\Update;
/**
* Allow messages that coming from @replies.
*/
#[Attribute(Attribute::TARGET_METHOD)]
class FilterCommentReply extends Filter
{
public function apply(Update $update): bool
{
return $update instanceof CommentReply;
}
}

View File

@ -0,0 +1,24 @@
<?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 Mahdi <mahdi.talaee1379@gmail.com>
* @copyright 2016-2023 Mahdi <mahdi.talaee1379@gmail.com>
* @license https://opensource.org/licenses/AGPL-3.0 AGPLv3
* @link https://docs.madelineproto.xyz MadelineProto documentation
*/
namespace danog\MadelineProto\EventHandler\Message;
/**
* Represents a reply message that in channel comments.
*/
final class CommentReply extends GroupMessage
{
}

View File

@ -29,7 +29,7 @@ use Webmozart\Assert\InvalidArgumentException;
/**
* Represents an incoming or outgoing group message.
*/
final class GroupMessage extends Message
class GroupMessage extends Message
{
/**
* Get info about a [channel/supergroup](https://core.telegram.org/api/channel) participant.

View File

@ -49,6 +49,7 @@ use danog\MadelineProto\EventHandler\Delete\DeleteScheduledMessages;
use danog\MadelineProto\EventHandler\InlineQuery;
use danog\MadelineProto\EventHandler\Message;
use danog\MadelineProto\EventHandler\Message\ChannelMessage;
use danog\MadelineProto\EventHandler\Message\CommentReply;
use danog\MadelineProto\EventHandler\Message\GroupMessage;
use danog\MadelineProto\EventHandler\Message\PrivateMessage;
use danog\MadelineProto\EventHandler\Message\SecretMessage;
@ -778,7 +779,7 @@ trait UpdateHandler
};
}
if (($info['User']['username'] ?? '') === 'replies') {
return null;
return new CommentReply($this, $message, $info, $scheduled);
}
if ($message['_'] === 'encryptedMessage') {
return new SecretMessage($this, $message, $info, $scheduled);