Merge remote-tracking branch 'origin/master'

This commit is contained in:
Him188 2020-03-07 11:29:23 +08:00
commit 92504fc313
10 changed files with 102 additions and 28 deletions

40
.github/workflows/main2.yml vendored Normal file
View File

@ -0,0 +1,40 @@
# This is a basic workflow to help you get started with Actions
name: Shadow
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
release:
types:
- created
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle and shadowJar
run: ./gradlew :mirai-core:shadowJar :mirai-core-qqandroid:shadowJar
- name: Upload artifact
uses: actions/upload-artifact@v1.0.0
with:
# Artifact name
name: mirai-core-all
# Directory containing files to upload
path: "mirai-core/build/libs/mirai-core-*-all.jar"
- name: Upload artifact
uses: actions/upload-artifact@v1.0.0
with:
# Artifact name
name: mirai-core-qqandroid-all
# Directory containing files to upload
path: "mirai-core-qqandroid/build/libs/mirai-core-qqandroid-*-all.jar"

View File

@ -160,7 +160,7 @@ internal open class QQAndroidClient(
@UseExperimental(RawAccountIdUse::class)
@Suppress("PropertyName")
internal var _uin: Long = bot.account.id
internal var _uin: Long = bot.uin
var t530: ByteArray? = null
var t528: ByteArray? = null

View File

@ -54,12 +54,6 @@ actual abstract class Bot actual constructor() : CoroutineScope, LowLevelBotAPIA
*/
actual abstract val context: Context
/**
* 账号信息
*/
@MiraiInternalAPI
actual abstract val account: BotAccount
/**
* QQ 号码. 实际类型为 uint
*/

View File

@ -70,12 +70,6 @@ expect abstract class Bot() : CoroutineScope, LowLevelBotAPIAccessor {
*/
abstract val context: Context
/**
* 账号信息
*/
@MiraiInternalAPI
abstract val account: BotAccount
/**
* QQ 号码. 实际类型为 uint
*/

View File

@ -12,6 +12,7 @@
package net.mamoe.mirai
import io.ktor.utils.io.core.toByteArray
import net.mamoe.mirai.utils.MiraiExperimentalAPI
import net.mamoe.mirai.utils.MiraiInternalAPI
import net.mamoe.mirai.utils.md5
import kotlin.annotation.AnnotationTarget.*
@ -23,6 +24,8 @@ data class BotAccount(
*/
@RawAccountIdUse
val id: Long,
@MiraiExperimentalAPI
@MiraiInternalAPI
val passwordMd5: ByteArray // md5
) {
constructor(id: Long, passwordPlainText: String) : this(id, md5(passwordPlainText.toByteArray()))

View File

@ -7,7 +7,7 @@
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
@file:Suppress("EXPERIMENTAL_API_USAGE")
@file:Suppress("EXPERIMENTAL_API_USAGE", "DEPRECATION_ERROR")
package net.mamoe.mirai
@ -40,12 +40,13 @@ abstract class BotImpl<N : BotNetworkHandler> constructor(
?: CoroutineExceptionHandler { _, e -> logger.error("An exception was thrown under a coroutine of Bot", e) })
override val context: Context by context.unsafeWeakRef()
@Suppress("CanBePrimaryConstructorProperty") // for logger
@UseExperimental(LowLevelAPI::class)
@Suppress("CanBePrimaryConstructorProperty", "OverridingDeprecatedMember") // for logger
final override val account: BotAccount = account
@UseExperimental(RawAccountIdUse::class)
override val uin: Long
get() = account.id
get() = this.account.id
final override val logger: MiraiLogger by lazy { configuration.botLoggerSupplier(this) }
init {

View File

@ -17,6 +17,7 @@ import net.mamoe.mirai.data.GroupInfo
import net.mamoe.mirai.data.MemberInfo
import net.mamoe.mirai.message.data.MessageSource
import net.mamoe.mirai.utils.MiraiExperimentalAPI
import net.mamoe.mirai.utils.MiraiInternalAPI
import net.mamoe.mirai.utils.WeakRef
/**
@ -37,6 +38,14 @@ annotation class LowLevelAPI
@Suppress("FunctionName", "unused")
@LowLevelAPI
interface LowLevelBotAPIAccessor {
/**
* 账号信息
*/
@Deprecated("将来会做修改", level = DeprecationLevel.ERROR)
@MiraiExperimentalAPI
@LowLevelAPI
@MiraiInternalAPI
abstract val account: BotAccount
/**
* 构造一个 [_lowLevelNewQQ] 对象. 它持有对 [Bot] 的弱引用([WeakRef]).

View File

@ -58,4 +58,8 @@ class CombinedMessage(
override fun toString(): String {
return element.toString() + left.toString()
}
fun isFlat(): Boolean {
return element is SingleMessage && left is SingleMessage
}
}

View File

@ -61,7 +61,7 @@ interface MessageChain : Message, Iterable<SingleMessage> {
fun <M : Message> getOrNull(key: Message.Key<M>): M? = firstOrNull(key)
/**
* 遍历每一个有内容的消息, [At], [AtAll], [PlainText], [Image], [Face], [XMLMessage].
* 遍历每一个有内容的消息, [At], [AtAll], [PlainText], [Image], [Face], [XMLMessage], [QuoteReply].
* 仅供 `Java` 使用
*/
@Suppress("FunctionName", "INAPPLICABLE_JVM_NAME")
@ -71,13 +71,26 @@ interface MessageChain : Message, Iterable<SingleMessage> {
fun `__forEachContent for Java__`(block: (Message) -> Unit) {
this.foreachContent(block)
}
/**
* 遍历每一个消息, [MessageSource] [At], [AtAll], [PlainText], [Image], [Face], [XMLMessage], [QuoteReply].
* 仅供 `Java` 使用
*/
@Suppress("FunctionName", "INAPPLICABLE_JVM_NAME")
@JsName("forEach")
@JvmName("forEach")
@MiraiInternalAPI
fun `__forEach for Java__`(block: (Message) -> Unit) {
this.forEach(block)
}
}
// region accessors
/**
* 遍历每一个有内容的消息, [At], [AtAll], [PlainText], [Image], [Face], [XMLMessage]
* 遍历每一个有内容的消息, [At], [AtAll], [PlainText], [Image], [Face], [XMLMessage], [QuoteReply]
*/
@JvmSynthetic
inline fun MessageChain.foreachContent(block: (Message) -> Unit) {
this.forEach {
if (it !is MessageMetadata) block(it)
@ -87,23 +100,27 @@ inline fun MessageChain.foreachContent(block: (Message) -> Unit) {
/**
* 获取第一个 [M] 类型的 [Message] 实例
*/
@JvmSynthetic
inline fun <reified M : Message?> MessageChain.firstOrNull(): M? = this.firstOrNull { it is M } as M?
/**
* 获取第一个 [M] 类型的 [Message] 实例
* @throws [NoSuchElementException] 如果找不到该类型的实例
*/
@JvmSynthetic
inline fun <reified M : Message> MessageChain.first(): M = this.first { it is M } as M
/**
* 获取第一个 [M] 类型的 [Message] 实例
*/
@JvmSynthetic
inline fun <reified M : Message> MessageChain.any(): Boolean = this.any { it is M }
/**
* 获取第一个 [M] 类型的 [Message] 实例
*/
@JvmSynthetic
@Suppress("UNCHECKED_CAST")
fun <M : Message> MessageChain.firstOrNull(key: Message.Key<M>): M? = when (key) {
At -> first<At>()
@ -120,6 +137,7 @@ fun <M : Message> MessageChain.firstOrNull(key: Message.Key<M>): M? = when (key)
* 获取第一个 [M] 类型的 [Message] 实例
* @throws [NoSuchElementException] 如果找不到该类型的实例
*/
@JvmSynthetic
@Suppress("UNCHECKED_CAST")
fun <M : Message> MessageChain.first(key: Message.Key<M>): M =
firstOrNull(key) ?: throw NoSuchElementException("no such element: $key")
@ -127,6 +145,7 @@ fun <M : Message> MessageChain.first(key: Message.Key<M>): M =
/**
* 获取第一个 [M] 类型的 [Message] 实例
*/
@JvmSynthetic
@Suppress("UNCHECKED_CAST")
fun <M : Message> MessageChain.any(key: Message.Key<M>): Boolean = firstOrNull(key) != null
@ -211,9 +230,6 @@ fun Message.asMessageChain(): MessageChain = when (this) {
else -> SingleMessageChainImpl(this as SingleMessage)
}
@Deprecated("use asMessageChain instead", ReplaceWith("this.asMessageChain()"), DeprecationLevel.ERROR)
fun Message.toChain(): MessageChain = this.asMessageChain()
/**
* 直接将 [this] 委托为一个 [MessageChain]
*/
@ -233,8 +249,18 @@ fun Collection<Message>.asMessageChain(): MessageChain = MessageChainImplBySeque
@JvmSynthetic
fun Iterable<SingleMessage>.asMessageChain(): MessageChain = MessageChainImplByIterable(this)
@JvmSynthetic
inline fun MessageChain.asMessageChain(): MessageChain = this // 避免套娃
@JvmSynthetic
fun CombinedMessage.asMessageChain(): MessageChain {
if (left is SingleMessage && this.element is SingleMessage) {
@Suppress("UNCHECKED_CAST")
return (this as Iterable<SingleMessage>).asMessageChain()
}
return (this as Iterable<Message>).asMessageChain()
} // 避免套娃
/**
* [this] [扁平化后][flatten] 委托为一个 [MessageChain]
*/
@ -324,11 +350,20 @@ fun Sequence<SingleMessage>.flatten(): Sequence<SingleMessage> = this // fast pa
fun Message.flatten(): Sequence<SingleMessage> {
return when (this) {
is MessageChain -> this.asSequence()
is CombinedMessage -> this.asSequence().flatten()
is CombinedMessage -> this.flatten()
else -> sequenceOf(this as SingleMessage)
}
}
fun CombinedMessage.flatten(): Sequence<SingleMessage> {
if (this.isFlat()){
@Suppress("UNCHECKED_CAST")
return (this as Iterable<SingleMessage>).asSequence()
} else return this.asSequence().flatten()
}
fun MessageChain.flatten(): Sequence<SingleMessage> = this.asSequence() // fast path
// endregion converters
// region implementations

View File

@ -64,12 +64,6 @@ actual abstract class Bot actual constructor() : CoroutineScope, LowLevelBotAPIA
*/
actual abstract val context: Context
/**
* 账号信息
*/
@MiraiInternalAPI
actual abstract val account: BotAccount
/**
* QQ 号码. 实际类型为 uint
*/