recall.php
1.86 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
<?php
/**
* Created by PhpStorm.
* User: HanSon
* Date: 2016/12/7
* Time: 16:33
*/
require_once __DIR__ . './../vendor/autoload.php';
use Hanson\Vbot\Foundation\Vbot;
use Hanson\Vbot\Message\Message;
use Hanson\Vbot\Message\Image;
use Hanson\Vbot\Message\Entity\Text;
use Hanson\Vbot\Message\Emoticon;
use Hanson\Vbot\Message\Video;
$path = __DIR__ . '/./../tmp/';
$robot = new Vbot([
'tmp' => $path,
'debug' => true
]);
$robot->server->setMessageHandler(function($message) use ($path){
/** @var $message Message */
// 发送撤回消息 (排除自己)
if($message->type === 'Recall' && $message->rawMsg['FromUserName'] !== myself()->username ){
$msg = message()->get($message->msgId);
if($msg){
$nickname = $msg['sender'] ? $msg['sender']['NickName'] : account()->getAccount($msg['username'])['NickName'];
if($msg['type'] === 'Image'){
Text::send($message->username, "{$nickname} 撤回了一张照片");
Image::send($message->username, realpath($path . "jpg/{$message->msgId}.jpg"));
}elseif($msg['type'] === 'Emoticon'){
Text::send($message->username, "{$nickname} 撤回了一个表情");
Emoticon::send($message->username, realpath($path . "gif/{$message->msgId}.gif"));
}elseif($msg['type'] === 'Video' || $msg['type'] === 'VideoCall'){
Text::send($message->username, "{$nickname} 撤回了一个视频");
Video::send($message->username, realpath($path . "mp4/{$message->msgId}.mp4"));
}elseif($msg['type'] === 'Voice'){
Text::send($message->username, "{$nickname} 撤回了一条语音");
}else{
Text::send($message->username, "{$nickname} 撤回了一条信息 \"{$msg['content']}\"");
}
}
}
});
$robot->server->run();