Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation
This project
Loading...
Sign in
hfpp2012
/
vbot
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit b052cf3a
authored
Mar 16, 2017
by
HanSon
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
修复邀请进群时的bug
增加子类型“邀请”、“被踢出”
1 parent
4e1523c6
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
8 deletions
example/index.php
src/Core/MessageFactory.php
src/Core/MessageHandler.php
src/Message/Entity/GroupChange.php
example/index.php
View file @
b052cf3
...
@@ -205,10 +205,10 @@ $robot->server->setMessageHandler(function ($message) use ($path) {
...
@@ -205,10 +205,10 @@ $robot->server->setMessageHandler(function ($message) use ($path) {
if
(
$message
instanceof
GroupChange
)
{
if
(
$message
instanceof
GroupChange
)
{
/** @var $message GroupChange */
/** @var $message GroupChange */
if
(
$message
->
action
===
'ADD'
)
{
if
(
$message
->
action
===
'ADD'
)
{
\Hanson\Vbot\Support\Console
::
lo
g
(
'新人进群'
);
\Hanson\Vbot\Support\Console
::
debu
g
(
'新人进群'
);
return
'欢迎新人 '
.
$message
->
nickname
;
return
'欢迎新人 '
.
$message
->
nickname
;
}
elseif
(
$message
->
action
===
'REMOVE'
)
{
}
elseif
(
$message
->
action
===
'REMOVE'
)
{
\Hanson\Vbot\Support\Console
::
lo
g
(
'群主踢人了'
);
\Hanson\Vbot\Support\Console
::
debu
g
(
'群主踢人了'
);
return
$message
->
content
;
return
$message
->
content
;
}
elseif
(
$message
->
action
===
'RENAME'
)
{
}
elseif
(
$message
->
action
===
'RENAME'
)
{
// \Hanson\Vbot\Support\Console::log($message->from['NickName'] . ' 改名为 ' . $message->rename);
// \Hanson\Vbot\Support\Console::log($message->from['NickName'] . ' 改名为 ' . $message->rename);
...
@@ -216,6 +216,10 @@ $robot->server->setMessageHandler(function ($message) use ($path) {
...
@@ -216,6 +216,10 @@ $robot->server->setMessageHandler(function ($message) use ($path) {
group
()
->
setGroupName
(
$message
->
from
[
'UserName'
],
'vbot 测试群'
);
group
()
->
setGroupName
(
$message
->
from
[
'UserName'
],
'vbot 测试群'
);
return
'行不改名,坐不改姓!'
;
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'
]);
}
}
}
}
...
...
src/Core/MessageFactory.php
View file @
b052cf3
...
@@ -68,7 +68,7 @@ class MessageFactory
...
@@ -68,7 +68,7 @@ class MessageFactory
else
if
(
str_contains
(
$msg
[
'Content'
],
'添加'
)
||
str_contains
(
$msg
[
'Content'
],
'have added'
)
||
str_contains
(
$msg
[
'Content'
],
'打招呼'
)){
else
if
(
str_contains
(
$msg
[
'Content'
],
'添加'
)
||
str_contains
(
$msg
[
'Content'
],
'have added'
)
||
str_contains
(
$msg
[
'Content'
],
'打招呼'
)){
# 添加好友
# 添加好友
return
new
NewFriend
(
$msg
);
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
);
return
new
GroupChange
(
$msg
);
}
}
break
;
break
;
...
...
src/Core/MessageHandler.php
View file @
b052cf3
...
@@ -184,6 +184,12 @@ class MessageHandler
...
@@ -184,6 +184,12 @@ class MessageHandler
$message
=
$this
->
sync
->
sync
();
$message
=
$this
->
sync
->
sync
();
if
(
count
(
$message
[
'ModContactList'
])
>
0
){
foreach
(
$message
[
'ModContactList'
]
as
$contact
)
{
group
()
->
put
(
$contact
[
'UserName'
],
$contact
);
}
}
if
(
$message
[
'AddMsgList'
]){
if
(
$message
[
'AddMsgList'
]){
foreach
(
$message
[
'AddMsgList'
]
as
$msg
)
{
foreach
(
$message
[
'AddMsgList'
]
as
$msg
)
{
$content
=
$this
->
messageFactory
->
make
(
$msg
);
$content
=
$this
->
messageFactory
->
make
(
$msg
);
...
...
src/Message/Entity/GroupChange.php
View file @
b052cf3
...
@@ -18,8 +18,27 @@ class GroupChange extends Message implements MessageInterface
...
@@ -18,8 +18,27 @@ class GroupChange extends Message implements MessageInterface
public
$action
;
public
$action
;
/**
* 群名重命名的名称
*
* @var
*/
public
$rename
;
public
$rename
;
/**
* 被踢出群时的群信息
*
* @var
*/
public
$group
;
/**
* 新人进群的昵称(可能单个可能多个)
*
* @var
*/
public
$nickname
;
public
function
__construct
(
$msg
)
public
function
__construct
(
$msg
)
{
{
parent
::
__construct
(
$msg
);
parent
::
__construct
(
$msg
);
...
@@ -29,20 +48,25 @@ class GroupChange extends Message implements MessageInterface
...
@@ -29,20 +48,25 @@ class GroupChange extends Message implements MessageInterface
public
function
make
()
public
function
make
()
{
{
if
(
str_contains
(
$this
->
msg
[
'Content'
],
'邀请你'
)){
Console
::
debug
(
$this
->
msg
[
'Content'
]);
print_r
(
$this
->
msg
);
if
(
str_contains
(
$this
->
msg
[
'Content'
],
'邀请你'
))
{
$this
->
action
=
'INVITE'
;
$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
->
action
=
'ADD'
;
$this
->
nickname
=
$match
[
1
];
Console
::
debug
(
"检测到
{
$this
->
from
[
'NickName'
]
}
有新成员,正在刷新群成员列表..."
);
Console
::
debug
(
"检测到
{
$this
->
from
[
'NickName'
]
}
有新成员,正在刷新群成员列表..."
);
(
new
ContactFactory
())
->
makeContactList
();
(
new
ContactFactory
())
->
makeContactList
();
Console
::
debug
(
'群成员更新成功!'
);
Console
::
debug
(
'群成员更新成功!'
);
}
elseif
(
str_contains
(
$this
->
msg
[
'Content'
],
'移出了群聊'
))
{
}
elseif
(
str_contains
(
$this
->
msg
[
'Content'
],
'移出了群聊'
))
{
$this
->
action
=
'REMOVE'
;
$this
->
action
=
'REMOVE'
;
}
elseif
(
str_contains
(
$this
->
msg
[
'Content'
],
'改群名为'
))
{
}
elseif
(
str_contains
(
$this
->
msg
[
'Content'
],
'改群名为'
))
{
$this
->
action
=
'RENAME'
;
$this
->
action
=
'RENAME'
;
preg_match
(
'/改群名为“(.+)”/'
,
$this
->
msg
[
'Content'
],
$match
);
preg_match
(
'/改群名为“(.+)”/'
,
$this
->
msg
[
'Content'
],
$match
);
$this
->
updateGroupName
(
$match
[
1
]);
$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'
];
$this
->
content
=
$this
->
msg
[
'Content'
];
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment