Commit b6f54dbb authored by Him188's avatar Him188

Fixed image

parent 3f56faae
This diff is collapsed.
...@@ -27,8 +27,9 @@ internal fun IoBuffer.parseLongText0x19(): PlainText { ...@@ -27,8 +27,9 @@ internal fun IoBuffer.parseLongText0x19(): PlainText {
//01 00 59 AA 02 56 30 01 3A 40 6E 35 46 4F 62 68 75 4B 6F 65 31 4E 63 45 41 6B 77 4B 51 5A 5A 4C 47 54 57 43 68 30 4B 56 7A 57 44 38 67 58 70 37 62 77 6A 67 51 69 66 66 53 4A 63 4F 69 78 4F 75 37 36 49 49 4F 37 48 32 55 63 9A 01 0F 80 01 01 C8 01 00 F0 01 00 F8 01 00 90 02 00 14 01 75 01 01 6B 01 78 9C CD 92 BB 4E C3 30 14 86 77 9E C2 32 73 DA A4 21 24 48 4E AA F4 06 A5 B4 51 55 A0 A8 0B 4A 5D 27 35 E4 82 72 69 4B B7 6E 08 06 C4 C0 06 42 48 30 20 21 60 62 EB E3 34 F4 31 70 4A 11 23 23 FC 96 2C F9 D8 BF CF F1 77 8C F2 23 D7 01 03 12 84 D4 F7 54 28 64 78 08 88 87 FD 1E F5 6C 15 C6 91 C5 29 30 AF AD 00 26 E4 86 36 E8 06 94 58 2A CC FC 73 41 E0 1E 5A D4 21 0D D3 25 2A 2C 55 0A 1B D2 BA 5E E0 24 91 D7 B9 B5 72 41 E1 74 B9 5C E0 78 25 27 8B 92 28 14 45 45 FF 76 B4 E8 98 39 18 05 13 47 0B 24 03 4A 86 F5 D8 89 68 3D B4 21 B0 1C 93 71 11 21 08 49 30 A0 98 54 4B 6C 25 A5 E6 80 84 B4 A7 42 4F AA 18 DD 7E 5C F3 89 D0 C0 65 FD 78 58 6B 76 3A 3B 9B BB ED 62 9F AF ED 8F DB 25 C5 3E 38 91 BB C3 23 BB 49 2D AB B5 8D 0D 3A 32 62 79 BD 5A 35 E4 AD DC 1E 86 40 03 88 46 C4 05 8E 79 EA C7 11 EB 09 64 91 88 46 0E D1 C0 5F 73 FD 4D 00 65 97 95 02 D4 0F 34 94 65 D3 B2 78 80 7D C7 0F 54 B8 AA F0 E9 60 8F 4A EE 1E 3F 6E 2E 84 E4 F6 7E 3E 7D 9E 5D 5E 25 EF 67 C9 E4 15 FC DC 81 B2 29 08 0D 85 7E 1C 60 02 BC 45 33 E7 93 F3 D9 C3 D3 FC E5 6D 36 BD 86 2C C3 D7 66 7A 98 FD 4F ED 13 9B C7 C1 78 02 00 04 00 00 00 23 0E 00 07 01 00 04 00 00 00 09 //01 00 59 AA 02 56 30 01 3A 40 6E 35 46 4F 62 68 75 4B 6F 65 31 4E 63 45 41 6B 77 4B 51 5A 5A 4C 47 54 57 43 68 30 4B 56 7A 57 44 38 67 58 70 37 62 77 6A 67 51 69 66 66 53 4A 63 4F 69 78 4F 75 37 36 49 49 4F 37 48 32 55 63 9A 01 0F 80 01 01 C8 01 00 F0 01 00 F8 01 00 90 02 00 14 01 75 01 01 6B 01 78 9C CD 92 BB 4E C3 30 14 86 77 9E C2 32 73 DA A4 21 24 48 4E AA F4 06 A5 B4 51 55 A0 A8 0B 4A 5D 27 35 E4 82 72 69 4B B7 6E 08 06 C4 C0 06 42 48 30 20 21 60 62 EB E3 34 F4 31 70 4A 11 23 23 FC 96 2C F9 D8 BF CF F1 77 8C F2 23 D7 01 03 12 84 D4 F7 54 28 64 78 08 88 87 FD 1E F5 6C 15 C6 91 C5 29 30 AF AD 00 26 E4 86 36 E8 06 94 58 2A CC FC 73 41 E0 1E 5A D4 21 0D D3 25 2A 2C 55 0A 1B D2 BA 5E E0 24 91 D7 B9 B5 72 41 E1 74 B9 5C E0 78 25 27 8B 92 28 14 45 45 FF 76 B4 E8 98 39 18 05 13 47 0B 24 03 4A 86 F5 D8 89 68 3D B4 21 B0 1C 93 71 11 21 08 49 30 A0 98 54 4B 6C 25 A5 E6 80 84 B4 A7 42 4F AA 18 DD 7E 5C F3 89 D0 C0 65 FD 78 58 6B 76 3A 3B 9B BB ED 62 9F AF ED 8F DB 25 C5 3E 38 91 BB C3 23 BB 49 2D AB B5 8D 0D 3A 32 62 79 BD 5A 35 E4 AD DC 1E 86 40 03 88 46 C4 05 8E 79 EA C7 11 EB 09 64 91 88 46 0E D1 C0 5F 73 FD 4D 00 65 97 95 02 D4 0F 34 94 65 D3 B2 78 80 7D C7 0F 54 B8 AA F0 E9 60 8F 4A EE 1E 3F 6E 2E 84 E4 F6 7E 3E 7D 9E 5D 5E 25 EF 67 C9 E4 15 FC DC 81 B2 29 08 0D 85 7E 1C 60 02 BC 45 33 E7 93 F3 D9 C3 D3 FC E5 6D 36 BD 86 2C C3 D7 66 7A 98 FD 4F ED 13 9B C7 C1 78 02 00 04 00 00 00 23 0E 00 07 01 00 04 00 00 00 09
discardExact(1)//0x01 discardExact(1)//0x01
val raw = readLVByteArray() val raw = readLVByteArray()
//TODO 这应该是手机发送时的字体或气泡之类的
println("parseLongText0x19.raw=${raw.toUHexString()}") println("parseLongText0x19.raw=${raw.toUHexString()}")
return PlainText(raw.toUHexString()) return PlainText("")
} }
internal fun IoBuffer.parseMessageImage0x06(): Image { internal fun IoBuffer.parseMessageImage0x06(): Image {
...@@ -100,6 +101,8 @@ internal fun ByteReadPacket.readMessage(): Message? { ...@@ -100,6 +101,8 @@ internal fun ByteReadPacket.readMessage(): Message? {
println("0x14的未知压缩的data=" + value.toUHexString()) println("0x14的未知压缩的data=" + value.toUHexString())
//todo 未知压缩算法 //todo 未知压缩算法
return PlainText("")
//后面似乎还有一节? //后面似乎还有一节?
//discardExact(7)//02 00 04 00 00 00 23 //discardExact(7)//02 00 04 00 00 00 23
return PlainText(value.toUHexString()) return PlainText(value.toUHexString())
......
...@@ -8,4 +8,6 @@ dependencies { ...@@ -8,4 +8,6 @@ dependencies {
compile group: 'com.alibaba', name: 'fastjson', version: '1.2.62' compile group: 'com.alibaba', name: 'fastjson', version: '1.2.62'
implementation 'org.jsoup:jsoup:1.12.1' implementation 'org.jsoup:jsoup:1.12.1'
implementation files('./lib/ExImageGallery.jar')
} }
package demo.gentleman package demo.gentleman
import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.*
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.launch import net.mamoe.ex.content.RandomAccessHDImage
import net.mamoe.ex.network.ExNetwork
import net.mamoe.ex.network.connections.defaults.DownloadHDImageStreamSpider
import net.mamoe.ex.network.connections.defaults.ExIPWhiteListSpider
import net.mamoe.mirai.contact.Contact import net.mamoe.mirai.contact.Contact
import net.mamoe.mirai.contact.Group
import net.mamoe.mirai.contact.QQ
import net.mamoe.mirai.message.sendTo
import net.mamoe.mirai.message.uploadImage
import net.mamoe.robot.AsyncTaskPool
import java.io.Closeable
import java.io.InputStream
import java.util.*
import java.util.concurrent.ExecutionException
import java.util.concurrent.Future
/** /**
...@@ -23,6 +36,104 @@ object Gentlemen : MutableMap<UInt, Gentleman> by mutableMapOf() { ...@@ -23,6 +36,104 @@ object Gentlemen : MutableMap<UInt, Gentleman> by mutableMapOf() {
fun getOrPut(key: Contact): Gentleman = this.getOrPut(key.id) { Gentleman(key) } fun getOrPut(key: Contact): Gentleman = this.getOrPut(key.id) { Gentleman(key) }
} }
private val sessionMap = LinkedHashMap<Long, HPictureSession>()
val ERROR_LINK = "https://i.loli.net/2019/08/05/usINjXSiZxrQJkT.jpg"
val TITLE_PICTURE_LINK = "https://i.loli.net/2019/08/04/B5ZMw1rdzVQI7Yv.jpg"
var minstar = 100
class HPictureSession constructor(private val group: Group, private val sender: QQ, val keyword: String) : Closeable {
private var hdImage: RandomAccessHDImage? = null
var sentCount: Int = 0
set(sentCount) {
field = this.sentCount
}//已经发送了几个 ImageSet
private var fetchTask: Future<RandomAccessHDImage>? = null
init {
AsyncTaskPool.submit {
try {
Thread.sleep((1000 * 60 * 10).toLong())//10min
} catch (ignored: InterruptedException) {
}
close()
}
}
init {
GlobalScope.launch { reloadImage() }
}
private suspend fun reloadImage() {
if (keyword.isEmpty()) {
group.sendMessage("正在搜寻随机色图")
} else {
group.sendMessage("正在搜寻有关 $keyword 的色图")
}
try {
withContext(IO) {
if (!ExNetwork.doSpider(ExIPWhiteListSpider()).get()) {
group.sendMessage("无法连接EX")
close()
return@withContext
}
}
} catch (e: InterruptedException) {
e.printStackTrace()
close()
return
} catch (e: ExecutionException) {
e.printStackTrace()
close()
return
}
this.fetchTask = ExNetwork.getRandomImage(keyword, minstar) { value ->
this.hdImage = value
if (this.hdImage == null) {
runBlocking { group.sendMessage("没找到") }
close()
} else {
with(this.hdImage!!) {
if (this.picId != null) {
runBlocking {
group.sendMessage(picId)
}
} else {
AsyncTaskPool.submit {
try {
runBlocking {
group.uploadImage(ExNetwork.doSpider(DownloadHDImageStreamSpider(this@with)).get() as InputStream).sendTo(group)
}
} catch (var7: Exception) {
var7.printStackTrace()
}
}
}
}
}
}
}
override fun close() {
this.hdImage = null
if (this.fetchTask != null) {
if (!this.fetchTask!!.isCancelled && !this.fetchTask!!.isDone) {
this.fetchTask!!.cancel(true)
}
}
this.fetchTask = null
sessionMap.entries.removeIf { longHPictureSessionEntry -> longHPictureSessionEntry.value === this }
}
}
@ExperimentalCoroutinesApi @ExperimentalCoroutinesApi
class Gentleman(private val contact: Contact) : Channel<GentleImage> by Channel(IMAGE_BUFFER_CAPACITY) { class Gentleman(private val contact: Contact) : Channel<GentleImage> by Channel(IMAGE_BUFFER_CAPACITY) {
init { init {
...@@ -30,7 +141,7 @@ class Gentleman(private val contact: Contact) : Channel<GentleImage> by Channel( ...@@ -30,7 +141,7 @@ class Gentleman(private val contact: Contact) : Channel<GentleImage> by Channel(
GlobalScope.launch { GlobalScope.launch {
while (!isClosedForSend) { while (!isClosedForSend) {
send(GentleImage().apply { send(GentleImage().apply {
sample_url = "http://dev.itxtech.org:10322/randomImg.uue?tdsourcetag=s_pctim_aiomsg" sample_url = "http://dev.itxtech.org:10322/randomImg.uue?tdsourcetag=s_pctim_aiomsg&size=large"
contact = this@Gentleman.contact contact = this@Gentleman.contact
image.await() image.await()
......
...@@ -2,12 +2,14 @@ ...@@ -2,12 +2,14 @@
package demo.gentleman package demo.gentleman
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import net.mamoe.mirai.Bot import net.mamoe.mirai.Bot
import net.mamoe.mirai.BotAccount import net.mamoe.mirai.BotAccount
import net.mamoe.mirai.event.subscribeGroupMessages
import net.mamoe.mirai.event.subscribeMessages import net.mamoe.mirai.event.subscribeMessages
import net.mamoe.mirai.login import net.mamoe.mirai.login
import net.mamoe.mirai.message.Image
import net.mamoe.mirai.message.ImageId
import net.mamoe.mirai.network.protocol.tim.packet.login.requireSuccess import net.mamoe.mirai.network.protocol.tim.packet.login.requireSuccess
import java.io.File import java.io.File
...@@ -37,17 +39,30 @@ suspend fun main() { ...@@ -37,17 +39,30 @@ suspend fun main() {
bot.subscribeMessages { bot.subscribeMessages {
"你好" reply "你好!" "你好" reply "你好!"
startsWith("发送图片", removePrefix = true) { startsWith("随机色图", removePrefix = true) {
reply(Image(ImageId(it))) withContext(Dispatchers.Default) {
try {
repeat(it.toIntOrNull() ?: 1) {
launch {
Gentlemen.getOrPut(subject).receive().image.await().send()
}
}
} catch (e: Exception) {
reply(e.message ?: "exception: null")
}
}
} }
case("随机色图") { }
Gentlemen.getOrPut(subject).receive().image.await().send()
}
"色图" caseReply { bot.subscribeGroupMessages {
startsWith("色图", removePrefix = true) {
HPictureSession(group, sender, it)
}
"" startsWith("minstar=", removePrefix = true) {
minstar = it.toInt()
reply("minStar set to $minstar")
} }
} }
......
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