Commit cfd5b2e8 authored by Him188's avatar Him188

Image uploading is now available

parent d6201a14
......@@ -10,7 +10,7 @@ import java.security.MessageDigest
import javax.imageio.ImageIO
import java.awt.image.BufferedImage as JavaBufferedImage
fun JavaBufferedImage.toMiraiImage(formatName: String = "png"): BufferedImage {
fun JavaBufferedImage.toMiraiImage(formatName: String = "gif"): BufferedImage {
val digest = MessageDigest.getInstance("md5")
digest.reset()
......
......@@ -72,7 +72,7 @@ private suspend fun Connection.postImage(image: ByteReadPacket): Boolean = this
.requestBody(String(image.readBytes(), Charsets.ISO_8859_1))
.method(Connection.Method.POST)
.postDataCharset("ISO_8859_1")
.header("Content-type", "image/png")
.header("Content-type", "image/gif")
.ignoreContentType(true)
.suspendExecute()
.statusCode() == 200
......
......@@ -11,7 +11,7 @@ import javax.imageio.ImageIO
val sessionKey: ByteArray = "F1 ED F2 BC 55 17 7B FE CC CC F3 08 D1 8D A7 0E".hexToBytes()
fun main() = println({
val image = ImageIO.read(File("C:\\Users\\Him18\\Desktop\\test2.png").readBytes().inputStream()).toMiraiImage("png")
val image = ImageIO.read(File("C:\\Users\\Him18\\Desktop\\test2.gif").readBytes().inputStream()).toMiraiImage("png")
// File("C:\\Users\\Him18\\Desktop\\test2.jpg").writeBytes(image.fileData.readBytes())
GroupImageIdRequestPacket(
......
......@@ -87,14 +87,14 @@ suspend fun main() {
"上传好友图片" in it.message -> withTimeoutOrNull(5000) {
val id = QQ(bot, 1040400290u)
.uploadImage(withContext(Dispatchers.IO) { ImageIO.read(File("C:\\Users\\Him18\\Desktop\\${it.message.toString().substringAfter("上传好友图片")}").readBytes().inputStream()) }.toMiraiImage("png"))
.uploadImage(withContext(Dispatchers.IO) { ImageIO.read(File("C:\\Users\\Him18\\Desktop\\${it.message.toString().substringAfter("上传好友图片")}").inputStream()) }.toMiraiImage("gif"))
it.reply(id.value)
delay(1000)
it.reply(Image(id))
}
"上传群图片" in it.message -> withTimeoutOrNull(5000) {
val image = withContext(Dispatchers.IO) { ImageIO.read(File("C:\\Users\\Him18\\Desktop\\${it.message.toString().substringAfter("上传群图片")}").readBytes().inputStream()) }.toMiraiImage("png")
val image = withContext(Dispatchers.IO) { ImageIO.read(File("C:\\Users\\Him18\\Desktop\\${it.message.toString().substringAfter("上传群图片")}").inputStream()) }.toMiraiImage("gif")
Group(bot, 580266363u).uploadImage(image)
it.reply(image.groupImageId.value)
delay(1000)
......
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