Commit df56c86f authored by Him188's avatar Him188

Fix build

parent aa0bf81a
...@@ -5,6 +5,7 @@ import android.net.wifi.WifiManager ...@@ -5,6 +5,7 @@ import android.net.wifi.WifiManager
import android.os.Build import android.os.Build
import android.telephony.TelephonyManager import android.telephony.TelephonyManager
import kotlinx.io.core.toByteArray import kotlinx.io.core.toByteArray
import net.mamoe.mirai.utils.Context
import net.mamoe.mirai.utils.localIpAddress import net.mamoe.mirai.utils.localIpAddress
import net.mamoe.mirai.utils.md5 import net.mamoe.mirai.utils.md5
import java.io.File import java.io.File
......
...@@ -11,6 +11,6 @@ class SyncCookie( ...@@ -11,6 +11,6 @@ class SyncCookie(
@SerialId(4) val unknown2: Long = 3497826378, @SerialId(4) val unknown2: Long = 3497826378,
@SerialId(5) val const1: Long = 1680172298, @SerialId(5) val const1: Long = 1680172298,
@SerialId(6) val const2: Long = 2424173273, @SerialId(6) val const2: Long = 2424173273,
@SerialId(7) val unknown3: Long = 83, @SerialId(7) val unknown3: Long = 0,
@SerialId(8) val unknown4: Long = 0 @SerialId(8) val unknown4: Long = 0
) : ProtoBuf ) : ProtoBuf
\ No newline at end of file
...@@ -27,7 +27,6 @@ import net.mamoe.mirai.qqandroid.utils.toRichTextElems ...@@ -27,7 +27,6 @@ import net.mamoe.mirai.qqandroid.utils.toRichTextElems
import net.mamoe.mirai.utils.cryptor.contentToString import net.mamoe.mirai.utils.cryptor.contentToString
import net.mamoe.mirai.utils.currentTimeSeconds import net.mamoe.mirai.utils.currentTimeSeconds
import net.mamoe.mirai.utils.io.hexToBytes import net.mamoe.mirai.utils.io.hexToBytes
import net.mamoe.mirai.utils.io.toReadPacket
import kotlin.math.absoluteValue import kotlin.math.absoluteValue
import kotlin.random.Random import kotlin.random.Random
...@@ -61,8 +60,8 @@ internal class MessageSvc { ...@@ -61,8 +60,8 @@ internal class MessageSvc {
client: QQAndroidClient, client: QQAndroidClient,
msgTime: Long //PbPushMsg.msg.msgHead.msgTime msgTime: Long //PbPushMsg.msg.msgHead.msgTime
): OutgoingPacket = buildOutgoingUniPacket( ): OutgoingPacket = buildOutgoingUniPacket(
client, client//,
extraData = EXTRA_DATA.toReadPacket() // extraData = EXTRA_DATA.toReadPacket()
) { ) {
writeProtoBuf( writeProtoBuf(
MsgSvc.PbGetMsgReq.serializer(), MsgSvc.PbGetMsgReq.serializer(),
......
...@@ -24,4 +24,10 @@ object TIMPC : BotFactory { ...@@ -24,4 +24,10 @@ object TIMPC : BotFactory {
* 使用指定的 [配置][configuration] 构造 [Bot] 实例 * 使用指定的 [配置][configuration] 构造 [Bot] 实例
*/ */
fun Bot(qq: Long, password: String, configuration: BotConfiguration = BotConfiguration.Default): Bot = TIMPCBot(BotAccount(qq, password), configuration) fun Bot(qq: Long, password: String, configuration: BotConfiguration = BotConfiguration.Default): Bot = TIMPCBot(BotAccount(qq, password), configuration)
} }
\ No newline at end of file
/**
* 使用指定的 [配置][configuration] 构造 [Bot] 实例
*/
inline fun TIMPC.Bot(qq: Long, password: String, configuration: (BotConfiguration.() -> Unit)): Bot =
this.Bot(qq, password, BotConfiguration().apply(configuration))
\ No newline at end of file
...@@ -91,7 +91,7 @@ internal class TIMPCBotNetworkHandler internal constructor(coroutineContext: Cor ...@@ -91,7 +91,7 @@ internal class TIMPCBotNetworkHandler internal constructor(coroutineContext: Cor
heartbeatJob?.join() heartbeatJob?.join()
} }
override fun dispose(cause: Throwable?) { override fun close(cause: Throwable?) {
super.close(cause) super.close(cause)
this.heartbeatJob?.cancel(CancellationException("handler closed")) this.heartbeatJob?.cancel(CancellationException("handler closed"))
...@@ -312,6 +312,7 @@ internal class TIMPCBotNetworkHandler internal constructor(coroutineContext: Cor ...@@ -312,6 +312,7 @@ internal class TIMPCBotNetworkHandler internal constructor(coroutineContext: Cor
else -> error("No decrypter is found") else -> error("No decrypter is found")
} as? D ?: error("Internal error: could not cast decrypter which is found for factory to class Decrypter") } as? D ?: error("Internal error: could not cast decrypter which is found for factory to class Decrypter")
@UseExperimental(MiraiInternalAPI::class)
suspend fun onPacketReceived(packet: Any) {//complex function, but it doesn't matter suspend fun onPacketReceived(packet: Any) {//complex function, but it doesn't matter
when (packet) { when (packet) {
is TouchPacket.TouchResponse.OK -> { is TouchPacket.TouchResponse.OK -> {
......
...@@ -4,6 +4,7 @@ package net.mamoe.mirai ...@@ -4,6 +4,7 @@ package net.mamoe.mirai
import net.mamoe.mirai.utils.BotConfiguration import net.mamoe.mirai.utils.BotConfiguration
import net.mamoe.mirai.utils.Context import net.mamoe.mirai.utils.Context
import net.mamoe.mirai.utils.ContextImpl
// Do not use ServiceLoader. Probably not working on MPP // Do not use ServiceLoader. Probably not working on MPP
@PublishedApi @PublishedApi
...@@ -41,4 +42,17 @@ fun Bot(context: Context, qq: Long, password: String, configuration: BotConfigur ...@@ -41,4 +42,17 @@ fun Bot(context: Context, qq: Long, password: String, configuration: BotConfigur
* 加载现有协议的 [BotFactory], 并使用指定的 [配置][configuration] 构造 [Bot] 实例 * 加载现有协议的 [BotFactory], 并使用指定的 [配置][configuration] 构造 [Bot] 实例
*/ */
inline fun Bot(context: Context, qq: Long, password: String, configuration: (BotConfiguration.() -> Unit)): Bot = inline fun Bot(context: Context, qq: Long, password: String, configuration: (BotConfiguration.() -> Unit)): Bot =
factory.Bot(context, qq, password, configuration) factory.Bot(context, qq, password, configuration)
\ No newline at end of file
/**
* 加载现有协议的 [BotFactory], 并使用指定的 [配置][configuration] 构造 [Bot] 实例
*/
fun Bot(qq: Long, password: String, configuration: BotConfiguration = BotConfiguration.Default): Bot =
factory.Bot(ContextImpl(), qq, password, configuration)
/**
* 加载现有协议的 [BotFactory], 并使用指定的 [配置][configuration] 构造 [Bot] 实例
*/
inline fun Bot(qq: Long, password: String, configuration: (BotConfiguration.() -> Unit)): Bot =
factory.Bot(ContextImpl(), qq, password, configuration)
\ No newline at end of file
...@@ -17,6 +17,7 @@ import net.mamoe.mirai.message.data.ImageId ...@@ -17,6 +17,7 @@ import net.mamoe.mirai.message.data.ImageId
import net.mamoe.mirai.message.data.PlainText import net.mamoe.mirai.message.data.PlainText
import net.mamoe.mirai.message.data.firstOrNull import net.mamoe.mirai.message.data.firstOrNull
import net.mamoe.mirai.message.sendAsImageTo import net.mamoe.mirai.message.sendAsImageTo
import net.mamoe.mirai.timpc.Bot
import net.mamoe.mirai.timpc.TIMPC import net.mamoe.mirai.timpc.TIMPC
import net.mamoe.mirai.utils.suspendToExternalImage import net.mamoe.mirai.utils.suspendToExternalImage
import java.io.File import java.io.File
...@@ -39,10 +40,8 @@ private fun readTestAccount(): BotAccount? { ...@@ -39,10 +40,8 @@ private fun readTestAccount(): BotAccount? {
@Suppress("UNUSED_VARIABLE") @Suppress("UNUSED_VARIABLE")
suspend fun main() { suspend fun main() {
val bot = TIMPC.Bot( // JVM 下也可以不写 `TIMPC.` 引用顶层函数 val bot = TIMPC.Bot( // JVM 下也可以不写 `TIMPC.` 引用顶层函数
readTestAccount() ?: BotAccount(//填写你的账号 1994701121,
id = 1994701121, "123456"
passwordPlainText = "123456"
)
) { ) {
// 覆盖默认的配置 // 覆盖默认的配置
randomDeviceName = false randomDeviceName = false
...@@ -134,6 +133,7 @@ fun Bot.messageDSL() { ...@@ -134,6 +133,7 @@ fun Bot.messageDSL() {
reply(message) reply(message)
} }
listener.complete() // 停止监听
// 自定义的 filter, filter 中 it 为转为 String 的消息. // 自定义的 filter, filter 中 it 为转为 String 的消息.
// 也可以用任何能在处理时使用的变量, 如 subject, sender, message // 也可以用任何能在处理时使用的变量, 如 subject, sender, message
......
...@@ -14,6 +14,7 @@ import kotlinx.io.core.IoBuffer ...@@ -14,6 +14,7 @@ import kotlinx.io.core.IoBuffer
import kotlinx.io.core.readBytes import kotlinx.io.core.readBytes
import net.mamoe.mirai.Bot import net.mamoe.mirai.Bot
import net.mamoe.mirai.event.subscribeMessages import net.mamoe.mirai.event.subscribeMessages
import net.mamoe.mirai.timpc.Bot
import net.mamoe.mirai.timpc.TIMPC import net.mamoe.mirai.timpc.TIMPC
import net.mamoe.mirai.utils.LoginFailedException import net.mamoe.mirai.utils.LoginFailedException
import net.mamoe.mirai.utils.LoginSolver import net.mamoe.mirai.utils.LoginSolver
......
...@@ -8,7 +8,6 @@ import kotlinx.coroutines.delay ...@@ -8,7 +8,6 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import net.mamoe.mirai.Bot import net.mamoe.mirai.Bot
import net.mamoe.mirai.BotAccount
import net.mamoe.mirai.alsoLogin import net.mamoe.mirai.alsoLogin
import net.mamoe.mirai.contact.MemberPermission import net.mamoe.mirai.contact.MemberPermission
import net.mamoe.mirai.event.Subscribable import net.mamoe.mirai.event.Subscribable
...@@ -23,32 +22,18 @@ import net.mamoe.mirai.message.data.Image ...@@ -23,32 +22,18 @@ import net.mamoe.mirai.message.data.Image
import net.mamoe.mirai.message.data.buildXMLMessage import net.mamoe.mirai.message.data.buildXMLMessage
import net.mamoe.mirai.message.data.getValue import net.mamoe.mirai.message.data.getValue
import net.mamoe.mirai.message.sendAsImageTo import net.mamoe.mirai.message.sendAsImageTo
import net.mamoe.mirai.utils.ContextImpl
import java.io.File import java.io.File
import java.util.* import java.util.*
import javax.swing.filechooser.FileSystemView import javax.swing.filechooser.FileSystemView
import kotlin.random.Random import kotlin.random.Random
private fun readTestAccount(): BotAccount? {
val file = File("testAccount.txt")
if (!file.exists() || !file.canRead()) {
return null
}
val lines = file.readLines()
return try {
BotAccount(lines[0].toLong(), lines[1])
} catch (e: Throwable) {
null
}
}
@Suppress("UNUSED_VARIABLE") @Suppress("UNUSED_VARIABLE")
suspend fun main() { suspend fun main() {
val bot = Bot( val bot = Bot(
readTestAccount() ?: BotAccount( ContextImpl(),
id = 913366033, 913366033,
passwordPlainText = "a18260132383" "a18260132383"
)
) { ) {
// override config here. // override config here.
}.alsoLogin() }.alsoLogin()
......
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