Commit 3f56faae authored by Him188's avatar Him188

Fixed image

parent c973fbd0
...@@ -66,7 +66,7 @@ suspend fun httpPostFriendImage( ...@@ -66,7 +66,7 @@ suspend fun httpPostFriendImage(
imageInput = imageInput, imageInput = imageInput,
inputSize = inputSize, inputSize = inputSize,
uKeyHex = uKeyHex uKeyHex = uKeyHex
) as HttpStatusCode).value.also { println(it) } == 200 ) as HttpStatusCode).value == 200
/** /**
* 上传群图片 * 上传群图片
...@@ -85,7 +85,7 @@ suspend fun httpPostGroupImage( ...@@ -85,7 +85,7 @@ suspend fun httpPostGroupImage(
imageInput = imageInput, imageInput = imageInput,
inputSize = inputSize, inputSize = inputSize,
uKeyHex = uKeyHex uKeyHex = uKeyHex
) as HttpStatusCode).value.also { println(it) } == 200 ) as HttpStatusCode).value == 200
@Suppress("SpellCheckingInspection") @Suppress("SpellCheckingInspection")
private suspend inline fun <reified T> HttpClient.postImage( private suspend inline fun <reified T> HttpClient.postImage(
...@@ -95,28 +95,31 @@ private suspend inline fun <reified T> HttpClient.postImage( ...@@ -95,28 +95,31 @@ private suspend inline fun <reified T> HttpClient.postImage(
imageInput: Input, imageInput: Input,
inputSize: Long, inputSize: Long,
uKeyHex: String uKeyHex: String
): T = post { ): T = try {
url { post {
protocol = URLProtocol.HTTP url {
host = "htdata2.qq.com" protocol = URLProtocol.HTTP
path("cgi-bin/httpconn") host = "htdata2.qq.com"
path("cgi-bin/httpconn")
parameters["htcmd"] = htcmd parameters["htcmd"] = htcmd
parameters["uin"] = uin.toLong().toString() parameters["uin"] = uin.toLong().toString()
if (groupcode != null) parameters["groupcode"] = groupcode.value.toLong().toString() if (groupcode != null) parameters["groupcode"] = groupcode.value.toLong().toString()
parameters["term"] = "pc" parameters["term"] = "pc"
parameters["ver"] = "5603" parameters["ver"] = "5603"
parameters["filesize"] = inputSize.toString() parameters["filesize"] = inputSize.toString()
parameters["range"] = 0.toString() parameters["range"] = 0.toString()
parameters["ukey"] = uKeyHex parameters["ukey"] = uKeyHex
userAgent("QQClient") userAgent("QQClient")
} }
println(url.buildString()) configureBody(inputSize, imageInput)
configureBody(inputSize, imageInput) }
} finally {
imageInput.close()
} }
internal expect fun HttpRequestBuilder.configureBody(inputSize: Long, input: Input) internal expect fun HttpRequestBuilder.configureBody(inputSize: Long, input: Input)
\ No newline at end of file
...@@ -59,39 +59,6 @@ actual fun solveIpAddress(hostname: String): String = InetAddress.getByName(host ...@@ -59,39 +59,6 @@ actual fun solveIpAddress(hostname: String): String = InetAddress.getByName(host
actual fun localIpAddress(): String = InetAddress.getLocalHost().hostAddress actual fun localIpAddress(): String = InetAddress.getLocalHost().hostAddress
/*
actual suspend fun httpPostFriendImageOld(
uKeyHex: String,
botNumber: UInt,
imageData: ByteReadPacket
): Boolean = Jsoup.connect(
"http://htdata2.qq.com/cgi-bin/httpconn" +
"?htcmd=0x6ff0070" +
"&ver=5603" +
"&ukey=$uKeyHex" +
"&filesize=${imageData.remaining}" +
"&range=0" +
"&uin=$botNumber"
)
.postImage(imageData)
private suspend fun Connection.postImage(image: ByteReadPacket): Boolean = this
.userAgent("QQClient")
.header("Content-Length", image.remaining.toString())
.requestBody(String(image.readBytes(), Charsets.ISO_8859_1))
.method(Connection.Method.POST)
.postDataCharset("ISO_8859_1")
.header("Content-type", "image/gif")
.ignoreContentType(true)
.suspendExecute()
.statusCode() == 200
private suspend fun Connection.suspendExecute(): Connection.Response = withContext(Dispatchers.IO) {
execute()
}
*/
internal actual val httpClient: HttpClient = HttpClient(CIO) internal actual val httpClient: HttpClient = HttpClient(CIO)
internal actual fun HttpRequestBuilder.configureBody( internal actual fun HttpRequestBuilder.configureBody(
......
...@@ -4,7 +4,6 @@ import kotlinx.coroutines.* ...@@ -4,7 +4,6 @@ import kotlinx.coroutines.*
import net.mamoe.mirai.contact.Contact import net.mamoe.mirai.contact.Contact
import net.mamoe.mirai.message.Image import net.mamoe.mirai.message.Image
import net.mamoe.mirai.message.upload import net.mamoe.mirai.message.upload
import net.mamoe.mirai.utils.MiraiLogger
import org.jsoup.Jsoup import org.jsoup.Jsoup
class GentleImage { class GentleImage {
...@@ -42,7 +41,7 @@ class GentleImage { ...@@ -42,7 +41,7 @@ class GentleImage {
// CompletableDeferred(suspend { // CompletableDeferred(suspend {
delay((Math.random() * 5000L).toLong()) delay((Math.random() * 5000L).toLong())
MiraiLogger.logPurple("Downloading image: $name") // MiraiLogger.logPurple("Downloading image: $name")
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
Jsoup.connect(sample_url) Jsoup.connect(sample_url)
.userAgent(UserAgent.randomUserAgent) .userAgent(UserAgent.randomUserAgent)
...@@ -52,7 +51,7 @@ class GentleImage { ...@@ -52,7 +51,7 @@ class GentleImage {
.execute() .execute()
.bodyStream() .bodyStream()
}.upload(contact).also { }.upload(contact).also {
MiraiLogger.logPurple("Downloaded image: $name") //MiraiLogger.logPurple("Downloaded image: $name")
} }
// }()) // }())
// } // }
......
package demo.gentleman package demo.gentleman
import com.alibaba.fastjson.JSONArray import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.* import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.launch
import net.mamoe.mirai.contact.Contact import net.mamoe.mirai.contact.Contact
import org.jsoup.Connection
import org.jsoup.Jsoup
/** /**
* 最少缓存的图片数量 * 最少缓存的图片数量
*/ */
private const val IMAGE_BUFFER_CAPACITY: Int = 5 private const val IMAGE_BUFFER_CAPACITY: Int = 50
/** /**
* 每次补充的数量 * 每次补充的数量
...@@ -30,12 +29,20 @@ class Gentleman(private val contact: Contact) : Channel<GentleImage> by Channel( ...@@ -30,12 +29,20 @@ class Gentleman(private val contact: Contact) : Channel<GentleImage> by Channel(
GlobalScope.launch { GlobalScope.launch {
while (!isClosedForSend) { while (!isClosedForSend) {
send(GentleImage().apply {
sample_url = "http://dev.itxtech.org:10322/randomImg.uue?tdsourcetag=s_pctim_aiomsg"
contact = this@Gentleman.contact
image.await()
})
/*
val response = withContext(Dispatchers.IO) { val response = withContext(Dispatchers.IO) {
tryNTimes(2) { tryNTimes(2) {
Jsoup.connect("https://yande.re/post.json?") Jsoup.connect("https://yande.re/post.json?")
.userAgent(UserAgent.randomUserAgent) .userAgent(UserAgent.randomUserAgent)
.data("limit", "20") .data("limit", "20")
.data("page", (Math.random() * 4000).toString()) .data("page", (Random.Default.nextInt(12000)).toString())
.ignoreContentType(true) .ignoreContentType(true)
.timeout(20_000) .timeout(20_000)
.method(Connection.Method.GET) .method(Connection.Method.GET)
...@@ -57,7 +64,7 @@ class Gentleman(private val contact: Contact) : Channel<GentleImage> by Channel( ...@@ -57,7 +64,7 @@ class Gentleman(private val contact: Contact) : Channel<GentleImage> by Channel(
it.image//start downloading it.image//start downloading
send(it) send(it)
} }*/
} }
} }
} }
......
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