diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/ContactImpl.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/ContactImpl.kt index a933dcfdf..5cad965a2 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/ContactImpl.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/ContactImpl.kt @@ -227,9 +227,9 @@ internal class MemberImpl( override val bot: QQAndroidBot get() = qq.bot - override suspend fun mute(durationSeconds: Int): Boolean { + override suspend fun mute(durationSeconds: Int) { if (group.botPermission != MemberPermission.OWNER && (!group.botPermission.isOperator() || this.isOperator())) { - return false + throw PermissionDeniedException() } bot.network.run { @@ -243,12 +243,11 @@ internal class MemberImpl( @Suppress("RemoveRedundantQualifierName") // or unresolved reference net.mamoe.mirai.event.events.MemberMuteEvent(this@MemberImpl, durationSeconds, null).broadcast() - return true } - override suspend fun unmute(): Boolean { + override suspend fun unmute() { if (group.botPermission != MemberPermission.OWNER && (!group.botPermission.isOperator() || this.isOperator())) { - return false + throw PermissionDeniedException() } bot.network.run { @@ -262,16 +261,15 @@ internal class MemberImpl( @Suppress("RemoveRedundantQualifierName") // or unresolved reference net.mamoe.mirai.event.events.MemberUnmuteEvent(this@MemberImpl, null).broadcast() - return true } - override suspend fun kick(message: String): Boolean { + override suspend fun kick(message: String) { if (group.botPermission != MemberPermission.OWNER && (!group.botPermission.isOperator() || this.isOperator())) { - return false + throw PermissionDeniedException() } bot.network.run { - return TroopManagement.Kick( + TroopManagement.Kick( client = bot.client, member = this@MemberImpl, message = message diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Group.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Group.kt index c705ef844..8813ecdd7 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Group.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Group.kt @@ -16,6 +16,7 @@ import net.mamoe.mirai.data.MemberInfo import net.mamoe.mirai.event.events.* import net.mamoe.mirai.utils.MiraiExperimentalAPI import kotlin.jvm.JvmName +import kotlin.jvm.JvmStatic /** * 群. 在 QQ Android 中叫做 "Troop" @@ -145,6 +146,7 @@ interface Group : Contact, CoroutineScope { /** * by @kar98k */ + @JvmStatic fun calculateGroupUinByGroupCode(groupCode: Long): Long { var left: Long = groupCode / 1000000L @@ -161,6 +163,7 @@ interface Group : Contact, CoroutineScope { return left * 1000000L + groupCode % 1000000L } + @JvmStatic fun calculateGroupCodeByGroupUin(groupUin: Long): Long { var left: Long = groupUin / 1000000L diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Member.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Member.kt index 2e8f9b859..66e8f2ca3 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Member.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Member.kt @@ -35,20 +35,22 @@ interface Member : QQ, Contact { /** * 群名片. 可能为空. 修改时将会触发事件 * - * 在修改时将会异步上传至服务器. 无权限修改时将会抛出异常 [PermissionDeniedException] + * 在修改时将会异步上传至服务器. * * @see [groupCardOrNick] 获取非空群名片或昵称 * * @see MemberCardChangeEvent 群名片被管理员, 自己或 [Bot] 改动事件 + * @throws PermissionDeniedException 无权限修改时 */ var nameCard: String /** * 群头衔 * - * 在修改时将会异步上传至服务器. 无权限修改时将会抛出异常 [PermissionDeniedException] + * 在修改时将会异步上传至服务器. * * @see MemberSpecialTitleChangeEvent 群名片被管理员, 自己或 [Bot] 改动事件 + * @throws PermissionDeniedException 无权限修改时 */ var specialTitle: String @@ -63,22 +65,25 @@ interface Member : QQ, Contact { * @see Int.daysToSeconds * * @see MemberMuteEvent 成员被禁言事件 + * @throws PermissionDeniedException 无权限修改时 */ - suspend fun mute(durationSeconds: Int): Boolean + suspend fun mute(durationSeconds: Int) /** - * 解除禁言. 机器人无权限时返回 `false`. + * 解除禁言. * * @see MemberUnmuteEvent 成员被取消禁言事件. + * @throws PermissionDeniedException 无权限修改时 */ - suspend fun unmute(): Boolean + suspend fun unmute() /** - * 踢出该成员. 机器人无权限时返回 `false`. + * 踢出该成员. * * @see MemberLeaveEvent.Kick 成员被踢出事件. + * @throws PermissionDeniedException 无权限修改时 */ - suspend fun kick(message: String = ""): Boolean + suspend fun kick(message: String = "") /** * 当且仅当 `[other] is [Member] && [other].id == this.id && [other].group == this.group` 时为 true @@ -94,10 +99,10 @@ interface Member : QQ, Contact { val Member.groupCardOrNick: String get() = this.nameCard.takeIf { it.isNotEmpty() } ?: this.nick @ExperimentalTime -suspend inline fun Member.mute(duration: Duration): Boolean { +suspend inline fun Member.mute(duration: Duration) { require(duration.inDays <= 30) { "duration must be at most 1 month" } require(duration.inSeconds > 0) { "duration must be greater than 0 second" } - return this.mute(duration.inSeconds.toInt()) + this.mute(duration.inSeconds.toInt()) } suspend inline fun Member.mute(durationSeconds: Long) = this.mute(durationSeconds.toInt()) \ No newline at end of file