Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
df8c9e94
Commit
df8c9e94
authored
May 27, 2020
by
Him188
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
4b893563
7fd5cfe3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
167 additions
and
103 deletions
+167
-103
README.md
README.md
+1
-0
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.common.kt
...n/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.common.kt
+118
-57
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/NewContact.kt
...irai/qqandroid/network/protocol/packet/chat/NewContact.kt
+23
-46
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/lowLevelApi.kt
...core/src/commonMain/kotlin/net.mamoe.mirai/lowLevelApi.kt
+25
-0
No files found.
README.md
View file @
df8c9e94
...
@@ -94,6 +94,7 @@ mirai 既可以作为项目中的 QQ 协议支持库, 也可以作为单独的
...
@@ -94,6 +94,7 @@ mirai 既可以作为项目中的 QQ 协议支持库, 也可以作为单独的
-
(社区)
`Lua`
:
[
lua-mirai
](
https://github.com/only52607/lua-mirai
)
基于mirai-core 的Lua SDK,并提供了java扩展支持,可在lua中调用java代码开发机器人
-
(社区)
`Lua`
:
[
lua-mirai
](
https://github.com/only52607/lua-mirai
)
基于mirai-core 的Lua SDK,并提供了java扩展支持,可在lua中调用java代码开发机器人
-
(社区)
`C++`
:
[
mirai-cpp
](
https://github.com/cyanray/mirai-cpp
)
mirai-http-api 的 C++ 封装,方便使用 C++ 开发 mirai-http-api 插件
-
(社区)
`C++`
:
[
mirai-cpp
](
https://github.com/cyanray/mirai-cpp
)
mirai-http-api 的 C++ 封装,方便使用 C++ 开发 mirai-http-api 插件
-
(社区)
`C++`
:
[
miraipp
](
https://github.com/Chlorie/miraipp-template
)
mirai-http-api 的另一个 C++ 封装,使用现代 C++ 特性,并提供了较完善的说明文档
-
(社区)
`C++`
:
[
miraipp
](
https://github.com/Chlorie/miraipp-template
)
mirai-http-api 的另一个 C++ 封装,使用现代 C++ 特性,并提供了较完善的说明文档
-
(社区)
`C#`
:
[
Mirai-CSharp
](
https://github.com/Executor-Cheng/Mirai-CSharp
)
基于 mirai-api-http 的 C# SDK
-
(社区)
`Rust`
:
[
mirai-rs
](
https://github.com/HoshinoTented/mirai-rs
)
mirai-http-api 的 Rust 封装
-
(社区)
`Rust`
:
[
mirai-rs
](
https://github.com/HoshinoTented/mirai-rs
)
mirai-http-api 的 Rust 封装
-
(官方)其他任意语言:使用由
[
mirai-api-http
](
https://github.com/mamoe/mirai-api-http
)
提供的 http 接口进行接入
-
(官方)其他任意语言:使用由
[
mirai-api-http
](
https://github.com/mamoe/mirai-api-http
)
提供的 http 接口进行接入
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.common.kt
View file @
df8c9e94
...
@@ -91,17 +91,13 @@ internal class QQAndroidBot constructor(
...
@@ -91,17 +91,13 @@ internal class QQAndroidBot constructor(
"the request $event is outdated: You had already responded it on another device."
"the request $event is outdated: You had already responded it on another device."
}
}
network
.
run
{
_lowLevelSolveNewFriendRequestEvent
(
NewContact
.
SystemMsgNewFriend
.
Action
(
eventId
=
event
.
eventId
,
bot
.
client
,
fromId
=
event
.
fromId
,
event
,
fromNick
=
event
.
fromNick
,
accept
=
true
accept
=
true
,
).
sendWithoutExpect
()
blackList
=
false
bot
.
friends
.
delegate
.
addLast
(
bot
.
_lowLevelNewFriend
(
object
:
FriendInfo
{
)
override
val
uin
:
Long
get
()
=
event
.
fromId
override
val
nick
:
String
get
()
=
event
.
fromNick
}))
}
}
}
override
suspend
fun
rejectNewFriendRequest
(
event
:
NewFriendRequestEvent
,
blackList
:
Boolean
)
{
override
suspend
fun
rejectNewFriendRequest
(
event
:
NewFriendRequestEvent
,
blackList
:
Boolean
)
{
...
@@ -117,14 +113,13 @@ internal class QQAndroidBot constructor(
...
@@ -117,14 +113,13 @@ internal class QQAndroidBot constructor(
"the request $event is outdated: You had already responded it on another device."
"the request $event is outdated: You had already responded it on another device."
}
}
network
.
run
{
_lowLevelSolveNewFriendRequestEvent
(
NewContact
.
SystemMsgNewFriend
.
Action
(
eventId
=
event
.
eventId
,
bot
.
client
,
fromId
=
event
.
fromId
,
event
,
fromNick
=
event
.
fromNick
,
accept
=
false
,
accept
=
false
,
blackList
=
blackList
blackList
=
blackList
).
sendWithoutExpect
()
)
}
}
}
@OptIn
(
LowLevelAPI
::
class
)
@OptIn
(
LowLevelAPI
::
class
)
...
@@ -139,21 +134,14 @@ internal class QQAndroidBot constructor(
...
@@ -139,21 +134,14 @@ internal class QQAndroidBot constructor(
"the request $this is outdated: Another operator has already responded it."
"the request $this is outdated: Another operator has already responded it."
}
}
network
.
run
{
_lowLevelSolveMemberJoinRequestEvent
(
NewContact
.
SystemMsgNewGroup
.
Action
(
eventId
=
event
.
eventId
,
bot
.
client
,
fromId
=
event
.
fromId
,
event
,
fromNick
=
event
.
fromNick
,
accept
=
true
groupId
=
event
.
groupId
,
).
sendWithoutExpect
()
accept
=
true
,
event
.
group
.
members
.
delegate
.
addLast
(
event
.
group
.
newMember
(
object
:
MemberInfo
{
blackList
=
false
override
val
nameCard
:
String
get
()
=
""
)
override
val
permission
:
MemberPermission
get
()
=
MemberPermission
.
MEMBER
override
val
specialTitle
:
String
get
()
=
""
override
val
muteTimestamp
:
Int
get
()
=
0
override
val
uin
:
Long
get
()
=
event
.
fromId
override
val
nick
:
String
get
()
=
event
.
fromNick
}))
}
}
}
@Suppress
(
"DuplicatedCode"
)
@Suppress
(
"DuplicatedCode"
)
...
@@ -167,14 +155,15 @@ internal class QQAndroidBot constructor(
...
@@ -167,14 +155,15 @@ internal class QQAndroidBot constructor(
check
(!
event
.
group
.
members
.
contains
(
event
.
fromId
))
{
check
(!
event
.
group
.
members
.
contains
(
event
.
fromId
))
{
"the request $this is outdated: Another operator has already responded it."
"the request $this is outdated: Another operator has already responded it."
}
}
network
.
run
{
NewContact
.
SystemMsgNewGroup
.
Action
(
_lowLevelSolveMemberJoinRequestEvent
(
bot
.
client
,
eventId
=
event
.
eventId
,
event
,
fromId
=
event
.
fromId
,
accept
=
false
,
fromNick
=
event
.
fromNick
,
blackList
=
blackList
groupId
=
event
.
groupId
,
).
sendWithoutExpect
()
accept
=
false
,
}
blackList
=
blackList
)
}
}
private
inline
fun
checkGroupPermission
(
eventBot
:
Bot
,
eventGroup
:
Group
,
eventName
:
()
->
String
)
{
private
inline
fun
checkGroupPermission
(
eventBot
:
Bot
,
eventGroup
:
Group
,
eventName
:
()
->
String
)
{
...
@@ -198,14 +187,15 @@ internal class QQAndroidBot constructor(
...
@@ -198,14 +187,15 @@ internal class QQAndroidBot constructor(
check
(
event
.
responded
.
compareAndSet
(
false
,
true
))
{
check
(
event
.
responded
.
compareAndSet
(
false
,
true
))
{
"the request $this has already been responded"
"the request $this has already been responded"
}
}
network
.
run
{
NewContact
.
SystemMsgNewGroup
.
Action
(
_lowLevelSolveMemberJoinRequestEvent
(
bot
.
client
,
eventId
=
event
.
eventId
,
event
,
fromId
=
event
.
fromId
,
accept
=
null
,
fromNick
=
event
.
fromNick
,
blackList
=
blackList
groupId
=
event
.
groupId
,
).
sendWithoutExpect
()
accept
=
null
,
}
blackList
=
blackList
)
}
}
override
suspend
fun
acceptInvitedJoinGroupRequest
(
event
:
BotInvitedJoinGroupRequestEvent
)
=
override
suspend
fun
acceptInvitedJoinGroupRequest
(
event
:
BotInvitedJoinGroupRequestEvent
)
=
...
@@ -224,13 +214,12 @@ internal class QQAndroidBot constructor(
...
@@ -224,13 +214,12 @@ internal class QQAndroidBot constructor(
"the request $this is outdated: Bot has been already in the group."
"the request $this is outdated: Bot has been already in the group."
}
}
network
.
run
{
_lowLevelSolveBotInvitedJoinGroupRequestEvent
(
NewContact
.
SystemMsgNewGroup
.
Action
(
eventId
=
event
.
eventId
,
bot
.
client
,
invitorId
=
event
.
invitorId
,
event
,
groupId
=
event
.
groupId
,
accept
=
accept
accept
=
accept
).
sendWithoutExpect
()
)
}
}
}
}
}
...
@@ -719,6 +708,78 @@ internal abstract class QQAndroidBotBase constructor(
...
@@ -719,6 +708,78 @@ internal abstract class QQAndroidBotBase constructor(
}
}
}
}
@LowLevelAPI
@MiraiExperimentalAPI
override
suspend
fun
_lowLevelSolveNewFriendRequestEvent
(
eventId
:
Long
,
fromId
:
Long
,
fromNick
:
String
,
accept
:
Boolean
,
blackList
:
Boolean
)
{
network
.
apply
{
NewContact
.
SystemMsgNewFriend
.
Action
(
bot
.
client
,
eventId
=
eventId
,
fromId
=
fromId
,
accept
=
accept
,
blackList
=
blackList
).
sendWithoutExpect
()
bot
.
friends
.
delegate
.
addLast
(
bot
.
_lowLevelNewFriend
(
object
:
FriendInfo
{
override
val
uin
:
Long
get
()
=
fromId
override
val
nick
:
String
get
()
=
fromNick
}))
}
}
@LowLevelAPI
@MiraiExperimentalAPI
override
suspend
fun
_lowLevelSolveBotInvitedJoinGroupRequestEvent
(
eventId
:
Long
,
invitorId
:
Long
,
groupId
:
Long
,
accept
:
Boolean
)
{
network
.
run
{
NewContact
.
SystemMsgNewGroup
.
Action
(
bot
.
client
,
eventId
=
eventId
,
fromId
=
invitorId
,
groupId
=
groupId
,
isInvited
=
true
,
accept
=
accept
).
sendWithoutExpect
()
}
}
@LowLevelAPI
@MiraiExperimentalAPI
override
suspend
fun
_lowLevelSolveMemberJoinRequestEvent
(
eventId
:
Long
,
fromId
:
Long
,
fromNick
:
String
,
groupId
:
Long
,
accept
:
Boolean
?,
blackList
:
Boolean
)
{
network
.
apply
{
NewContact
.
SystemMsgNewGroup
.
Action
(
bot
.
client
,
eventId
=
eventId
,
fromId
=
fromId
,
groupId
=
groupId
,
isInvited
=
false
,
accept
=
accept
,
blackList
=
blackList
).
sendWithoutExpect
()
groups
[
groupId
].
apply
{
members
.
delegate
.
addLast
(
newMember
(
object
:
MemberInfo
{
override
val
nameCard
:
String
get
()
=
""
override
val
permission
:
MemberPermission
get
()
=
MemberPermission
.
MEMBER
override
val
specialTitle
:
String
get
()
=
""
override
val
muteTimestamp
:
Int
get
()
=
0
override
val
uin
:
Long
get
()
=
fromId
override
val
nick
:
String
get
()
=
fromNick
}))
}
}
}
@Suppress
(
"DEPRECATION"
,
"OverridingDeprecatedMember"
)
@Suppress
(
"DEPRECATION"
,
"OverridingDeprecatedMember"
)
override
suspend
fun
queryImageUrl
(
image
:
Image
):
String
=
when
(
image
)
{
override
suspend
fun
queryImageUrl
(
image
:
Image
):
String
=
when
(
image
)
{
is
OnlineFriendImageImpl
->
image
.
originUrl
is
OnlineFriendImageImpl
->
image
.
originUrl
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/NewContact.kt
View file @
df8c9e94
...
@@ -13,7 +13,6 @@ package net.mamoe.mirai.qqandroid.network.protocol.packet.chat
...
@@ -13,7 +13,6 @@ package net.mamoe.mirai.qqandroid.network.protocol.packet.chat
import
kotlinx.io.core.ByteReadPacket
import
kotlinx.io.core.ByteReadPacket
import
kotlinx.io.core.readBytes
import
kotlinx.io.core.readBytes
import
net.mamoe.mirai.contact.Group
import
net.mamoe.mirai.event.events.*
import
net.mamoe.mirai.event.events.*
import
net.mamoe.mirai.getGroupOrNull
import
net.mamoe.mirai.getGroupOrNull
import
net.mamoe.mirai.qqandroid.QQAndroidBot
import
net.mamoe.mirai.qqandroid.QQAndroidBot
...
@@ -58,17 +57,15 @@ internal class NewContact {
...
@@ -58,17 +57,15 @@ internal class NewContact {
override
suspend
fun
ByteReadPacket
.
decode
(
bot
:
QQAndroidBot
):
NewFriendRequestEvent
?
{
override
suspend
fun
ByteReadPacket
.
decode
(
bot
:
QQAndroidBot
):
NewFriendRequestEvent
?
{
readBytes
().
loadAs
(
Structmsg
.
RspSystemMsgNew
.
serializer
()).
run
{
readBytes
().
loadAs
(
Structmsg
.
RspSystemMsgNew
.
serializer
()).
run
{
val
struct
=
friendmsgs
?.
firstOrNull
()
val
struct
=
friendmsgs
?.
firstOrNull
()
return
if
(
struct
==
null
)
null
else
{
return
struct
?.
msg
?.
run
{
struct
.
msg
?.
run
{
NewFriendRequestEvent
(
NewFriendRequestEvent
(
bot
,
bot
,
struct
.
msgSeq
,
struct
.
msgSeq
,
msgAdditional
,
msgAdditional
,
struct
.
reqUin
,
struct
.
reqUin
,
groupCode
,
groupCode
,
reqUinNick
reqUinNick
)
)
}
}
}
}
}
}
}
...
@@ -77,7 +74,8 @@ internal class NewContact {
...
@@ -77,7 +74,8 @@ internal class NewContact {
operator
fun
invoke
(
operator
fun
invoke
(
client
:
QQAndroidClient
,
client
:
QQAndroidClient
,
event
:
NewFriendRequestEvent
,
eventId
:
Long
,
fromId
:
Long
,
accept
:
Boolean
,
accept
:
Boolean
,
blackList
:
Boolean
=
false
blackList
:
Boolean
=
false
)
=
)
=
...
@@ -92,8 +90,8 @@ internal class NewContact {
...
@@ -92,8 +90,8 @@ internal class NewContact {
remark
=
""
,
remark
=
""
,
blacklist
=
!
accept
&&
blackList
blacklist
=
!
accept
&&
blackList
),
),
msgSeq
=
event
.
event
Id
,
msgSeq
=
eventId
,
reqUin
=
event
.
fromId
,
reqUin
=
fromId
,
srcId
=
6
,
srcId
=
6
,
subSrcId
=
7
,
subSrcId
=
7
,
subType
=
1
subType
=
1
...
@@ -147,7 +145,7 @@ internal class NewContact {
...
@@ -147,7 +145,7 @@ internal class NewContact {
readBytes
().
loadAs
(
Structmsg
.
RspSystemMsgNew
.
serializer
()).
run
{
readBytes
().
loadAs
(
Structmsg
.
RspSystemMsgNew
.
serializer
()).
run
{
val
struct
=
groupmsgs
?.
firstOrNull
()
val
struct
=
groupmsgs
?.
firstOrNull
()
return
if
(
struct
==
null
)
null
else
struct
.
msg
?.
run
<
Structmsg
.
SystemMsg
,
Packet
>
{
return
struct
?
.
msg
?.
run
<
Structmsg
.
SystemMsg
,
Packet
>
{
//this.soutv("SystemMsg")
//this.soutv("SystemMsg")
when
(
subType
)
{
when
(
subType
)
{
1
->
{
//管理员邀请
1
->
{
//管理员邀请
...
@@ -200,7 +198,10 @@ internal class NewContact {
...
@@ -200,7 +198,10 @@ internal class NewContact {
operator
fun
invoke
(
operator
fun
invoke
(
client
:
QQAndroidClient
,
client
:
QQAndroidClient
,
event
:
MemberJoinRequestEvent
,
eventId
:
Long
,
fromId
:
Long
,
groupId
:
Long
,
isInvited
:
Boolean
,
accept
:
Boolean
?,
accept
:
Boolean
?,
blackList
:
Boolean
=
false
blackList
:
Boolean
=
false
)
=
)
=
...
@@ -214,41 +215,17 @@ internal class NewContact {
...
@@ -214,41 +215,17 @@ internal class NewContact {
true
->
11
// accept
true
->
11
// accept
false
->
12
// reject
false
->
12
// reject
},
},
groupCode
=
event
.
groupId
,
groupCode
=
groupId
,
msg
=
""
,
msg
=
""
,
remark
=
""
,
remark
=
""
,
blacklist
=
blackList
blacklist
=
blackList
),
),
groupMsgType
=
1
,
groupMsgType
=
if
(
isInvited
)
2
else
1
,
language
=
1000
,
msgSeq
=
event
.
eventId
,
reqUin
=
event
.
fromId
,
srcId
=
3
,
subSrcId
=
31
,
subType
=
1
)
)
}
operator
fun
invoke
(
client
:
QQAndroidClient
,
event
:
BotInvitedJoinGroupRequestEvent
,
accept
:
Boolean
)
=
buildOutgoingUniPacket
(
client
)
{
writeProtoBuf
(
Structmsg
.
ReqSystemMsgAction
.
serializer
(),
Structmsg
.
ReqSystemMsgAction
(
actionInfo
=
Structmsg
.
SystemMsgActionInfo
(
type
=
if
(
accept
)
11
else
12
,
groupCode
=
Group
.
calculateGroupCodeByGroupUin
(
event
.
groupId
)
),
groupMsgType
=
2
,
language
=
1000
,
language
=
1000
,
msgSeq
=
event
.
event
Id
,
msgSeq
=
eventId
,
reqUin
=
event
.
invitor
Id
,
reqUin
=
from
Id
,
srcId
=
3
,
srcId
=
3
,
subSrcId
=
10016
,
subSrcId
=
if
(
isInvited
)
10016
else
31
,
subType
=
1
subType
=
1
)
)
)
)
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/lowLevelApi.kt
View file @
df8c9e94
...
@@ -13,6 +13,9 @@ import kotlinx.coroutines.Job
...
@@ -13,6 +13,9 @@ import kotlinx.coroutines.Job
import
net.mamoe.mirai.contact.Friend
import
net.mamoe.mirai.contact.Friend
import
net.mamoe.mirai.contact.Group
import
net.mamoe.mirai.contact.Group
import
net.mamoe.mirai.data.*
import
net.mamoe.mirai.data.*
import
net.mamoe.mirai.event.events.BotInvitedJoinGroupRequestEvent
import
net.mamoe.mirai.event.events.MemberJoinRequestEvent
import
net.mamoe.mirai.event.events.NewFriendRequestEvent
import
net.mamoe.mirai.utils.MiraiExperimentalAPI
import
net.mamoe.mirai.utils.MiraiExperimentalAPI
import
net.mamoe.mirai.utils.WeakRef
import
net.mamoe.mirai.utils.WeakRef
...
@@ -113,4 +116,26 @@ interface LowLevelBotAPIAccessor {
...
@@ -113,4 +116,26 @@ interface LowLevelBotAPIAccessor {
@LowLevelAPI
@LowLevelAPI
@MiraiExperimentalAPI
@MiraiExperimentalAPI
suspend
fun
_lowLevelGetGroupActiveData
(
groupId
:
Long
):
GroupActiveData
suspend
fun
_lowLevelGetGroupActiveData
(
groupId
:
Long
):
GroupActiveData
/**
* 处理一个账号请求添加机器人为好友的事件
*/
@LowLevelAPI
@MiraiExperimentalAPI
suspend
fun
_lowLevelSolveNewFriendRequestEvent
(
eventId
:
Long
,
fromId
:
Long
,
fromNick
:
String
,
accept
:
Boolean
,
blackList
:
Boolean
)
/**
* 处理被邀请加入一个群请求事件
*/
@LowLevelAPI
@MiraiExperimentalAPI
suspend
fun
_lowLevelSolveBotInvitedJoinGroupRequestEvent
(
eventId
:
Long
,
invitorId
:
Long
,
groupId
:
Long
,
accept
:
Boolean
)
/**
* 处理账号请求加入群事件
*/
@LowLevelAPI
@MiraiExperimentalAPI
suspend
fun
_lowLevelSolveMemberJoinRequestEvent
(
eventId
:
Long
,
fromId
:
Long
,
fromNick
:
String
,
groupId
:
Long
,
accept
:
Boolean
?,
blackList
:
Boolean
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment