GroupChange.php
1.56 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
53
54
55
56
57
<?php
/**
* Created by PhpStorm.
* User: Hanson
* Date: 2017/2/12
* Time: 20:44
*/
namespace Hanson\Vbot\Message\Entity;
use Hanson\Vbot\Collections\ContactFactory;
use Hanson\Vbot\Message\MessageInterface;
use Hanson\Vbot\Support\Console;
class GroupChange extends Message implements MessageInterface
{
public $action;
public $rename;
public function __construct($msg)
{
parent::__construct($msg);
$this->make();
}
public function make()
{
if(str_contains($this->msg['Content'], '邀请你')){
print_r($this->msg);
$this->action = 'INVITE';
}elseif(str_contains($this->msg['Content'], '加入了群聊')){
$this->action = 'ADD';
Console::debug("检测到 {$this->from['NickName']} 有新成员,正在刷新群成员列表...");
(new ContactFactory())->makeContactList();
Console::debug('群成员更新成功!');
}elseif(str_contains($this->msg['Content'], '移出了群聊')){
$this->action = 'REMOVE';
}elseif(str_contains($this->msg['Content'], '改群名为')){
$this->action = 'RENAME';
preg_match('/改群名为“(.+)”/', $this->msg['Content'], $match);
$this->updateGroupName($match[1]);
}
$this->content = $this->msg['Content'];
}
private function updateGroupName($name)
{
$group = group()->get($this->from['UserName']);
$group['NickName'] = $this->rename = $name;
group()->put($group['UserName'], $group);
}
}