diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/TroopManagement.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/TroopManagement.kt index 58b3dc827..3ccc9b1e9 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/TroopManagement.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/TroopManagement.kt @@ -8,6 +8,7 @@ import net.mamoe.mirai.qqandroid.QQAndroidBot import net.mamoe.mirai.qqandroid.io.serialization.writeProtoBuf import net.mamoe.mirai.qqandroid.network.QQAndroidClient import net.mamoe.mirai.qqandroid.network.protocol.data.proto.OidbSso +import net.mamoe.mirai.qqandroid.network.protocol.packet.EMPTY_BYTE_ARRAY import net.mamoe.mirai.qqandroid.network.protocol.packet.OutgoingPacket import net.mamoe.mirai.qqandroid.network.protocol.packet.OutgoingPacketFactory import net.mamoe.mirai.qqandroid.network.protocol.packet.buildOutgoingUniPacket @@ -47,14 +48,34 @@ internal object TroopManagement { ) } } + object Response : Packet } - internal object MuteAll : OutgoingPacketFactory("OidbSvc.0x89a_0") { - override suspend fun ByteReadPacket.decode(bot: QQAndroidBot): LoginPacket.LoginPacketResponse { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + internal object MuteAll : OutgoingPacketFactory("OidbSvc.0x89a_0") { + override suspend fun ByteReadPacket.decode(bot: QQAndroidBot): Response { + return Response } + + operator fun invoke( + client: QQAndroidClient, + groupCode: Long + ): OutgoingPacket { + return buildOutgoingUniPacket(client) { + writeProtoBuf( + OidbSso.OIDBSSOPkg.serializer(), + OidbSso.OIDBSSOPkg( + command = 2202, + serviceType = 0, + result = 0, + bodybuffer = EMPTY_BYTE_ARRAY//TODO + ) + ) + } + } + + object Response : Packet } internal object EditNametag : OutgoingPacketFactory("OidbSvc.0x8fc_2") { diff --git a/mirai-demos/mirai-demo-gentleman/src/main/kotlin/demo/gentleman/GentleImage.kt b/mirai-demos/mirai-demo-gentleman/src/main/kotlin/demo/gentleman/GentleImage.kt index 99755d61c..05bec8bb6 100644 --- a/mirai-demos/mirai-demo-gentleman/src/main/kotlin/demo/gentleman/GentleImage.kt +++ b/mirai-demos/mirai-demo-gentleman/src/main/kotlin/demo/gentleman/GentleImage.kt @@ -2,6 +2,7 @@ package demo.gentleman import com.alibaba.fastjson.JSON import kotlinx.coroutines.* +import kotlinx.serialization.json.JsonObject import net.mamoe.mirai.contact.Contact import net.mamoe.mirai.message.data.Image import net.mamoe.mirai.message.uploadAsImage @@ -12,31 +13,41 @@ class GentleImage { // `Deferred` causes a runtime ClassCastException - val image: Deferred by lazy { - GlobalScope.async { - //delay((Math.random() * 5000L).toLong()) - class Result { - var id: String = "" - } + val image: Deferred by lazy { getImage(0) } + val seImage: Deferred by lazy { getImage(1) } + + fun getImage(r18: Int): Deferred { + GlobalScope.async { withTimeoutOrNull(5 * 1000) { withContext(Dispatchers.IO) { val result = JSON.parseObject( - Jsoup.connect("http://dev.itxtech.org:10322/v2/randomImg.uue").ignoreContentType(true).timeout(10_0000).get().body().text(), - Result::class.java - ) + Jsoup.connect("https://api.lolicon.app/setu/?r18=$r18").ignoreContentType(true).timeout(10_0000).get().body().text(), + ) - Jsoup.connect("http://dev.itxtech.org:10322/img.uue?size=large&id=${result.id}") - .userAgent(UserAgent.randomUserAgent) - .timeout(10_0000) + var url = ""; + var pid = ""; + with(result.getJSONArray("data").getJSONObject(0)) { + url = this.getString("url") + pid = this.getString("pid") + } + + val image = Jsoup + .connect(url) + .followRedirects(true) + .timeout(180_000) .ignoreContentType(true) - .maxBodySize(Int.MAX_VALUE) + .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") + .referrer("https://www.pixiv.net/member_illust.php?mode=medium&illust_id=$pid") + .ignoreHttpErrors(true) + .maxBodySize(10000000) .execute() - .bodyStream() + + if (image.statusCode() != 200) error("Failed to download image") } - }?.uploadAsImage(contact) ?: error("Unable to download image") + image.bodyStream().uploadAsImage(contact) ?: error("Unable to download image") + } } } - } diff --git a/mirai-demos/mirai-demo-gentleman/src/main/kotlin/demo/gentleman/Main.kt b/mirai-demos/mirai-demo-gentleman/src/main/kotlin/demo/gentleman/Main.kt index 422ae5956..787850a25 100644 --- a/mirai-demos/mirai-demo-gentleman/src/main/kotlin/demo/gentleman/Main.kt +++ b/mirai-demos/mirai-demo-gentleman/src/main/kotlin/demo/gentleman/Main.kt @@ -151,7 +151,7 @@ suspend fun main() { file.sendAsImageTo(subject) } - startsWith("随机图片", removePrefix = true) { + startsWith("色图", removePrefix = true) { repeat(it.toIntOrNull() ?: 1) { GlobalScope.launch { delay(Random.Default.nextLong(100, 1000)) @@ -160,6 +160,15 @@ suspend fun main() { } } + startsWith("不够色", removePrefix = true) { + repeat(it.toIntOrNull() ?: 1) { + GlobalScope.launch { + delay(Random.Default.nextLong(100, 1000)) + Gentlemen.provide(subject).receive().seImage.await().send() + } + } + } + startsWith("添加好友", removePrefix = true) { reply(bot.addFriend(it.toLong()).toString()) }