-
Notifications
You must be signed in to change notification settings - Fork 4
Message filtering support #14
Changes from 1 commit
fe7fc8f
252137d
d0bac36
9a9f44c
d4ec81a
9b5b8f8
05af0f0
0c30d2e
637af13
06a3cb9
feccdf5
aa1a8a5
ef1897b
5880cc5
1d66cd1
8e3c51d
d2109d2
862ed45
2aed4c3
30ee474
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |
| use Phergie\Irc\Bot\React\EventQueue; | ||
| use Phergie\Irc\Client\React\LoopAwareInterface; | ||
| use Phergie\Irc\Event\UserEvent; | ||
| use Phergie\Irc\Plugin\React\EventFilter\FilterInterface; | ||
| use React\Promise\Deferred; | ||
| use Phergie\Plugin\Http\Request; | ||
|
|
||
|
|
@@ -27,7 +28,8 @@ | |
| */ | ||
| class Plugin extends AbstractPlugin implements LoopAwareInterface | ||
| { | ||
| const URL_HANDLER_INTERFACE = 'Phergie\Irc\Plugin\React\Url\UrlHandlerInterface'; | ||
| const URL_HANDLER_INTERFACE = 'Phergie\Irc\Plugin\React\Url\UrlHandlerInterface'; | ||
| const EVENT_FILTER_INTERFACE = 'Phergie\Irc\Plugin\React\EventFilter\FilterInterface'; | ||
|
|
||
| /** | ||
| * @var UrlHandlerInterface | ||
|
|
@@ -42,6 +44,11 @@ class Plugin extends AbstractPlugin implements LoopAwareInterface | |
| */ | ||
| protected $hostUrlEmitsOnly = false; | ||
|
|
||
| /** | ||
| * @var FilterInterface | ||
| */ | ||
| protected $filter = null; | ||
|
|
||
| /** | ||
| * @var LoopInterface | ||
| */ | ||
|
|
@@ -73,6 +80,12 @@ public function __construct(array $config = []) | |
| if (isset($config['hostUrlEmitsOnly'])) { | ||
| $this->hostUrlEmitsOnly = boolval($config['hostUrlEmitsOnly']); | ||
| } | ||
| if ( | ||
| isset($config['filter']) && | ||
| in_array(static::EVENT_FILTER_INTERFACE, class_implements($config['filter'])) | ||
| ) { | ||
| $this->filter = $config['filter']; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -113,6 +126,12 @@ public function logDebug($message) | |
|
|
||
| public function handleIrcReceived(UserEvent $event, EventQueue $queue) | ||
| { | ||
| if ( | ||
| $this->filter !== null && | ||
| $this->filter->filter($event) !== false | ||
| ) { | ||
| return; | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original impetus for filing #11 was to facilitate filtering out URLs by hostname. If the event filter doesn't have access to the parsed URLs or has to parse them a second time, it seems to defeat that point. It's already possible to use this plugin with the EventFilter plugin via configuration without any changes to this plugin (see usage documentation). What I want is filtering specific to URLs.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, currently writing a set of filters that lets user filter based on hostname, path, protocol, and port. |
||
| $params = $event->getParams(); | ||
| $extractor = new \Twitter_Extractor($params['text']); | ||
| $urls = $extractor->extractURLs(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any particular reason for using a constant versus just referencing
FilterInterface::classwhere needed?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Force of 5.4 habbit, I'll update both of them