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
52b848eb
Commit
52b848eb
authored
Feb 20, 2020
by
ryoii
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin'
parents
9c4e7bdf
078bb973
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
172 additions
and
58 deletions
+172
-58
CHANGELOG.md
CHANGELOG.md
+15
-0
gradle.properties
gradle.properties
+1
-1
mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleTerminalUI.kt
.../kotlin/net/mamoe/mirai/console/MiraiConsoleTerminalUI.kt
+3
-1
mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsole.kt
...e/src/main/kotlin/net/mamoe/mirai/console/MiraiConsole.kt
+1
-0
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/ContactImpl.kt
...ommonMain/kotlin/net/mamoe/mirai/qqandroid/ContactImpl.kt
+23
-21
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/MessageSvc.kt
...ndroid/network/protocol/packet/chat/receive/MessageSvc.kt
+1
-0
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.kt
...ndroid/network/protocol/packet/chat/receive/OnlinePush.kt
+35
-21
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Contact.kt
.../src/commonMain/kotlin/net.mamoe.mirai/contact/Contact.kt
+10
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Group.kt
...re/src/commonMain/kotlin/net.mamoe.mirai/contact/Group.kt
+7
-5
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Member.kt
...e/src/commonMain/kotlin/net.mamoe.mirai/contact/Member.kt
+34
-6
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Permission.kt
...c/commonMain/kotlin/net.mamoe.mirai/contact/Permission.kt
+11
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/data/MemberInfo.kt
.../src/commonMain/kotlin/net.mamoe.mirai/data/MemberInfo.kt
+2
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/BotEvents.kt
...mmonMain/kotlin/net.mamoe.mirai/event/events/BotEvents.kt
+29
-2
No files found.
CHANGELOG.md
View file @
52b848eb
...
@@ -2,6 +2,21 @@
...
@@ -2,6 +2,21 @@
开发版本. 频繁更新, 不保证高稳定性
开发版本. 频繁更新, 不保证高稳定性
## `0.18.0` 2020/2/20
### mirai-core
-
添加
`MessageSource.time`
-
添加事件监听时额外的
`coroutineContext`
-
为一些带有
`operator`
的事件添加
`.isByBot`
的属性扩展
-
优化事件广播逻辑, 修复可能无法触发监听的问题
-
为所有
`Contact`
添加
`toString()`
(#80)
### mirai-core-qqandroid
-
支持成员禁言状态和时间查询
`Member.muteTimeRemaining`
-
修复
`At`
的
`display`
(#73), 同时修复
`QuoteReply`
无法显示问题 (#54).
-
广播
`BotReloginEvent`
(#78)
-
支持机器人自身禁言时间的更新和查询 (#82)
## `0.17.0` 2020/2/20
## `0.17.0` 2020/2/20
### mirai-core
### mirai-core
...
...
gradle.properties
View file @
52b848eb
# style guide
# style guide
kotlin.code.style
=
official
kotlin.code.style
=
official
# config
# config
mirai_version
=
0.1
7
.0
mirai_version
=
0.1
8
.0
mirai_japt_version
=
1.0.1
mirai_japt_version
=
1.0.1
kotlin.incremental.multiplatform
=
true
kotlin.incremental.multiplatform
=
true
kotlin.parallel.tasks.in.project
=
true
kotlin.parallel.tasks.in.project
=
true
...
...
mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleTerminalUI.kt
View file @
52b848eb
...
@@ -482,7 +482,9 @@ object MiraiConsoleTerminalUI : MiraiConsoleUI {
...
@@ -482,7 +482,9 @@ object MiraiConsoleTerminalUI : MiraiConsoleUI {
val
width
=
terminal
.
terminalSize
.
columns
-
6
val
width
=
terminal
.
terminalSize
.
columns
-
6
var
x
=
string
var
x
=
string
while
(
true
)
{
while
(
true
)
{
if
(
x
==
""
)
break
if
(
x
==
""
)
{
break
}
val
toWrite
=
if
(
x
.
actualLength
()
>
width
)
{
val
toWrite
=
if
(
x
.
actualLength
()
>
width
)
{
val
index
=
x
.
getSubStringIndexByActualLength
(
width
)
val
index
=
x
.
getSubStringIndexByActualLength
(
width
)
x
.
substring
(
0
,
index
).
also
{
x
.
substring
(
0
,
index
).
also
{
...
...
mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsole.kt
View file @
52b848eb
...
@@ -305,6 +305,7 @@ object MiraiConsole {
...
@@ -305,6 +305,7 @@ object MiraiConsole {
if
(!
CommandManager
.
runCommand
(
fullCommand
))
{
if
(!
CommandManager
.
runCommand
(
fullCommand
))
{
logger
(
"未知指令 $fullCommand"
)
logger
(
"未知指令 $fullCommand"
)
}
}
}
}
}
}
}
}
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/ContactImpl.kt
View file @
52b848eb
...
@@ -162,16 +162,11 @@ internal class QQImpl(
...
@@ -162,16 +162,11 @@ internal class QQImpl(
TODO
(
"not implemented"
)
TODO
(
"not implemented"
)
}
}
override
fun
equals
(
other
:
Any
?):
Boolean
{
override
fun
toString
():
String
=
"QQ($id)"
if
(
this
===
other
)
return
true
return
other
is
QQ
&&
other
.
id
==
this
.
id
}
override
fun
hashCode
():
Int
=
super
.
hashCode
()
}
}
@Suppress
(
"MemberVisibilityCanBePrivate"
)
@Suppress
(
"MemberVisibilityCanBePrivate"
,
"DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE"
)
internal
class
MemberImpl
(
internal
class
MemberImpl
(
qq
:
QQImpl
,
qq
:
QQImpl
,
group
:
GroupImpl
,
group
:
GroupImpl
,
...
@@ -182,9 +177,21 @@ internal class MemberImpl(
...
@@ -182,9 +177,21 @@ internal class MemberImpl(
val
qq
:
QQImpl
by
qq
.
unsafeWeakRef
()
val
qq
:
QQImpl
by
qq
.
unsafeWeakRef
()
override
var
permission
:
MemberPermission
=
memberInfo
.
permission
override
var
permission
:
MemberPermission
=
memberInfo
.
permission
@Suppress
(
"PropertyName"
)
internal
var
_nameCard
:
String
=
memberInfo
.
nameCard
internal
var
_nameCard
:
String
=
memberInfo
.
nameCard
@Suppress
(
"PropertyName"
)
internal
var
_specialTitle
:
String
=
memberInfo
.
specialTitle
internal
var
_specialTitle
:
String
=
memberInfo
.
specialTitle
@Suppress
(
"PropertyName"
)
var
_muteTimestamp
:
Int
=
memberInfo
.
muteTimestamp
override
val
muteTimeRemaining
:
Int
=
if
(
_muteTimestamp
==
0
||
_muteTimestamp
==
0
xFFFFFFFF
.
toInt
())
{
0
}
else
{
_muteTimestamp
-
currentTimeSeconds
.
toInt
()
-
bot
.
client
.
timeDifference
.
toInt
()
}
override
var
nameCard
:
String
override
var
nameCard
:
String
get
()
=
_nameCard
get
()
=
_nameCard
set
(
newValue
)
{
set
(
newValue
)
{
...
@@ -220,7 +227,7 @@ internal class MemberImpl(
...
@@ -220,7 +227,7 @@ internal class MemberImpl(
newValue
newValue
).
sendWithoutExpect
()
).
sendWithoutExpect
()
}
}
MemberSpecialTitleChangeEvent
(
oldValue
,
newValue
,
this
@MemberImpl
).
broadcast
()
MemberSpecialTitleChangeEvent
(
oldValue
,
newValue
,
this
@MemberImpl
,
null
).
broadcast
()
}
}
}
}
}
}
...
@@ -279,12 +286,9 @@ internal class MemberImpl(
...
@@ -279,12 +286,9 @@ internal class MemberImpl(
}
}
}
}
override
fun
equals
(
other
:
Any
?):
Boolean
{
override
fun
toString
():
String
{
if
(
this
===
other
)
return
true
return
"Member($id)"
return
other
is
Member
&&
other
.
id
==
this
.
id
}
}
override
fun
hashCode
():
Int
=
super
.
hashCode
()
}
}
internal
class
MemberInfoImpl
(
internal
class
MemberInfoImpl
(
...
@@ -301,6 +305,7 @@ internal class MemberInfoImpl(
...
@@ -301,6 +305,7 @@ internal class MemberInfoImpl(
else
->
MemberPermission
.
MEMBER
else
->
MemberPermission
.
MEMBER
}
}
override
val
specialTitle
:
String
get
()
=
jceInfo
.
sSpecialTitle
?:
""
override
val
specialTitle
:
String
get
()
=
jceInfo
.
sSpecialTitle
?:
""
override
val
muteTimestamp
:
Int
get
()
=
jceInfo
.
dwShutupTimestap
?.
toInt
()
?:
0
}
}
/**
/**
...
@@ -323,13 +328,13 @@ internal class GroupImpl(
...
@@ -323,13 +328,13 @@ internal class GroupImpl(
@UseExperimental
(
MiraiExperimentalAPI
::
class
)
@UseExperimental
(
MiraiExperimentalAPI
::
class
)
override
lateinit
var
botPermission
:
MemberPermission
override
lateinit
var
botPermission
:
MemberPermission
var
_botMute
Remaining
:
Int
=
groupInfo
.
botMuteRemaining
var
_botMute
Timestamp
:
Int
=
groupInfo
.
botMuteRemaining
override
val
botMuteRemaining
:
Int
=
override
val
botMuteRemaining
:
Int
=
if
(
_botMute
Remaining
==
0
||
_botMuteRemaining
==
0
xFFFFFFFF
.
toInt
())
{
if
(
_botMute
Timestamp
==
0
||
_botMuteTimestamp
==
0
xFFFFFFFF
.
toInt
())
{
0
0
}
else
{
}
else
{
_botMute
Remaining
-
currentTimeSeconds
.
toInt
()
-
bot
.
client
.
timeDifference
.
toInt
()
_botMute
Timestamp
-
currentTimeSeconds
.
toInt
()
-
bot
.
client
.
timeDifference
.
toInt
()
}
}
override
val
members
:
ContactList
<
Member
>
=
ContactList
(
members
.
mapNotNull
{
override
val
members
:
ContactList
<
Member
>
=
ContactList
(
members
.
mapNotNull
{
...
@@ -600,10 +605,7 @@ internal class GroupImpl(
...
@@ -600,10 +605,7 @@ internal class GroupImpl(
image
.
input
.
close
()
image
.
input
.
close
()
}
}
override
fun
equals
(
other
:
Any
?):
Boolean
{
override
fun
toString
():
String
{
if
(
this
===
other
)
return
true
return
"Group($id)"
return
other
is
Group
&&
other
.
id
==
this
.
id
}
}
override
fun
hashCode
():
Int
=
super
.
hashCode
()
}
}
\ No newline at end of file
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/MessageSvc.kt
View file @
52b848eb
...
@@ -194,6 +194,7 @@ internal class MessageSvc {
...
@@ -194,6 +194,7 @@ internal class MessageSvc {
override
val
nameCard
:
String
get
()
=
""
override
val
nameCard
:
String
get
()
=
""
override
val
permission
:
MemberPermission
get
()
=
MemberPermission
.
MEMBER
override
val
permission
:
MemberPermission
get
()
=
MemberPermission
.
MEMBER
override
val
specialTitle
:
String
get
()
=
""
override
val
specialTitle
:
String
get
()
=
""
override
val
muteTimestamp
:
Int
get
()
=
0
override
val
uin
:
Long
get
()
=
msg
.
msgHead
.
authUin
override
val
uin
:
Long
get
()
=
msg
.
msgHead
.
authUin
override
val
nick
:
String
get
()
=
msg
.
msgHead
.
authNick
.
takeIf
{
it
.
isNotEmpty
()
}
?:
msg
.
msgHead
.
fromNick
override
val
nick
:
String
get
()
=
msg
.
msgHead
.
authNick
.
takeIf
{
it
.
isNotEmpty
()
}
?:
msg
.
msgHead
.
fromNick
}).
also
{
group
.
members
.
delegate
.
addLast
(
it
)
})
}).
also
{
group
.
members
.
delegate
.
addLast
(
it
)
})
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.kt
View file @
52b848eb
...
@@ -142,9 +142,10 @@ internal class OnlinePush {
...
@@ -142,9 +142,10 @@ internal class OnlinePush {
@UseExperimental
(
ExperimentalStdlibApi
::
class
)
@UseExperimental
(
ExperimentalStdlibApi
::
class
)
override
suspend
fun
ByteReadPacket
.
decode
(
bot
:
QQAndroidBot
,
sequenceId
:
Int
):
Packet
{
override
suspend
fun
ByteReadPacket
.
decode
(
bot
:
QQAndroidBot
,
sequenceId
:
Int
):
Packet
{
val
reqPushMsg
=
decodeUniPacket
(
OnlinePushPack
.
SvcReqPushMsg
.
serializer
(),
"req"
)
val
reqPushMsg
=
decodeUniPacket
(
OnlinePushPack
.
SvcReqPushMsg
.
serializer
(),
"req"
)
val
packets
=
reqPushMsg
.
vMsgInfos
.
mapNotNull
{
msgInfo
:
MsgInfo
->
msgInfo
.
vMsg
!!
.
read
{
@Suppress
(
"USELESS_CAST"
)
// 不要信任 kotlin 类型推断
val
packets
:
List
<
Packet
>
=
reqPushMsg
.
vMsgInfos
.
mapNotNull
{
msgInfo
:
MsgInfo
->
msgInfo
.
vMsg
!!
.
read
{
when
{
when
{
msgInfo
.
shMsgType
.
toInt
()
==
732
->
{
msgInfo
.
shMsgType
.
toInt
()
==
732
->
{
val
group
=
bot
.
getGroup
(
this
.
readUInt
().
toLong
())
val
group
=
bot
.
getGroup
(
this
.
readUInt
().
toLong
())
...
@@ -162,41 +163,54 @@ internal class OnlinePush {
...
@@ -162,41 +163,54 @@ internal class OnlinePush {
val
target
=
this
.
readUInt
().
toLong
()
val
target
=
this
.
readUInt
().
toLong
()
val
time
=
this
.
readInt
()
val
time
=
this
.
readInt
()
return
@
mapNotNull
if
(
target
==
0L
)
{
if
(
target
==
0L
)
{
if
(
time
==
0
)
{
if
(
time
==
0
)
{
GroupMuteAllEvent
(
return
@
mapNotNull
GroupMuteAllEvent
(
origin
=
group
.
isMuteAll
.
also
{
group
.
_muteAll
=
false
},
origin
=
group
.
isMuteAll
.
also
{
group
.
_muteAll
=
false
},
new
=
false
,
new
=
false
,
operator
=
operator
,
operator
=
operator
,
group
=
group
group
=
group
)
)
as
Packet
}
else
{
}
else
{
GroupMuteAllEvent
(
return
@
mapNotNull
GroupMuteAllEvent
(
origin
=
group
.
isMuteAll
.
also
{
group
.
_muteAll
=
true
},
origin
=
group
.
isMuteAll
.
also
{
group
.
_muteAll
=
true
},
new
=
true
,
new
=
true
,
operator
=
operator
,
operator
=
operator
,
group
=
group
group
=
group
)
)
as
Packet
}
}
}
else
{
}
else
{
if
(
target
==
bot
.
uin
)
{
if
(
target
==
bot
.
uin
)
{
@Suppress
(
"IMPLICIT_CAST_TO_ANY"
)
// false positive
if
(
group
.
_botMuteTimestamp
!=
time
)
{
return
@
mapNotNull
if
(
time
==
0
)
{
if
(
time
==
0
)
{
BotUnmuteEvent
(
operator
)
group
.
_botMuteTimestamp
=
0
}
else
return
@
mapNotNull
BotUnmuteEvent
(
operator
)
as
Packet
BotMuteEvent
(
durationSeconds
=
time
,
operator
=
operator
)
}
else
{
group
.
_botMuteTimestamp
=
time
return
@
mapNotNull
BotMuteEvent
(
durationSeconds
=
time
,
operator
=
operator
)
as
Packet
}
}
else
{
return
@
mapNotNull
null
}
}
else
{
}
else
{
val
member
=
group
[
target
]
val
member
=
group
[
target
]
@Suppress
(
"IMPLICIT_CAST_TO_ANY"
)
// false positive
member
as
MemberImpl
return
@
mapNotNull
if
(
time
==
0
)
{
if
(
member
.
_muteTimestamp
!=
time
)
{
MemberUnmuteEvent
(
operator
=
operator
,
member
=
member
)
if
(
time
==
0
)
{
member
.
_muteTimestamp
=
0
return
@
mapNotNull
MemberUnmuteEvent
(
member
,
operator
)
as
Packet
}
else
{
member
.
_muteTimestamp
=
time
return
@
mapNotNull
MemberMuteEvent
(
member
,
time
,
operator
)
as
Packet
}
}
else
{
}
else
{
MemberMuteEvent
(
operator
=
operator
,
member
=
member
,
durationSeconds
=
time
)
return
@
mapNotNull
null
}
}
}
}
}
}
}
}
3585
->
{
// 匿名
3585
->
{
// 匿名
val
operator
=
group
[
this
.
readUInt
().
toLong
()]
val
operator
=
group
[
this
.
readUInt
().
toLong
()]
val
switch
=
this
.
readInt
()
==
0
val
switch
=
this
.
readInt
()
==
0
return
@
mapNotNull
GroupAllowAnonymousChatEvent
(
return
@
mapNotNull
GroupAllowAnonymousChatEvent
(
...
@@ -239,7 +253,7 @@ internal class OnlinePush {
...
@@ -239,7 +253,7 @@ internal class OnlinePush {
}
}
else
->
{
else
->
{
bot
.
network
.
logger
.
debug
{
"Unknown server messages $message"
}
bot
.
network
.
logger
.
debug
{
"Unknown server messages $message"
}
return
@
mapNotNull
NoPacket
return
@
mapNotNull
null
}
}
}
}
}
}
...
@@ -250,6 +264,7 @@ internal class OnlinePush {
...
@@ -250,6 +264,7 @@ internal class OnlinePush {
// }
// }
else
->
{
else
->
{
bot
.
network
.
logger
.
debug
{
"unknown group internal type $internalType , data: "
+
this
.
readBytes
().
toUHexString
()
+
" "
}
bot
.
network
.
logger
.
debug
{
"unknown group internal type $internalType , data: "
+
this
.
readBytes
().
toUHexString
()
+
" "
}
return
@
mapNotNull
null
}
}
}
}
}
}
...
@@ -257,19 +272,18 @@ internal class OnlinePush {
...
@@ -257,19 +272,18 @@ internal class OnlinePush {
bot
.
network
.
logger
.
debug
{
"unknown shtype ${msgInfo.shMsgType.toInt()}"
}
bot
.
network
.
logger
.
debug
{
"unknown shtype ${msgInfo.shMsgType.toInt()}"
}
// val content = msgInfo.vMsg.loadAs(OnlinePushPack.MsgType0x210.serializer())
// val content = msgInfo.vMsg.loadAs(OnlinePushPack.MsgType0x210.serializer())
// println(content.contentToString())
// println(content.contentToString())
return
@
mapNotNull
null
}
}
else
->
{
else
->
{
bot
.
network
.
logger
.
debug
{
"unknown shtype ${msgInfo.shMsgType.toInt()}"
}
bot
.
network
.
logger
.
debug
{
"unknown shtype ${msgInfo.shMsgType.toInt()}"
}
return
@
mapNotNull
null
}
}
}
}
}
}
return
@
mapNotNull
null
}
}
return
MultiPacket
(
packets
)
return
MultiPacket
(
packets
)
}
}
override
suspend
fun
QQAndroidBot
.
handle
(
packet
:
Packet
,
sequenceId
:
Int
):
OutgoingPacket
?
{
override
suspend
fun
QQAndroidBot
.
handle
(
packet
:
Packet
,
sequenceId
:
Int
):
OutgoingPacket
?
{
return
buildResponseUniPacket
(
client
,
sequenceId
=
sequenceId
)
{
return
buildResponseUniPacket
(
client
,
sequenceId
=
sequenceId
)
{
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Contact.kt
View file @
52b848eb
...
@@ -74,6 +74,16 @@ interface Contact : CoroutineScope {
...
@@ -74,6 +74,16 @@ interface Contact : CoroutineScope {
* 而 [QQ] 含义为一个独立的人, 可以是好友, 也可以是陌生人.
* 而 [QQ] 含义为一个独立的人, 可以是好友, 也可以是陌生人.
*/
*/
override
fun
equals
(
other
:
Any
?):
Boolean
override
fun
equals
(
other
:
Any
?):
Boolean
/**
* @return `bot.hashCode() * 31 + id.hashCode()`
*/
override
fun
hashCode
():
Int
/**
* @return "QQ($id)" or "Group($id)" or "Member($id)"
*/
override
fun
toString
():
String
}
}
suspend
inline
fun
Contact
.
sendMessage
(
message
:
Message
)
=
sendMessage
(
message
.
toChain
())
suspend
inline
fun
Contact
.
sendMessage
(
message
:
Message
)
=
sendMessage
(
message
.
toChain
())
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Group.kt
View file @
52b848eb
...
@@ -12,6 +12,7 @@
...
@@ -12,6 +12,7 @@
package
net.mamoe.mirai.contact
package
net.mamoe.mirai.contact
import
kotlinx.coroutines.CoroutineScope
import
kotlinx.coroutines.CoroutineScope
import
net.mamoe.mirai.Bot
import
net.mamoe.mirai.data.MemberInfo
import
net.mamoe.mirai.data.MemberInfo
import
net.mamoe.mirai.event.events.*
import
net.mamoe.mirai.event.events.*
import
net.mamoe.mirai.utils.MiraiExperimentalAPI
import
net.mamoe.mirai.utils.MiraiExperimentalAPI
...
@@ -89,19 +90,19 @@ interface Group : Contact, CoroutineScope {
...
@@ -89,19 +90,19 @@ interface Group : Contact, CoroutineScope {
/**
/**
* 机器人被禁言还剩余多少秒
* 机器人被禁言还剩余多少秒
*
*
* @see BotMuteEvent
* @see BotMuteEvent
机器人被禁言事件
* @see isBotMuted
* @see isBotMuted
判断机器人是否正在被禁言
*/
*/
val
botMuteRemaining
:
Int
val
botMuteRemaining
:
Int
/**
/**
* 机器人在这个群里的权限
* 机器人在这个群里的权限
*
*
* **MiraiExperimentalAPI**: 在未来可能会被修改
* @see Group.checkBotPermission 检查 [Bot] 在这个群里的权限
* @see Group.checkBotPermissionOperator 要求 [Bot] 在这个群里的权限为 [管理员或群主][MemberPermission.isOperator]
*
*
* @see BotGroupPermissionChangeEvent
* @see BotGroupPermissionChangeEvent
机器人群员修改
*/
*/
@MiraiExperimentalAPI
val
botPermission
:
MemberPermission
val
botPermission
:
MemberPermission
...
@@ -129,6 +130,7 @@ interface Group : Contact, CoroutineScope {
...
@@ -129,6 +130,7 @@ interface Group : Contact, CoroutineScope {
/**
/**
* 让机器人退出这个群. 机器人必须为非群主才能退出. 否则将会失败
* 让机器人退出这个群. 机器人必须为非群主才能退出. 否则将会失败
*/
*/
@MiraiExperimentalAPI
(
"还未支持"
)
suspend
fun
quit
():
Boolean
suspend
fun
quit
():
Boolean
/**
/**
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Member.kt
View file @
52b848eb
/*
/*
* Copyright 2020 Mamoe Technologies and contributors.
* Copyright 2020 Mamoe Technologies and contributors.
*
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可
以
在以下链接找到该许可证.
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
* https://github.com/mamoe/mirai/blob/master/LICENSE
...
@@ -29,33 +29,50 @@ interface Member : QQ, Contact {
...
@@ -29,33 +29,50 @@ interface Member : QQ, Contact {
/**
/**
* 成员的权限, 动态更新.
* 成员的权限, 动态更新.
*
* @see MemberPermissionChangeEvent 权限变更事件. 由群主或机器人的操作触发.
*/
*/
val
permission
:
MemberPermission
val
permission
:
MemberPermission
/**
/**
* 群名片. 可能为空. 修改时将会触发事件
* 群名片. 可能为空.
*
* 管理员和群主都可修改任何人(包括群主)的群名片.
*
*
* 在修改时将会异步上传至服务器.
* 在修改时将会异步上传至服务器.
*
*
* @see [nameCardOrNick] 获取非空群名片或昵称
* @see [nameCardOrNick] 获取非空群名片或昵称
*
*
* @see MemberCardChangeEvent 群名片被管理员, 自己或 [Bot] 改动事件
* @see MemberCardChangeEvent 群名片被管理员, 自己或 [Bot] 改动事件
. 修改时也会触发此事件.
* @throws PermissionDeniedException 无权限修改时
* @throws PermissionDeniedException 无权限修改时
*/
*/
var
nameCard
:
String
var
nameCard
:
String
/**
/**
* 群头衔
* 群头衔.
*
* 仅群主可以修改群头衔.
*
*
* 在修改时将会异步上传至服务器.
* 在修改时将会异步上传至服务器.
*
*
* @see MemberSpecialTitleChangeEvent 群名片被管理员, 自己或 [Bot] 改动事件
* @see MemberSpecialTitleChangeEvent 群名片被管理员, 自己或 [Bot] 改动事件
. 修改时也会触发此事件.
* @throws PermissionDeniedException 无权限修改时
* @throws PermissionDeniedException 无权限修改时
*/
*/
var
specialTitle
:
String
var
specialTitle
:
String
/**
/**
* 禁言
* 被禁言剩余时长. 单位为秒.
*
* @see isMuted 判断改成员是否处于禁言状态
* @see mute 设置禁言
* @see unmute 取消禁言
*/
val
muteTimeRemaining
:
Int
/**
* 禁言.
*
* 管理员可禁言成员, 群主可禁言管理员和群员.
*
*
* @param durationSeconds 持续时间. 精确到秒. 范围区间表示为 `(0s, 30days]`. 超过范围则会抛出异常.
* @param durationSeconds 持续时间. 精确到秒. 范围区间表示为 `(0s, 30days]`. 超过范围则会抛出异常.
* @return 机器人无权限时返回 `false`
* @return 机器人无权限时返回 `false`
...
@@ -72,6 +89,8 @@ interface Member : QQ, Contact {
...
@@ -72,6 +89,8 @@ interface Member : QQ, Contact {
/**
/**
* 解除禁言.
* 解除禁言.
*
*
* 管理员可解除成员的禁言, 群主可解除管理员和群员的禁言.
*
* @see MemberUnmuteEvent 成员被取消禁言事件.
* @see MemberUnmuteEvent 成员被取消禁言事件.
* @throws PermissionDeniedException 无权限修改时
* @throws PermissionDeniedException 无权限修改时
*/
*/
...
@@ -80,6 +99,8 @@ interface Member : QQ, Contact {
...
@@ -80,6 +99,8 @@ interface Member : QQ, Contact {
/**
/**
* 踢出该成员.
* 踢出该成员.
*
*
* 管理员可踢出成员, 群主可踢出管理员和群员.
*
* @see MemberLeaveEvent.Kick 成员被踢出事件.
* @see MemberLeaveEvent.Kick 成员被踢出事件.
* @throws PermissionDeniedException 无权限修改时
* @throws PermissionDeniedException 无权限修改时
*/
*/
...
@@ -98,6 +119,13 @@ interface Member : QQ, Contact {
...
@@ -98,6 +119,13 @@ interface Member : QQ, Contact {
*/
*/
val
Member
.
nameCardOrNick
:
String
get
()
=
this
.
nameCard
.
takeIf
{
it
.
isNotEmpty
()
}
?:
this
.
nick
val
Member
.
nameCardOrNick
:
String
get
()
=
this
.
nameCard
.
takeIf
{
it
.
isNotEmpty
()
}
?:
this
.
nick
/**
* 判断改成员是否处于禁言状态.
*/
fun
Member
.
isMuted
():
Boolean
{
return
muteTimeRemaining
!=
0
&&
muteTimeRemaining
!=
0
xFFFFFFFF
.
toInt
()
}
@ExperimentalTime
@ExperimentalTime
suspend
inline
fun
Member
.
mute
(
duration
:
Duration
)
{
suspend
inline
fun
Member
.
mute
(
duration
:
Duration
)
{
require
(
duration
.
inDays
<=
30
)
{
"duration must be at most 1 month"
}
require
(
duration
.
inDays
<=
30
)
{
"duration must be at most 1 month"
}
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Permission.kt
View file @
52b848eb
...
@@ -9,6 +9,7 @@
...
@@ -9,6 +9,7 @@
package
net.mamoe.mirai.contact
package
net.mamoe.mirai.contact
import
net.mamoe.mirai.Bot
import
net.mamoe.mirai.utils.MiraiExperimentalAPI
import
net.mamoe.mirai.utils.MiraiExperimentalAPI
...
@@ -68,7 +69,6 @@ inline fun Member.isAdministrator(): Boolean = this.permission.isAdministrator()
...
@@ -68,7 +69,6 @@ inline fun Member.isAdministrator(): Boolean = this.permission.isAdministrator()
inline
fun
Member
.
isOperator
():
Boolean
=
this
.
permission
.
isOperator
()
inline
fun
Member
.
isOperator
():
Boolean
=
this
.
permission
.
isOperator
()
/**
/**
* 权限不足
* 权限不足
*/
*/
...
@@ -77,6 +77,11 @@ expect class PermissionDeniedException : IllegalStateException {
...
@@ -77,6 +77,11 @@ expect class PermissionDeniedException : IllegalStateException {
constructor
(
message
:
String
?)
constructor
(
message
:
String
?)
}
}
/**
* 要求 [Bot] 在这个群里的权限为 [required], 否则抛出异常 [PermissionDeniedException]
*
* @throws PermissionDeniedException
*/
@UseExperimental
(
MiraiExperimentalAPI
::
class
)
@UseExperimental
(
MiraiExperimentalAPI
::
class
)
inline
fun
Group
.
checkBotPermission
(
inline
fun
Group
.
checkBotPermission
(
required
:
MemberPermission
,
required
:
MemberPermission
,
...
@@ -89,6 +94,11 @@ inline fun Group.checkBotPermission(
...
@@ -89,6 +94,11 @@ inline fun Group.checkBotPermission(
}
}
}
}
/**
* 要求 [Bot] 在这个群里的权限为 [管理员或群主][MemberPermission.isOperator], 否则抛出异常 [PermissionDeniedException]
*
* @throws PermissionDeniedException
*/
@UseExperimental
(
MiraiExperimentalAPI
::
class
)
@UseExperimental
(
MiraiExperimentalAPI
::
class
)
inline
fun
Group
.
checkBotPermissionOperator
(
inline
fun
Group
.
checkBotPermissionOperator
(
lazyMessage
:
()
->
String
=
{
lazyMessage
:
()
->
String
=
{
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/data/MemberInfo.kt
View file @
52b848eb
...
@@ -17,4 +17,6 @@ interface MemberInfo : FriendInfo {
...
@@ -17,4 +17,6 @@ interface MemberInfo : FriendInfo {
val
permission
:
MemberPermission
val
permission
:
MemberPermission
val
specialTitle
:
String
val
specialTitle
:
String
val
muteTimestamp
:
Int
}
}
\ No newline at end of file
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/BotEvents.kt
View file @
52b848eb
...
@@ -7,6 +7,8 @@
...
@@ -7,6 +7,8 @@
* https://github.com/mamoe/mirai/blob/master/LICENSE
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
*/
@
file
:
Suppress
(
"unused"
)
package
net.mamoe.mirai.event.events
package
net.mamoe.mirai.event.events
import
net.mamoe.mirai.Bot
import
net.mamoe.mirai.Bot
...
@@ -194,7 +196,7 @@ data class GroupNameChangeEvent(
...
@@ -194,7 +196,7 @@ data class GroupNameChangeEvent(
override
val
origin
:
String
,
override
val
origin
:
String
,
override
val
new
:
String
,
override
val
new
:
String
,
override
val
group
:
Group
,
override
val
group
:
Group
,
val
isByBot
:
Boolean
val
isByBot
:
Boolean
// 无法获取 operator
)
:
GroupSettingChangeEvent
<
String
>,
Packet
)
:
GroupSettingChangeEvent
<
String
>,
Packet
/**
/**
...
@@ -210,6 +212,8 @@ data class GroupEntranceAnnouncementChangeEvent(
...
@@ -210,6 +212,8 @@ data class GroupEntranceAnnouncementChangeEvent(
val
operator
:
Member
?
val
operator
:
Member
?
)
:
GroupSettingChangeEvent
<
String
>,
Packet
)
:
GroupSettingChangeEvent
<
String
>,
Packet
val
GroupEntranceAnnouncementChangeEvent
.
isByBot
:
Boolean
get
()
=
operator
!=
null
/**
/**
* 群 "全员禁言" 功能状态改变. 此事件广播前修改就已经完成.
* 群 "全员禁言" 功能状态改变. 此事件广播前修改就已经完成.
...
@@ -224,6 +228,8 @@ data class GroupMuteAllEvent(
...
@@ -224,6 +228,8 @@ data class GroupMuteAllEvent(
val
operator
:
Member
?
val
operator
:
Member
?
)
:
GroupSettingChangeEvent
<
Boolean
>,
Packet
)
:
GroupSettingChangeEvent
<
Boolean
>,
Packet
val
GroupMuteAllEvent
.
isByBot
:
Boolean
get
()
=
operator
!=
null
/**
/**
* 群 "匿名聊天" 功能状态改变. 此事件广播前修改就已经完成.
* 群 "匿名聊天" 功能状态改变. 此事件广播前修改就已经完成.
*/
*/
...
@@ -237,6 +243,8 @@ data class GroupAllowAnonymousChatEvent(
...
@@ -237,6 +243,8 @@ data class GroupAllowAnonymousChatEvent(
val
operator
:
Member
?
val
operator
:
Member
?
)
:
GroupSettingChangeEvent
<
Boolean
>,
Packet
)
:
GroupSettingChangeEvent
<
Boolean
>,
Packet
val
GroupAllowAnonymousChatEvent
.
isByBot
:
Boolean
get
()
=
operator
!=
null
/**
/**
* 群 "坦白说" 功能状态改变. 此事件广播前修改就已经完成.
* 群 "坦白说" 功能状态改变. 此事件广播前修改就已经完成.
*/
*/
...
@@ -260,6 +268,8 @@ data class GroupAllowMemberInviteEvent(
...
@@ -260,6 +268,8 @@ data class GroupAllowMemberInviteEvent(
val
operator
:
Member
?
val
operator
:
Member
?
)
:
GroupSettingChangeEvent
<
Boolean
>,
Packet
)
:
GroupSettingChangeEvent
<
Boolean
>,
Packet
val
GroupAllowMemberInviteEvent
.
isByBot
:
Boolean
get
()
=
operator
!=
null
// endregion
// endregion
...
@@ -293,6 +303,8 @@ sealed class MemberLeaveEvent : GroupMemberEvent {
...
@@ -293,6 +303,8 @@ sealed class MemberLeaveEvent : GroupMemberEvent {
data class
Quit
(
override
val
member
:
Member
)
:
MemberLeaveEvent
()
data class
Quit
(
override
val
member
:
Member
)
:
MemberLeaveEvent
()
}
}
val
MemberLeaveEvent
.
Kick
.
isByBot
:
Boolean
get
()
=
operator
!=
null
// endregion
// endregion
// region 名片和头衔
// region 名片和头衔
...
@@ -319,6 +331,8 @@ data class MemberCardChangeEvent(
...
@@ -319,6 +331,8 @@ data class MemberCardChangeEvent(
val
operator
:
Member
?
val
operator
:
Member
?
)
:
GroupMemberEvent
)
:
GroupMemberEvent
val
MemberCardChangeEvent
.
isByBot
:
Boolean
get
()
=
operator
!=
null
/**
/**
* 群头衔改动. 一定为群主操作
* 群头衔改动. 一定为群主操作
*/
*/
...
@@ -333,9 +347,18 @@ data class MemberSpecialTitleChangeEvent(
...
@@ -333,9 +347,18 @@ data class MemberSpecialTitleChangeEvent(
*/
*/
val
new
:
String
,
val
new
:
String
,
override
val
member
:
Member
override
val
member
:
Member
,
/**
* 操作人.
* 不为 null 时一定为群主. 可能与 [member] 引用相同, 此时为群员自己修改.
* 为 null 时则是机器人操作.
*/
val
operator
:
Member
?
)
:
GroupMemberEvent
)
:
GroupMemberEvent
val
MemberSpecialTitleChangeEvent
.
isByBot
:
Boolean
get
()
=
operator
!=
null
// endregion
// endregion
...
@@ -367,6 +390,8 @@ data class MemberMuteEvent(
...
@@ -367,6 +390,8 @@ data class MemberMuteEvent(
val
operator
:
Member
?
val
operator
:
Member
?
)
:
GroupMemberEvent
,
Packet
)
:
GroupMemberEvent
,
Packet
val
MemberMuteEvent
.
isByBot
:
Boolean
get
()
=
operator
!=
null
/**
/**
* 群成员被取消禁言事件. 被禁言的成员都不可能是机器人本人
* 群成员被取消禁言事件. 被禁言的成员都不可能是机器人本人
*/
*/
...
@@ -378,6 +403,8 @@ data class MemberUnmuteEvent(
...
@@ -378,6 +403,8 @@ data class MemberUnmuteEvent(
val
operator
:
Member
?
val
operator
:
Member
?
)
:
GroupMemberEvent
,
Packet
)
:
GroupMemberEvent
,
Packet
val
MemberUnmuteEvent
.
isByBot
:
Boolean
get
()
=
operator
!=
null
// endregion
// endregion
// endregion
// endregion
...
...
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