-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathHypeQuote.php
56 lines (48 loc) · 1.49 KB
/
HypeQuote.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
<?php
namespace ShitwareLtd\Shitbot\Commands;
use Discord\Parts\Channel\Message;
use Psr\Http\Message\ResponseInterface;
use ShitwareLtd\Shitbot\Shitbot;
use ShitwareLtd\Shitbot\Support\Helpers;
use Throwable;
use function React\Async\coroutine;
class HypeQuote extends Command
{
/**
* @return string
*/
public function trigger(): string
{
return '!hype';
}
/**
* @param Message $entity
* @param array $args
* @return void
*/
public function handle(Message $entity, array $args): void
{
coroutine(function (Message $entity) {
if ($this->skip($entity)) {
return;
}
try {
/** @var ResponseInterface $response */
$response = yield Shitbot::browser()->get(
url: 'https://quotes.shitware.ltd/api/random',
headers: [
'Authorization' => 'Bearer '.Shitbot::config('HYPE_TOKEN'),
'Content-Type' => 'application/json',
]
);
$result = Helpers::json($response)['data'];
$entity->reply("🗨️ {$result['quote']} - {$result['quotee']}");
} catch (Throwable $e) {
$this->sendError(
entity: $entity,
error: $e->getMessage()
);
}
}, $entity);
}
}