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;
}
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();
}
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)