mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-03 15:10:14 +08:00
Low level api for mute AnonymousMember
This commit is contained in:
parent
0bb34ee05b
commit
1083e5d625
@ -10,6 +10,7 @@
|
||||
package net.mamoe.mirai
|
||||
|
||||
import kotlinx.coroutines.Job
|
||||
import net.mamoe.mirai.contact.AnonymousMember
|
||||
import net.mamoe.mirai.contact.Friend
|
||||
import net.mamoe.mirai.contact.Group
|
||||
import net.mamoe.mirai.data.*
|
||||
@ -201,4 +202,18 @@ public interface LowLevelApiAccessor {
|
||||
md5: ByteArray,
|
||||
groupId: Long,
|
||||
)
|
||||
|
||||
/**
|
||||
* 禁言一个匿名用户
|
||||
*
|
||||
* @param anonymousId [AnonymousMember.anonymousId]
|
||||
*/
|
||||
@LowLevelApi
|
||||
public suspend fun _lowLevelMuteAnonymous(
|
||||
bot: Bot,
|
||||
anonymousId: String,
|
||||
anonymousNick: String,
|
||||
groupId: Long,
|
||||
seconds: Int,
|
||||
)
|
||||
}
|
||||
|
@ -13,9 +13,7 @@ import io.ktor.client.request.*
|
||||
import io.ktor.client.request.forms.*
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.withContext
|
||||
import kotlinx.serialization.json.int
|
||||
import kotlinx.serialization.json.jsonObject
|
||||
import kotlinx.serialization.json.jsonPrimitive
|
||||
import kotlinx.serialization.json.*
|
||||
import net.mamoe.mirai.*
|
||||
import net.mamoe.mirai.contact.*
|
||||
import net.mamoe.mirai.data.*
|
||||
@ -758,6 +756,36 @@ internal open class MiraiImpl : IMirai, LowLevelApiAccessor {
|
||||
|
||||
}
|
||||
|
||||
override suspend fun _lowLevelMuteAnonymous(
|
||||
bot: Bot,
|
||||
anonymousId: String,
|
||||
anonymousNick: String,
|
||||
groupId: Long,
|
||||
seconds: Int
|
||||
) {
|
||||
bot as QQAndroidBot
|
||||
val response = MiraiPlatformUtils.Http.post<String> {
|
||||
url("https://qqweb.qq.com/c/anonymoustalk/blacklist")
|
||||
body = MultiPartFormDataContent(formData {
|
||||
append("anony_id", anonymousId)
|
||||
append("group_code", groupId)
|
||||
append("seconds", seconds)
|
||||
append("anony_nick", anonymousNick)
|
||||
append("bkn", bot.bkn)
|
||||
})
|
||||
headers {
|
||||
append(
|
||||
"cookie",
|
||||
"uin=o${bot.id}; skey=${bot.client.wLoginSigInfo.sKey.data.encodeToString()};"
|
||||
)
|
||||
}
|
||||
}
|
||||
val jsonObj = Json.decodeFromString(JsonObject.serializer(), response)
|
||||
if ((jsonObj["retcode"] ?: jsonObj["cgicode"] ?: error("missing response code")).jsonPrimitive.long != 0L) {
|
||||
throw IllegalStateException(response)
|
||||
}
|
||||
}
|
||||
|
||||
override fun createImage(imageId: String): Image {
|
||||
return when {
|
||||
imageId matches FRIEND_IMAGE_ID_REGEX_1 -> OfflineFriendImage(imageId)
|
||||
|
Loading…
Reference in New Issue
Block a user