forked from danog/MadelineProto
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement PSR-4 autoloading for plugin paths
- Loading branch information
Showing
17 changed files
with
324 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace danog\MadelineProto\EventHandler\Filter; | ||
|
||
use Attribute; | ||
use danog\MadelineProto\EventHandler; | ||
use danog\MadelineProto\EventHandler\Message\GroupMessage; | ||
use danog\MadelineProto\EventHandler\Update; | ||
|
||
/** | ||
* Allow incoming or outgoing group messages made by a certain list of senders. | ||
*/ | ||
#[Attribute(Attribute::TARGET_METHOD)] | ||
final class FilterFromSenders extends Filter | ||
{ | ||
/** @var array<string|int> */ | ||
private readonly array $peers; | ||
/** @var list<string|int> */ | ||
private readonly array $peersResolved; | ||
public function __construct(string|int ...$idOrUsername) | ||
{ | ||
$this->peers = \array_unique($idOrUsername); | ||
} | ||
public function initialize(EventHandler $API): ?Filter | ||
{ | ||
$res = []; | ||
foreach ($this->peers as $peer) { | ||
$res []= $API->getId($peer); | ||
} | ||
$this->peersResolved = $res; | ||
return null; | ||
} | ||
public function apply(Update $update): bool | ||
{ | ||
return $update instanceof GroupMessage && \in_array($update->senderId, $this->peersResolved, true); | ||
} | ||
} |
Oops, something went wrong.