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
e5404b39
Commit
e5404b39
authored
May 03, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify MemberPermission comparing
parent
c2fa014c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
16 deletions
+27
-16
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.common.kt
...n/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.common.kt
+2
-2
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/GroupImpl.kt
...ain/kotlin/net/mamoe/mirai/qqandroid/contact/GroupImpl.kt
+8
-5
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/MemberImpl.kt
...in/kotlin/net/mamoe/mirai/qqandroid/contact/MemberImpl.kt
+1
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/MemberPermission.kt
...onMain/kotlin/net.mamoe.mirai/contact/MemberPermission.kt
+16
-8
No files found.
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.common.kt
View file @
e5404b39
...
@@ -188,7 +188,7 @@ internal class QQAndroidBot constructor(
...
@@ -188,7 +188,7 @@ internal class QQAndroidBot constructor(
}
}
}
}
group
.
checkBotPermission
Operator
(
)
group
.
checkBotPermission
(
MemberPermission
.
ADMINISTRATOR
)
}
}
override
suspend
fun
ignoreMemberJoinRequest
(
event
:
MemberJoinRequestEvent
,
blackList
:
Boolean
)
{
override
suspend
fun
ignoreMemberJoinRequest
(
event
:
MemberJoinRequestEvent
,
blackList
:
Boolean
)
{
...
@@ -369,7 +369,7 @@ internal abstract class QQAndroidBotBase constructor(
...
@@ -369,7 +369,7 @@ internal abstract class QQAndroidBotBase constructor(
else
->
error
(
"stub"
)
else
->
error
(
"stub"
)
}
}
if
(
this
.
id
!=
source
.
fromId
)
{
if
(
this
.
id
!=
source
.
fromId
)
{
group
.
checkBotPermission
Operator
(
)
group
.
checkBotPermission
(
MemberPermission
.
ADMINISTRATOR
)
}
}
MessageRecallEvent
.
GroupRecall
(
MessageRecallEvent
.
GroupRecall
(
this
,
this
,
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/GroupImpl.kt
View file @
e5404b39
...
@@ -109,7 +109,8 @@ internal class GroupImpl(
...
@@ -109,7 +109,8 @@ internal class GroupImpl(
override
var
name
:
String
override
var
name
:
String
get
()
=
_name
get
()
=
_name
set
(
newValue
)
{
set
(
newValue
)
{
checkBotPermissionOperator
()
checkBotPermission
(
MemberPermission
.
ADMINISTRATOR
)
if
(
_name
!=
newValue
)
{
if
(
_name
!=
newValue
)
{
val
oldValue
=
_name
val
oldValue
=
_name
_name
=
newValue
_name
=
newValue
...
@@ -131,7 +132,7 @@ internal class GroupImpl(
...
@@ -131,7 +132,7 @@ internal class GroupImpl(
override
var
entranceAnnouncement
:
String
override
var
entranceAnnouncement
:
String
get
()
=
_announcement
get
()
=
_announcement
set
(
newValue
)
{
set
(
newValue
)
{
checkBotPermission
Operator
(
)
checkBotPermission
(
MemberPermission
.
ADMINISTRATOR
)
if
(
_announcement
!=
newValue
)
{
if
(
_announcement
!=
newValue
)
{
val
oldValue
=
_announcement
val
oldValue
=
_announcement
_announcement
=
newValue
_announcement
=
newValue
...
@@ -152,7 +153,7 @@ internal class GroupImpl(
...
@@ -152,7 +153,7 @@ internal class GroupImpl(
override
var
isAllowMemberInvite
:
Boolean
override
var
isAllowMemberInvite
:
Boolean
get
()
=
_allowMemberInvite
get
()
=
_allowMemberInvite
set
(
newValue
)
{
set
(
newValue
)
{
checkBotPermission
Operator
(
)
checkBotPermission
(
MemberPermission
.
ADMINISTRATOR
)
if
(
_allowMemberInvite
!=
newValue
)
{
if
(
_allowMemberInvite
!=
newValue
)
{
val
oldValue
=
_allowMemberInvite
val
oldValue
=
_allowMemberInvite
_allowMemberInvite
=
newValue
_allowMemberInvite
=
newValue
...
@@ -186,7 +187,8 @@ internal class GroupImpl(
...
@@ -186,7 +187,8 @@ internal class GroupImpl(
override
var
isConfessTalkEnabled
:
Boolean
override
var
isConfessTalkEnabled
:
Boolean
get
()
=
_confessTalk
get
()
=
_confessTalk
set
(
newValue
)
{
set
(
newValue
)
{
checkBotPermissionOperator
()
checkBotPermission
(
MemberPermission
.
ADMINISTRATOR
)
if
(
_confessTalk
!=
newValue
)
{
if
(
_confessTalk
!=
newValue
)
{
val
oldValue
=
_confessTalk
val
oldValue
=
_confessTalk
_confessTalk
=
newValue
_confessTalk
=
newValue
...
@@ -207,7 +209,8 @@ internal class GroupImpl(
...
@@ -207,7 +209,8 @@ internal class GroupImpl(
override
var
isMuteAll
:
Boolean
override
var
isMuteAll
:
Boolean
get
()
=
_muteAll
get
()
=
_muteAll
set
(
newValue
)
{
set
(
newValue
)
{
checkBotPermissionOperator
()
checkBotPermission
(
MemberPermission
.
ADMINISTRATOR
)
if
(
_muteAll
!=
newValue
)
{
if
(
_muteAll
!=
newValue
)
{
val
oldValue
=
_muteAll
val
oldValue
=
_muteAll
_muteAll
=
newValue
_muteAll
=
newValue
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/MemberImpl.kt
View file @
e5404b39
...
@@ -105,7 +105,7 @@ internal class MemberImpl constructor(
...
@@ -105,7 +105,7 @@ internal class MemberImpl constructor(
get
()
=
_nameCard
get
()
=
_nameCard
set
(
newValue
)
{
set
(
newValue
)
{
if
(
id
!=
bot
.
id
)
{
if
(
id
!=
bot
.
id
)
{
group
.
checkBotPermission
Operator
(
)
group
.
checkBotPermission
(
MemberPermission
.
ADMINISTRATOR
)
}
}
if
(
_nameCard
!=
newValue
)
{
if
(
_nameCard
!=
newValue
)
{
val
oldValue
=
_nameCard
val
oldValue
=
_nameCard
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/MemberPermission.kt
View file @
e5404b39
...
@@ -7,17 +7,25 @@
...
@@ -7,17 +7,25 @@
* https://github.com/mamoe/mirai/blob/master/LICENSE
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
*/
@
file
:
Suppress
(
"NOTHING_TO_INLINE"
)
@
file
:
Suppress
(
"NOTHING_TO_INLINE"
,
"INVISIBLE_MEMBER"
,
"INVISIBLE_REFERENCE"
)
package
net.mamoe.mirai.contact
package
net.mamoe.mirai.contact
import
net.mamoe.mirai.Bot
import
net.mamoe.mirai.Bot
import
net.mamoe.mirai.utils.SinceMirai
import
net.mamoe.mirai.utils.SinceMirai
import
kotlin.internal.InlineOnly
/**
/**
* 群成员的权限.
* 群成员的权限.
*
*
* 可通过 [compareTo] 判断是否有更高的权限.
* 可通过 [compareTo] 判断是否有更高的权限.
*
* @see isOwner 判断权限是否为群主
* @see isOperator 判断权限是否为管理员或群主
*
* @see Member.isOwner 对 [Member] 的扩展函数, 判断此成员是否为群主
* @see Member.isOperator 对 [Member] 的扩展函数, 判断此成员是否为管理员或群主
* @see Member.isAdministrator 对 [Member] 的扩展函数, 判断此成员是否为管理员
*/
*/
enum
class
MemberPermission
:
Comparable
<
MemberPermission
>
{
enum
class
MemberPermission
:
Comparable
<
MemberPermission
>
{
/**
/**
...
@@ -46,16 +54,19 @@ enum class MemberPermission : Comparable<MemberPermission> {
...
@@ -46,16 +54,19 @@ enum class MemberPermission : Comparable<MemberPermission> {
/**
/**
* 判断权限是否为群主
* 判断权限是否为群主
*/
*/
@InlineOnly
inline
fun
MemberPermission
.
isOwner
():
Boolean
=
this
==
MemberPermission
.
OWNER
inline
fun
MemberPermission
.
isOwner
():
Boolean
=
this
==
MemberPermission
.
OWNER
/**
/**
* 判断权限是否为管理员
* 判断权限是否为管理员
*/
*/
@InlineOnly
inline
fun
MemberPermission
.
isAdministrator
():
Boolean
=
this
==
MemberPermission
.
ADMINISTRATOR
inline
fun
MemberPermission
.
isAdministrator
():
Boolean
=
this
==
MemberPermission
.
ADMINISTRATOR
/**
/**
* 判断权限是否为管理员或群主
* 判断权限是否为管理员或群主
*/
*/
@InlineOnly
inline
fun
MemberPermission
.
isOperator
():
Boolean
=
isAdministrator
()
||
isOwner
()
inline
fun
MemberPermission
.
isOperator
():
Boolean
=
isAdministrator
()
||
isOwner
()
...
@@ -85,7 +96,7 @@ class PermissionDeniedException : IllegalStateException {
...
@@ -85,7 +96,7 @@ class PermissionDeniedException : IllegalStateException {
}
}
/**
/**
* 要求 [Bot] 在这个群里的权限为 [required], 否则抛出异常 [PermissionDeniedException]
* 要求 [Bot] 在这个群里的权限
至少
为 [required], 否则抛出异常 [PermissionDeniedException]
*
*
* @throws PermissionDeniedException
* @throws PermissionDeniedException
*/
*/
...
@@ -95,7 +106,7 @@ inline fun Group.checkBotPermission(
...
@@ -95,7 +106,7 @@ inline fun Group.checkBotPermission(
"Permission denied: required $required, got actual $botPermission for $bot in group $id"
"Permission denied: required $required, got actual $botPermission for $bot in group $id"
}
}
)
{
)
{
if
(
botPermission
!=
required
)
{
if
(
botPermission
<
required
)
{
throw
PermissionDeniedException
(
lazyMessage
())
throw
PermissionDeniedException
(
lazyMessage
())
}
}
}
}
...
@@ -105,12 +116,9 @@ inline fun Group.checkBotPermission(
...
@@ -105,12 +116,9 @@ inline fun Group.checkBotPermission(
*
*
* @throws PermissionDeniedException
* @throws PermissionDeniedException
*/
*/
@Deprecated
(
"use checkBotPermission"
,
ReplaceWith
(
"checkBotPermission(MemberPermission.ADMINISTRATOR)"
))
inline
fun
Group
.
checkBotPermissionOperator
(
inline
fun
Group
.
checkBotPermissionOperator
(
crossinline
lazyMessage
:
()
->
String
=
{
crossinline
lazyMessage
:
()
->
String
=
{
"Permission denied: required ${MemberPermission.ADMINISTRATOR} or ${MemberPermission.OWNER}, got actual $botPermission for $bot in group $id"
"Permission denied: required ${MemberPermission.ADMINISTRATOR} or ${MemberPermission.OWNER}, got actual $botPermission for $bot in group $id"
}
}
)
{
)
=
checkBotPermission
(
MemberPermission
.
ADMINISTRATOR
,
lazyMessage
)
if
(!
botPermission
.
isOperator
())
{
\ No newline at end of file
throw
PermissionDeniedException
(
lazyMessage
())
}
}
\ No newline at end of file
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