-
Notifications
You must be signed in to change notification settings - Fork 715
群组变动GroupChange
HanSon edited this page Mar 17, 2017
·
2 revisions
重命名群名称后 $message->from['NickName']
还是久的名称,rename是新的名称,当此群再次发送消息时,$message->from['NickName']
为最新昵称
属性 | 类型 | 含义 |
---|---|---|
msg | array | 消息的原始数组 |
action | string | 变动类型 ADD-增加成员 REMOVE-移除成员 RENAME-更改群名称 INVITE-被邀请进群 BE_REMOVE-被踢出群 |
rename | string | 重命名后的新名 |
$robot->server->setMessageHandler(function ($message){
// 群组变动
if($message instanceof GroupChange){
/** @var $message GroupChange */
if ($message->action === 'ADD') {
\Hanson\Vbot\Support\Console::debug('新人进群');
return '欢迎新人 ' . $message->nickname;
} elseif ($message->action === 'REMOVE') {
\Hanson\Vbot\Support\Console::debug('群主踢人了');
return $message->content;
} elseif ($message->action === 'RENAME') {
// \Hanson\Vbot\Support\Console::log($message->from['NickName'] . ' 改名为 ' . $message->rename);
if (group()->getUsernameById(1) == $message->from['UserName'] && $message->rename !== 'vbot 测试群') {
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']);
}
}
});