Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Some Bounded methods #1395

Merged
merged 27 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/EventHandler/AbstractMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,38 @@ public function reply(
updateStickersetsOrder: $updateStickersetsOrder
);
}

/**
* Adds the user to the blacklist.
*
* @param boolean $stories
* @return boolean
*/
public function block(bool $stories): bool
{
return $this->getClient()->methodCallAsyncRead(
'contacts.block',
[
'id' => $this->senderId,
'my_stories_from' => $stories,
]
);
}

/**
* Deletes the user from the blacklist.
*
* @param boolean $stories
* @return boolean
*/
public function unblock(bool $stories): bool
{
return $this->getClient()->methodCallAsyncRead(
'contacts.block',
[
'id' => $this->senderId,
'my_stories_from' => $stories,
]
);
}
}
32 changes: 32 additions & 0 deletions src/EventHandler/Media/Gif.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,36 @@ public function __construct(
}
$this->hasStickers = $hasStickers;
}

/**
* Add GIF to saved gifs list
*
* @return bool
*/
public function save(): bool
{
return $this->getClient()->methodCallAsyncRead(
'messages.saveGif',
[
'id' => $this->botApiFileId,
'unsave' => false
]
);
}

/**
* Remove GIF from saved gifs list
*
* @return bool
*/
public function unsave(): bool
{
return $this->getClient()->methodCallAsyncRead(
'messages.saveGif',
[
'id' => $this->botApiFileId,
'unsave' => true
]
);
}
}
66 changes: 66 additions & 0 deletions src/EventHandler/Message/ChannelMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,16 @@

namespace danog\MadelineProto\EventHandler\Message;

use AssertionError;
use danog\MadelineProto\EventHandler\Message;
use danog\MadelineProto\MTProto;
use danog\MadelineProto\EventHandler\Participant;
use danog\MadelineProto\EventHandler\Participant\Left;
use danog\MadelineProto\EventHandler\Participant\Admin;
use danog\MadelineProto\EventHandler\Participant\Member;
use danog\MadelineProto\EventHandler\Participant\MySelf;
use danog\MadelineProto\EventHandler\Participant\Banned;
use danog\MadelineProto\EventHandler\Participant\Creator;

/**
* Represents an incoming or outgoing channel message.
Expand All @@ -32,4 +40,62 @@ public function __construct(
) {
parent::__construct($API, $rawMessage, $info);
}

/**
* Disable message signatures in channels
*/
public function disableSignatures(): void
{
$this->getClient()->methodCallAsyncRead(
'channels.toggleSignatures',
[
'channel' => $this->chatId,
'enabled' => false,
]
);
}

/**
* Enable message signatures in channels
*/
public function enableSignatures(): void
{
$this->getClient()->methodCallAsyncRead(
'channels.toggleSignatures',
[
'channel' => $this->chatId,
'enabled' => true,
]
);
}

/**
* Get info about a [channel/supergroup](https://core.telegram.org/api/channel) participant
*
* @param string|integer $member Participant to get info about.
* @return Participant
* @throws AssertionError
*/
public function getMember(string|int $member): Participant
{
$client = $this->getClient();
$member = $client->getId($member);
$result = $client->methodCallAsyncRead(
'channels.getParticipant',
[
'channel' => $this->chatId,
'participant' => $member,
]
)['participant'];

return match ($result['_']) {
'channelParticipant' => new Member($result),
'channelParticipantLeft' => new Left($client, $result),
'channelParticipantSelf' => new MySelf($result),
'channelParticipantAdmin' => new Admin($result),
'channelParticipantBanned' => new Banned($client, $result),
'channelParticipantCreator' => new Creator($result),
default => throw new AssertionError("undefined Participant type: {$result['_']}")
};
}
}
39 changes: 38 additions & 1 deletion src/EventHandler/Message/GroupMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,48 @@

namespace danog\MadelineProto\EventHandler\Message;

use AssertionError;
use danog\MadelineProto\EventHandler\Message;

