mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-08 17:20:11 +08:00
Rename BufferedImage as ExternalImage
This commit is contained in:
parent
0334d33d7e
commit
3ab540d5f2
@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
package net.mamoe.mirai.network.protocol.tim.packet
|
package net.mamoe.mirai.network.protocol.tim.packet
|
||||||
|
|
||||||
import kotlinx.coroutines.GlobalScope
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import kotlinx.io.core.*
|
import kotlinx.io.core.*
|
||||||
import net.mamoe.mirai.contact.QQ
|
import net.mamoe.mirai.contact.QQ
|
||||||
import net.mamoe.mirai.message.ImageId
|
import net.mamoe.mirai.message.ImageId
|
||||||
@ -17,7 +15,7 @@ import net.mamoe.mirai.utils.io.*
|
|||||||
/**
|
/**
|
||||||
* 上传图片
|
* 上传图片
|
||||||
*/
|
*/
|
||||||
suspend fun QQ.uploadImage(image: BufferedImage): ImageId = with(bot.network.session) {
|
suspend fun QQ.uploadImage(image: ExternalImage): ImageId = with(bot.network.session) {
|
||||||
//SubmitImageFilenamePacket(account, account, "sdiovaoidsa.png", sessionKey).sendAndExpect<ServerSubmitImageFilenameResponsePacket>().join()
|
//SubmitImageFilenamePacket(account, account, "sdiovaoidsa.png", sessionKey).sendAndExpect<ServerSubmitImageFilenameResponsePacket>().join()
|
||||||
DebugLogger.logPurple("正在上传好友图片, md5=${image.md5.toUHexString()}")
|
DebugLogger.logPurple("正在上传好友图片, md5=${image.md5.toUHexString()}")
|
||||||
return FriendImageIdRequestPacket(this.qqAccount, sessionKey, this.qqAccount, image).sendAndExpect<FriendImageIdRequestPacket.Response, ImageId> {
|
return FriendImageIdRequestPacket(this.qqAccount, sessionKey, this.qqAccount, image).sendAndExpect<FriendImageIdRequestPacket.Response, ImageId> {
|
||||||
@ -103,10 +101,10 @@ class SubmitImageFilenamePacket(
|
|||||||
@PacketId(0x03_52u)
|
@PacketId(0x03_52u)
|
||||||
@PacketVersion(date = "2019.10.20", timVersion = "2.3.2.21173")
|
@PacketVersion(date = "2019.10.20", timVersion = "2.3.2.21173")
|
||||||
class FriendImageIdRequestPacket(
|
class FriendImageIdRequestPacket(
|
||||||
private val botNumber: UInt,
|
private val botNumber: UInt,
|
||||||
private val sessionKey: ByteArray,
|
private val sessionKey: ByteArray,
|
||||||
private val target: UInt,
|
private val target: UInt,
|
||||||
private val image: BufferedImage
|
private val image: ExternalImage
|
||||||
) : OutgoingPacket() {
|
) : OutgoingPacket() {
|
||||||
|
|
||||||
//00 00 00 07 00 00 00 4B 08 01 12 03 98 01 01 08 01 12 47 08 A2 FF 8C F0 03 10 89 FC A6 8C 0B 18 00 22 10 2B 23 D7 05 CA D1 F2 CF 37 10 FE 58 26 92 FC C4 28 FD 08 32 1A 7B 00 47 00 47 00 42 00 7E 00 49 00 31 00 5A 00 4D 00 43 00 28 00 25 00 49 00 38 01 48 00 70 42 78 42
|
//00 00 00 07 00 00 00 4B 08 01 12 03 98 01 01 08 01 12 47 08 A2 FF 8C F0 03 10 89 FC A6 8C 0B 18 00 22 10 2B 23 D7 05 CA D1 F2 CF 37 10 FE 58 26 92 FC C4 28 FD 08 32 1A 7B 00 47 00 47 00 42 00 7E 00 49 00 31 00 5A 00 4D 00 43 00 28 00 25 00 49 00 38 01 48 00 70 42 78 42
|
||||||
@ -221,7 +219,6 @@ class FriendImageIdRequestPacket(
|
|||||||
writeUVarInt(image.inputSize.toUInt())
|
writeUVarInt(image.inputSize.toUInt())
|
||||||
|
|
||||||
|
|
||||||
GlobalScope.launch { }
|
|
||||||
writeUByte(0x32u)
|
writeUByte(0x32u)
|
||||||
//长度应为1A
|
//长度应为1A
|
||||||
writeUVarintLVPacket {
|
writeUVarintLVPacket {
|
||||||
|
@ -12,20 +12,20 @@ import net.mamoe.mirai.utils.io.toUHexString
|
|||||||
|
|
||||||
|
|
||||||
suspend fun Group.uploadImage(
|
suspend fun Group.uploadImage(
|
||||||
image: BufferedImage
|
image: ExternalImage
|
||||||
) = with(bot.network.session) {
|
) = with(bot.network.session) {
|
||||||
GroupImageIdRequestPacket(bot.qqAccount, groupId, image, sessionKey)
|
GroupImageIdRequestPacket(bot.qqAccount, internalId, image, sessionKey)
|
||||||
.sendAndExpect<GroupImageIdRequestPacket.Response, Unit> {
|
.sendAndExpect<GroupImageIdRequestPacket.Response, Unit> {
|
||||||
if (it.uKey != null) {
|
if (it.uKey != null) {
|
||||||
httpPostGroupImage(
|
httpPostGroupImage(
|
||||||
botAccount = bot.qqAccount,
|
botAccount = bot.qqAccount,
|
||||||
groupNumber = groupId,
|
groupNumber = internalId,
|
||||||
imageInput = image.input,
|
imageInput = image.input,
|
||||||
inputSize = image.inputSize,
|
inputSize = image.inputSize,
|
||||||
uKeyHex = it.uKey!!.toUHexString("")
|
uKeyHex = it.uKey!!.toUHexString("")
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}.await()
|
}.await()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -34,10 +34,10 @@ suspend fun Group.uploadImage(
|
|||||||
@PacketId(0x0388u)
|
@PacketId(0x0388u)
|
||||||
@PacketVersion(date = "2019.10.20", timVersion = "2.3.2.21173")
|
@PacketVersion(date = "2019.10.20", timVersion = "2.3.2.21173")
|
||||||
class GroupImageIdRequestPacket(
|
class GroupImageIdRequestPacket(
|
||||||
private val bot: UInt,
|
private val bot: UInt,
|
||||||
private val groupId: UInt,
|
private val groupId: UInt,
|
||||||
private val image: BufferedImage,
|
private val image: ExternalImage,
|
||||||
private val sessionKey: ByteArray
|
private val sessionKey: ByteArray
|
||||||
) : OutgoingPacket() {
|
) : OutgoingPacket() {
|
||||||
|
|
||||||
override fun encode(builder: BytePacketBuilder) = with(builder) {
|
override fun encode(builder: BytePacketBuilder) = with(builder) {
|
||||||
|
@ -6,15 +6,15 @@ import kotlinx.io.core.ByteReadPacket
|
|||||||
import kotlinx.io.core.Input
|
import kotlinx.io.core.Input
|
||||||
import net.mamoe.mirai.message.ImageId
|
import net.mamoe.mirai.message.ImageId
|
||||||
|
|
||||||
fun BufferedImage(
|
fun ExternalImage(
|
||||||
width: Int,
|
width: Int,
|
||||||
height: Int,
|
height: Int,
|
||||||
md5: ByteArray,
|
md5: ByteArray,
|
||||||
format: String,
|
format: String,
|
||||||
data: ByteReadPacket
|
data: ByteReadPacket
|
||||||
) = BufferedImage(width, height, md5, format, data, data.remaining)
|
) = ExternalImage(width, height, md5, format, data, data.remaining)
|
||||||
|
|
||||||
class BufferedImage(
|
class ExternalImage(
|
||||||
val width: Int,
|
val width: Int,
|
||||||
val height: Int,
|
val height: Int,
|
||||||
val md5: ByteArray,
|
val md5: ByteArray,
|
||||||
@ -28,7 +28,7 @@ class BufferedImage(
|
|||||||
*/
|
*/
|
||||||
val groupImageId: ImageId by lazy { ImageId("{${md5[0..3]}-${md5[4..5]}-${md5[6..7]}-${md5[8..9]}-${md5[10..15]}}.$format") }
|
val groupImageId: ImageId by lazy { ImageId("{${md5[0..3]}-${md5[4..5]}-${md5[6..7]}-${md5[8..9]}-${md5[10..15]}}.$format") }
|
||||||
|
|
||||||
override fun toString(): String = "[BufferedImage(${width}x${height} $format)]"
|
override fun toString(): String = "[ExternalImage(${width}x${height} $format)]"
|
||||||
}
|
}
|
||||||
|
|
||||||
private operator fun ByteArray.get(range: IntRange): String = buildString {
|
private operator fun ByteArray.get(range: IntRange): String = buildString {
|
@ -13,7 +13,7 @@ import java.security.MessageDigest
|
|||||||
import javax.imageio.ImageIO
|
import javax.imageio.ImageIO
|
||||||
import java.awt.image.BufferedImage as JavaBufferedImage
|
import java.awt.image.BufferedImage as JavaBufferedImage
|
||||||
|
|
||||||
fun JavaBufferedImage.toMiraiImage(formatName: String = "gif"): BufferedImage {
|
fun JavaBufferedImage.toMiraiImage(formatName: String = "gif"): ExternalImage {
|
||||||
val digest = MessageDigest.getInstance("md5")
|
val digest = MessageDigest.getInstance("md5")
|
||||||
digest.reset()
|
digest.reset()
|
||||||
|
|
||||||
@ -28,10 +28,10 @@ fun JavaBufferedImage.toMiraiImage(formatName: String = "gif"): BufferedImage {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return BufferedImage(width, height, digest.digest(), formatName, buffer)
|
return ExternalImage(width, height, digest.digest(), formatName, buffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun BufferedImage.toJavaImage(): JavaBufferedImage = ImageIO.read(object : InputStream() {
|
fun ExternalImage.toJavaImage(): JavaBufferedImage = ImageIO.read(object : InputStream() {
|
||||||
override fun read(): Int = with(this@toJavaImage.input) {
|
override fun read(): Int = with(this@toJavaImage.input) {
|
||||||
if (!endOfInput)
|
if (!endOfInput)
|
||||||
readByte().toInt()
|
readByte().toInt()
|
||||||
@ -39,7 +39,7 @@ fun BufferedImage.toJavaImage(): JavaBufferedImage = ImageIO.read(object : Input
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
fun File.toMiraiImage(): BufferedImage {
|
fun File.toMiraiImage(): ExternalImage {
|
||||||
val image = ImageIO.getImageReaders(this.inputStream()).asSequence().first()
|
val image = ImageIO.getImageReaders(this.inputStream()).asSequence().first()
|
||||||
|
|
||||||
val digest = MessageDigest.getInstance("md5")
|
val digest = MessageDigest.getInstance("md5")
|
||||||
@ -53,7 +53,7 @@ fun File.toMiraiImage(): BufferedImage {
|
|||||||
})
|
})
|
||||||
|
|
||||||
val dimension = image.defaultReadParam.sourceRenderSize
|
val dimension = image.defaultReadParam.sourceRenderSize
|
||||||
return BufferedImage(
|
return ExternalImage(
|
||||||
width = dimension.width,
|
width = dimension.width,
|
||||||
height = dimension.height,
|
height = dimension.height,
|
||||||
md5 = digest.digest(),
|
md5 = digest.digest(),
|
||||||
|
Loading…
Reference in New Issue
Block a user