mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-31 03:22:36 +08:00
Image Provider
This commit is contained in:
parent
44585d2df6
commit
5daf97015a
@ -8,6 +8,7 @@ import net.mamoe.mirai.qqandroid.QQAndroidBot
|
|||||||
import net.mamoe.mirai.qqandroid.io.serialization.writeProtoBuf
|
import net.mamoe.mirai.qqandroid.io.serialization.writeProtoBuf
|
||||||
import net.mamoe.mirai.qqandroid.network.QQAndroidClient
|
import net.mamoe.mirai.qqandroid.network.QQAndroidClient
|
||||||
import net.mamoe.mirai.qqandroid.network.protocol.data.proto.OidbSso
|
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.OutgoingPacket
|
||||||
import net.mamoe.mirai.qqandroid.network.protocol.packet.OutgoingPacketFactory
|
import net.mamoe.mirai.qqandroid.network.protocol.packet.OutgoingPacketFactory
|
||||||
import net.mamoe.mirai.qqandroid.network.protocol.packet.buildOutgoingUniPacket
|
import net.mamoe.mirai.qqandroid.network.protocol.packet.buildOutgoingUniPacket
|
||||||
@ -47,14 +48,34 @@ internal object TroopManagement {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object Response : Packet
|
object Response : Packet
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
internal object MuteAll : OutgoingPacketFactory<LoginPacket.LoginPacketResponse>("OidbSvc.0x89a_0") {
|
internal object MuteAll : OutgoingPacketFactory<MuteAll.Response>("OidbSvc.0x89a_0") {
|
||||||
override suspend fun ByteReadPacket.decode(bot: QQAndroidBot): LoginPacket.LoginPacketResponse {
|
override suspend fun ByteReadPacket.decode(bot: QQAndroidBot): Response {
|
||||||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
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<LoginPacket.LoginPacketResponse>("OidbSvc.0x8fc_2") {
|
internal object EditNametag : OutgoingPacketFactory<LoginPacket.LoginPacketResponse>("OidbSvc.0x8fc_2") {
|
||||||
|
@ -2,6 +2,7 @@ package demo.gentleman
|
|||||||
|
|
||||||
import com.alibaba.fastjson.JSON
|
import com.alibaba.fastjson.JSON
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
|
import kotlinx.serialization.json.JsonObject
|
||||||
import net.mamoe.mirai.contact.Contact
|
import net.mamoe.mirai.contact.Contact
|
||||||
import net.mamoe.mirai.message.data.Image
|
import net.mamoe.mirai.message.data.Image
|
||||||
import net.mamoe.mirai.message.uploadAsImage
|
import net.mamoe.mirai.message.uploadAsImage
|
||||||
@ -12,31 +13,41 @@ class GentleImage {
|
|||||||
|
|
||||||
// `Deferred<Image?>` causes a runtime ClassCastException
|
// `Deferred<Image?>` causes a runtime ClassCastException
|
||||||
|
|
||||||
val image: Deferred<Image> by lazy {
|
val image: Deferred<Image> by lazy { getImage(0) }
|
||||||
GlobalScope.async {
|
|
||||||
//delay((Math.random() * 5000L).toLong())
|
|
||||||
class Result {
|
|
||||||
var id: String = ""
|
|
||||||
}
|
|
||||||
|
|
||||||
|
val seImage: Deferred<Image> by lazy { getImage(1) }
|
||||||
|
|
||||||
|
fun getImage(r18: Int): Deferred<Image> {
|
||||||
|
GlobalScope.async {
|
||||||
withTimeoutOrNull(5 * 1000) {
|
withTimeoutOrNull(5 * 1000) {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
val result = JSON.parseObject(
|
val result = JSON.parseObject(
|
||||||
Jsoup.connect("http://dev.itxtech.org:10322/v2/randomImg.uue").ignoreContentType(true).timeout(10_0000).get().body().text(),
|
Jsoup.connect("https://api.lolicon.app/setu/?r18=$r18").ignoreContentType(true).timeout(10_0000).get().body().text(),
|
||||||
Result::class.java
|
)
|
||||||
)
|
|
||||||
|
|
||||||
Jsoup.connect("http://dev.itxtech.org:10322/img.uue?size=large&id=${result.id}")
|
var url = "";
|
||||||
.userAgent(UserAgent.randomUserAgent)
|
var pid = "";
|
||||||
.timeout(10_0000)
|
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)
|
.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()
|
.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")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ suspend fun main() {
|
|||||||
file.sendAsImageTo(subject)
|
file.sendAsImageTo(subject)
|
||||||
}
|
}
|
||||||
|
|
||||||
startsWith("随机图片", removePrefix = true) {
|
startsWith("色图", removePrefix = true) {
|
||||||
repeat(it.toIntOrNull() ?: 1) {
|
repeat(it.toIntOrNull() ?: 1) {
|
||||||
GlobalScope.launch {
|
GlobalScope.launch {
|
||||||
delay(Random.Default.nextLong(100, 1000))
|
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) {
|
startsWith("添加好友", removePrefix = true) {
|
||||||
reply(bot.addFriend(it.toLong()).toString())
|
reply(bot.addFriend(it.toLong()).toString())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user