Commit ead17724 authored by Him188's avatar Him188

update docs

parent e7725bdc
...@@ -83,14 +83,14 @@ interface Message { ...@@ -83,14 +83,14 @@ interface Message {
if (tail is MessageChain) tail.concat(this)/*MessageChainImpl(this).also { tail.forEach { child -> it.concat(child) } }*/ if (tail is MessageChain) tail.concat(this)/*MessageChainImpl(this).also { tail.forEach { child -> it.concat(child) } }*/
else MessageChainImpl(this, tail) else MessageChainImpl(this, tail)
infix operator fun plus(another: Message): MessageChain = this.concat(another) operator fun plus(another: Message): MessageChain = this.concat(another)
infix operator fun plus(another: String): MessageChain = this.concat(another.toMessage()) operator fun plus(another: String): MessageChain = this.concat(another.toMessage())
} }
/** /**
* 将 [this] 发送给指定联系人 * 将 [this] 发送给指定联系人
*/ */
suspend fun Message.sendTo(contact: Contact) = contact.sendMessage(this) suspend inline fun Message.sendTo(contact: Contact) = contact.sendMessage(this)
// endregion // endregion
// region PlainText // region PlainText
...@@ -172,7 +172,7 @@ inline class Face(val id: FaceID) : Message { ...@@ -172,7 +172,7 @@ inline class Face(val id: FaceID) : Message {
// region MessageChain // region MessageChain
// ==================================== MessageChain ==================================== // ==================================== MessageChain ====================================
// region constructors // region constructor functions
/** /**
* 构造无初始元素的可修改的 [MessageChain]. 初始大小将会被设定为 8 * 构造无初始元素的可修改的 [MessageChain]. 初始大小将会被设定为 8
*/ */
......
...@@ -5,8 +5,6 @@ package net.mamoe.mirai.network.protocol.tim.packet.action ...@@ -5,8 +5,6 @@ package net.mamoe.mirai.network.protocol.tim.packet.action
import kotlinx.io.core.* import kotlinx.io.core.*
import net.mamoe.mirai.message.MessageChain import net.mamoe.mirai.message.MessageChain
import net.mamoe.mirai.message.internal.toPacket import net.mamoe.mirai.message.internal.toPacket
import net.mamoe.mirai.message.toChain
import net.mamoe.mirai.message.toMessage
import net.mamoe.mirai.network.protocol.tim.TIMProtocol import net.mamoe.mirai.network.protocol.tim.TIMProtocol
import net.mamoe.mirai.network.protocol.tim.packet.OutgoingPacket import net.mamoe.mirai.network.protocol.tim.packet.OutgoingPacket
import net.mamoe.mirai.network.protocol.tim.packet.PacketId import net.mamoe.mirai.network.protocol.tim.packet.PacketId
...@@ -15,10 +13,6 @@ import net.mamoe.mirai.network.protocol.tim.packet.ResponsePacket ...@@ -15,10 +13,6 @@ import net.mamoe.mirai.network.protocol.tim.packet.ResponsePacket
import net.mamoe.mirai.utils.io.* import net.mamoe.mirai.utils.io.*
import net.mamoe.mirai.utils.md5 import net.mamoe.mirai.utils.md5
fun main() {
println("牛逼".toMessage().toChain().toPacket(true).readBytes().toUHexString())
}
@PacketId(0x00_CDu) @PacketId(0x00_CDu)
@PacketVersion(date = "2019.10.19", timVersion = "2.3.2.21173") @PacketVersion(date = "2019.10.19", timVersion = "2.3.2.21173")
class SendFriendMessagePacket( class SendFriendMessagePacket(
......
...@@ -83,7 +83,10 @@ class LoginResponseSuccessPacket(input: ByteReadPacket) : ServerLoginResponsePac ...@@ -83,7 +83,10 @@ class LoginResponseSuccessPacket(input: ByteReadPacket) : ServerLoginResponsePac
discardExact(60)//00 20 01 60 C5 A1 39 7A 12 8E BC 34 C3 56 70 E3 1A ED 20 67 ED A9 DB 06 C1 70 81 3C 01 69 0D FF 63 DA 00 00 01 03 00 14 00 01 00 10 60 C9 5D A7 45 70 04 7F 21 7D 84 50 5C 66 A5 C6 discardExact(60)//00 20 01 60 C5 A1 39 7A 12 8E BC 34 C3 56 70 E3 1A ED 20 67 ED A9 DB 06 C1 70 81 3C 01 69 0D FF 63 DA 00 00 01 03 00 14 00 01 00 10 60 C9 5D A7 45 70 04 7F 21 7D 84 50 5C 66 A5 C6
discardExact(when (readUByte().toUInt()) { discardExact(when (readUByte().toUInt()) {
0x00u -> if (readUByte().toUInt() == 0x33u) 28 else null 0x00u -> when (readUByte().toUInt()) {
0x33u -> 28
else -> null
}
0x01u -> when (readUByte().toUInt()) { 0x01u -> when (readUByte().toUInt()) {
0x07u -> 0 0x07u -> 0
0x10u -> 64 0x10u -> 64
......
...@@ -75,7 +75,7 @@ suspend fun ExternalImage.upload(contact: Contact): Image = when (contact) { ...@@ -75,7 +75,7 @@ suspend fun ExternalImage.upload(contact: Contact): Image = when (contact) {
/** /**
* 将图片发送给 [this] * 将图片发送给 [this]
*/ */
suspend fun Contact.sendImage(image: ExternalImage) = image.sendTo(this) suspend inline fun Contact.sendImage(image: ExternalImage) = image.sendTo(this)
private operator fun ByteArray.get(range: IntRange): String = buildString { private operator fun ByteArray.get(range: IntRange): String = buildString {
range.forEach { range.forEach {
......
package demo.gentleman package demo.gentleman
import kotlinx.coroutines.* import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.channels.Channel
import net.mamoe.ex.content.RandomAccessHDImage import kotlinx.coroutines.launch
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
/** /**
...@@ -37,103 +24,6 @@ object Gentlemen : MutableMap<UInt, Gentleman> by mutableMapOf() { ...@@ -37,103 +24,6 @@ object Gentlemen : MutableMap<UInt, Gentleman> by mutableMapOf() {
} }
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 {
...@@ -180,14 +70,3 @@ class Gentleman(private val contact: Contact) : Channel<GentleImage> by Channel( ...@@ -180,14 +70,3 @@ class Gentleman(private val contact: Contact) : Channel<GentleImage> by Channel(
} }
} }
} }
\ No newline at end of file
object ForbiddenKeyWords : List<String> by listOf(
"miku",
"vocaloid",
"kuriyama",
"mirai"
) {
override fun contains(element: String): Boolean {
return this.stream().anyMatch { element.contains(it, ignoreCase = true) }
}
}
\ No newline at end of file
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