Mute Permission

This commit is contained in:
jiahua.liu 2020-02-04 11:32:13 +08:00
parent 1a206612e5
commit a68ad3adac

View File

@ -68,7 +68,6 @@ internal class MemberImpl(
override val coroutineContext: CoroutineContext, override val coroutineContext: CoroutineContext,
override val permission: MemberPermission override val permission: MemberPermission
) : ContactImpl(), Member, QQ by qq { ) : ContactImpl(), Member, QQ by qq {
override val bot: QQAndroidBot get() = qq.bot
override val group: GroupImpl by group.unsafeWeakRef() override val group: GroupImpl by group.unsafeWeakRef()
val qq: QQImpl by qq.unsafeWeakRef() val qq: QQImpl by qq.unsafeWeakRef()
@ -76,26 +75,30 @@ internal class MemberImpl(
override suspend fun mute(durationSeconds: Int): Boolean { override suspend fun mute(durationSeconds: Int): Boolean {
if(bot.uin==this@MemberImpl.qq.id)//不能自己禁言自己 if (bot.uin == this.qq.id) {
{
return false return false
} }
//判断有无禁言权限 //判断有无禁言权限
var myPermission = group.get(bot.uin).permission val myPermission = group[bot.uin].permission
if (myPermission == MemberPermission.ADMINISTRATOR || myPermission == MemberPermission.OWNER) { val targetPermission = this.permission
if (myPermission == MemberPermission.OWNER || (myPermission == MemberPermission.ADMINISTRATOR && permission == MemberPermission.MEMBER)) { if (myPermission != MemberPermission.OWNER) {
bot.network.run { if (targetPermission == MemberPermission.OWNER || targetPermission == MemberPermission.ADMINISTRATOR) {
val response = TroopManagement.Mute(
client = bot.client,
member = this@MemberImpl,
timeInSecond = durationSeconds
).sendAndExpect<TroopManagement.Mute.Response>()
}
return true
}else{
return false return false
} }
} else { } else if (myPermission == MemberPermission.MEMBER) {
return false
}
try {
bot.network.run {
val response = TroopManagement.Mute(
client = bot.client,
groupCode = group.id,
memberUin = this@MemberImpl.id,
timeInSecond = durationSeconds
).sendAndExpect<TroopManagement.Mute.Response>()
}
return true
} catch (e: Exception) {
return false return false
} }
} }