-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAdmin.php
113 lines (96 loc) · 2.37 KB
/
Admin.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
namespace ShitwareLtd\Shitbot\Commands;
use Closure;
use Discord\Parts\Channel\Message;
use Discord\Parts\User\Activity;
use ShitwareLtd\Shitbot\Shitbot;
use ShitwareLtd\Shitbot\Support\Helpers;
use ShitwareLtd\Shitbot\Support\Status;
class Admin extends Command
{
/**
* @return string
*/
public function trigger(): string
{
return '!!!!';
}
/**
* @param Message $entity
* @param array $args
* @return void
*/
public function handle(Message $entity, array $args): void
{
if (! Helpers::isOwner($entity->author)) {
return;
}
$matched = match ($args[0] ?? false) {
'pause' => $this->pause(),
'play' => $this->play(),
'status' => $this->status($args),
'terminate' => $this->terminate(),
default => false,
};
if ($matched) {
$entity->react('a:verified:903877054271979522')
->then(function () use ($matched) {
if (is_callable($matched)) {
$matched();
}
});
}
}
/**
* @return bool
*/
private function pause(): bool
{
Shitbot::paused(true);
Status::set(
status: Activity::STATUS_IDLE,
type: Activity::TYPE_WATCHING,
name: 'the void. 💤'
);
return true;
}
/**
* @return bool
*/
private function play(): bool
{
Shitbot::paused(false);
Status::setDefault();
return true;
}
/**
* @param array $args
* @return bool
*/
private function status(array $args): bool
{
$flags = array_splice(
array: $args,
offset: 1,
length: 2
);
$name = array_splice(
array: $args,
offset: 1,
length: count($args) - 1
);
Status::set(
status: $flags[0],
type: (int) $flags[1],
name: Helpers::implodeContent($name)
);
return true;
}
/**
* @return Closure
*/
private function terminate(): Closure
{
return fn () => Shitbot::discord()->close();
}
}