mirror of
https://github.com/mamoe/mirai.git
synced 2025-02-13 03:16:05 +08:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
94c746a011
3
.gitignore
vendored
3
.gitignore
vendored
@ -40,4 +40,5 @@ mirai.iml
|
||||
local.properties
|
||||
|
||||
# Maven publishing credits
|
||||
keys.properties
|
||||
keys.properties
|
||||
/plugins/
|
||||
|
@ -0,0 +1,107 @@
|
||||
package net.mamoe.mirai.qqandroid.network.protocol.packet.image
|
||||
|
||||
import kotlinx.io.core.ByteReadPacket
|
||||
import kotlinx.serialization.SerialId
|
||||
import kotlinx.serialization.Serializable
|
||||
import net.mamoe.mirai.data.Packet
|
||||
import net.mamoe.mirai.qqandroid.QQAndroidBot
|
||||
import net.mamoe.mirai.qqandroid.network.protocol.packet.PacketFactory
|
||||
import net.mamoe.mirai.qqandroid.network.protocol.packet.login.PacketId
|
||||
import net.mamoe.mirai.utils.currentTimeSeconds
|
||||
|
||||
@UseExperimental(ExperimentalUnsignedTypes::class)
|
||||
internal object ImagePacket : PacketFactory<ImagePacket.RequestImgUrlResponse>() {
|
||||
init {
|
||||
this._id = PacketId(commandId = 0x0000, commandName = "LongConn.OffPicDown")
|
||||
}
|
||||
|
||||
|
||||
sealed class RequestImgUrlResponse : Packet {
|
||||
object Success : RequestImgUrlResponse()
|
||||
}
|
||||
|
||||
|
||||
fun createCmd0x325Packet(req: ImgReq, networkType: Int = 5): Cmd0x352Packet {
|
||||
if (req is UploadImgReq)
|
||||
return Cmd0x352Packet(1, req, null, null, networkType)
|
||||
if (req is GetImgUrlReq)
|
||||
return Cmd0x352Packet(2, null, req, null, networkType)
|
||||
error("Unknown ImgReq")
|
||||
}
|
||||
|
||||
@Serializable
|
||||
internal class Cmd0x352Packet(
|
||||
@SerialId(1) val subCommand: Int, //2是GetImgUrlReq 1是UploadImgReq
|
||||
@SerialId(2) val uploadImgReq: UploadImgReq? = null,// optional
|
||||
@SerialId(3) val getImgUrlReq: GetImgUrlReq? = null,// optional
|
||||
@SerialId(4) val deleteImgReq: String? = "",// optional (没有做也不准备做, 没用)
|
||||
@SerialId(10) val networkType: Int = 5// 数据网络=5
|
||||
)
|
||||
|
||||
interface ImgReq
|
||||
@Serializable
|
||||
class UploadImgReq(
|
||||
@SerialId(1) val srcUni: Int,
|
||||
@SerialId(2) val dstUni: Int,
|
||||
@SerialId(3) val fileId: Int,
|
||||
@SerialId(4) val fileMd5: ByteArray,
|
||||
@SerialId(5) val fileSize: Int,
|
||||
@SerialId(6) val fileName: String,
|
||||
@SerialId(7) val srcTerm: Int,
|
||||
@SerialId(8) val platformType: Int,
|
||||
@SerialId(9) val innerIP: Int = 0,
|
||||
@SerialId(10) val addressBook: Int = 0,//chatType == 1006为1 我觉得发0没问题
|
||||
@SerialId(11) val retry: Int,
|
||||
@SerialId(12) val buType: Int,
|
||||
@SerialId(13) val imgOriginal: Int,//是否为原图
|
||||
@SerialId(14) val imgWidth: Int,
|
||||
@SerialId(15) val imgHeight: Int,
|
||||
@SerialId(16) val imgType: Int,
|
||||
@SerialId(17) val buildVer: String = "8.2.0.1296",//版本号
|
||||
@SerialId(18) val fileIndex: ByteArray,
|
||||
@SerialId(19) val fileStoreDays: Int,
|
||||
@SerialId(20) val stepFlag: Int,
|
||||
@SerialId(21) val rejectTryFast: Int,//bool
|
||||
@SerialId(22) val srvUpload: Int,
|
||||
@SerialId(23) val transferUrl: ByteArray
|
||||
) : ImgReq
|
||||
|
||||
@Serializable
|
||||
class GetImgUrlReq(
|
||||
@SerialId(1) val srcUni: Int,
|
||||
@SerialId(2) val dstUni: Int,
|
||||
@SerialId(3) val fileResID: String,//UUID
|
||||
/**
|
||||
* UUID例子:
|
||||
*/
|
||||
@SerialId(4) val urlFlag: Int = 1,
|
||||
//5 unknown, 好像没用
|
||||
@SerialId(6) val urlType: Int = 4,
|
||||
@SerialId(7) val requestTerm: Int = 5,//确定
|
||||
@SerialId(8) val requestPlatformType: Int = 9,//确定
|
||||
@SerialId(9) val srcFileType: Int = 1,//2=ftn,1=picplatform,255
|
||||
@SerialId(10) val innerIP: Int = 0,//确定
|
||||
@SerialId(11) val addressBook: Int = 0,//chatType == 1006为1 我觉得发0没问题
|
||||
/**
|
||||
* chattype
|
||||
* 1008时为Troop
|
||||
* 1 时为?
|
||||
* 9999时为?
|
||||
* 1036时为?
|
||||
* 1006时为?
|
||||
*/
|
||||
@SerialId(12) val buType: Int = 1,//确定
|
||||
@SerialId(13) val buildVer: String = "8.2.0.1296",//版本号
|
||||
@SerialId(14) val timestamp: Int = currentTimeSeconds.toInt(),//(pic_up_timestamp)
|
||||
@SerialId(15) val requestTransferType: Int = 1
|
||||
) : ImgReq
|
||||
|
||||
|
||||
override suspend fun ByteReadPacket.decode(bot: QQAndroidBot): RequestImgUrlResponse {
|
||||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -14,21 +14,16 @@ class ImageProvider {
|
||||
|
||||
val image: Deferred<Image> by lazy {
|
||||
GlobalScope.async {
|
||||
//delay((Math.random() * 5000L).toLong())
|
||||
class Result {
|
||||
var id: String = ""
|
||||
}
|
||||
|
||||
withTimeoutOrNull(5 * 1000) {
|
||||
withContext(Dispatchers.IO) {
|
||||
val result = JSON.parseObject(
|
||||
Jsoup.connect("http://dev.itxtech.org:10322/v2/randomImg.uue").ignoreContentType(true).timeout(
|
||||
val result = JSON.parseArray(
|
||||
Jsoup.connect("https://yande.re/post.json?limit=1&page=${(Math.random() * 10000).toInt()}").ignoreContentType(
|
||||
true
|
||||
).timeout(
|
||||
10_0000
|
||||
).get().body().text(),
|
||||
Result::class.java
|
||||
).get().body().text()
|
||||
)
|
||||
|
||||
Jsoup.connect("http://dev.itxtech.org:10322/img.uue?size=large&id=${result.id}")
|
||||
Jsoup.connect(result.getJSONObject(0).getString("jpeg_url"))
|
||||
.userAgent("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; ja-jp) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27")
|
||||
.timeout(10_0000)
|
||||
.ignoreContentType(true)
|
||||
@ -36,7 +31,7 @@ class ImageProvider {
|
||||
.execute()
|
||||
.bodyStream()
|
||||
}
|
||||
}?.uploadAsImage(contact) ?: error("Unable to download image")
|
||||
}?.uploadAsImage(contact) ?: error("Unable to download image|连接这个图站需要你的网络在外网")
|
||||
}
|
||||
}
|
||||
|
||||
|
BIN
plugins/image-sender-1.0.0-all.jar
Normal file
BIN
plugins/image-sender-1.0.0-all.jar
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user