Commit b052cf3a by HanSon

修复邀请进群时的bug

增加子类型“邀请”、“被踢出”
1 parent 4e1523c6
......@@ -205,10 +205,10 @@ $robot->server->setMessageHandler(function ($message) use ($path) {
if ($message instanceof GroupChange) {
/** @var $message GroupChange */
if ($message->action === 'ADD') {
\Hanson\Vbot\Support\Console::log('新人进群');
\Hanson\Vbot\Support\Console::debug('新人进群');
return '欢迎新人 ' . $message->nickname;
} elseif ($message->action === 'REMOVE') {
\Hanson\Vbot\Support\Console::log('群主踢人了');
\Hanson\Vbot\Support\Console::debug('群主踢人了');
return $message->content;
} elseif ($message->action === 'RENAME') {
// \Hanson\Vbot\Support\Console::log($message->from['NickName'] . ' 改名为 ' . $message->rename);
......@@ -216,6 +216,10 @@ $robot->server->setMessageHandler(function ($message) use ($path) {
group()->setGroupName($message->from['UserName'], 'vbot 测试群');
return '行不改名,坐不改姓!';
}
} elseif ($message->action === 'BE_REMOVE') {
\Hanson\Vbot\Support\Console::debug('你被踢出了群 ' . $message->group['NickName']);
} elseif ($message->action === 'INVITE') {
\Hanson\Vbot\Support\Console::debug('你被邀请进群 ' . $message->from['NickName']);
}
}
......
......@@ -68,7 +68,7 @@ class MessageFactory
else if(str_contains($msg['Content'], '添加') || str_contains($msg['Content'], 'have added') || str_contains($msg['Content'], '打招呼')){
# 添加好友
return new NewFriend($msg);
}else if(str_contains($msg['Content'], '加入了群聊') || str_contains($msg['Content'], '移出了群聊') || str_contains($msg['Content'], '改群名为')){
}else if(str_contains($msg['Content'], '加入了群聊') || str_contains($msg['Content'], '移出了群聊') || str_contains($msg['Content'], '改群名为') || str_contains($msg['Content'], '移出群聊') || str_contains($msg['Content'], '邀请你')){
return new GroupChange($msg);
}
break;
......
......@@ -184,6 +184,12 @@ class MessageHandler
$message = $this->sync->sync();
if(count($message['ModContactList']) > 0){
foreach ($message['ModContactList'] as $contact) {
group()->put($contact['UserName'], $contact);
}
}
if($message['AddMsgList']){
foreach ($message['AddMsgList'] as $msg) {
$content = $this->messageFactory->make($msg);
......
......@@ -18,8 +18,27 @@ class GroupChange extends Message implements MessageInterface
public $action;
/**
* 群名重命名的名称
*
* @var
*/
public $rename;
/**
* 被踢出群时的群信息
*
* @var
*/
public $group;
/**
* 新人进群的昵称(可能单个可能多个)
*
* @var
*/
public $nickname;
public function __construct($msg)
{
parent::__construct($msg);
......@@ -29,20 +48,25 @@ class GroupChange extends Message implements MessageInterface
public function make()
{
if(str_contains($this->msg['Content'], '邀请你')){
print_r($this->msg);
Console::debug($this->msg['Content']);
if (str_contains($this->msg['Content'], '邀请你')) {
$this->action = 'INVITE';
}elseif(str_contains($this->msg['Content'], '加入了群聊')){
} elseif (str_contains($this->msg['Content'], '加入了群聊')) {
preg_match('/".+".+"(.+)"加入了群聊/', $this->msg['Content'], $match);
$this->action = 'ADD';
$this->nickname = $match[1];
Console::debug("检测到 {$this->from['NickName']} 有新成员,正在刷新群成员列表...");
(new ContactFactory())->makeContactList();
Console::debug('群成员更新成功!');
}elseif(str_contains($this->msg['Content'], '移出了群聊')){
} elseif (str_contains($this->msg['Content'], '移出了群聊')) {
$this->action = 'REMOVE';
}elseif(str_contains($this->msg['Content'], '改群名为')){
} elseif (str_contains($this->msg['Content'], '改群名为')) {
$this->action = 'RENAME';
preg_match('/改群名为“(.+)”/', $this->msg['Content'], $match);
$this->updateGroupName($match[1]);
} elseif (str_contains($this->msg['Content'], '移出群聊')) {
$this->action = 'BE_REMOVE';
$this->group = group()->pull($this->from['UserName']);
}
$this->content = $this->msg['Content'];
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!