use danog\MadelineProto\EventHandler\Participant;
use danog\MadelineProto\EventHandler\Participant\Left;
use danog\MadelineProto\EventHandler\Participant\Admin;
use danog\MadelineProto\EventHandler\Participant\Member;
use danog\MadelineProto\EventHandler\Participant\MySelf;
use danog\MadelineProto\EventHandler\Participant\Banned;
use danog\MadelineProto\EventHandler\Participant\Creator;
/**
* Represents an incoming or outgoing group message.
*/
final class GroupMessage extends Message
{
/**
* Get info about a [channel/supergroup](https://core.telegram.org/api/channel) participant
*
* @param string|integer|null $member Participant to get info about; can be empty or null to get info about the sender of the message.
* @return Participant
* @throws AssertionError
*/
public function getMember(string|int|null $member = null): Participant
{
$client = $this->getClient();
$member ??= $this->senderId;
$member = $client->getId($member);
$result = $client->methodCallAsyncRead(
'channels.getParticipant',
[
'channel' => $this->chatId,
'participant' => $member,
]
)['participant'];

return match ($result['_']) {
'channelParticipant' => new Member($result),
'channelParticipantLeft' => new Left($client, $result),
'channelParticipantSelf' => new MySelf($result),
'channelParticipantAdmin' => new Admin($result),
'channelParticipantBanned' => new Banned($client, $result),
'channelParticipantCreator' => new Creator($result),
default => throw new AssertionError("undefined Participant type: {$result['_']}")
};
}
}
17 changes: 17 additions & 0 deletions src/EventHandler/Message/PrivateMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,27 @@
namespace danog\MadelineProto\EventHandler\Message;

use danog\MadelineProto\EventHandler\Message;
use danog\MadelineProto\EventHandler\Message\Service\DialogScreenshotTaken;

/**
* Represents an incoming or outgoing private message.
*/
final class PrivateMessage extends Message
{
/**
* Notify the other user in a private chat that a screenshot of the chat was taken
*
* @return DialogScreenshotTaken
*/
public function screenShot(): DialogScreenshotTaken
{
$result = $this->getClient()->methodCallAsyncRead(
'messages.sendScreenshotNotification',
[
'peer' => $this->chatId,
'reply_to' => [ '_' => 'inputReplyToMessage', 'reply_to_msg_id' => 0 ],
]
);
return $this->getClient()->wrapMessage($this->getClient()->extractMessage($result));
}
}
37 changes: 37 additions & 0 deletions src/EventHandler/Message/Service/AbstractDialogCallGroup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?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\Message\Service;

use danog\MadelineProto\EventHandler\Message\ServiceMessage;
use danog\MadelineProto\MTProto;

/** @internal */
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mark only the constructor as @internal, not the class pls

abstract class AbstractDialogCallGroup extends ServiceMessage
{
public function __construct(
MTProto $API,
array $rawMessage,
array $info,

/** Group call ID */
public readonly int $id,
/** Group call access hash */
public readonly int $accessHash
) {
parent::__construct($API, $rawMessage, $info);
}
}
41 changes: 41 additions & 0 deletions src/EventHandler/Message/Service/DialogCallGroup/Called.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?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\Message\Service\DialogCallGroup;

use danog\MadelineProto\EventHandler\Message\Service\AbstractDialogCallGroup;
use danog\MadelineProto\MTProto;

/**
* The group call has ended.
*/
final class Called extends AbstractDialogCallGroup
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we name the namespace DialogGroupCall?
Also, can we just name the class GroupCallEnded? I don't like using such non-descriptive names for the class (even if more info is included in the namespace).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for the other classes in the DialogGroupCall namespace

{
public function __construct(
MTProto $API,
array $rawMessage,
array $info,

/** Group call ID */
int $id,
/** Group call access hash */
int $accessHash,
/** Group call duration */
public readonly int $duration
) {
parent::__construct($API, $rawMessage, $info, $id, $accessHash);
}
}
41 changes: 41 additions & 0 deletions src/EventHandler/Message/Service/DialogCallGroup/Invited.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?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\Message\Service\DialogCallGroup;

use danog\MadelineProto\EventHandler\Message\Service\AbstractDialogCallGroup;
use danog\MadelineProto\MTProto;

/**
* A set of users was invited to the group call.
*/
final class Invited extends AbstractDialogCallGroup
{
public function __construct(
MTProto $API,
array $rawMessage,
array $info,

/** Group call ID */
int $id,
/** Group call access hash */
int $accessHash,
/** The invited users */
public readonly array $users
) {
parent::__construct($API, $rawMessage, $info, $id, $accessHash);
}
}
41 changes: 41 additions & 0 deletions src/EventHandler/Message/Service/DialogCallGroup/Scheduled.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?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\Message\Service\DialogCallGroup;

use danog\MadelineProto\EventHandler\Message\Service\AbstractDialogCallGroup;
use danog\MadelineProto\MTProto;

/**
* A group call was scheduled.
*/
final class Scheduled extends AbstractDialogCallGroup
{
public function __construct(
MTProto $API,
array $rawMessage,
array $info,

/** Group call ID */
int $id,
/** Group call access hash */
int $accessHash,
/** When is this group call scheduled to start */
public readonly int $scheduleDate
) {
parent::__construct($API, $rawMessage, $info, $id, $accessHash);
}
}
Loading