mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-10 18:40:15 +08:00
Update permitteeIds to new temp user structure
This commit is contained in:
parent
4a5cedc592
commit
0b957d6475
@ -605,7 +605,7 @@ public open class GroupTempCommandSender internal constructor(
|
|||||||
public override fun toString(): String = "GroupTempCommandSender($user)"
|
public override fun toString(): String = "GroupTempCommandSender($user)"
|
||||||
|
|
||||||
public override val permitteeId: PermitteeId =
|
public override val permitteeId: PermitteeId =
|
||||||
AbstractPermitteeId.ExactTemp(user.group.id, user.id)
|
AbstractPermitteeId.ExactGroupTemp(user.group.id, user.id)
|
||||||
|
|
||||||
@JvmBlockingBridge
|
@JvmBlockingBridge
|
||||||
public override suspend fun sendMessage(message: String): MessageReceipt<Member> = sendMessage(PlainText(message))
|
public override suspend fun sendMessage(message: String): MessageReceipt<Member> = sendMessage(PlainText(message))
|
||||||
@ -646,7 +646,7 @@ public open class OtherClientCommandSender internal constructor(
|
|||||||
public override val subject: Friend get() = user
|
public override val subject: Friend get() = user
|
||||||
public override fun toString(): String = "OtherClientCommandSender($user)"
|
public override fun toString(): String = "OtherClientCommandSender($user)"
|
||||||
|
|
||||||
public override val permitteeId: PermitteeId = AbstractPermitteeId.ExactStranger(user.id)
|
public override val permitteeId: PermitteeId = AbstractPermitteeId.AnyOtherClient
|
||||||
|
|
||||||
@JvmBlockingBridge
|
@JvmBlockingBridge
|
||||||
public override suspend fun sendMessage(message: String): MessageReceipt<OtherClient> = sendMessage(PlainText(message))
|
public override suspend fun sendMessage(message: String): MessageReceipt<OtherClient> = sendMessage(PlainText(message))
|
||||||
|
@ -18,6 +18,7 @@ internal fun parseFromStringImpl(string: String): AbstractPermitteeId {
|
|||||||
val str = string.trim { it.isWhitespace() }.toLowerCase()
|
val str = string.trim { it.isWhitespace() }.toLowerCase()
|
||||||
if (str == "*") return AnyContact
|
if (str == "*") return AnyContact
|
||||||
if (str == "console") return Console
|
if (str == "console") return Console
|
||||||
|
if (str == "client*") return AnyOtherClient
|
||||||
if (str.isNotEmpty()) {
|
if (str.isNotEmpty()) {
|
||||||
when (str[0]) {
|
when (str[0]) {
|
||||||
'g' -> {
|
'g' -> {
|
||||||
@ -35,6 +36,11 @@ internal fun parseFromStringImpl(string: String): AbstractPermitteeId {
|
|||||||
if (arg == "*") return AnyUser
|
if (arg == "*") return AnyUser
|
||||||
else arg.toLongOrNull()?.let(::ExactUser)?.let { return it }
|
else arg.toLongOrNull()?.let(::ExactUser)?.let { return it }
|
||||||
}
|
}
|
||||||
|
's' -> {
|
||||||
|
val arg = str.substring(1)
|
||||||
|
if (arg == "*") return AnyStranger
|
||||||
|
else arg.toLongOrNull()?.let(::ExactStranger)?.let { return it }
|
||||||
|
}
|
||||||
'c' -> {
|
'c' -> {
|
||||||
val arg = str.substring(1)
|
val arg = str.substring(1)
|
||||||
if (arg == "*") return AnyContact
|
if (arg == "*") return AnyContact
|
||||||
@ -65,10 +71,10 @@ internal fun parseFromStringImpl(string: String): AbstractPermitteeId {
|
|||||||
if (components.size == 2) {
|
if (components.size == 2) {
|
||||||
val groupId = components[0].toLongOrNull() ?: return@run
|
val groupId = components[0].toLongOrNull() ?: return@run
|
||||||
|
|
||||||
if (components[1] == "*") return AnyTemp(groupId)
|
if (components[1] == "*") return AnyGroupTemp(groupId)
|
||||||
else {
|
else {
|
||||||
val memberId = components[1].toLongOrNull() ?: return@run
|
val memberId = components[1].toLongOrNull() ?: return@run
|
||||||
return ExactTemp(groupId, memberId)
|
return ExactGroupTemp(groupId, memberId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ import net.mamoe.mirai.console.internal.permission.parseFromStringImpl
|
|||||||
import net.mamoe.mirai.console.permission.AbstractPermitteeId.*
|
import net.mamoe.mirai.console.permission.AbstractPermitteeId.*
|
||||||
import net.mamoe.mirai.console.util.ConsoleExperimentalApi
|
import net.mamoe.mirai.console.util.ConsoleExperimentalApi
|
||||||
import net.mamoe.mirai.contact.*
|
import net.mamoe.mirai.contact.*
|
||||||
|
import net.mamoe.mirai.utils.MiraiExperimentalApi
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* [被许可人][Permittee] 的标识符
|
* [被许可人][Permittee] 的标识符
|
||||||
@ -92,11 +93,26 @@ public interface PermitteeId {
|
|||||||
get() = ExactGroup(id)
|
get() = ExactGroup(id)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建 [AbstractPermitteeId.ExactTemp]
|
* 创建 [AbstractPermitteeId.ExactGroupTemp]
|
||||||
*/
|
*/
|
||||||
@get:JvmSynthetic
|
@get:JvmSynthetic
|
||||||
public val Member.permitteeIdOnTemp: ExactTemp
|
public val Member.permitteeIdOnTemp: ExactGroupTemp
|
||||||
get() = ExactTemp(group.id, id)
|
get() = ExactGroupTemp(group.id, id)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建 [AbstractPermitteeId.ExactStranger]
|
||||||
|
*/
|
||||||
|
@get:JvmSynthetic
|
||||||
|
public val Stranger.permitteeId: ExactStranger
|
||||||
|
get() = ExactStranger(id)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建 [AbstractPermitteeId.ExactStranger]
|
||||||
|
*/
|
||||||
|
@MiraiExperimentalApi
|
||||||
|
@get:JvmSynthetic
|
||||||
|
public inline val OtherClient.permitteeId: AnyOtherClient
|
||||||
|
get() = AnyOtherClient
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,24 +127,7 @@ public interface PermitteeId {
|
|||||||
*
|
*
|
||||||
* (不区分大小写. 不区分 Bot).
|
* (不区分大小写. 不区分 Bot).
|
||||||
*
|
*
|
||||||
*
|
* [查看字符串表示列表](https://github.com/mamoe/mirai-console/docs/Permissions.md#字符串表示)
|
||||||
* | 被许可人类型 | 字符串表示示例 | 备注 |
|
|
||||||
* |:----------------:|:-----------:|:-------------------------------------|
|
|
||||||
* | 控制台 | console | |
|
|
||||||
* | 精确群 | g123456 | 表示群, 而不表示群成员 |
|
|
||||||
* | 精确好友 | f123456 | 必须通过好友消息 |
|
|
||||||
* | 精确临时会话 | t123456.789 | 群 123456 内的成员 789. 必须通过临时会话 |
|
|
||||||
* | 精确群成员 | m123456.789 | 群 123456 内的成员 789. 同时包含临时会话. |
|
|
||||||
* | 精确用户 | u123456 | 同时包含群成员, 好友, 临时会话 |
|
|
||||||
* | 任意群 | g* | |
|
|
||||||
* | 任意群的任意群员 | m* | |
|
|
||||||
* | 精确群的任意群员 | m123456.* | 群 123456 内的任意成员. 同时包含临时会话. |
|
|
||||||
* | 任意群的任意临时会话 | t* | 必须通过临时会话 |
|
|
||||||
* | 精确群的任意临时会话 | t123456.* | 群 123456 内的任意成员. 必须通过临时会话 |
|
|
||||||
* | 任意好友 | f* | |
|
|
||||||
* | 任意用户 | u* | 任何人在任何环境 |
|
|
||||||
* | 任意对象 | * | 即任何人, 任何群, 控制台 |
|
|
||||||
*
|
|
||||||
*
|
*
|
||||||
* #### 关系图
|
* #### 关系图
|
||||||
*
|
*
|
||||||
@ -273,6 +272,15 @@ public sealed class AbstractPermitteeId(
|
|||||||
override fun asString(): String = "f$id"
|
override fun asString(): String = "f$id"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated(
|
||||||
|
"use AnyGroupTemp",
|
||||||
|
ReplaceWith("AnyGroupTemp", "net.mamoe.mirai.console.permission.AbstractPermitteeId.AnyGroupTemp"),
|
||||||
|
DeprecationLevel.ERROR
|
||||||
|
)
|
||||||
|
public abstract class AnyTemp(
|
||||||
|
groupId: Long,
|
||||||
|
) : AbstractPermitteeId(AnyMember(groupId), AnyTempFromAnyGroup)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 表示任何一个通过一个群 *在临时会话发送消息的* [群成员][Member]
|
* 表示任何一个通过一个群 *在临时会话发送消息的* [群成员][Member]
|
||||||
*
|
*
|
||||||
@ -280,9 +288,9 @@ public sealed class AbstractPermitteeId(
|
|||||||
* - **间接父标识符**: [AnyMemberFromAnyGroup], [AnyUser], [AnyContact]
|
* - **间接父标识符**: [AnyMemberFromAnyGroup], [AnyUser], [AnyContact]
|
||||||
* - 字符串表示: "t$groupId.*"
|
* - 字符串表示: "t$groupId.*"
|
||||||
*/
|
*/
|
||||||
public data class AnyTemp(
|
public data class AnyGroupTemp(
|
||||||
public val groupId: Long,
|
public val groupId: Long,
|
||||||
) : AbstractPermitteeId(AnyMember(groupId), AnyTempFromAnyGroup) {
|
) : @Suppress("DEPRECATION_ERROR") AnyTemp(groupId) {
|
||||||
override fun asString(): String = "t$groupId.*"
|
override fun asString(): String = "t$groupId.*"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -297,6 +305,16 @@ public sealed class AbstractPermitteeId(
|
|||||||
override fun asString(): String = "t*"
|
override fun asString(): String = "t*"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated(
|
||||||
|
"use ExactGroupTemp",
|
||||||
|
ReplaceWith("ExactGroupTemp", "net.mamoe.mirai.console.permission.AbstractPermitteeId.ExactGroupTemp"),
|
||||||
|
DeprecationLevel.ERROR
|
||||||
|
)
|
||||||
|
public abstract class ExactTemp internal constructor(
|
||||||
|
groupId: Long,
|
||||||
|
memberId: Long,
|
||||||
|
) : AbstractPermitteeId(ExactMember(groupId, memberId))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 表示唯一的一个 *在临时会话发送消息的* [群成员][Member]
|
* 表示唯一的一个 *在临时会话发送消息的* [群成员][Member]
|
||||||
*
|
*
|
||||||
@ -304,10 +322,10 @@ public sealed class AbstractPermitteeId(
|
|||||||
* - **间接父标识符**: [AnyUser], [AnyMember], [ExactUser], [AnyContact], [AnyMemberFromAnyGroup]
|
* - **间接父标识符**: [AnyUser], [AnyMember], [ExactUser], [AnyContact], [AnyMemberFromAnyGroup]
|
||||||
* - 字符串表示: "t$groupId.$memberId"
|
* - 字符串表示: "t$groupId.$memberId"
|
||||||
*/
|
*/
|
||||||
public data class ExactTemp(
|
public data class ExactGroupTemp(
|
||||||
public val groupId: Long,
|
public val groupId: Long,
|
||||||
public val memberId: Long,
|
public val memberId: Long,
|
||||||
) : AbstractPermitteeId(ExactMember(groupId, memberId)) {
|
) : @Suppress("DEPRECATION_ERROR") ExactTemp(groupId, memberId) {
|
||||||
override fun asString(): String = "t$groupId.$memberId"
|
override fun asString(): String = "t$groupId.$memberId"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -324,19 +342,6 @@ public sealed class AbstractPermitteeId(
|
|||||||
override fun asString(): String = "s$id"
|
override fun asString(): String = "s$id"
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 表示唯一的一个 [其他客户端][OtherClient]
|
|
||||||
*
|
|
||||||
* - **直接父标识符**: [AnyOtherClient]
|
|
||||||
* - **间接父标识符**: [AnyContact]
|
|
||||||
* - 字符串表示: "o$id"
|
|
||||||
*/
|
|
||||||
public data class ExactOtherClient(
|
|
||||||
public val id: Long,
|
|
||||||
) : AbstractPermitteeId(AnyOtherClient) {
|
|
||||||
override fun asString(): String = "o$id"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 表示任何 [用户][User]
|
* 表示任何 [用户][User]
|
||||||
@ -360,17 +365,6 @@ public sealed class AbstractPermitteeId(
|
|||||||
override fun asString(): String = "s*"
|
override fun asString(): String = "s*"
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 表示任何 [其他客户端][OtherClient]
|
|
||||||
*
|
|
||||||
* - **直接父标识符**: [AnyContact]
|
|
||||||
* - **间接父标识符**: 无
|
|
||||||
* - 字符串表示: "o*"
|
|
||||||
*/
|
|
||||||
public object AnyOtherClient : AbstractPermitteeId(AnyContact) {
|
|
||||||
override fun asString(): String = "o*"
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 表示精确 [用户][User]
|
* 表示精确 [用户][User]
|
||||||
*
|
*
|
||||||
@ -405,4 +399,15 @@ public sealed class AbstractPermitteeId(
|
|||||||
public object Console : AbstractPermitteeId() {
|
public object Console : AbstractPermitteeId() {
|
||||||
override fun asString(): String = "console"
|
override fun asString(): String = "console"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 表示任何其他客户端
|
||||||
|
*
|
||||||
|
* - **直接父标识符**: [AnyContact]
|
||||||
|
* - **间接父标识符**: 无
|
||||||
|
* - 字符串表示: "client*"
|
||||||
|
*/
|
||||||
|
public object AnyOtherClient : AbstractPermitteeId(AnyContact) {
|
||||||
|
override fun asString(): String = "client*"
|
||||||
|
}
|
||||||
}
|
}
|
@ -114,26 +114,28 @@ interface PermitteeId {
|
|||||||
(不区分大小写. 不区分 Bot).
|
(不区分大小写. 不区分 Bot).
|
||||||
|
|
||||||
| 被许可人类型 | 字符串表示示例 | 备注 |
|
| 被许可人类型 | 字符串表示示例 | 备注 |
|
||||||
|:----------------:|:-----------:|:-------------------------------------|
|
|:----------------:|:-----------:|:------------------------------------|
|
||||||
| 控制台 | console | |
|
| 控制台 | console | |
|
||||||
|
| 任意其他客户端 | client* | 即 Bot 自己发消息给自己 |
|
||||||
| 精确群 | g123456 | 表示群, 而不表示群成员 |
|
| 精确群 | g123456 | 表示群, 而不表示群成员 |
|
||||||
| 精确好友 | f123456 | 必须通过好友消息 |
|
| 精确好友 | f123456 | 必须通过好友消息 |
|
||||||
| 精确临时会话 | t123456.789 | 群 123456 内的成员 789. 必须通过临时会话 |
|
| 精确群临时会话 | t123456.789 | 群 123456 内的成员 789. 必须通过临时会话 |
|
||||||
| 精确群成员 | m123456.789 | 群 123456 内的成员 789. 同时包含临时会话. |
|
| 精确群成员 | m123456.789 | 群 123456 内的成员 789. 同时包含临时会话 |
|
||||||
| 精确用户 | u123456 | 同时包含群成员, 好友, 临时会话 |
|
| 精确用户 | u123456 | 同时包含群成员, 好友, 临时会话 |
|
||||||
| 任意群 | g\* | g 意为 group |
|
| 任意群 | g\* | g 意为 group |
|
||||||
| 任意群的任意群员 | m\* | m 意为 member |
|
| 任意群的任意群员 | m\* | m 意为 member |
|
||||||
| 精确群的任意群员 | m123456.\* | 群 123456 内的任意成员. 同时包含临时会话. |
|
| 精确群的任意群员 | m123456.\* | 群 123456 内的任意成员. 同时包含临时会话 |
|
||||||
| 任意群的任意临时会话 | t\* | t 意为 temp. 必须通过临时会话 |
|
| 任意临时会话 | t\* | t 意为 temp. 必须通过临时会话 |
|
||||||
| 精确群的任意临时会话 | t123456.\* | 群 123456 内的任意成员. 必须通过临时会话 |
|
| 精确群的任意临时会话 | t123456.\* | 群 123456 内的任意成员. 必须通过临时会话 |
|
||||||
| 任意好友 | f\* | f 意为 friend |
|
| 任意好友 | f\* | f 意为 friend |
|
||||||
| 任意用户 | u\* | u 意为 user. 任何人在任何环境 |
|
| 任意用户 | u\* | u 意为 user. 任何人在任何环境 |
|
||||||
| 任意对象 | \* | 即任何人, 任何群, 控制台 |
|
| 任意陌生人 | s\* | s 意为 stranger. 任何人在任何环境 |
|
||||||
|
| 任意联系对象 | \* | 即任何人, 任何群. 不包括控制台 |
|
||||||
|
|
||||||
### 获取被许可人
|
### 获取被许可人
|
||||||
|
|
||||||
通常使用 `CommandSender.permitteeId`。
|
在 Kotlin 通常使用 `CommandSender.permitteeId`,在 Java 使用 `CommandSender.getPermitteeId( )`。
|
||||||
也可以直接构造 [`AbstractPermitteeId`] 的子类。或者在 Kotlin 使用扩展 `User.permitteeId`
|
也可以直接构造 [`AbstractPermitteeId`] 的子类。或者在 Kotlin 使用扩展 `User.permitteeId`。
|
||||||
|
|
||||||
## 权限服务
|
## 权限服务
|
||||||
|
|
||||||
|
@ -171,8 +171,8 @@ internal fun CommandReceiverParameter<*>.renderAsName(): String {
|
|||||||
classifier.isSubclassOf(FriendCommandSender::class) -> "好友"
|
classifier.isSubclassOf(FriendCommandSender::class) -> "好友"
|
||||||
classifier.isSubclassOf(MemberCommandSenderOnMessage::class) -> "群内发言"
|
classifier.isSubclassOf(MemberCommandSenderOnMessage::class) -> "群内发言"
|
||||||
classifier.isSubclassOf(MemberCommandSender::class) -> "群成员"
|
classifier.isSubclassOf(MemberCommandSender::class) -> "群成员"
|
||||||
classifier.isSubclassOf(TempCommandSenderOnMessage::class) -> "临时会话"
|
classifier.isSubclassOf(GroupTempCommandSenderOnMessage::class) -> "群临时会话"
|
||||||
classifier.isSubclassOf(TempCommandSender::class) -> "临时好友"
|
classifier.isSubclassOf(GroupTempCommandSender::class) -> "群临时好友"
|
||||||
classifier.isSubclassOf(UserCommandSender::class) -> "用户"
|
classifier.isSubclassOf(UserCommandSender::class) -> "用户"
|
||||||
else -> classifier.simpleName ?: classifier.toString()
|
else -> classifier.simpleName ?: classifier.toString()
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,6 @@
|
|||||||
package net.mamoe.mirai.console.gradle
|
package net.mamoe.mirai.console.gradle
|
||||||
|
|
||||||
internal object VersionConstants {
|
internal object VersionConstants {
|
||||||
const val CONSOLE_VERSION = "2.0-RC-dev-1" // value is written here automatically during build
|
const val CONSOLE_VERSION = "2.0-RC-dev-2" // value is written here automatically during build
|
||||||
const val CORE_VERSION = "2.0-RC-dev-8" // value is written here automatically during build
|
const val CORE_VERSION = "2.0-RC-dev-9" // value is written here automatically during build
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user