make working event filter

This commit is contained in:
Mateusz Pieła 2021-04-27 09:43:13 +02:00
parent 0b96c27957
commit 096f91cd74
4 changed files with 42 additions and 3 deletions

View file

@ -32,6 +32,20 @@ class webhook extends core
return $this->json->text; 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;
}
} }
?> ?>

View file

@ -28,10 +28,15 @@ class xmpp extends core{
$this->xmpp_client->connect(); $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) foreach($this->config->xmpp_recipients as $receipient)
{ {
if($this->checkIfEventFilter($event_filter,$receipient['event_filter']))
{
continue;
}
$type = $this->getChatType($receipient['type']); $type = $this->getChatType($receipient['type']);
if($type === "groupchat") { 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 private function getChatType(int $type): string
{ {
if($type === 1) if($type === 1)

View file

@ -66,8 +66,12 @@ class config
* 1 = Normal chat * 1 = Normal chat
* 2 = Group chat * 2 = Group chat
* *
* Muc Nickname
*
*
* Event_Filter
*/ */
public $xmpp_recipients = array( public $xmpp_recipients = array(
array("jid" => "", "type" => 1, "muc_nickname" => ""), array("jid" => "", "type" => 1, "muc_nickname" => "", "event_filter" => ""),
); );
} }

View file

@ -83,7 +83,7 @@ class app
$xmpp->start(); $xmpp->start();
$xmpp->connect(); $xmpp->connect();
$xmpp->sendMessage($wh->getMessage()); $xmpp->sendMessage($wh->getMessage(),$wh->getEventFilter());
$xmpp->disconnect(); $xmpp->disconnect();
} }