-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.php
More file actions
52 lines (42 loc) · 1.09 KB
/
Copy pathplugin.php
File metadata and controls
52 lines (42 loc) · 1.09 KB
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
abstract class Plugin
{
protected $bot;
function __construct($bot)
{
$this->bot = $bot;
}
abstract function do($message);
}
class DogPlugin extends Plugin
{
function construct($bot)
{
parent::__construct($bot);
}
private function get()
{
$apiURL = "https://v1.alapi.cn/api/dog?format=json";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiURL);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
function do($message)
{
if ($message->content != "舔狗") {
return;
}
$res = json_decode($this->get(), true);
if ($res && $res['code'] === 200) {
$content = $res['data']['content'];
$toUser = $message->fromUser;
echo "content:" . $content . PHP_EOL;
$this->bot->sendMessage($toUser, $content);
}
}
}