Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
0494b374
Commit
0494b374
authored
Oct 20, 2019
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Image sending is now available
parent
bc57001e
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
78 additions
and
46 deletions
+78
-46
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/Message.kt
.../src/commonMain/kotlin/net.mamoe.mirai/message/Message.kt
+1
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/internal/MessageDataInternal.kt
...n/net.mamoe.mirai/message/internal/MessageDataInternal.kt
+7
-5
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/TIMBotNetworkHandler.kt
....mamoe.mirai/network/protocol/tim/TIMBotNetworkHandler.kt
+0
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/UploadFriendImage.kt
...oe.mirai/network/protocol/tim/packet/UploadFriendImage.kt
+12
-11
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/UploadGroupImage.kt
...moe.mirai/network/protocol/tim/packet/UploadGroupImage.kt
+3
-3
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/BufferedImage.kt
.../commonMain/kotlin/net.mamoe.mirai/utils/BufferedImage.kt
+6
-10
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/BufferedImageJvm.kt
.../jvmMain/kotlin/net/mamoe/mirai/utils/BufferedImageJvm.kt
+42
-0
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/PlatformUtilsJvm.kt
.../jvmMain/kotlin/net/mamoe/mirai/utils/PlatformUtilsJvm.kt
+1
-9
mirai-core/src/jvmTest/kotlin/TestGroupImage.kt
mirai-core/src/jvmTest/kotlin/TestGroupImage.kt
+2
-2
mirai-demos/mirai-demo-1/src/main/java/demo1/Main.kt
mirai-demos/mirai-demo-1/src/main/java/demo1/Main.kt
+4
-4
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/Message.kt
View file @
0494b374
...
@@ -90,7 +90,7 @@ data class PlainText(override val stringValue: String) : Message() {
...
@@ -90,7 +90,7 @@ data class PlainText(override val stringValue: String) : Message() {
* 图片消息. 在发送时将会区分群图片和好友图片发送.
* 图片消息. 在发送时将会区分群图片和好友图片发送.
* 由接收消息时构建, 可直接发送
* 由接收消息时构建, 可直接发送
*
*
* @param id
类似 `/01ee6426-5ff1-4cf0-8278-e8634d2909ef` 或
`{F61593B5-5B98-1798-3F47-2A91D32ED2FC}.jpg`
* @param id
好友的为 `/01ee6426-5ff1-4cf0-8278-e8634d2909ef`, 群的为
`{F61593B5-5B98-1798-3F47-2A91D32ED2FC}.jpg`
* @param filename 文件名. 这将决定图片的显示
* @param filename 文件名. 这将决定图片的显示
*/
*/
data class
Image
(
val
id
:
ImageId
,
val
filename
:
String
=
""
)
:
Message
()
{
data class
Image
(
val
id
:
ImageId
,
val
filename
:
String
=
""
)
:
Message
()
{
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/internal/MessageDataInternal.kt
View file @
0494b374
...
@@ -203,11 +203,10 @@ fun MessageChain.toPacket(forGroup: Boolean): ByteReadPacket = buildPacket {
...
@@ -203,11 +203,10 @@ fun MessageChain.toPacket(forGroup: Boolean): ByteReadPacket = buildPacket {
* 2F 37 33 38 33 35 38 36 37 2D 38 64 65 31 2D 34 65 30 66 2D 61 33 36 35 2D 34 39 62 30 33 39 63 34 61 39 31 66 41
* 2F 37 33 38 33 35 38 36 37 2D 38 64 65 31 2D 34 65 30 66 2D 61 33 36 35 2D 34 39 62 30 33 39 63 34 61 39 31 66 41
*/
*/
writeShortLVPacket
{
writeShortLVPacket
{
//todo
writeByte
(
0
x02
)
writeByte
(
0
x02
)
//"46 52 25 46 60 30 59 4F 4A 5A 51 48 31 46 4A 53 4C 51 4C 4A 33 46 31 2E 6A 70 67".hexToBytes().stringOfWitch()
//"46 52 25 46 60 30 59 4F 4A 5A 51 48 31 46 4A 53 4C 51 4C 4A 33 46 31 2E 6A 70 67".hexToBytes().stringOfWitch()
// writeShortLVString(filename)//图片文件名 FR%F`0YOJZQH1FJSLQLJ3F1.jpg
// writeShortLVString(filename)//图片文件名 FR%F`0YOJZQH1FJSLQLJ3F1.jpg
writeShortLVString
(
id
.
value
.
substring
(
1
..
24
)
+
".gif"
)
//图片文件名
FR%F`0YOJZQH1FJSLQLJ3F1.jpg
writeShortLVString
(
id
.
value
.
substring
(
1
..
24
)
+
".gif"
)
//图片文件名
. 后缀不影响. 但无后缀会导致 PC QQ 无法显示这个图片
writeHex
(
"03 00 04 00 00 02 A2 04"
)
writeHex
(
"03 00 04 00 00 02 A2 04"
)
writeShortLVString
(
id
.
value
)
writeShortLVString
(
id
.
value
)
writeHex
(
"14 00 04 03 00 00 00 0B 00 00 18"
)
writeHex
(
"14 00 04 03 00 00 00 0B 00 00 18"
)
...
@@ -215,11 +214,14 @@ fun MessageChain.toPacket(forGroup: Boolean): ByteReadPacket = buildPacket {
...
@@ -215,11 +214,14 @@ fun MessageChain.toPacket(forGroup: Boolean): ByteReadPacket = buildPacket {
writeHex
(
"19 00 04 00 00 00 4E 1A 00 04 00 00 00 23 FF 00 63 16 20 20 39 39 31 30 20 38 38 31 43 42 20 20 20 20 20 20 20 "
)
writeHex
(
"19 00 04 00 00 00 4E 1A 00 04 00 00 00 23 FF 00 63 16 20 20 39 39 31 30 20 38 38 31 43 42 20 20 20 20 20 20 20 "
)
writeStringUtf8
(
"674e"
)
//补长度
writeStringUtf8
(
"674e"
)
//没有 "e" 服务器就不回复
writeStringUtf8
(
id
.
value
.
substring
(
1
..
id
.
value
.
lastIndex
-
4
).
replace
(
"-"
,
"B"
))
//这一串文件名决定手机QQ保存的图片. 可以随意
writeStringUtf8
(
".gif"
)
writeStringUtf8
(
id
.
value
.
substring
(
1
..
id
.
value
.
lastIndex
-
4
))
//这一串文件名决定手机 QQ 保存的图片. 可以随意
writeStringUtf8
(
".gif"
)
//后缀要有
writeUByte
(
0
x66u
)
writeUByte
(
0
x66u
)
//有时候 PC QQ 看不到发这些消息, 但手机可以. 可能是 ID 过期了, 手机有缓存而电脑没有
/*
/*
* writeHex("19 00 04 00 00 00 4E 1A 00 04 00 00 00 23 FF 00 63 16 20 20 39 39 31 30 20 38 38 31 43 42 20 20 20 20 20 20 20 ")
* writeHex("19 00 04 00 00 00 4E 1A 00 04 00 00 00 23 FF 00 63 16 20 20 39 39 31 30 20 38 38 31 43 42 20 20 20 20 20 20 20 ")
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/TIMBotNetworkHandler.kt
View file @
0494b374
...
@@ -187,7 +187,6 @@ internal class TIMBotNetworkHandler internal constructor(private val bot: Bot) :
...
@@ -187,7 +187,6 @@ internal class TIMBotNetworkHandler internal constructor(private val bot: Bot) :
bot
.
logCyan
(
"Packet received: $packet"
)
bot
.
logCyan
(
"Packet received: $packet"
)
}
}
//coz removeIf is not inline
handlersLock
.
withLock
{
handlersLock
.
withLock
{
temporaryPacketHandlers
.
removeIfInlined
{
temporaryPacketHandlers
.
removeIfInlined
{
it
.
shouldRemove
(
this
@TIMBotNetworkHandler
[
ActionPacketHandler
].
session
,
packet
)
it
.
shouldRemove
(
this
@TIMBotNetworkHandler
[
ActionPacketHandler
].
session
,
packet
)
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/UploadFriendImage.kt
View file @
0494b374
...
@@ -14,7 +14,7 @@ import net.mamoe.mirai.utils.*
...
@@ -14,7 +14,7 @@ import net.mamoe.mirai.utils.*
/**
/**
* 上传图片
* 上传图片
*/
*/
suspend
fun
QQ
.
uploadImage
(
image
:
Platform
Image
):
ImageId
=
with
(
bot
.
network
.
session
)
{
suspend
fun
QQ
.
uploadImage
(
image
:
Buffered
Image
):
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
(
account
,
sessionKey
,
account
,
image
).
sendAndExpect
<
FriendImageIdRequestPacket
.
Response
,
ImageId
>
{
return
FriendImageIdRequestPacket
(
account
,
sessionKey
,
account
,
image
).
sendAndExpect
<
FriendImageIdRequestPacket
.
Response
,
ImageId
>
{
...
@@ -22,12 +22,12 @@ suspend fun QQ.uploadImage(image: PlatformImage): ImageId = with(bot.network.ses
...
@@ -22,12 +22,12 @@ suspend fun QQ.uploadImage(image: PlatformImage): ImageId = with(bot.network.ses
require
(
httpPostFriendImage
(
require
(
httpPostFriendImage
(
uKeyHex
=
it
.
uKey
!!
.
toUHexString
(
""
),
uKeyHex
=
it
.
uKey
!!
.
toUHexString
(
""
),
botNumber
=
bot
.
qqAccount
,
botNumber
=
bot
.
qqAccount
,
imageData
=
image
.
fileD
ata
,
imageData
=
image
.
d
ata
,
fileSize
=
image
.
fileSize
,
fileSize
=
image
.
fileSize
,
qq
=
account
qq
=
account
))
))
it
.
imageId
!!
it
.
imageId
!!
}
else
image
.
id
//todo 是这个么
}
else
TODO
(
"分析服务器已有图片时的 imageId"
)
}.
await
()
}.
await
()
}
}
...
@@ -40,6 +40,9 @@ suspend fun QQ.uploadImage(image: PlatformImage): ImageId = with(bot.network.ses
...
@@ -40,6 +40,9 @@ suspend fun QQ.uploadImage(image: PlatformImage): ImageId = with(bot.network.ses
//01 3E 03 3F A2 76 E4 B8 DD 00 00 50 7C 00 0A 00 01 00 01 00 2D 55 73 65 72 44 61 74 61 49 6D 61 67 65 3A 43 32 43 5C 40 53 51 25 4F 46 43 50 36 4C 48 30 47 34 43 47 57 53 49 52 46 37 32 2E 70 6E 67
//01 3E 03 3F A2 76 E4 B8 DD 00 00 50 7C 00 0A 00 01 00 01 00 2D 55 73 65 72 44 61 74 61 49 6D 61 67 65 3A 43 32 43 5C 40 53 51 25 4F 46 43 50 36 4C 48 30 47 34 43 47 57 53 49 52 46 37 32 2E 70 6E 67
// 00 01 61 A7 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 2E 01
// 00 01 61 A7 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 2E 01
/**
* 似乎没有必要. 服务器的返回永远都是 01 00 00 00 02 00 00
*/
@PacketId
(
0
X01_BDu
)
@PacketId
(
0
X01_BDu
)
@PacketVersion
(
date
=
"2019.10.19"
,
timVersion
=
"2.3.2.21173"
)
@PacketVersion
(
date
=
"2019.10.19"
,
timVersion
=
"2.3.2.21173"
)
class
SubmitImageFilenamePacket
(
class
SubmitImageFilenamePacket
(
...
@@ -95,16 +98,14 @@ class SubmitImageFilenamePacket(
...
@@ -95,16 +98,14 @@ class SubmitImageFilenamePacket(
* 服务器返回以下之一:
* 服务器返回以下之一:
* - 服务器已经存有这个图片
* - 服务器已经存有这个图片
* - 服务器未存有, 返回一个 key 用于客户端上传
* - 服务器未存有, 返回一个 key 用于客户端上传
*
* @author Him188moe
*/
*/
@PacketId
(
0
x03_52u
)
@PacketId
(
0
x03_52u
)
@PacketVersion
(
date
=
"2019.10.
19
"
,
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
:
Platform
Image
private
val
image
:
Buffered
Image
)
:
ClientPacket
()
{
)
:
ClientPacket
()
{
//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
...
@@ -240,9 +241,9 @@ class FriendImageIdRequestPacket(
...
@@ -240,9 +241,9 @@ class FriendImageIdRequestPacket(
writeUShort
(
0
x48_00u
)
writeUShort
(
0
x48_00u
)
writeUByte
(
0
x70u
)
writeUByte
(
0
x70u
)
writeUVarInt
(
image
.
imageW
idth
.
toUInt
())
writeUVarInt
(
image
.
w
idth
.
toUInt
())
writeUByte
(
0
x78u
)
writeUByte
(
0
x78u
)
writeUVarInt
(
image
.
imageH
eight
.
toUInt
())
writeUVarInt
(
image
.
h
eight
.
toUInt
())
}
}
writeShort
((
packet
.
remaining
-
7
).
toShort
())
//why?
writeShort
((
packet
.
remaining
-
7
).
toShort
())
//why?
writePacket
(
packet
)
writePacket
(
packet
)
...
@@ -283,9 +284,9 @@ class FriendImageIdRequestPacket(
...
@@ -283,9 +284,9 @@ class FriendImageIdRequestPacket(
}
else
{
}
else
{
//服务器已经有这个图片了
//服务器已经有这个图片了
DebugLogger
.
logPurple
(
"服务器已有好友图片 "
)
DebugLogger
.
logPurple
(
"服务器已有好友图片 "
)
println
(
"获取图片 repsonse 后文="
+
readRemainingBytes
().
toUHexString
())
TODO
(
"分析后文获取 imageId"
)
}
}
println
(
"获取图片 repsonse 后文="
+
readRemainingBytes
().
toUHexString
())
}
}
}
}
}
}
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/UploadGroupImage.kt
View file @
0494b374
...
@@ -10,13 +10,13 @@ import net.mamoe.mirai.utils.*
...
@@ -10,13 +10,13 @@ import net.mamoe.mirai.utils.*
suspend
fun
Group
.
uploadImage
(
suspend
fun
Group
.
uploadImage
(
image
:
Platform
Image
image
:
Buffered
Image
)
=
with
(
bot
.
network
.
session
)
{
)
=
with
(
bot
.
network
.
session
)
{
GroupImageIdRequestPacket
(
bot
.
qqAccount
,
groupId
,
image
,
sessionKey
)
GroupImageIdRequestPacket
(
bot
.
qqAccount
,
groupId
,
image
,
sessionKey
)
.
sendAndExpect
<
GroupImageIdRequestPacket
.
Response
,
Unit
>
{
.
sendAndExpect
<
GroupImageIdRequestPacket
.
Response
,
Unit
>
{
if
(
it
.
uKey
!=
null
)
{
if
(
it
.
uKey
!=
null
)
{
httpPostGroupImage
(
httpPostGroupImage
(
imageData
=
image
.
fileD
ata
,
imageData
=
image
.
d
ata
,
fileSize
=
image
.
fileSize
,
fileSize
=
image
.
fileSize
,
uKeyHex
=
it
.
uKey
!!
.
toUHexString
()
uKeyHex
=
it
.
uKey
!!
.
toUHexString
()
)
)
...
@@ -32,7 +32,7 @@ suspend fun Group.uploadImage(
...
@@ -32,7 +32,7 @@ suspend fun Group.uploadImage(
class
GroupImageIdRequestPacket
(
class
GroupImageIdRequestPacket
(
private
val
bot
:
UInt
,
private
val
bot
:
UInt
,
private
val
groupId
:
UInt
,
private
val
groupId
:
UInt
,
private
val
image
:
Platform
Image
,
private
val
image
:
Buffered
Image
,
private
val
sessionKey
:
ByteArray
private
val
sessionKey
:
ByteArray
)
:
ClientPacket
()
{
)
:
ClientPacket
()
{
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/
Platform
Image.kt
→
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/
Buffered
Image.kt
View file @
0494b374
...
@@ -3,26 +3,22 @@ package net.mamoe.mirai.utils
...
@@ -3,26 +3,22 @@ package net.mamoe.mirai.utils
import
kotlinx.io.core.ByteReadPacket
import
kotlinx.io.core.ByteReadPacket
import
net.mamoe.mirai.message.ImageId
import
net.mamoe.mirai.message.ImageId
class
Platform
Image
(
class
Buffered
Image
(
val
width
:
Int
,
val
width
:
Int
,
val
height
:
Int
,
val
height
:
Int
,
val
md5
:
ByteArray
,
val
md5
:
ByteArray
,
val
format
:
String
,
val
format
:
String
,
val
fileD
ata
:
ByteReadPacket
val
d
ata
:
ByteReadPacket
)
{
)
{
val
fileSize
:
Long
=
fileD
ata
.
remaining
val
fileSize
:
Long
=
d
ata
.
remaining
val
i
d
:
ImageId
by
lazy
{
ImageId
(
"{${md5[0..3]}-${md5[4..5]}-${md5[6..7]}-${md5[8..9]}-${md5[10..15]}}.$format"
)
}
val
groupImageI
d
:
ImageId
by
lazy
{
ImageId
(
"{${md5[0..3]}-${md5[4..5]}-${md5[6..7]}-${md5[8..9]}-${md5[10..15]}}.$format"
)
}
override
fun
toString
():
String
=
"[
Platform
Image(${width}x${height} $format)]"
override
fun
toString
():
String
=
"[
Buffered
Image(${width}x${height} $format)]"
}
}
private
operator
fun
ByteArray
.
get
(
range
:
IntRange
):
String
=
buildString
{
private
operator
fun
ByteArray
.
get
(
range
:
IntRange
):
String
=
buildString
{
range
.
forEach
{
range
.
forEach
{
append
(
this
@
get
[
it
].
toUHexString
())
append
(
this
@
get
[
it
].
toUHexString
())
}
}
}
}
\ No newline at end of file
expect
val
PlatformImage
.
imageWidth
:
Int
expect
val
PlatformImage
.
imageHeight
:
Int
\ No newline at end of file
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/
Platform
ImageJvm.kt
→
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/
Buffered
ImageJvm.kt
View file @
0494b374
...
@@ -3,17 +3,19 @@
...
@@ -3,17 +3,19 @@
package
net.mamoe.mirai.utils
package
net.mamoe.mirai.utils
import
kotlinx.io.core.buildPacket
import
kotlinx.io.core.buildPacket
import
java.awt.image.BufferedImage
import
kotlinx.io.streams.writePacket
import
java.io.InputStream
import
java.io.OutputStream
import
java.io.OutputStream
import
java.security.MessageDigest
import
java.security.MessageDigest
import
javax.imageio.ImageIO
import
javax.imageio.ImageIO
import
java.awt.image.BufferedImage
as
JavaBufferedImage
fun
BufferedImage
.
toPlatformImage
(
formatName
:
String
=
"png"
):
Platform
Image
{
fun
JavaBufferedImage
.
toMiraiImage
(
formatName
:
String
=
"png"
):
Buffered
Image
{
val
digest
=
MessageDigest
.
getInstance
(
"md5"
)
val
digest
=
MessageDigest
.
getInstance
(
"md5"
)
digest
.
reset
()
digest
.
reset
()
val
buffer
=
buildPacket
{
val
buffer
=
buildPacket
{
ImageIO
.
write
(
this
@
to
Platform
Image
,
formatName
,
object
:
OutputStream
()
{
ImageIO
.
write
(
this
@
to
Mirai
Image
,
formatName
,
object
:
OutputStream
()
{
override
fun
write
(
b
:
Int
)
{
override
fun
write
(
b
:
Int
)
{
b
.
toByte
().
let
{
b
.
toByte
().
let
{
this
@
buildPacket
.
writeByte
(
it
)
this
@
buildPacket
.
writeByte
(
it
)
...
@@ -23,9 +25,18 @@ fun BufferedImage.toPlatformImage(formatName: String = "png"): PlatformImage {
...
@@ -23,9 +25,18 @@ fun BufferedImage.toPlatformImage(formatName: String = "png"): PlatformImage {
})
})
}
}
return
PlatformImage
(
this
.
width
,
this
.
height
,
digest
.
digest
(),
formatName
,
buffer
)
return
BufferedImage
(
width
,
height
,
digest
.
digest
(),
formatName
,
buffer
)
}
}
actual
val
PlatformImage
.
imageWidth
:
Int
get
()
=
this
.
width
fun
BufferedImage
.
toJavaImage
():
JavaBufferedImage
=
ImageIO
.
read
(
object
:
InputStream
()
{
override
fun
read
():
Int
=
with
(
this
@
toJavaImage
.
data
)
{
if
(
remaining
!=
0L
)
readByte
().
toInt
()
else
-
1
}
})
actual
val
PlatformImage
.
imageHeight
:
Int
get
()
=
this
.
height
/**
\ No newline at end of file
* 将缓存的图片写入流. 注意, 写入后缓存将会被清空.
*/
fun
OutputStream
.
writeImage
(
image
:
BufferedImage
)
=
this
.
writePacket
(
image
.
data
)
\ No newline at end of file
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/PlatformUtilsJvm.kt
View file @
0494b374
...
@@ -5,8 +5,8 @@ package net.mamoe.mirai.utils
...
@@ -5,8 +5,8 @@ package net.mamoe.mirai.utils
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.withContext
import
kotlinx.coroutines.withContext
import
kotlinx.io.core.ByteReadPacket
import
kotlinx.io.core.ByteReadPacket
import
kotlinx.io.streams.writePacket
import
org.jsoup.Connection
import
org.jsoup.Connection
import
java.io.OutputStream
import
java.net.HttpURLConnection
import
java.net.HttpURLConnection
import
java.net.InetAddress
import
java.net.InetAddress
import
java.net.URL
import
java.net.URL
...
@@ -117,12 +117,4 @@ actual suspend fun httpPostGroupImage(uKeyHex: String, fileSize: Long, imageData
...
@@ -117,12 +117,4 @@ actual suspend fun httpPostGroupImage(uKeyHex: String, fileSize: Long, imageData
private
suspend
fun
Connection
.
suspendExecute
():
Connection
.
Response
=
withContext
(
Dispatchers
.
IO
)
{
private
suspend
fun
Connection
.
suspendExecute
():
Connection
.
Response
=
withContext
(
Dispatchers
.
IO
)
{
execute
()
execute
()
}
private
fun
OutputStream
.
writePacket
(
packet
:
ByteReadPacket
)
{
val
byteArray
=
ByteArray
(
1
)
repeat
(
packet
.
remaining
.
toInt
())
{
packet
.
readAvailable
(
byteArray
)
this
.
write
(
byteArray
)
}
}
}
\ No newline at end of file
mirai-core/src/jvmTest/kotlin/TestGroupImage.kt
View file @
0494b374
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
import
net.mamoe.mirai.network.protocol.tim.packet.GroupImageIdRequestPacket
import
net.mamoe.mirai.network.protocol.tim.packet.GroupImageIdRequestPacket
import
net.mamoe.mirai.utils.hexToBytes
import
net.mamoe.mirai.utils.hexToBytes
import
net.mamoe.mirai.utils.readRemainingBytes
import
net.mamoe.mirai.utils.readRemainingBytes
import
net.mamoe.mirai.utils.to
Platform
Image
import
net.mamoe.mirai.utils.to
Mirai
Image
import
net.mamoe.mirai.utils.toUHexString
import
net.mamoe.mirai.utils.toUHexString
import
java.io.File
import
java.io.File
import
javax.imageio.ImageIO
import
javax.imageio.ImageIO
...
@@ -11,7 +11,7 @@ import javax.imageio.ImageIO
...
@@ -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
()
val
sessionKey
:
ByteArray
=
"F1 ED F2 BC 55 17 7B FE CC CC F3 08 D1 8D A7 0E"
.
hexToBytes
()
fun
main
()
=
println
({
fun
main
()
=
println
({
val
image
=
ImageIO
.
read
(
File
(
"C:\\Users\\Him18\\Desktop\\test2.png"
).
readBytes
().
inputStream
()).
to
Platform
Image
(
"png"
)
val
image
=
ImageIO
.
read
(
File
(
"C:\\Users\\Him18\\Desktop\\test2.png"
).
readBytes
().
inputStream
()).
to
Mirai
Image
(
"png"
)
// File("C:\\Users\\Him18\\Desktop\\test2.jpg").writeBytes(image.fileData.readBytes())
// File("C:\\Users\\Him18\\Desktop\\test2.jpg").writeBytes(image.fileData.readBytes())
GroupImageIdRequestPacket
(
GroupImageIdRequestPacket
(
...
...
mirai-demos/mirai-demo-1/src/main/java/demo1/Main.kt
View file @
0494b374
...
@@ -81,18 +81,18 @@ suspend fun main() {
...
@@ -81,18 +81,18 @@ suspend fun main() {
"上传好友图片"
in
it
.
message
->
withTimeoutOrNull
(
3000
)
{
"上传好友图片"
in
it
.
message
->
withTimeoutOrNull
(
3000
)
{
val
id
=
QQ
(
bot
,
1040400290
u
)
val
id
=
QQ
(
bot
,
1040400290
u
)
.
uploadImage
(
withContext
(
Dispatchers
.
IO
)
{
ImageIO
.
read
(
File
(
"C:\\Users\\Him18\\Desktop\\色图.jpg"
).
readBytes
().
inputStream
())
}.
to
Platform
Image
(
"png"
))
.
uploadImage
(
withContext
(
Dispatchers
.
IO
)
{
ImageIO
.
read
(
File
(
"C:\\Users\\Him18\\Desktop\\色图.jpg"
).
readBytes
().
inputStream
())
}.
to
Mirai
Image
(
"png"
))
it
.
reply
(
id
.
value
)
it
.
reply
(
id
.
value
)
delay
(
1000
)
delay
(
1000
)
it
.
reply
(
Image
(
id
))
it
.
reply
(
Image
(
id
))
}
}
"上传群图片"
in
it
.
message
->
withTimeoutOrNull
(
3000
)
{
"上传群图片"
in
it
.
message
->
withTimeoutOrNull
(
3000
)
{
val
image
=
withContext
(
Dispatchers
.
IO
)
{
ImageIO
.
read
(
File
(
"C:\\Users\\Him18\\Desktop\\色图.jpg"
).
readBytes
().
inputStream
())
}.
to
Platform
Image
(
"png"
)
val
image
=
withContext
(
Dispatchers
.
IO
)
{
ImageIO
.
read
(
File
(
"C:\\Users\\Him18\\Desktop\\色图.jpg"
).
readBytes
().
inputStream
())
}.
to
Mirai
Image
(
"png"
)
Group
(
bot
,
580266363
u
).
uploadImage
(
image
)
Group
(
bot
,
580266363
u
).
uploadImage
(
image
)
it
.
reply
(
image
.
i
d
.
value
)
it
.
reply
(
image
.
groupImageI
d
.
value
)
delay
(
1000
)
delay
(
1000
)
Group
(
bot
,
580266363
u
).
sendMessage
(
Image
(
image
.
i
d
))
Group
(
bot
,
580266363
u
).
sendMessage
(
Image
(
image
.
groupImageI
d
))
}
}
"发群图片"
in
it
.
message
->
{
"发群图片"
in
it
.
message
->
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment