Commit cc2343e2 authored by Him188's avatar Him188

Simplify logical process

parent c15651b9
...@@ -36,27 +36,27 @@ class OverFileSizeMaxException : IllegalStateException() ...@@ -36,27 +36,27 @@ class OverFileSizeMaxException : IllegalStateException()
*/ */
suspend fun Group.uploadImage(image: ExternalImage): ImageId = withSession { suspend fun Group.uploadImage(image: ExternalImage): ImageId = withSession {
val userContext = coroutineContext val userContext = coroutineContext
GroupImageIdRequestPacket(bot.qqAccount, internalId, image, sessionKey) val response = GroupImageIdRequestPacket(bot.qqAccount, internalId, image, sessionKey).sendAndExpect<GroupImageIdRequestPacket.Response>()
.sendAndExpectAsync<GroupImageIdRequestPacket.Response, Unit> {
withContext(userContext) { withContext(userContext) {
when (it) { when (response) {
is GroupImageIdRequestPacket.Response.RequireUpload -> httpClient.postImage( is GroupImageIdRequestPacket.Response.RequireUpload -> httpClient.postImage(
htcmd = "0x6ff0071", htcmd = "0x6ff0071",
uin = bot.qqAccount, uin = bot.qqAccount,
groupId = GroupId(id), groupId = GroupId(id),
imageInput = image.input, imageInput = image.input,
inputSize = image.inputSize, inputSize = image.inputSize,
uKeyHex = it.uKey.toUHexString("") uKeyHex = response.uKey.toUHexString("")
) )
is GroupImageIdRequestPacket.Response.AlreadyExists -> {
}
is GroupImageIdRequestPacket.Response.AlreadyExists -> { is GroupImageIdRequestPacket.Response.OverFileSizeMax -> throw OverFileSizeMaxException()
} }
}
is GroupImageIdRequestPacket.Response.OverFileSizeMax -> throw OverFileSizeMaxException() return image.groupImageId
}
}
}.join()
image.groupImageId
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment