diff --git a/classes/webhook.php b/classes/webhook.php index 45862f9..711ce04 100644 --- a/classes/webhook.php +++ b/classes/webhook.php @@ -32,6 +32,20 @@ class webhook extends core return $this->json->text; } + + public function getEventFilter() + { + if(isset($this->json->event) && $this->json->event) + { + return $this->json->event; + } + elseif(isset($_GET['event']) && $_GET['event']) + { + return $_GET['event']; + } + + return false; + } } ?> \ No newline at end of file diff --git a/classes/xmpp.php b/classes/xmpp.php index c366a5c..5b12655 100644 --- a/classes/xmpp.php +++ b/classes/xmpp.php @@ -28,10 +28,15 @@ class xmpp extends core{ $this->xmpp_client->connect(); } - public function sendMessage(string $text): void + public function sendMessage(string $text,string $event_filter): void { foreach($this->config->xmpp_recipients as $receipient) { + if($this->checkIfEventFilter($event_filter,$receipient['event_filter'])) + { + continue; + } + $type = $this->getChatType($receipient['type']); if($type === "groupchat") { @@ -42,6 +47,22 @@ class xmpp extends core{ } } + private function checkIfEventFilter(string $event_filter,string $receipient_event_filter) + { + $check_filter = false; + if(!empty($event_filter)) { + if ($event_filter !== false && $event_filter !== "all") { + $check_filter = true; + } + + if ($check_filter && $receipient_event_filter !== $event_filter) { + return true; + } + } + + return false; + } + private function getChatType(int $type): string { if($type === 1) diff --git a/config/config.php.dist b/config/config.php.dist index dd7b412..e0ced35 100644 --- a/config/config.php.dist +++ b/config/config.php.dist @@ -66,8 +66,12 @@ class config * 1 = Normal chat * 2 = Group chat * + * Muc Nickname + * + * + * Event_Filter */ public $xmpp_recipients = array( - array("jid" => "", "type" => 1, "muc_nickname" => ""), + array("jid" => "", "type" => 1, "muc_nickname" => "", "event_filter" => ""), ); } \ No newline at end of file diff --git a/includes/app.php b/includes/app.php index d5a284a..0a62482 100644 --- a/includes/app.php +++ b/includes/app.php @@ -83,7 +83,7 @@ class app $xmpp->start(); $xmpp->connect(); - $xmpp->sendMessage($wh->getMessage()); + $xmpp->sendMessage($wh->getMessage(),$wh->getEventFilter()); $xmpp->disconnect(); }