-
-
Notifications
You must be signed in to change notification settings - Fork 714
/
Copy pathOnlinePlugin.php
52 lines (43 loc) · 1.41 KB
/
OnlinePlugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php declare(strict_types=1);
namespace MadelinePlugin\Danogentili;
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;
final class OnlinePlugin extends PluginEventHandler
{
private bool $isOnline = true;
/**
* 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'];
}
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;
}
}