2023-07-14 16:34:52 +02:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
|
2023-07-14 18:29:20 +02:00
|
|
|
namespace MadelinePlugin\Danogentili;
|
|
|
|
|
2023-07-14 16:34:52 +02:00
|
|
|
use danog\MadelineProto\EventHandler\Attributes\Cron;
|
|
|
|
use danog\MadelineProto\EventHandler\Filter\FilterCommand;
|
|
|
|
use danog\MadelineProto\EventHandler\Message;
|
|
|
|
use danog\MadelineProto\EventHandler\SimpleFilter\FromAdmin;
|
|
|
|
use danog\MadelineProto\EventHandler\SimpleFilter\Incoming;
|
|
|
|
use danog\MadelineProto\PluginEventHandler;
|
|
|
|
|
2023-07-14 18:29:20 +02:00
|
|
|
final class OnlinePlugin extends PluginEventHandler
|
2023-07-14 16:34:52 +02:00
|
|
|
{
|
|
|
|
private bool $isOnline = true;
|
|
|
|
|
2023-08-27 11:04:18 +02:00
|
|
|
/**
|
|
|
|
* Returns a list of names for properties that will be automatically saved to the session database (MySQL/postgres/redis if configured, the session file otherwise).
|
|
|
|
*/
|
|
|
|
public function __sleep(): array
|
|
|
|
{
|
|
|
|
return ['isOnline'];
|
|
|
|
}
|
|
|
|
|
2023-07-14 16:34:52 +02:00
|
|
|
public function setOnline(bool $online): void
|
|
|
|
{
|
|
|
|
$this->isOnline = $online;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isPluginEnabled(): bool
|
|
|
|
{
|
|
|
|
// Only users can be online/offline
|
|
|
|
return $this->getSelf()['bot'] === false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#[Cron(period: 60.0)]
|
|
|
|
public function cron(): void
|
|
|
|
{
|
|
|
|
$this->account->updateStatus(offline: !$this->isOnline);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[FilterCommand('online')]
|
|
|
|
public function toggleOnline(Incoming&Message&FromAdmin $message): void
|
|
|
|
{
|
|
|
|
$this->isOnline = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#[FilterCommand('offline')]
|
|
|
|
public function toggleOffline(Incoming&Message&FromAdmin $message): void
|
|
|
|
{
|
|
|
|
$this->isOnline = false;
|
|
|
|
}
|
|
|
|
}
|