Merge remote-tracking branch 'origin/explicit-api' into dev

# Conflicts:
#	gradle.properties
This commit is contained in:
Him188 2020-07-29 23:59:19 +08:00
commit 1a81fbd794
98 changed files with 2028 additions and 1939 deletions

View File

@ -16,8 +16,8 @@ buildscript {
dependencies {
classpath("com.github.jengelman.gradle.plugins:shadow:5.2.0")
classpath("com.android.tools.build:gradle:${Versions.Android.androidGradlePlugin}")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.Kotlin.stdlib}")
classpath("org.jetbrains.kotlin:kotlin-serialization:${Versions.Kotlin.stdlib}")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.Kotlin.compiler}")
classpath("org.jetbrains.kotlin:kotlin-serialization:${Versions.Kotlin.compiler}")
classpath("org.jetbrains.kotlinx:atomicfu-gradle-plugin:${Versions.Kotlin.atomicFU}")
classpath("org.jetbrains.kotlinx:binary-compatibility-validator:${Versions.Kotlin.binaryValidator}")
}

View File

@ -13,6 +13,7 @@ object Versions {
}
object Kotlin {
const val compiler = "1.4-M3"
const val stdlib = "1.3.72"
const val coroutines = "1.3.7"
const val atomicFU = "0.14.2"
@ -41,4 +42,4 @@ object Versions {
fun kotlinx(id: String, version: String) = "org.jetbrains.kotlinx:kotlinx-$id:$version"
@Suppress("unused")
fun ktor(id: String, version: String) = "io.ktor:ktor-$id:$version"
fun ktor(id: String, version: String = Versions.Kotlin.ktor) = "io.ktor:ktor-$id:$version"

View File

@ -21,7 +21,7 @@ kotlin {
main {
dependencies {
api(kotlin("stdlib"))
api(kotlin("stdlib", Versions.Kotlin.stdlib))
runtimeOnly(project(":mirai-core-qqandroid"))
compileOnly("net.mamoe:mirai-core-qqandroid:0.38.0")
}
@ -29,7 +29,7 @@ kotlin {
test {
dependencies {
api(kotlin("stdlib"))
api(kotlin("stdlib", Versions.Kotlin.stdlib))
api(kotlin("test"))
api(kotlin("test-junit"))
runtimeOnly(project(":mirai-core-qqandroid"))

View File

@ -5,3 +5,5 @@ kotlin.incremental.multiplatform=true
kotlin.parallel.tasks.in.project=true
org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=512m -Dfile.encoding=UTF-8
org.gradle.parallel=true
#kotlin.mpp.enableGranularSourceSetsMetadata=true

View File

@ -21,14 +21,14 @@ kotlin {
main {
dependencies {
api(kotlin("stdlib"))
api(kotlin("stdlib", Versions.Kotlin.stdlib))
api(project(":mirai-core-qqandroid"))
}
}
test {
dependencies {
api(kotlin("stdlib"))
api(kotlin("stdlib", Versions.Kotlin.stdlib))
api(kotlin("test"))
api(kotlin("test-junit"))
api(project(":mirai-core-qqandroid"))

View File

@ -36,7 +36,7 @@ kotlin {
jvm("jvm") {
}
sourceSets {
sourceSets.apply {
all {
languageSettings.enableLanguageFeature("InlineClasses")
languageSettings.useExperimentalAnnotation("kotlin.Experimental")
@ -47,6 +47,10 @@ kotlin {
languageSettings.useExperimentalAnnotation("kotlin.experimental.ExperimentalTypeInference")
languageSettings.useExperimentalAnnotation("kotlin.time.ExperimentalTime")
languageSettings.useExperimentalAnnotation("kotlin.contracts.ExperimentalContracts")
languageSettings.languageVersion = "1.3"
languageSettings.apiVersion = "1.3"
languageSettings.progressiveMode = true
dependencies {
@ -83,8 +87,8 @@ kotlin {
val androidTest by getting {
dependencies {
implementation(kotlin("test", Versions.Kotlin.stdlib))
implementation(kotlin("test-junit", Versions.Kotlin.stdlib))
implementation(kotlin("test", Versions.Kotlin.compiler))
implementation(kotlin("test-junit", Versions.Kotlin.compiler))
implementation(kotlin("test-annotations-common"))
implementation(kotlin("test-common"))
}
@ -105,8 +109,8 @@ kotlin {
val jvmTest by getting {
dependencies {
dependsOn(commonTest)
implementation(kotlin("test", Versions.Kotlin.stdlib))
implementation(kotlin("test-junit", Versions.Kotlin.stdlib))
implementation(kotlin("test", Versions.Kotlin.compiler))
implementation(kotlin("test-junit", Versions.Kotlin.compiler))
implementation("org.pcap4j:pcap4j-distribution:1.8.2")
runtimeOnly(files("build/classes/kotlin/jvm/main")) // classpath is not properly set by IDE

View File

@ -14,6 +14,8 @@ description = "Mirai API module"
val isAndroidSDKAvailable: Boolean by project
kotlin {
explicitApi()
if (isAndroidSDKAvailable) {
apply(from = rootProject.file("gradle/android.gradle"))
android("android") {
@ -38,7 +40,7 @@ kotlin {
// withJava() // https://youtrack.jetbrains.com/issue/KT-39991
}
sourceSets {
sourceSets.apply {
all {
languageSettings.enableLanguageFeature("InlineClasses")
languageSettings.useExperimentalAnnotation("kotlin.Experimental")
@ -49,12 +51,16 @@ kotlin {
languageSettings.useExperimentalAnnotation("kotlin.experimental.ExperimentalTypeInference")
languageSettings.useExperimentalAnnotation("kotlin.time.ExperimentalTime")
languageSettings.useExperimentalAnnotation("kotlin.contracts.ExperimentalContracts")
languageSettings.languageVersion = "1.3"
languageSettings.apiVersion = "1.3"
languageSettings.progressiveMode = true
}
commonMain {
val commonMain by getting {
dependencies {
api(kotlin("stdlib"))
api(kotlin("stdlib", Versions.Kotlin.stdlib))
api(kotlin("serialization"))
api(kotlin("reflect"))
@ -66,11 +72,12 @@ kotlin {
api("org.jetbrains.kotlinx:atomicfu-common:${Versions.Kotlin.atomicFU}")
api(ktor("client-cio", Versions.Kotlin.ktor))
api(ktor("client-core", Versions.Kotlin.ktor))
api(ktor("network", Versions.Kotlin.ktor))
api(ktor("client-cio"))
api(ktor("client-core"))
api(ktor("network"))
}
}
commonTest {
dependencies {
implementation(kotlin("test-annotations-common"))

View File

@ -9,7 +9,7 @@
@file:Suppress(
"EXPERIMENTAL_API_USAGE", "unused", "FunctionName", "NOTHING_TO_INLINE", "UnusedImport",
"EXPERIMENTAL_OVERRIDE"
"EXPERIMENTAL_OVERRIDE", "CanBeParameter", "MemberVisibilityCanBePrivate"
)
package net.mamoe.mirai
@ -33,7 +33,7 @@ import kotlin.jvm.JvmSynthetic
* 登录, 返回 [this]
*/
@JvmSynthetic
suspend inline fun <B : Bot> B.alsoLogin(): B = also { login() }
public suspend inline fun <B : Bot> B.alsoLogin(): B = also { login() }
/**
* 机器人对象. 一个机器人实例登录一个 QQ 账号.
@ -47,10 +47,10 @@ suspend inline fun <B : Bot> B.alsoLogin(): B = also { login() }
* @see BotFactory 构造 [Bot] 的工厂, [Bot] 唯一的构造方式.
*/
@Suppress("INAPPLICABLE_JVM_NAME", "EXPOSED_SUPER_CLASS")
abstract class Bot internal constructor(
val configuration: BotConfiguration
public abstract class Bot internal constructor(
public val configuration: BotConfiguration
) : CoroutineScope, LowLevelBotAPIAccessor, BotJavaFriendlyAPI, ContactOrBot {
final override val coroutineContext: CoroutineContext = // for id
public final override val coroutineContext: CoroutineContext = // for id
configuration.parentCoroutineContext
.plus(SupervisorJob(configuration.parentCoroutineContext[Job]))
.plus(configuration.parentCoroutineContext[CoroutineExceptionHandler]
@ -61,22 +61,22 @@ abstract class Bot internal constructor(
.plus(CoroutineName("Mirai Bot"))
companion object {
public companion object {
@JvmField
@Suppress("ObjectPropertyName")
internal val _instances: LockFreeLinkedList<WeakRef<Bot>> = LockFreeLinkedList()
@PlannedRemoval("1.2.0")
@PlannedRemoval("2.0.0")
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
@JvmStatic
val instances: List<WeakRef<Bot>>
public val instances: List<WeakRef<Bot>>
get() = _instances.toList()
/**
* 复制一份此时的 [Bot] 实例列表.
*/
@JvmStatic
val botInstances: List<Bot>
public val botInstances: List<Bot>
get() = _instances.asSequence().mapNotNull { it.get() }.toList()
/**
@ -84,28 +84,28 @@ abstract class Bot internal constructor(
*/
@SinceMirai("1.1.0")
@JvmStatic
val botInstancesSequence: Sequence<Bot>
public val botInstancesSequence: Sequence<Bot>
get() = _instances.asSequence().mapNotNull { it.get() }
/**
* 遍历每一个 [Bot] 实例
*/
@JvmSynthetic
fun forEachInstance(block: (Bot) -> Unit) = _instances.forEach { it.get()?.let(block) }
public fun forEachInstance(block: (Bot) -> Unit): Unit = _instances.forEach { it.get()?.let(block) }
/**
* 获取一个 [Bot] 实例, 无对应实例时抛出 [NoSuchElementException]
*/
@JvmStatic
@Throws(NoSuchElementException::class)
fun getInstance(qq: Long): Bot =
public fun getInstance(qq: Long): Bot =
getInstanceOrNull(qq) ?: throw NoSuchElementException(qq.toString())
/**
* 获取一个 [Bot] 实例, 无对应实例时返回 `null`
*/
@JvmStatic
fun getInstanceOrNull(qq: Long): Bot? =
public fun getInstanceOrNull(qq: Long): Bot? =
_instances.asSequence().mapNotNull { it.get() }.firstOrNull { it.id == qq }
}
@ -123,28 +123,28 @@ abstract class Bot internal constructor(
* Android 实现为 `android.content.Context`
*/
@MiraiExperimentalAPI
abstract val context: Context
public abstract val context: Context
/**
* QQ 号码. 实际类型为 uint
*/
abstract override val id: Long
public abstract override val id: Long
/**
* 昵称
*/
abstract val nick: String
public abstract val nick: String
/**
* 日志记录器
*/
abstract val logger: MiraiLogger
public abstract val logger: MiraiLogger
/**
* 判断 Bot 是否在线 (可正常收发消息)
*/
@SinceMirai("1.0.1")
abstract val isOnline: Boolean
public abstract val isOnline: Boolean
// region contacts
@ -152,30 +152,32 @@ abstract class Bot internal constructor(
* [User.id] [Bot.id] 相同的 [_lowLevelNewFriend] 实例
*/
@MiraiExperimentalAPI
abstract val selfQQ: Friend
public abstract val selfQQ: Friend
/**
* 机器人的好友列表. 与服务器同步更新
*/
abstract val friends: ContactList<Friend>
public abstract val friends: ContactList<Friend>
/**
* 获取一个好友对象.
* @throws [NoSuchElementException] 当不存在这个好友时抛出
*/
fun getFriend(id: Long): Friend = friends.firstOrNull { it.id == id } ?: throw NoSuchElementException("friend $id")
public fun getFriend(id: Long): Friend =
friends.firstOrNull { it.id == id } ?: throw NoSuchElementException("friend $id")
/**
* 机器人加入的群列表. 与服务器同步更新
*/
abstract val groups: ContactList<Group>
public abstract val groups: ContactList<Group>
/**
* 获取一个机器人加入的群.
* @throws NoSuchElementException 当不存在这个群时抛出
*/
fun getGroup(id: Long): Group = groups.firstOrNull { it.id == id } ?: throw NoSuchElementException("group $id")
public fun getGroup(id: Long): Group =
groups.firstOrNull { it.id == id } ?: throw NoSuchElementException("group $id")
// endregion
@ -191,7 +193,7 @@ abstract class Bot internal constructor(
* @see alsoLogin `.apply { login() }` 捷径
*/
@JvmSynthetic
abstract suspend fun login()
public abstract suspend fun login()
// endregion
@ -212,7 +214,7 @@ abstract class Bot internal constructor(
* @see MessageSource.recall 撤回消息扩展
*/
@JvmSynthetic
abstract suspend fun recall(source: MessageSource)
public abstract suspend fun recall(source: MessageSource)
/**
* 获取图片下载链接
@ -226,7 +228,7 @@ abstract class Bot internal constructor(
level = DeprecationLevel.ERROR
)
@JvmSynthetic
abstract suspend fun queryImageUrl(image: Image): String
public abstract suspend fun queryImageUrl(image: Image): String
/**
* 构造一个 [OfflineMessageSource]
@ -238,7 +240,7 @@ abstract class Bot internal constructor(
* @param targetUin 为用户时为 [Friend.id], 为群时需使用 [Group.calculateGroupUinByGroupCode] 计算
*/
@MiraiExperimentalAPI("This is very experimental and is subject to change.")
abstract fun constructMessageSource(
public abstract fun constructMessageSource(
kind: OfflineMessageSource.Kind,
fromUin: Long, targetUin: Long,
id: Int, time: Int, internalId: Int,
@ -254,7 +256,7 @@ abstract class Bot internal constructor(
@PlannedRemoval("1.2.0")
@Deprecated("use member function.", replaceWith = ReplaceWith("event.accept()"), level = DeprecationLevel.ERROR)
@JvmSynthetic
abstract suspend fun acceptNewFriendRequest(event: NewFriendRequestEvent)
public abstract suspend fun acceptNewFriendRequest(event: NewFriendRequestEvent)
/**
* 拒绝好友验证
@ -269,7 +271,7 @@ abstract class Bot internal constructor(
level = DeprecationLevel.ERROR
)
@JvmSynthetic
abstract suspend fun rejectNewFriendRequest(event: NewFriendRequestEvent, blackList: Boolean = false)
public abstract suspend fun rejectNewFriendRequest(event: NewFriendRequestEvent, blackList: Boolean = false)
/**
* 通过加群验证需管理员权限
@ -279,7 +281,7 @@ abstract class Bot internal constructor(
@PlannedRemoval("1.2.0")
@Deprecated("use member function.", replaceWith = ReplaceWith("event.accept()"), level = DeprecationLevel.ERROR)
@JvmSynthetic
abstract suspend fun acceptMemberJoinRequest(event: MemberJoinRequestEvent)
public abstract suspend fun acceptMemberJoinRequest(event: MemberJoinRequestEvent)
/**
* 拒绝加群验证需管理员权限
@ -293,10 +295,14 @@ abstract class Bot internal constructor(
replaceWith = ReplaceWith("event.reject(blackList)"),
level = DeprecationLevel.HIDDEN
)
abstract suspend fun rejectMemberJoinRequest(event: MemberJoinRequestEvent, blackList: Boolean = false)
public abstract suspend fun rejectMemberJoinRequest(event: MemberJoinRequestEvent, blackList: Boolean = false)
@JvmSynthetic
abstract suspend fun rejectMemberJoinRequest(event: MemberJoinRequestEvent, blackList: Boolean = false, message: String = "")
public abstract suspend fun rejectMemberJoinRequest(
event: MemberJoinRequestEvent,
blackList: Boolean = false,
message: String = ""
)
/**
* 忽略加群验证需管理员权限
@ -311,7 +317,7 @@ abstract class Bot internal constructor(
level = DeprecationLevel.ERROR
)
@JvmSynthetic
abstract suspend fun ignoreMemberJoinRequest(event: MemberJoinRequestEvent, blackList: Boolean = false)
public abstract suspend fun ignoreMemberJoinRequest(event: MemberJoinRequestEvent, blackList: Boolean = false)
/**
* 接收邀请入群需管理员权限
@ -321,7 +327,7 @@ abstract class Bot internal constructor(
@PlannedRemoval("1.2.0")
@Deprecated("use member function.", replaceWith = ReplaceWith("event.accept()"), level = DeprecationLevel.ERROR)
@JvmSynthetic
abstract suspend fun acceptInvitedJoinGroupRequest(event: BotInvitedJoinGroupRequestEvent)
public abstract suspend fun acceptInvitedJoinGroupRequest(event: BotInvitedJoinGroupRequestEvent)
/**
* 忽略邀请入群需管理员权限
@ -331,7 +337,7 @@ abstract class Bot internal constructor(
@PlannedRemoval("1.2.0")
@Deprecated("use member function.", replaceWith = ReplaceWith("event.ignore()"), level = DeprecationLevel.ERROR)
@JvmSynthetic
abstract suspend fun ignoreInvitedJoinGroupRequest(event: BotInvitedJoinGroupRequestEvent)
public abstract suspend fun ignoreInvitedJoinGroupRequest(event: BotInvitedJoinGroupRequestEvent)
// endregion
@ -345,16 +351,16 @@ abstract class Bot internal constructor(
*
* @see closeAndJoin 取消并 [Bot.join], 以确保 [Bot] 相关的活动被完全关闭
*/
abstract fun close(cause: Throwable? = null)
public abstract fun close(cause: Throwable? = null)
final override fun toString(): String = "Bot($id)"
public final override fun toString(): String = "Bot($id)"
}
/**
* 获取 [Job] 的协程 [Job]. [Job] 为一个 [SupervisorJob]
*/
@get:JvmSynthetic
val Bot.supervisorJob: CompletableJob
public val Bot.supervisorJob: CompletableJob
get() = this.coroutineContext[Job] as CompletableJob
/**
@ -362,7 +368,7 @@ val Bot.supervisorJob: CompletableJob
* 即使 [Bot] 离线, 也会等待直到协程关闭.
*/
@JvmSynthetic
suspend inline fun Bot.join() = this.coroutineContext[Job]!!.join()
public suspend inline fun Bot.join(): Unit = this.coroutineContext[Job]!!.join()
/**
* 撤回这条消息.
@ -374,7 +380,7 @@ suspend inline fun Bot.join() = this.coroutineContext[Job]!!.join()
* @see Bot.recall
*/
@JvmSynthetic
suspend inline fun Bot.recall(message: MessageChain) =
public suspend inline fun Bot.recall(message: MessageChain): Unit =
this.recall(message.source)
/**
@ -385,7 +391,7 @@ suspend inline fun Bot.recall(message: MessageChain) =
* @see recall
*/
@JvmSynthetic
inline fun CoroutineScope.recallIn(
public inline fun CoroutineScope.recallIn(
source: MessageSource,
millis: Long,
coroutineContext: CoroutineContext = EmptyCoroutineContext
@ -402,7 +408,7 @@ inline fun CoroutineScope.recallIn(
* @see recall
*/
@JvmSynthetic
inline fun CoroutineScope.recallIn(
public inline fun CoroutineScope.recallIn(
message: MessageChain,
millis: Long,
coroutineContext: CoroutineContext = EmptyCoroutineContext
@ -419,19 +425,19 @@ inline fun CoroutineScope.recallIn(
* @param cause 原因. null 时视为正常关闭, null 时视为异常关闭
*/
@JvmSynthetic
suspend inline fun Bot.closeAndJoin(cause: Throwable? = null) {
public suspend inline fun Bot.closeAndJoin(cause: Throwable? = null) {
close(cause)
coroutineContext[Job]?.join()
}
@JvmSynthetic
inline fun Bot.containsFriend(id: Long): Boolean = this.friends.contains(id)
public inline fun Bot.containsFriend(id: Long): Boolean = this.friends.contains(id)
@JvmSynthetic
inline fun Bot.containsGroup(id: Long): Boolean = this.groups.contains(id)
public inline fun Bot.containsGroup(id: Long): Boolean = this.groups.contains(id)
@JvmSynthetic
inline fun Bot.getFriendOrNull(id: Long): Friend? = this.friends.getOrNull(id)
public inline fun Bot.getFriendOrNull(id: Long): Friend? = this.friends.getOrNull(id)
@JvmSynthetic
inline fun Bot.getGroupOrNull(id: Long): Group? = this.groups.getOrNull(id)
public inline fun Bot.getGroupOrNull(id: Long): Group? = this.groups.getOrNull(id)

View File

@ -23,12 +23,12 @@ import kotlin.jvm.JvmSynthetic
*
* JVM, 请查看 `BotFactoryJvm`
*/
expect interface BotFactory {
public expect interface BotFactory {
/**
* 使用指定的 [配置][configuration] 构造 [Bot] 实例
*/
@JvmName("newBot")
fun Bot(
public fun Bot(
context: Context,
qq: Long,
password: String,
@ -39,7 +39,7 @@ expect interface BotFactory {
* 使用指定的 [配置][configuration] 构造 [Bot] 实例
*/
@JvmName("newBot")
fun Bot(
public fun Bot(
context: Context,
qq: Long,
passwordMd5: ByteArray,
@ -51,7 +51,7 @@ expect interface BotFactory {
* 使用指定的 [配置][configuration] 构造 [Bot] 实例
*/
@JvmSynthetic
inline fun BotFactory.Bot(
public inline fun BotFactory.Bot(
context: Context,
qq: Long,
password: String,
@ -62,7 +62,7 @@ inline fun BotFactory.Bot(
* 使用指定的 [配置][configuration] 构造 [Bot] 实例
*/
@JvmSynthetic
inline fun BotFactory.Bot(
public inline fun BotFactory.Bot(
context: Context,
qq: Long,
password: ByteArray,

View File

@ -35,12 +35,12 @@ import kotlin.jvm.JvmSynthetic
* 联系对象, 即可以与 [Bot] 互动的对象. 包含 [用户][User], [][Group].
*/
@Suppress("EXPOSED_SUPER_CLASS")
abstract class Contact : ContactOrBot, CoroutineScope, ContactJavaFriendlyAPI {
public abstract class Contact : ContactOrBot, CoroutineScope, ContactJavaFriendlyAPI {
/**
* 这个联系对象所属 [Bot].
*/
@WeakRefProperty
abstract val bot: Bot
public abstract val bot: Bot
/**
* 可以是 QQ 号码或者群号码.
@ -48,7 +48,7 @@ abstract class Contact : ContactOrBot, CoroutineScope, ContactJavaFriendlyAPI {
* @see User.id
* @see Group.id
*/
abstract override val id: Long
public abstract override val id: Long
/**
* 向这个对象发送消息.
@ -66,12 +66,12 @@ abstract class Contact : ContactOrBot, CoroutineScope, ContactJavaFriendlyAPI {
* @return 消息回执. [引用回复][MessageReceipt.quote]仅群聊 [撤回][MessageReceipt.recall] 这条消息.
*/
@JvmSynthetic
abstract suspend fun sendMessage(message: Message): MessageReceipt<Contact>
public abstract suspend fun sendMessage(message: Message): MessageReceipt<Contact>
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE", "VIRTUAL_MEMBER_HIDDEN", "OVERRIDE_BY_INLINE")
@kotlin.internal.InlineOnly
@JvmSynthetic
suspend inline fun sendMessage(message: String): MessageReceipt<Contact> {
public suspend inline fun sendMessage(message: String): MessageReceipt<Contact> {
return sendMessage(message.toMessage())
}
@ -87,34 +87,34 @@ abstract class Contact : ContactOrBot, CoroutineScope, ContactJavaFriendlyAPI {
* @throws OverFileSizeMaxException 当图片文件过大而被服务器拒绝上传时抛出. (最大大小约为 20 MB, mirai 限制的大小为 30 MB)
*/
@JvmSynthetic
abstract suspend fun uploadImage(image: ExternalImage): Image
public abstract suspend fun uploadImage(image: ExternalImage): Image
final override fun equals(other: Any?): Boolean = super.equals(other)
final override fun hashCode(): Int = super.hashCode()
public final override fun equals(other: Any?): Boolean = super.equals(other)
public final override fun hashCode(): Int = super.hashCode()
/**
* @return "Friend($id)" or "Group($id)" or "Member($id)"
*/
abstract override fun toString(): String
public abstract override fun toString(): String
}
/**
* @see Bot.recall
*/
@JvmSynthetic
suspend inline fun Contact.recall(source: MessageChain) = this.bot.recall(source)
public suspend inline fun Contact.recall(source: MessageChain): Unit = this.bot.recall(source)
/**
* @see Bot.recall
*/
@JvmSynthetic
suspend inline fun Contact.recall(source: MessageSource) = this.bot.recall(source)
public suspend inline fun Contact.recall(source: MessageSource): Unit = this.bot.recall(source)
/**
* @see Bot.recallIn
*/
@JvmSynthetic
inline fun Contact.recallIn(
public inline fun Contact.recallIn(
message: MessageChain,
millis: Long,
coroutineContext: CoroutineContext = EmptyCoroutineContext
@ -124,7 +124,7 @@ inline fun Contact.recallIn(
* @see Bot.recallIn
*/
@JvmSynthetic
inline fun Contact.recallIn(
public inline fun Contact.recallIn(
source: MessageSource,
millis: Long,
coroutineContext: CoroutineContext = EmptyCoroutineContext

View File

@ -22,24 +22,24 @@ import kotlin.jvm.JvmField
* @see ContactList.asSequence
*/
@Suppress("unused")
class ContactList<C : Contact>
public class ContactList<C : Contact>
internal constructor(@JvmField internal val delegate: LockFreeLinkedList<C>) : Collection<C> {
operator fun get(id: Long): C =
public operator fun get(id: Long): C =
delegate.asSequence().firstOrNull { it.id == id } ?: throw NoSuchElementException("Contact id $id")
fun getOrNull(id: Long): C? = delegate.getOrNull(id)
public fun getOrNull(id: Long): C? = delegate.getOrNull(id)
override val size: Int get() = delegate.size
override operator fun contains(element: C): Boolean = delegate.contains(element)
operator fun contains(id: Long): Boolean = delegate.getOrNull(id) != null
override fun containsAll(elements: Collection<C>): Boolean = elements.all { contains(it) }
override fun isEmpty(): Boolean = delegate.isEmpty()
public override val size: Int get() = delegate.size
public override operator fun contains(element: C): Boolean = delegate.contains(element)
public operator fun contains(id: Long): Boolean = delegate.getOrNull(id) != null
public override fun containsAll(elements: Collection<C>): Boolean = elements.all { contains(it) }
public override fun isEmpty(): Boolean = delegate.isEmpty()
override fun toString(): String =
public override fun toString(): String =
delegate.asSequence().joinToString(separator = ", ", prefix = "ContactList(", postfix = ")")
override fun iterator(): Iterator<C> {
public override fun iterator(): Iterator<C> {
return this.delegate.asSequence().iterator()
}
}
@ -51,7 +51,7 @@ internal constructor(@JvmField internal val delegate: LockFreeLinkedList<C>) : C
* [123456, 321654, 123654]
* ```
*/
val ContactList<*>.idContentString: String
public val ContactList<*>.idContentString: String
get() = "[" + buildString { delegate.forEach { append(it.id).append(", ") } }.dropLast(
2
) + "]"

View File

@ -19,9 +19,9 @@ import net.mamoe.mirai.Bot
* @see Contact
* @see Bot
*/
interface ContactOrBot : CoroutineScope {
public interface ContactOrBot : CoroutineScope {
/**
* QQ 号或群号.
*/
val id: Long
public val id: Long
}

View File

@ -20,16 +20,16 @@ import kotlin.time.seconds
*
* @see Contact.sendMessage
*/
class MessageTooLargeException(
val target: Contact,
public class MessageTooLargeException(
public val target: Contact,
/**
* 原发送消息
*/
val originalMessage: Message,
public val originalMessage: Message,
/**
* 经过事件拦截处理后的消息
*/
val messageAfterEvent: Message,
public val messageAfterEvent: Message,
exceptionMessage: String
) : RuntimeException(exceptionMessage)
@ -38,8 +38,8 @@ class MessageTooLargeException(
*
* @see Group.sendMessage
*/
class BotIsBeingMutedException(
val target: Group
public class BotIsBeingMutedException(
public val target: Group
) : RuntimeException("bot is being muted, remaining ${target.botMuteRemaining.seconds.asHumanReadable} seconds")
inline val BotIsBeingMutedException.botMuteRemaining: Int get() = target.botMuteRemaining
public inline val BotIsBeingMutedException.botMuteRemaining: Int get() = target.botMuteRemaining

View File

@ -34,22 +34,22 @@ import kotlin.jvm.JvmSynthetic
* @see FriendMessageEvent
*/
@Suppress("DEPRECATION_ERROR")
abstract class Friend : User(), CoroutineScope {
public abstract class Friend : User(), CoroutineScope {
/**
* QQ 号码
*/
abstract override val id: Long
public abstract override val id: Long
/**
* 昵称
*/
abstract override val nick: String
public abstract override val nick: String
/**
* 头像下载链接
*/
override val avatarUrl: String
public override val avatarUrl: String
get() = "http://q1.qlogo.cn/g?b=qq&nk=$id&s=640"
/**

View File

@ -32,7 +32,7 @@ import kotlin.jvm.JvmSynthetic
/**
* .
*/
abstract class Group : Contact(), CoroutineScope {
public abstract class Group : Contact(), CoroutineScope {
/**
* 群名称.
*
@ -42,30 +42,30 @@ abstract class Group : Contact(), CoroutineScope {
* @see GroupNameChangeEvent 群名片修改事件
* @throws PermissionDeniedException 无权限修改时将会抛出异常
*/
abstract var name: String
public abstract var name: String
/**
* 群设置
*/
abstract val settings: GroupSettings
public abstract val settings: GroupSettings
/**
* 同为 groupCode, 用户看到的群号码.
*/
abstract override val id: Long
public abstract override val id: Long
/**
* 群主.
*
* @return 若机器人是群主, 返回 [botAsMember]. 否则返回相应的成员
*/
abstract val owner: Member
public abstract val owner: Member
/**
* [Bot] 在群内的 [Member] 实例
*/
@MiraiExperimentalAPI
abstract val botAsMember: Member
public abstract val botAsMember: Member
/**
* 机器人被禁言还剩余多少秒
@ -73,7 +73,7 @@ abstract class Group : Contact(), CoroutineScope {
* @see BotMuteEvent 机器人被禁言事件
* @see isBotMuted 判断机器人是否正在被禁言
*/
abstract val botMuteRemaining: Int
public abstract val botMuteRemaining: Int
/**
* 机器人在这个群里的权限
@ -82,38 +82,38 @@ abstract class Group : Contact(), CoroutineScope {
*
* @see BotGroupPermissionChangeEvent 机器人群员修改
*/
abstract val botPermission: MemberPermission
public abstract val botPermission: MemberPermission
/**
* 群头像下载链接.
*/
val avatarUrl: String
public val avatarUrl: String
get() = "https://p.qlogo.cn/gh/$id/${id}/640"
/**
* 群成员列表, 不含机器人自己, 含群主.
* [Group] 实例创建的时候查询一次. 并与事件同步事件更新
*/
abstract val members: ContactList<Member>
public abstract val members: ContactList<Member>
/**
* 获取群成员实例. 不存在时抛出 [kotlin.NoSuchElementException]
* [id] [Bot.id] 时返回 [botAsMember]
*/
@Throws(NoSuchElementException::class)
abstract operator fun get(id: Long): Member
public abstract operator fun get(id: Long): Member
/**
* 获取群成员实例, 不存在则 null
* [id] [Bot.id] 时返回 [botAsMember]
*/
abstract fun getOrNull(id: Long): Member?
public abstract fun getOrNull(id: Long): Member?
/**
* 检查此 id 的群成员是否存在
* [id] [Bot.id] 时返回 `true`
*/
abstract operator fun contains(id: Long): Boolean
public abstract operator fun contains(id: Long): Boolean
/**
@ -122,7 +122,7 @@ abstract class Group : Contact(), CoroutineScope {
* @return 退出成功时 true; 已经退出时 false
*/
@JvmSynthetic
abstract suspend fun quit(): Boolean
public abstract suspend fun quit(): Boolean
/**
* 构造一个 [Member].
@ -130,7 +130,7 @@ abstract class Group : Contact(), CoroutineScope {
*/
@LowLevelAPI
@MiraiExperimentalAPI("dangerous")
abstract fun newMember(memberInfo: MemberInfo): Member
public abstract fun newMember(memberInfo: MemberInfo): Member
/**
* 向这个对象发送消息.
@ -148,7 +148,7 @@ abstract class Group : Contact(), CoroutineScope {
* @return 消息回执. 可进行撤回 ([MessageReceipt.recall])
*/
@JvmSynthetic
abstract override suspend fun sendMessage(message: Message): MessageReceipt<Group>
public abstract override suspend fun sendMessage(message: Message): MessageReceipt<Group>
/**
* @see sendMessage
@ -156,7 +156,7 @@ abstract class Group : Contact(), CoroutineScope {
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE", "VIRTUAL_MEMBER_HIDDEN", "OVERRIDE_BY_INLINE")
@kotlin.internal.InlineOnly
@JvmSynthetic
suspend inline fun sendMessage(message: String): MessageReceipt<Group> {
public suspend inline fun sendMessage(message: String): MessageReceipt<Group> {
return sendMessage(message.toMessage())
}
@ -172,16 +172,16 @@ abstract class Group : Contact(), CoroutineScope {
* @throws OverFileSizeMaxException 当图片文件过大而被服务器拒绝上传时. (最大大小约为 20 MB)
*/
@JvmSynthetic
abstract override suspend fun uploadImage(image: ExternalImage): Image
public abstract override suspend fun uploadImage(image: ExternalImage): Image
companion object {
public companion object {
/**
* 使用 groupCode 计算 groupUin. 这两个值仅在 mirai 内部协议区分, 一般人使用时无需在意.
* @suppress internal api
*/
@MiraiExperimentalAPI
@JvmStatic
fun calculateGroupUinByGroupCode(groupCode: Long): Long =
public fun calculateGroupUinByGroupCode(groupCode: Long): Long =
CommonGroupCalculations.calculateGroupUinByGroupCode(groupCode)
/**
@ -190,7 +190,7 @@ abstract class Group : Contact(), CoroutineScope {
*/
@MiraiExperimentalAPI
@JvmStatic
fun calculateGroupCodeByGroupUin(groupUin: Long): Long =
public fun calculateGroupCodeByGroupUin(groupUin: Long): Long =
CommonGroupCalculations.calculateGroupCodeByGroupUin(groupUin)
}
@ -200,7 +200,7 @@ abstract class Group : Contact(), CoroutineScope {
@Suppress("FunctionName")
@JvmName("quit")
@JavaFriendlyAPI
fun __quitBlockingForJava__(): Boolean = runBlocking { quit() }
public fun __quitBlockingForJava__(): Boolean = runBlocking { quit() }
}
/**
@ -208,7 +208,7 @@ abstract class Group : Contact(), CoroutineScope {
*
* @see Group.settings 获取群设置
*/
interface GroupSettings {
public interface GroupSettings {
/**
* 入群公告, 没有时为空字符串.
*
@ -217,7 +217,7 @@ interface GroupSettings {
* @see GroupEntranceAnnouncementChangeEvent
* @throws PermissionDeniedException 无权限修改时将会抛出异常
*/
var entranceAnnouncement: String
public var entranceAnnouncement: String
/**
* 全体禁言状态. `true` 为开启.
@ -227,7 +227,7 @@ interface GroupSettings {
* @see GroupMuteAllEvent
* @throws PermissionDeniedException 无权限修改时将会抛出异常
*/
var isMuteAll: Boolean
public var isMuteAll: Boolean
/**
* 坦白说状态. `true` 为允许.
@ -239,7 +239,7 @@ interface GroupSettings {
*/
@PlannedRemoval("1.3.0")
@Deprecated("mirai 将不再支持此用例较少的设置", level = DeprecationLevel.WARNING)
var isConfessTalkEnabled: Boolean
public var isConfessTalkEnabled: Boolean
/**
* 允许群员邀请好友入群的状态. `true` 为允许
@ -249,18 +249,18 @@ interface GroupSettings {
* @see GroupAllowMemberInviteEvent
* @throws PermissionDeniedException 无权限修改时将会抛出异常
*/
var isAllowMemberInvite: Boolean
public var isAllowMemberInvite: Boolean
/**
* 自动加群审批
*/
@MiraiExperimentalAPI
val isAutoApproveEnabled: Boolean
public val isAutoApproveEnabled: Boolean
/**
* 匿名聊天
*/
val isAnonymousChatEnabled: Boolean
public val isAnonymousChatEnabled: Boolean
}
@ -269,7 +269,7 @@ interface GroupSettings {
*
* @see Group.botMuteRemaining 剩余禁言时间
*/
inline val Group.isBotMuted: Boolean get() = this.botMuteRemaining != 0
public inline val Group.isBotMuted: Boolean get() = this.botMuteRemaining != 0
internal object CommonGroupCalculations {

View File

@ -20,9 +20,6 @@ import net.mamoe.mirai.message.data.Message
import net.mamoe.mirai.message.data.isContentEmpty
import net.mamoe.mirai.message.data.toMessage
import net.mamoe.mirai.message.recall
import net.mamoe.mirai.utils.hoursToSeconds
import net.mamoe.mirai.utils.daysToSeconds
import net.mamoe.mirai.utils.minutesToSeconds
import net.mamoe.mirai.utils.WeakRefProperty
import kotlin.jvm.JvmSynthetic
import kotlin.time.Duration
@ -39,19 +36,19 @@ import kotlin.time.ExperimentalTime
*/
@Suppress("INAPPLICABLE_JVM_NAME", "EXPOSED_SUPER_CLASS")
@OptIn(JavaFriendlyAPI::class)
abstract class Member : MemberJavaFriendlyAPI, User() {
public abstract class Member : MemberJavaFriendlyAPI, User() {
/**
* 所在的群.
*/
@WeakRefProperty
abstract val group: Group
public abstract val group: Group
/**
* 成员的权限, 动态更新.
*
* @see MemberPermissionChangeEvent 权限变更事件. 由群主或机器人的操作触发.
*/
abstract val permission: MemberPermission
public abstract val permission: MemberPermission
/**
* 群名片. 可能为空.
@ -65,7 +62,7 @@ abstract class Member : MemberJavaFriendlyAPI, User() {
* @see MemberCardChangeEvent 群名片被管理员, 自己或 [Bot] 改动事件. 修改时也会触发此事件.
* @throws PermissionDeniedException 无权限修改时
*/
abstract var nameCard: String
public abstract var nameCard: String
/**
* 群头衔.
@ -77,7 +74,7 @@ abstract class Member : MemberJavaFriendlyAPI, User() {
* @see MemberSpecialTitleChangeEvent 群名片被管理员, 自己或 [Bot] 改动事件. 修改时也会触发此事件.
* @throws PermissionDeniedException 无权限修改时
*/
abstract var specialTitle: String
public abstract var specialTitle: String
/**
* 被禁言剩余时长. 单位为秒.
@ -86,7 +83,7 @@ abstract class Member : MemberJavaFriendlyAPI, User() {
* @see mute 设置禁言
* @see unmute 取消禁言
*/
abstract val muteTimeRemaining: Int
public abstract val muteTimeRemaining: Int
/**
* 禁言.
@ -111,7 +108,7 @@ abstract class Member : MemberJavaFriendlyAPI, User() {
* @throws PermissionDeniedException 无权限修改时抛出
*/
@JvmSynthetic
abstract suspend fun mute(durationSeconds: Int)
public abstract suspend fun mute(durationSeconds: Int)
/**
* 解除禁言.
@ -125,7 +122,7 @@ abstract class Member : MemberJavaFriendlyAPI, User() {
* @throws PermissionDeniedException 无权限修改时抛出
*/
@JvmSynthetic
abstract suspend fun unmute()
public abstract suspend fun unmute()
/**
* 踢出该成员.
@ -136,7 +133,7 @@ abstract class Member : MemberJavaFriendlyAPI, User() {
* @throws PermissionDeniedException 无权限修改时
*/
@JvmSynthetic
abstract suspend fun kick(message: String = "")
public abstract suspend fun kick(message: String = "")
/**
* 向群成员发送消息.
@ -158,7 +155,7 @@ abstract class Member : MemberJavaFriendlyAPI, User() {
* @return 消息回执. 可进行撤回 ([MessageReceipt.recall])
*/
@JvmSynthetic
abstract override suspend fun sendMessage(message: Message): MessageReceipt<Member>
public abstract override suspend fun sendMessage(message: Message): MessageReceipt<Member>
/**
* @see sendMessage
@ -166,11 +163,11 @@ abstract class Member : MemberJavaFriendlyAPI, User() {
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE", "VIRTUAL_MEMBER_HIDDEN", "OVERRIDE_BY_INLINE")
@kotlin.internal.InlineOnly
@JvmSynthetic
suspend inline fun sendMessage(message: String): MessageReceipt<Member> {
public suspend inline fun sendMessage(message: String): MessageReceipt<Member> {
return sendMessage(message.toMessage())
}
final override fun toString(): String = "Member($id)"
public final override fun toString(): String = "Member($id)"
}
/**
@ -178,23 +175,23 @@ abstract class Member : MemberJavaFriendlyAPI, User() {
*
* @throws IllegalStateException 当此成员不是好友时抛出
*/
fun Member.asFriend(): Friend = this.bot.getFriendOrNull(this.id) ?: error("$this is not a friend")
public fun Member.asFriend(): Friend = this.bot.getFriendOrNull(this.id) ?: error("$this is not a friend")
/**
* 得到此成员作为好友的对象, 当此成员不是好友时返回 `null`
*/
fun Member.asFriendOrNull(): Friend? = this.bot.getFriendOrNull(this.id)
public fun Member.asFriendOrNull(): Friend? = this.bot.getFriendOrNull(this.id)
/**
* 判断此成员是否为好友
*/
inline val Member.isFriend: Boolean
public inline val Member.isFriend: Boolean
get() = this.bot.friends.contains(this.id)
/**
* 如果此成员是好友, 则执行 [block] 并返回其返回值. 否则返回 `null`
*/
inline fun <R> Member.takeIfIsFriend(block: (Friend) -> R): R? {
public inline fun <R> Member.takeIfIsFriend(block: (Friend) -> R): R? {
return this.asFriendOrNull()?.let(block)
}
@ -203,7 +200,7 @@ inline fun <R> Member.takeIfIsFriend(block: (Friend) -> R): R? {
*
* [群名片][Member.nameCard] 不为空则返回群名片, 为空则返回 [User.nick]
*/
val Member.nameCardOrNick: String get() = this.nameCard.takeIf { it.isNotEmpty() } ?: this.nick
public val Member.nameCardOrNick: String get() = this.nameCard.takeIf { it.isNotEmpty() } ?: this.nick
/**
* 获取非空群名片或昵称.
@ -212,7 +209,7 @@ val Member.nameCardOrNick: String get() = this.nameCard.takeIf { it.isNotEmpty()
*
* 否则返回 [Member.nick]
*/
val User.nameCardOrNick: String
public val User.nameCardOrNick: String
get() = when (this) {
is Member -> this.nameCardOrNick
else -> this.nick
@ -221,14 +218,14 @@ val User.nameCardOrNick: String
/**
* 判断群成员是否处于禁言状态.
*/
val Member.isMuted: Boolean
public val Member.isMuted: Boolean
get() = muteTimeRemaining != 0 && muteTimeRemaining != 0xFFFFFFFF.toInt()
/**
* @see Member.mute
*/
@ExperimentalTime
suspend inline fun Member.mute(duration: Duration) {
public suspend inline fun Member.mute(duration: Duration) {
require(duration.inDays <= 30) { "duration must be at most 1 month" }
require(duration.inSeconds > 0) { "duration must be greater than 0 second" }
this.mute(duration.inSeconds.toInt())
@ -237,4 +234,4 @@ suspend inline fun Member.mute(duration: Duration) {
/**
* @see Member.mute
*/
suspend inline fun Member.mute(durationSeconds: Long) = this.mute(durationSeconds.toInt())
public suspend inline fun Member.mute(durationSeconds: Long): Unit = this.mute(durationSeconds.toInt())

View File

@ -26,7 +26,7 @@ import kotlin.internal.InlineOnly
* @see Member.isOperator [Member] 的扩展函数, 判断此成员是否为管理员或群主
* @see Member.isAdministrator [Member] 的扩展函数, 判断此成员是否为管理员
*/
enum class MemberPermission : Comparable<MemberPermission> {
public enum class MemberPermission : Comparable<MemberPermission> {
/**
* 一般群成员
*/
@ -45,7 +45,7 @@ enum class MemberPermission : Comparable<MemberPermission> {
/**
* 权限等级. [OWNER] 2, [ADMINISTRATOR] 1, [MEMBER] 0
*/
val level: Int
public val level: Int
get() = ordinal
}
@ -53,44 +53,44 @@ enum class MemberPermission : Comparable<MemberPermission> {
* 判断权限是否为群主
*/
@InlineOnly
inline fun MemberPermission.isOwner(): Boolean = this == MemberPermission.OWNER
public inline fun MemberPermission.isOwner(): Boolean = this == MemberPermission.OWNER
/**
* 判断权限是否为管理员
*/
@InlineOnly
inline fun MemberPermission.isAdministrator(): Boolean = this == MemberPermission.ADMINISTRATOR
public inline fun MemberPermission.isAdministrator(): Boolean = this == MemberPermission.ADMINISTRATOR
/**
* 判断权限是否为管理员或群主
*/
@InlineOnly
inline fun MemberPermission.isOperator(): Boolean = isAdministrator() || isOwner()
public inline fun MemberPermission.isOperator(): Boolean = isAdministrator() || isOwner()
/**
* 判断权限是否为群主
*/
inline fun Member.isOwner(): Boolean = this.permission.isOwner()
public inline fun Member.isOwner(): Boolean = this.permission.isOwner()
/**
* 判断权限是否为管理员
*/
inline fun Member.isAdministrator(): Boolean = this.permission.isAdministrator()
public inline fun Member.isAdministrator(): Boolean = this.permission.isAdministrator()
/**
* 判断权限是否为管理员或群主
*/
inline fun Member.isOperator(): Boolean = this.permission.isOperator()
public inline fun Member.isOperator(): Boolean = this.permission.isOperator()
/**
* 权限不足
*/
@Suppress("unused")
class PermissionDeniedException : IllegalStateException {
constructor() : super("Permission denied")
constructor(message: String?) : super(message)
public class PermissionDeniedException : IllegalStateException {
public constructor() : super("Permission denied")
public constructor(message: String?) : super(message)
}
/**
@ -98,7 +98,7 @@ class PermissionDeniedException : IllegalStateException {
*
* @throws PermissionDeniedException
*/
inline fun Group.checkBotPermission(
public inline fun Group.checkBotPermission(
required: MemberPermission,
crossinline lazyMessage: () -> String = {
"Permission denied: required $required, got actual $botPermission for $bot in group $id"
@ -115,8 +115,8 @@ inline fun Group.checkBotPermission(
* @throws PermissionDeniedException
*/
@Deprecated("use checkBotPermission", ReplaceWith("checkBotPermission(MemberPermission.ADMINISTRATOR)"))
inline fun Group.checkBotPermissionOperator(
public inline fun Group.checkBotPermissionOperator(
crossinline lazyMessage: () -> String = {
"Permission denied: required ${MemberPermission.ADMINISTRATOR} or ${MemberPermission.OWNER}, got actual $botPermission for $bot in group $id"
}
) = checkBotPermission(MemberPermission.ADMINISTRATOR, lazyMessage)
): Unit = checkBotPermission(MemberPermission.ADMINISTRATOR, lazyMessage)

View File

@ -32,21 +32,21 @@ import kotlin.jvm.JvmSynthetic
*
* 对于同一个 [Bot] 任何一个人的 [User] 实例都是单一的.
*/
abstract class User : Contact(), CoroutineScope {
public abstract class User : Contact(), CoroutineScope {
/**
* QQ 号码
*/
abstract override val id: Long
public abstract override val id: Long
/**
* 昵称
*/
abstract val nick: String
public abstract val nick: String
/**
* 头像下载链接
*/
open val avatarUrl: String
public open val avatarUrl: String
get() = "http://q1.qlogo.cn/g?b=qq&nk=$id&s=640"
/**
@ -65,7 +65,7 @@ abstract class User : Contact(), CoroutineScope {
* @return 消息回执. 可进行撤回 ([MessageReceipt.recall])
*/
@JvmSynthetic
abstract override suspend fun sendMessage(message: Message): MessageReceipt<User>
public abstract override suspend fun sendMessage(message: Message): MessageReceipt<User>
/**
* @see sendMessage
@ -73,7 +73,7 @@ abstract class User : Contact(), CoroutineScope {
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE", "VIRTUAL_MEMBER_HIDDEN", "OVERRIDE_BY_INLINE")
@kotlin.internal.InlineOnly
@JvmSynthetic
suspend inline fun sendMessage(message: String): MessageReceipt<User> {
public suspend inline fun sendMessage(message: String): MessageReceipt<User> {
return sendMessage(message.toMessage())
}
@ -89,7 +89,7 @@ abstract class User : Contact(), CoroutineScope {
* @throws OverFileSizeMaxException 当图片文件过大而被服务器拒绝上传时. (最大大小约为 20 MB)
*/
@JvmSynthetic
abstract override suspend fun uploadImage(image: ExternalImage): Image
public abstract override suspend fun uploadImage(image: ExternalImage): Image
abstract override fun toString(): String
public abstract override fun toString(): String
}

View File

@ -12,8 +12,8 @@ package net.mamoe.mirai.data
import net.mamoe.mirai.LowLevelAPI
@LowLevelAPI
interface FriendInfo {
val uin: Long
public interface FriendInfo {
public val uin: Long
val nick: String
public val nick: String
}

View File

@ -11,7 +11,7 @@ import net.mamoe.mirai.utils.MiraiExperimentalAPI
*/
@MiraiExperimentalAPI
@Serializable
data class GroupActiveData(
public data class GroupActiveData(
@SerialName("ec")
val ec: Int? = null,
@ -29,7 +29,7 @@ data class GroupActiveData(
val role: Int? = 0
) {
@Serializable
data class GInfo(
public data class GInfo(
@SerialName("g_act_num")
@ -39,7 +39,7 @@ data class GroupActiveData(
val createTime: Int? = 0,
@SerialName("g_exit_num")
val exitNum: List<GExitNum?>? = null, //退群人数列表
val exitNum: List<GExitNum?>? = null, //退群人数列表
@SerialName("g_join_num")
val joinNum: List<GJoinNum?>? = null,
@ -66,7 +66,7 @@ data class GroupActiveData(
val isEnd: Int? = null
) {
@Serializable
data class GActNum(
public data class GActNum(
@SerialName("date")
val date: String? = null,
@ -76,7 +76,7 @@ data class GroupActiveData(
)
@Serializable
data class GExitNum(
public data class GExitNum(
@SerialName("date")
val date: String? = null,
@ -86,7 +86,7 @@ data class GroupActiveData(
)
@Serializable
data class GJoinNum(
public data class GJoinNum(
@SerialName("date")
val date: String? = null,
@ -96,7 +96,7 @@ data class GroupActiveData(
)
@Serializable
data class GMemNum(
public data class GMemNum(
@SerialName("date")
val date: String? = null,
@ -106,7 +106,7 @@ data class GroupActiveData(
)
@Serializable
data class GMostAct(
public data class GMostAct(
@SerialName("name")
val name: String? = null, // 名称 不完整
@ -122,7 +122,7 @@ data class GroupActiveData(
)
@Serializable
data class GSentence(
public data class GSentence(
@SerialName("date")
val date: String? = null,

View File

@ -13,7 +13,7 @@ import net.mamoe.mirai.utils.MiraiExperimentalAPI
*/
@MiraiExperimentalAPI
@Serializable
data class GroupAnnouncementList(
public data class GroupAnnouncementList(
val ec: Int, //状态码 0 是正常的
@SerialName("em") val msg: String, //信息
val feeds: List<GroupAnnouncement>? = null, //群公告列表
@ -22,7 +22,7 @@ data class GroupAnnouncementList(
@MiraiExperimentalAPI
@Serializable
data class GroupAnnouncement(
public data class GroupAnnouncement(
@SerialName("u") val sender: Long = 0,
val msg: GroupAnnouncementMsg,
val settings: GroupAnnouncementSettings? = null,
@ -30,12 +30,12 @@ data class GroupAnnouncement(
@SerialName("read_num") val readNum: Int = 0,
@SerialName("is_read") val isRead: Int = 0,
val pinned: Int = 0,
val fid:String? = null //公告的id
val fid: String? = null //公告的id
)
@MiraiExperimentalAPI
@Serializable
data class GroupAnnouncementMsg(
public data class GroupAnnouncementMsg(
val text: String,
val text_face: String? = null,
val title: String? = null
@ -43,7 +43,7 @@ data class GroupAnnouncementMsg(
@MiraiExperimentalAPI
@Serializable
data class GroupAnnouncementSettings(
public data class GroupAnnouncementSettings(
@SerialName("is_show_edit_card") val isShowEditCard: Int = 0,
@SerialName("remind_ts") val remindTs: Int = 0,
@SerialName("tip_window_type") val tipWindowType: Int = 0,

View File

@ -9,61 +9,61 @@ import net.mamoe.mirai.LowLevelAPI
* 通过 [Bot._lowLevelQueryGroupInfo] 得到
*/
@LowLevelAPI
interface GroupInfo {
public interface GroupInfo {
/**
* Uin
*/
val uin: Long
public val uin: Long
/**
* 群号码
*/ // 由 uin 计算得到
val groupCode: Long
public val groupCode: Long
/**
* 名称
*/
val name: String // 不一定能获取到
public val name: String // 不一定能获取到
/**
* 群主
*/
val owner: Long // 不一定能获取到
public val owner: Long // 不一定能获取到
/**
* 入群公告
*/
val memo: String // 不一定能获取到
public val memo: String // 不一定能获取到
/**
* 允许群员邀请其他人加入群
*/
val allowMemberInvite: Boolean
public val allowMemberInvite: Boolean
/**
* 允许匿名聊天
*/
val allowAnonymousChat: Boolean
public val allowAnonymousChat: Boolean
/**
* 自动审批加群请求
*/
val autoApprove: Boolean
public val autoApprove: Boolean
/**
* 坦白说开启状态
*/
val confessTalk: Boolean
public val confessTalk: Boolean
/**
* 全员禁言
*/
val muteAll: Boolean
public val muteAll: Boolean
/**
* 机器人被禁言还剩时间, .
*/
val botMuteTimestamp: Int
public val botMuteTimestamp: Int
/*
/**

View File

@ -13,12 +13,12 @@ import net.mamoe.mirai.LowLevelAPI
import net.mamoe.mirai.contact.MemberPermission
@LowLevelAPI
interface MemberInfo : FriendInfo {
val nameCard: String
public interface MemberInfo : FriendInfo {
public val nameCard: String
val permission: MemberPermission
public val permission: MemberPermission
val specialTitle: String
public val specialTitle: String
val muteTimestamp: Int
public val muteTimestamp: Int
}

View File

@ -14,11 +14,12 @@ package net.mamoe.mirai.data
/**
* 在线状态
*/
enum class OnlineStatus(val id: Int) {
public enum class OnlineStatus(public val id: Int) {
/**
* 我在线上
*/
ONLINE(11),
/**
* 离线
*/
@ -38,14 +39,17 @@ enum class OnlineStatus(val id: Int) {
* 忙碌
*/
BUSY(50),
/**
* Q 我吧
*/
Q_ME(60),
/**
* 请勿打扰
*/
DND(70),
/**
* 离线但接收消息
*/
@ -56,8 +60,8 @@ enum class OnlineStatus(val id: Int) {
*/
UNKNOWN(-1);
companion object {
fun ofId(id: Int): OnlineStatus = values().first { it.id == id }
fun ofIdOrNull(id: Int): OnlineStatus? = values().firstOrNull { it.id == id }
public companion object {
public fun ofId(id: Int): OnlineStatus = values().first { it.id == id }
public fun ofIdOrNull(id: Int): OnlineStatus? = values().firstOrNull { it.id == id }
}
}

View File

@ -44,7 +44,7 @@ import kotlin.jvm.Volatile
*
* @see CancellableEvent 可被取消的事件
*/
interface Event {
public interface Event {
/**
* 事件是否已被拦截.
*
@ -52,7 +52,7 @@ interface Event {
*
* @see intercept 拦截事件
*/
val isIntercepted: Boolean
public val isIntercepted: Boolean
/**
* 拦截这个事件
@ -64,7 +64,7 @@ interface Event {
* @see Listener.EventPriority 查看优先级相关信息
*/
@SinceMirai("1.0.0")
fun intercept()
public fun intercept()
}
/**
@ -72,11 +72,12 @@ interface Event {
*
* 在使用事件时应使用类型 [Event]. 在实现自定义事件时应继承 [AbstractEvent].
*/
abstract class AbstractEvent : Event {
public abstract class AbstractEvent : Event {
/** 限制一个事件实例不能并行广播. (适用于 object 广播的情况) */
@JvmField
internal val broadCastLock = Mutex()
@Suppress("PropertyName")
@JvmField
@Volatile
internal var _intercepted = false
@ -89,13 +90,13 @@ abstract class AbstractEvent : Event {
* @see Event.isIntercepted
*/
@SinceMirai("1.0.0")
override val isIntercepted: Boolean
public override val isIntercepted: Boolean
get() = _intercepted
/**
* @see Event.intercept
*/
override fun intercept() {
public override fun intercept() {
_intercepted = true
}
@ -103,12 +104,12 @@ abstract class AbstractEvent : Event {
/**
* @see CancellableEvent.isCancelled
*/
val isCancelled: Boolean get() = _cancelled
public val isCancelled: Boolean get() = _cancelled
/**
* @see CancellableEvent.cancel
*/
fun cancel() {
public fun cancel() {
check(this is CancellableEvent) {
"Event $this is not cancellable"
}
@ -119,14 +120,14 @@ abstract class AbstractEvent : Event {
/**
* 可被取消的事件
*/
interface CancellableEvent : Event {
public interface CancellableEvent : Event {
/**
* 事件是否已被取消.
*
* 事件需实现 [CancellableEvent] 接口才可以被取消,
* 否则此属性固定返回 false.
*/
val isCancelled: Boolean
public val isCancelled: Boolean
/**
* 取消这个事件.
@ -134,7 +135,7 @@ interface CancellableEvent : Event {
*
* @throws IllegalStateException 当事件未实现接口 [CancellableEvent] 时抛出
*/
fun cancel()
public fun cancel()
}
/**
@ -146,7 +147,7 @@ interface CancellableEvent : Event {
* @see __broadcastJava Java 使用
*/
@JvmSynthetic
suspend fun <E : Event> E.broadcast(): E = apply {
public suspend fun <E : Event> E.broadcast(): E = apply {
check(this is AbstractEvent) {
"Events must extend AbstractEvent"
}
@ -168,7 +169,7 @@ suspend fun <E : Event> E.broadcast(): E = apply {
@Suppress("FunctionName")
@JvmName("broadcast")
@JavaFriendlyAPI
fun <E : Event> E.__broadcastJava(): E = apply {
public fun <E : Event> E.__broadcastJava(): E = apply {
if (this is BroadcastControllable && !this.shouldBroadcast) {
return@apply
}
@ -180,16 +181,16 @@ fun <E : Event> E.__broadcastJava(): E = apply {
* 所有的 `subscribe` 都能正常添加到监听器列表, 但所有的广播都会直接返回.
*/
@MiraiExperimentalAPI
var EventDisabled = false
public var EventDisabled: Boolean = false
/**
* 可控制是否需要广播这个事件
*/
interface BroadcastControllable : Event {
public interface BroadcastControllable : Event {
/**
* 返回 `false` 时将不会广播这个事件.
*/
val shouldBroadcast: Boolean
public val shouldBroadcast: Boolean
get() = true
}

View File

@ -35,7 +35,7 @@ import kotlin.jvm.JvmSynthetic
* 接受者 T [MessageEvent]
* 参数 String 转为字符串了的消息 ([Message.toString])
*/
typealias MessageListener<T, R> = @MessageDsl suspend T.(String) -> R
public typealias MessageListener<T, R> = @MessageDsl suspend T.(String) -> R
/**
@ -48,7 +48,7 @@ typealias MessageListener<T, R> = @MessageDsl suspend T.(String) -> R
* @see subscribeFriendMessages
*/
@MessageDsl
open class MessageSubscribersBuilder<M : MessageEvent, out Ret, R : RR, RR>(
public open class MessageSubscribersBuilder<M : MessageEvent, out Ret, R : RR, RR>(
/**
* 用于 [MessageListener] 无返回值的替代.
*/
@ -57,54 +57,54 @@ open class MessageSubscribersBuilder<M : MessageEvent, out Ret, R : RR, RR>(
/**
* invoke 这个 lambda , 它将会把 [消息事件的处理器][MessageListener] 注册给事件, 并返回注册完成返回的监听器.
*/
val subscriber: (M.(String) -> Boolean, MessageListener<M, RR>) -> Ret
public val subscriber: (M.(String) -> Boolean, MessageListener<M, RR>) -> Ret
) {
@Suppress("DEPRECATION_ERROR")
open fun newListeningFilter(filter: M.(String) -> Boolean): ListeningFilter = ListeningFilter(filter)
public open fun newListeningFilter(filter: M.(String) -> Boolean): ListeningFilter = ListeningFilter(filter)
/**
* [contains], [startsWith] DSL 创建出的监听条件, 使用 [invoke] 将其注册给事件
*/
open inner class ListeningFilter @Deprecated( // keep it for development warning
public open inner class ListeningFilter @Deprecated( // keep it for development warning
"use newListeningFilter instead",
ReplaceWith("newListeningFilter(filter)"),
level = DeprecationLevel.ERROR
) constructor(
val filter: M.(String) -> Boolean
public val filter: M.(String) -> Boolean
) {
/** 进行逻辑 `or`. */
infix fun or(another: ListeningFilter): ListeningFilter =
public infix fun or(another: ListeningFilter): ListeningFilter =
newListeningFilter { filter.invoke(this, it) || another.filter.invoke(this, it) }
/** 进行逻辑 `and`. */
infix fun and(another: ListeningFilter): ListeningFilter =
public infix fun and(another: ListeningFilter): ListeningFilter =
newListeningFilter { filter.invoke(this, it) && another.filter.invoke(this, it) }
/** 进行逻辑 `xor`. */
infix fun xor(another: ListeningFilter): ListeningFilter =
public infix fun xor(another: ListeningFilter): ListeningFilter =
newListeningFilter { filter.invoke(this, it) xor another.filter.invoke(this, it) }
/** 进行逻辑 `nand`, 即 `not and`. */
infix fun nand(another: ListeningFilter): ListeningFilter =
public infix fun nand(another: ListeningFilter): ListeningFilter =
newListeningFilter { !filter.invoke(this, it) || !another.filter.invoke(this, it) }
/** 进行逻辑 `not` */
fun not(): ListeningFilter = newListeningFilter { !filter.invoke(this, it) }
public fun not(): ListeningFilter = newListeningFilter { !filter.invoke(this, it) }
/** 启动事件监听. */
// do not inline due to kotlin (1.3.61) bug: java.lang.IllegalAccessError
operator fun invoke(onEvent: MessageListener<M, R>): Ret = content(filter, onEvent)
public operator fun invoke(onEvent: MessageListener<M, R>): Ret = content(filter, onEvent)
}
/** 启动监听器, 在 [Bot] 未被禁言且消息满足条件 [this] 时回复原消息 */
@MessageDsl
open infix fun ListeningFilter.reply(toReply: String): Ret =
public open infix fun ListeningFilter.reply(toReply: String): Ret =
content(filter) { if ((this as? GroupMessageEvent)?.group?.isBotMuted != true) reply(toReply);this@MessageSubscribersBuilder.stub }
/** 启动监听器, 在 [Bot] 未被禁言且消息满足条件 [this] 时回复原消息 */
@MessageDsl
open infix fun ListeningFilter.reply(message: Message): Ret =
public open infix fun ListeningFilter.reply(message: Message): Ret =
content(filter) { if ((this as? GroupMessageEvent)?.group?.isBotMuted != true) reply(message);this@MessageSubscribersBuilder.stub }
/**
@ -112,7 +112,7 @@ open class MessageSubscribersBuilder<M : MessageEvent, out Ret, R : RR, RR>(
* 返回值 [Unit] 将被忽略, [Message] 将被直接回复, 其他内容将会 [Any.toString] 后发送.
*/
@MessageDsl
open infix fun ListeningFilter.reply(
public open infix fun ListeningFilter.reply(
replier: (@MessageDsl suspend M.(String) -> Any?)
): Ret =
content(filter) {
@ -123,12 +123,12 @@ open class MessageSubscribersBuilder<M : MessageEvent, out Ret, R : RR, RR>(
/** 启动监听器, 在 [Bot] 未被禁言且消息满足条件 [this] 时引用回复原消息 */
@MessageDsl
open infix fun ListeningFilter.quoteReply(toReply: String): Ret =
public open infix fun ListeningFilter.quoteReply(toReply: String): Ret =
content(filter) { if ((this as? GroupMessageEvent)?.group?.isBotMuted != true) quoteReply(toReply); this@MessageSubscribersBuilder.stub }
/** 启动监听器, 在 [Bot] 未被禁言且消息满足条件 [this] 时引用回复原消息 */
@MessageDsl
open infix fun ListeningFilter.quoteReply(toReply: Message): Ret =
public open infix fun ListeningFilter.quoteReply(toReply: Message): Ret =
content(filter) { if ((this as? GroupMessageEvent)?.group?.isBotMuted != true) quoteReply(toReply);this@MessageSubscribersBuilder.stub }
/**
@ -136,7 +136,7 @@ open class MessageSubscribersBuilder<M : MessageEvent, out Ret, R : RR, RR>(
* 返回值 [Unit] 将被忽略, [Message] 将被直接回复, 其他内容将会 [Any.toString] 后发送
*/
@MessageDsl
open infix fun ListeningFilter.quoteReply(replier: (@MessageDsl suspend M.(String) -> Any?)): Ret =
public open infix fun ListeningFilter.quoteReply(replier: (@MessageDsl suspend M.(String) -> Any?)): Ret =
content(filter) {
if ((this as? GroupMessageEvent)?.group?.isBotMuted != true)
this@MessageSubscribersBuilder.executeAndQuoteReply(this, replier)
@ -145,28 +145,28 @@ open class MessageSubscribersBuilder<M : MessageEvent, out Ret, R : RR, RR>(
/** 无触发条件, 每次收到消息都执行 [onEvent] */
@MessageDsl
open fun always(onEvent: MessageListener<M, RR>): Ret = subscriber({ true }, onEvent)
public open fun always(onEvent: MessageListener<M, RR>): Ret = subscriber({ true }, onEvent)
/** [消息内容][Message.contentToString] `==` [equals] */
@MessageDsl
fun case(equals: String, ignoreCase: Boolean = false, trim: Boolean = true): ListeningFilter =
public fun case(equals: String, ignoreCase: Boolean = false, trim: Boolean = true): ListeningFilter =
caseImpl(equals, ignoreCase, trim)
/** 如果[消息内容][Message.contentToString] `==` [equals] */
@MessageDsl
operator fun String.invoke(block: MessageListener<M, R>): Ret = case(this, onEvent = block)
public operator fun String.invoke(block: MessageListener<M, R>): Ret = case(this, onEvent = block)
/** 如果[消息内容][Message.contentToString] [matches] */
@MessageDsl
@JvmSynthetic
@JvmName("matchingExtension")
infix fun Regex.matching(block: MessageListener<M, R>): Ret = content({ it matches this@matching }, block)
public infix fun Regex.matching(block: MessageListener<M, R>): Ret = content({ it matches this@matching }, block)
/** 如果[消息内容][Message.contentToString] [Regex.find] 不为空 */
@MessageDsl
@JvmSynthetic
@JvmName("findingExtension")
infix fun Regex.finding(block: @MessageDsl suspend M.(MatchResult) -> R): Ret =
public infix fun Regex.finding(block: @MessageDsl suspend M.(MatchResult) -> R): Ret =
always { content -> this@finding.find(content)?.let { block(this, it) } ?: this@MessageSubscribersBuilder.stub }
/**
@ -175,7 +175,7 @@ open class MessageSubscribersBuilder<M : MessageEvent, out Ret, R : RR, RR>(
* @param ignoreCase `true` 则不区分大小写
*/
@MessageDsl
fun case(
public fun case(
equals: String, ignoreCase: Boolean = false, trim: Boolean = true,
onEvent: MessageListener<M, R>
): Ret = (if (trim) equals.trim() else equals).let { toCheck ->
@ -187,13 +187,14 @@ open class MessageSubscribersBuilder<M : MessageEvent, out Ret, R : RR, RR>(
/** [消息内容][Message.contentToString]包含 [sub] */
@MessageDsl
@JvmOverloads // bin comp
fun contains(sub: String, ignoreCase: Boolean = false): ListeningFilter = content { it.contains(sub, ignoreCase) }
public fun contains(sub: String, ignoreCase: Boolean = false): ListeningFilter =
content { it.contains(sub, ignoreCase) }
/**
* [消息内容][Message.contentToString]包含 [sub] 中的任意一个元素
*/
@MessageDsl
fun contains(
public fun contains(
sub: String, ignoreCase: Boolean = false, trim: Boolean = true,
onEvent: MessageListener<M, R>
): Ret = containsImpl(sub, ignoreCase, trim, onEvent)
@ -201,26 +202,26 @@ open class MessageSubscribersBuilder<M : MessageEvent, out Ret, R : RR, RR>(
/** [消息内容][Message.contentToString]包含 [sub] */
@JvmOverloads
@MessageDsl
fun containsAny(vararg sub: String, ignoreCase: Boolean = false, trim: Boolean = true): ListeningFilter =
public fun containsAny(vararg sub: String, ignoreCase: Boolean = false, trim: Boolean = true): ListeningFilter =
containsAnyImpl(*sub, ignoreCase = ignoreCase, trim = trim)
/** [消息内容][Message.contentToString]包含 [sub] */
@JvmOverloads
@MessageDsl
fun containsAll(vararg sub: String, ignoreCase: Boolean = false, trim: Boolean = true): ListeningFilter =
public fun containsAll(vararg sub: String, ignoreCase: Boolean = false, trim: Boolean = true): ListeningFilter =
containsAllImpl(sub, ignoreCase = ignoreCase, trim = trim)
/** 如果消息的前缀是 [prefix] */
@MessageDsl
fun startsWith(prefix: String, trim: Boolean = true): ListeningFilter {
public fun startsWith(prefix: String, trim: Boolean = true): ListeningFilter {
val toCheck = if (trim) prefix.trim() else prefix
return content { (if (trim) it.trim() else it).startsWith(toCheck) }
}
/** 如果消息的前缀是 [prefix] */
@MessageDsl
fun startsWith(
public fun startsWith(
prefix: String, removePrefix: Boolean = true, trim: Boolean = true,
onEvent: @MessageDsl suspend M.(String) -> R
): Ret = startsWithImpl(prefix, removePrefix, trim, onEvent)
@ -228,100 +229,101 @@ open class MessageSubscribersBuilder<M : MessageEvent, out Ret, R : RR, RR>(
/** 如果消息的结尾是 [suffix] */
@MessageDsl
@JvmOverloads // for binary compatibility
fun endsWith(suffix: String, trim: Boolean = true): ListeningFilter =
public fun endsWith(suffix: String, trim: Boolean = true): ListeningFilter =
content { if (trim) it.trimEnd().endsWith(suffix) else it.endsWith(suffix) }
/** 如果消息的结尾是 [suffix] */
@MessageDsl
fun endsWith(
public fun endsWith(
suffix: String, removeSuffix: Boolean = true, trim: Boolean = true,
onEvent: @MessageDsl suspend M.(String) -> R
): Ret = endsWithImpl(suffix, removeSuffix, trim, onEvent)
/** 如果是这个人发的消息. 消息目前只会是群消息 */
@MessageDsl
fun sentBy(name: String): ListeningFilter = content { this is GroupMessageEvent && this.senderName == name }
public fun sentBy(name: String): ListeningFilter = content { this is GroupMessageEvent && this.senderName == name }
/** 如果是这个人发的消息. 消息可以是好友消息也可以是群消息 */
@MessageDsl
fun sentBy(qq: Long): ListeningFilter = content { sender.id == qq }
public fun sentBy(qq: Long): ListeningFilter = content { sender.id == qq }
/** 如果是这个人发的消息. 消息可以是好友消息也可以是群消息 */
@MessageDsl
fun sentBy(friend: User): ListeningFilter = content { sender.id == friend.id }
public fun sentBy(friend: User): ListeningFilter = content { sender.id == friend.id }
/** 如果是这个人发的消息. 消息可以是好友消息也可以是群消息 */
@MessageDsl
fun sentBy(qq: Long, onEvent: MessageListener<M, R>): Ret = content { this.sender.id == qq }.invoke(onEvent)
public fun sentBy(qq: Long, onEvent: MessageListener<M, R>): Ret = content { this.sender.id == qq }.invoke(onEvent)
/** 如果是好友发来的消息 */
@MessageDsl
fun sentByFriend(onEvent: MessageListener<FriendMessageEvent, R>): Ret =
public fun sentByFriend(onEvent: MessageListener<FriendMessageEvent, R>): Ret =
content({ this is FriendMessageEvent }) { onEvent(this as FriendMessageEvent, it) }
/** 如果是好友发来的消息 */
@MessageDsl
fun sentByFriend(): ListeningFilter = newListeningFilter { this is FriendMessageEvent }
public fun sentByFriend(): ListeningFilter = newListeningFilter { this is FriendMessageEvent }
/** 如果是群临时会话消息 */
@MessageDsl
fun sentByTemp(): ListeningFilter = newListeningFilter { this is TempMessageEvent }
public fun sentByTemp(): ListeningFilter = newListeningFilter { this is TempMessageEvent }
/** 如果是管理员或群主发的消息 */
@MessageDsl
fun sentByOperator(): ListeningFilter = content { this is GroupMessageEvent && sender.permission.isOperator() }
public fun sentByOperator(): ListeningFilter =
content { this is GroupMessageEvent && sender.permission.isOperator() }
/** 如果是管理员发的消息 */
@MessageDsl
fun sentByAdministrator(): ListeningFilter =
public fun sentByAdministrator(): ListeningFilter =
content { this is GroupMessageEvent && sender.permission.isAdministrator() }
/** 如果是群主发的消息 */
@MessageDsl
fun sentByOwner(): ListeningFilter = content { this is GroupMessageEvent && sender.isOwner() }
public fun sentByOwner(): ListeningFilter = content { this is GroupMessageEvent && sender.isOwner() }
/** 如果是来自这个群的消息 */
@MessageDsl
fun sentFrom(groupId: Long): ListeningFilter = content { this is GroupMessageEvent && group.id == groupId }
public fun sentFrom(groupId: Long): ListeningFilter = content { this is GroupMessageEvent && group.id == groupId }
/** 如果是来自这个群的消息 */
@MessageDsl
fun sentFrom(group: Group): ListeningFilter = content { this is GroupMessageEvent && group.id == group.id }
public fun sentFrom(group: Group): ListeningFilter = content { this is GroupMessageEvent && group.id == group.id }
/** [消息内容][Message.contentToString]包含目标为 [Bot] 的 [At] */
@MessageDsl
fun atBot(): ListeningFilter = content { message.firstIsInstanceOrNull<At>()?.target == bot.id }
public fun atBot(): ListeningFilter = content { message.firstIsInstanceOrNull<At>()?.target == bot.id }
/** [消息内容][Message.contentToString]包含 [AtAll] */
@MessageDsl
fun atAll(): ListeningFilter = content { message.firstIsInstanceOrNull<AtAll>() != null }
public fun atAll(): ListeningFilter = content { message.firstIsInstanceOrNull<AtAll>() != null }
/** [消息内容][Message.contentToString]包含目标为 [target] 的 [At] */
@MessageDsl
fun at(target: Long): ListeningFilter = content { message.firstIsInstanceOrNull<At>()?.target == target }
public fun at(target: Long): ListeningFilter = content { message.firstIsInstanceOrNull<At>()?.target == target }
/** [消息内容][Message.contentToString]包含目标为 [target] 的 [At] */
@MessageDsl
fun at(target: User): ListeningFilter = content { message.firstIsInstanceOrNull<At>()?.target == target.id }
public fun at(target: User): ListeningFilter = content { message.firstIsInstanceOrNull<At>()?.target == target.id }
/** [消息内容][Message.contentToString]包含目标为 [Bot] 的 [At], 就执行 [onEvent] */
@MessageDsl
fun atBot(onEvent: @MessageDsl suspend M.(String) -> R): Ret =
public fun atBot(onEvent: @MessageDsl suspend M.(String) -> R): Ret =
content { message.firstIsInstanceOrNull<At>()?.target == bot.id }.invoke {
onEvent.invoke(this, message.contentToString())
}
@MessageDsl
inline fun <reified N : Message> has(noinline onEvent: @MessageDsl suspend M.(N) -> R): Ret =
public inline fun <reified N : Message> has(noinline onEvent: @MessageDsl suspend M.(N) -> R): Ret =
content { message.any { it is N } }.invoke { onEvent.invoke(this, message.firstIsInstance()) }
/** [消息内容][Message.contentToString]包含 [N] 类型的 [Message] */
@MessageDsl
inline fun <reified N : Message> has(): ListeningFilter = content { message.any { it is N } }
public inline fun <reified N : Message> has(): ListeningFilter = content { message.any { it is N } }
/** 如果 [mapper] 返回值非空, 就执行 [onEvent] */
@MessageDsl
open fun <N : Any> mapping(mapper: M.(String) -> N?, onEvent: @MessageDsl suspend M.(N) -> R): Ret =
public open fun <N : Any> mapping(mapper: M.(String) -> N?, onEvent: @MessageDsl suspend M.(N) -> R): Ret =
always {
onEvent.invoke(
this,
@ -331,16 +333,16 @@ open class MessageSubscribersBuilder<M : MessageEvent, out Ret, R : RR, RR>(
/** 如果 [filter] 返回 `true` */
@MessageDsl
fun content(filter: M.(String) -> Boolean): ListeningFilter = newListeningFilter(filter)
public fun content(filter: M.(String) -> Boolean): ListeningFilter = newListeningFilter(filter)
/** [消息内容][Message.contentToString]可由正则表达式匹配([Regex.matchEntire]) */
@MessageDsl
fun matching(regex: Regex): ListeningFilter = content { regex.matchEntire(it) != null }
public fun matching(regex: Regex): ListeningFilter = content { regex.matchEntire(it) != null }
/** [消息内容][Message.contentToString]可由正则表达式匹配([Regex.matchEntire]), 就执行 `onEvent` */
@MessageDsl
fun matching(regex: Regex, onEvent: @MessageDsl suspend M.(MatchResult) -> Unit): Ret =
public fun matching(regex: Regex, onEvent: @MessageDsl suspend M.(MatchResult) -> Unit): Ret =
always {
this@MessageSubscribersBuilder.executeAndReply(this) {
onEvent.invoke(
@ -352,11 +354,11 @@ open class MessageSubscribersBuilder<M : MessageEvent, out Ret, R : RR, RR>(
/** [消息内容][Message.contentToString]可由正则表达式查找([Regex.find]) */
@MessageDsl
fun finding(regex: Regex): ListeningFilter = content { regex.find(it) != null }
public fun finding(regex: Regex): ListeningFilter = content { regex.find(it) != null }
/** [消息内容][Message.contentToString]可由正则表达式查找([Regex.find]), 就执行 `onEvent` */
@MessageDsl
fun finding(regex: Regex, onEvent: @MessageDsl suspend M.(MatchResult) -> Unit): Ret =
public fun finding(regex: Regex, onEvent: @MessageDsl suspend M.(MatchResult) -> Unit): Ret =
always {
this@MessageSubscribersBuilder.executeAndReply(this) {
onEvent.invoke(
@ -369,7 +371,7 @@ open class MessageSubscribersBuilder<M : MessageEvent, out Ret, R : RR, RR>(
/** [消息内容][Message.contentToString]包含 [this] 则回复 [reply] */
@MessageDsl
open infix fun String.containsReply(reply: String): Ret =
public open infix fun String.containsReply(reply: String): Ret =
content({ this@containsReply in it }, { reply(reply); this@MessageSubscribersBuilder.stub })
/**
@ -380,7 +382,7 @@ open class MessageSubscribersBuilder<M : MessageEvent, out Ret, R : RR, RR>(
* @param replier 若返回 [Message] 则直接发送; 若返回 [Unit] 则不回复; 其他情况则 [Any.toString] 后回复
*/
@MessageDsl
open infix fun String.containsReply(replier: @MessageDsl suspend M.(String) -> Any?): Ret =
public open infix fun String.containsReply(replier: @MessageDsl suspend M.(String) -> Any?): Ret =
content({ this@containsReply in it }, { this@MessageSubscribersBuilder.executeAndReply(this, replier) })
/**
@ -391,7 +393,7 @@ open class MessageSubscribersBuilder<M : MessageEvent, out Ret, R : RR, RR>(
* @param replier 若返回 [Message] 则直接发送; 若返回 [Unit] 则不回复; 其他情况则 [Any.toString] 后回复
*/
@MessageDsl
open infix fun Regex.matchingReply(replier: @MessageDsl suspend M.(MatchResult) -> Any?): Ret =
public open infix fun Regex.matchingReply(replier: @MessageDsl suspend M.(MatchResult) -> Any?): Ret =
always {
this@MessageSubscribersBuilder.executeAndReply(this) {
replier.invoke(
@ -409,7 +411,7 @@ open class MessageSubscribersBuilder<M : MessageEvent, out Ret, R : RR, RR>(
* @param replier 若返回 [Message] 则直接发送; 若返回 [Unit] 则不回复; 其他情况则 [Any.toString] 后回复
*/
@MessageDsl
open infix fun Regex.findingReply(replier: @MessageDsl suspend M.(MatchResult) -> Any?): Ret =
public open infix fun Regex.findingReply(replier: @MessageDsl suspend M.(MatchResult) -> Any?): Ret =
always {
this@MessageSubscribersBuilder.executeAndReply(this) {
replier.invoke(
@ -425,7 +427,7 @@ open class MessageSubscribersBuilder<M : MessageEvent, out Ret, R : RR, RR>(
* @param replier 若返回 [Message] 则直接发送; 若返回 [Unit] 则不回复; 其他情况则 [Any.toString] 后回复
*/
@MessageDsl
open infix fun String.endsWithReply(replier: @MessageDsl suspend M.(String) -> Any?): Ret {
public open infix fun String.endsWithReply(replier: @MessageDsl suspend M.(String) -> Any?): Ret {
val toCheck = this.trimEnd()
return content({ it.trim().endsWith(toCheck) }, {
this@MessageSubscribersBuilder.executeAndReply(this) { replier(this, it.trim().removeSuffix(toCheck)) }
@ -434,21 +436,21 @@ open class MessageSubscribersBuilder<M : MessageEvent, out Ret, R : RR, RR>(
/** 当发送的消息内容为 [this] 就回复 [reply] */
@MessageDsl
open infix fun String.reply(reply: String): Ret {
public open infix fun String.reply(reply: String): Ret {
val toCheck = this.trim()
return content({ it.trim() == toCheck }, { reply(reply);this@MessageSubscribersBuilder.stub })
}
/** 当发送的消息内容为 [this] 就回复 [reply] */
@MessageDsl
open infix fun String.reply(reply: Message): Ret {
public open infix fun String.reply(reply: Message): Ret {
val toCheck = this.trim()
return content({ it.trim() == toCheck }, { reply(reply);this@MessageSubscribersBuilder.stub })
}
/** 当发送的消息内容为 [this] 就执行并回复 [replier] 的返回值 */
@MessageDsl
open infix fun String.reply(replier: @MessageDsl suspend M.(String) -> Any?): Ret {
public open infix fun String.reply(replier: @MessageDsl suspend M.(String) -> Any?): Ret {
val toCheck = this.trim()
return content({ it.trim() == toCheck }, {
@Suppress("DSL_SCOPE_VIOLATION_WARNING")
@ -465,14 +467,14 @@ open class MessageSubscribersBuilder<M : MessageEvent, out Ret, R : RR, RR>(
@Deprecated("use reply instead", ReplaceWith("this.reply(message)"), level = DeprecationLevel.ERROR)
@JvmName("reply3")
@MessageDsl
open infix fun ListeningFilter.`->`(toReply: String): Ret = this.reply(toReply)
public open infix fun ListeningFilter.`->`(toReply: String): Ret = this.reply(toReply)
/** 启动这个监听器, 在满足条件时回复原消息 */
@PlannedRemoval("1.2.0")
@Deprecated("use reply instead", ReplaceWith("this.reply(message)"), level = DeprecationLevel.ERROR)
@JvmName("reply3")
@MessageDsl
open infix fun ListeningFilter.`->`(message: Message): Ret = this.reply(message)
public open infix fun ListeningFilter.`->`(message: Message): Ret = this.reply(message)
@Suppress("REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE", "UNCHECKED_CAST") // false positive
internal suspend inline fun executeAndReply(m: M, replier: suspend M.(String) -> Any?): RR {
@ -501,4 +503,4 @@ open class MessageSubscribersBuilder<M : MessageEvent, out Ret, R : RR, RR>(
@Retention(AnnotationRetention.SOURCE)
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.CLASS, AnnotationTarget.TYPE)
@DslMarker
annotation class MessageDsl
public annotation class MessageDsl

View File

@ -55,7 +55,7 @@ import kotlin.jvm.JvmName
level = DeprecationLevel.HIDDEN
)
@kotlin.internal.LowPriorityInOverloadResolution
fun <R> Bot.subscribeMessages(
public fun <R> Bot.subscribeMessages(
coroutineContext: CoroutineContext = EmptyCoroutineContext,
concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT,
priority: Listener.EventPriority = EventPriority.MONITOR,
@ -80,7 +80,7 @@ fun <R> Bot.subscribeMessages(
"Deprecated for better Coroutine life cycle management. Please filter bot instance on your own.",
level = DeprecationLevel.HIDDEN
)
fun <R> Bot.subscribeGroupMessages(
public fun <R> Bot.subscribeGroupMessages(
coroutineContext: CoroutineContext = EmptyCoroutineContext,
concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT,
priority: Listener.EventPriority = EventPriority.MONITOR,
@ -105,7 +105,7 @@ fun <R> Bot.subscribeGroupMessages(
"Deprecated for better Coroutine life cycle management. Please filter bot instance on your own.",
level = DeprecationLevel.HIDDEN
)
fun <R> Bot.subscribeFriendMessages(
public fun <R> Bot.subscribeFriendMessages(
coroutineContext: CoroutineContext = EmptyCoroutineContext,
concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT,
priority: Listener.EventPriority = EventPriority.MONITOR,
@ -131,7 +131,7 @@ fun <R> Bot.subscribeFriendMessages(
"Deprecated for better Coroutine life cycle management. Please filter bot instance on your own.",
level = DeprecationLevel.HIDDEN
)
fun <R> Bot.subscribeTempMessages(
public fun <R> Bot.subscribeTempMessages(
coroutineContext: CoroutineContext = EmptyCoroutineContext,
concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT,
priority: Listener.EventPriority = EventPriority.MONITOR,
@ -156,7 +156,7 @@ fun <R> Bot.subscribeTempMessages(
"Deprecated for better Coroutine life cycle management. Please filter bot instance on your own.",
level = DeprecationLevel.HIDDEN
)
inline fun <reified E : BotEvent> Bot.incoming(
public inline fun <reified E : BotEvent> Bot.incoming(
coroutineContext: CoroutineContext = EmptyCoroutineContext,
concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT,
priority: Listener.EventPriority = EventPriority.MONITOR,
@ -175,7 +175,7 @@ inline fun <reified E : BotEvent> Bot.incoming(
@kotlin.internal.LowPriorityInOverloadResolution
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
@PlannedRemoval("1.2.0")
fun <R> CoroutineScope.subscribeMessages(
public fun <R> CoroutineScope.subscribeMessages(
coroutineContext: CoroutineContext = EmptyCoroutineContext,
concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT,
listeners: MessagePacketSubscribersBuilder.() -> R
@ -184,7 +184,7 @@ fun <R> CoroutineScope.subscribeMessages(
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
@kotlin.internal.LowPriorityInOverloadResolution
@PlannedRemoval("1.2.0")
fun <R> CoroutineScope.subscribeGroupMessages(
public fun <R> CoroutineScope.subscribeGroupMessages(
coroutineContext: CoroutineContext = EmptyCoroutineContext,
concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT,
listeners: GroupMessageSubscribersBuilder.() -> R
@ -193,7 +193,7 @@ fun <R> CoroutineScope.subscribeGroupMessages(
@kotlin.internal.LowPriorityInOverloadResolution
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
@PlannedRemoval("1.2.0")
fun <R> CoroutineScope.subscribeFriendMessages(
public fun <R> CoroutineScope.subscribeFriendMessages(
coroutineContext: CoroutineContext = EmptyCoroutineContext,
concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT,
listeners: FriendMessageSubscribersBuilder.() -> R
@ -202,7 +202,7 @@ fun <R> CoroutineScope.subscribeFriendMessages(
@kotlin.internal.LowPriorityInOverloadResolution
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
@PlannedRemoval("1.2.0")
fun <R> CoroutineScope.subscribeTempMessages(
public fun <R> CoroutineScope.subscribeTempMessages(
coroutineContext: CoroutineContext = EmptyCoroutineContext,
concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT,
listeners: TempMessageSubscribersBuilder.() -> R
@ -211,7 +211,7 @@ fun <R> CoroutineScope.subscribeTempMessages(
@kotlin.internal.LowPriorityInOverloadResolution
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
@PlannedRemoval("1.2.0")
fun <R> Bot.subscribeMessages(
public fun <R> Bot.subscribeMessages(
coroutineContext: CoroutineContext = EmptyCoroutineContext,
concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT,
listeners: MessagePacketSubscribersBuilder.() -> R
@ -220,7 +220,7 @@ fun <R> Bot.subscribeMessages(
@kotlin.internal.LowPriorityInOverloadResolution
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
@PlannedRemoval("1.2.0")
fun <R> Bot.subscribeGroupMessages(
public fun <R> Bot.subscribeGroupMessages(
coroutineContext: CoroutineContext = EmptyCoroutineContext,
concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT,
listeners: GroupMessageSubscribersBuilder.() -> R
@ -229,7 +229,7 @@ fun <R> Bot.subscribeGroupMessages(
@kotlin.internal.LowPriorityInOverloadResolution
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
@PlannedRemoval("1.2.0")
fun <R> Bot.subscribeFriendMessages(
public fun <R> Bot.subscribeFriendMessages(
coroutineContext: CoroutineContext = EmptyCoroutineContext,
concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT,
listeners: FriendMessageSubscribersBuilder.() -> R
@ -238,7 +238,7 @@ fun <R> Bot.subscribeFriendMessages(
@kotlin.internal.LowPriorityInOverloadResolution
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
@PlannedRemoval("1.2.0")
fun <R> Bot.subscribeTempMessages(
public fun <R> Bot.subscribeTempMessages(
coroutineContext: CoroutineContext = EmptyCoroutineContext,
concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT,
listeners: TempMessageSubscribersBuilder.() -> R

View File

@ -1,9 +1,9 @@
package net.mamoe.mirai.event.events
@Suppress("unused")
class EventCancelledException : RuntimeException {
constructor() : super()
constructor(message: String?) : super(message)
constructor(message: String?, cause: Throwable?) : super(message, cause)
constructor(cause: Throwable?) : super(cause)
public class EventCancelledException : RuntimeException {
public constructor() : super()
public constructor(message: String?) : super(message)
public constructor(message: String?, cause: Throwable?) : super(message, cause)
public constructor(cause: Throwable?) : super(cause)
}

View File

@ -28,23 +28,32 @@ import kotlin.jvm.JvmName
/**
* [Bot] 登录完成, 好友列表, 群组列表初始化完成
*/
data class BotOnlineEvent internal constructor(override val bot: Bot) : BotActiveEvent, AbstractEvent()
public data class BotOnlineEvent internal constructor(
public override val bot: Bot
) : BotActiveEvent, AbstractEvent()
/**
* [Bot] 离线.
*/
sealed class BotOfflineEvent : BotEvent, AbstractEvent() {
public sealed class BotOfflineEvent : BotEvent, AbstractEvent() {
/**
* 主动离线. 主动广播这个事件也可以让 [Bot] 关闭.
*/
data class Active(override val bot: Bot, override val cause: Throwable?) : BotOfflineEvent(), BotActiveEvent,
public data class Active(
public override val bot: Bot,
public override val cause: Throwable?
) : BotOfflineEvent(), BotActiveEvent,
CauseAware
/**
* 被挤下线
*/
data class Force internal constructor(override val bot: Bot, val title: String, val message: String) :
public data class Force internal constructor(
public override val bot: Bot,
public val title: String,
public val message: String
) :
BotOfflineEvent(), Packet,
BotPassiveEvent
@ -53,14 +62,20 @@ sealed class BotOfflineEvent : BotEvent, AbstractEvent() {
*/
@SinceMirai("1.1.0")
@MiraiInternalAPI("This is very experimental and might be changed")
data class MsfOffline internal constructor(override val bot: Bot, override val cause: Throwable?) :
public data class MsfOffline internal constructor(
public override val bot: Bot,
public override val cause: Throwable?
) :
BotOfflineEvent(), Packet,
BotPassiveEvent, CauseAware
/**
* 因网络问题而掉线
*/
data class Dropped internal constructor(override val bot: Bot, override val cause: Throwable?) : BotOfflineEvent(),
public data class Dropped internal constructor(
public override val bot: Bot,
public override val cause: Throwable?
) : BotOfflineEvent(),
Packet,
BotPassiveEvent, CauseAware
@ -68,28 +83,31 @@ sealed class BotOfflineEvent : BotEvent, AbstractEvent() {
* 服务器主动要求更换另一个服务器
*/
@MiraiInternalAPI
data class RequireReconnect internal constructor(override val bot: Bot) : BotOfflineEvent(), Packet, BotPassiveEvent
public data class RequireReconnect internal constructor(
public override val bot: Bot
) : BotOfflineEvent(), Packet,
BotPassiveEvent
@MiraiExperimentalAPI
interface CauseAware {
val cause: Throwable?
public interface CauseAware {
public val cause: Throwable?
}
}
/**
* [Bot] 主动或被动重新登录. 在此事件广播前就已经登录完毕.
*/
data class BotReloginEvent internal constructor(
override val bot: Bot,
val cause: Throwable?
public data class BotReloginEvent internal constructor(
public override val bot: Bot,
public val cause: Throwable?
) : BotEvent, BotActiveEvent, AbstractEvent()
/**
* [Bot] 头像被修改通过其他客户端修改了头像. 在此事件广播前就已经修改完毕.
* @see FriendAvatarChangedEvent
*/
data class BotAvatarChangedEvent(
override val bot: Bot
public data class BotAvatarChangedEvent(
public override val bot: Bot
) : BotEvent, Packet, AbstractEvent()
// region 图片

View File

@ -28,54 +28,54 @@ import kotlin.jvm.*
/**
* 好友昵称改变事件. 目前仅支持解析 (来自 PC 端的修改).
*/
data class FriendRemarkChangeEvent internal constructor(
override val friend: Friend,
val newName: String
public data class FriendRemarkChangeEvent internal constructor(
public override val friend: Friend,
public val newName: String
) : FriendEvent, Packet, AbstractEvent()
/**
* 成功添加了一个新好友的事件
*/
data class FriendAddEvent internal constructor(
public data class FriendAddEvent internal constructor(
/**
* 新好友. 已经添加到 [Bot.friends]
*/
override val friend: Friend
public override val friend: Friend
) : FriendEvent, Packet, AbstractEvent()
/**
* 好友已被删除的事件.
*/
data class FriendDeleteEvent internal constructor(
override val friend: Friend
public data class FriendDeleteEvent internal constructor(
public override val friend: Friend
) : FriendEvent, Packet, AbstractEvent()
/**
* 一个账号请求添加机器人为好友的事件
*/
@Suppress("DEPRECATION")
data class NewFriendRequestEvent internal constructor(
override val bot: Bot,
public data class NewFriendRequestEvent internal constructor(
public override val bot: Bot,
/**
* 事件唯一识别号
*/
val eventId: Long,
public val eventId: Long,
/**
* 申请好友消息
*/
val message: String,
public val message: String,
/**
* 请求人 [User.id]
*/
val fromId: Long,
public val fromId: Long,
/**
* 来自群 [Group.id], 其他途径时为 0
*/
val fromGroupId: Long,
public val fromGroupId: Long,
/**
* 群名片或好友昵称
*/
val fromNick: String
public val fromNick: String
) : BotEvent, Packet, AbstractEvent() {
@JvmField
internal val responded: MiraiAtomicBoolean = MiraiAtomicBoolean(false)
@ -83,23 +83,23 @@ data class NewFriendRequestEvent internal constructor(
/**
* @return 申请人来自的群. 当申请人来自其他途径申请时为 `null`
*/
val fromGroup: Group? = if (fromGroupId == 0L) null else bot.getGroup(fromGroupId)
public val fromGroup: Group? = if (fromGroupId == 0L) null else bot.getGroup(fromGroupId)
@JvmSynthetic
suspend fun accept() = bot.acceptNewFriendRequest(this)
public suspend fun accept(): Unit = bot.acceptNewFriendRequest(this)
@JvmSynthetic
suspend fun reject(blackList: Boolean = false) = bot.rejectNewFriendRequest(this, blackList)
public suspend fun reject(blackList: Boolean = false): Unit = bot.rejectNewFriendRequest(this, blackList)
@JavaFriendlyAPI
@JvmName("accept")
fun __acceptBlockingForJava__() = runBlocking { accept() }
public fun __acceptBlockingForJava__(): Unit = runBlocking { accept() }
@JavaFriendlyAPI
@JvmOverloads
@JvmName("reject")
fun __rejectBlockingForJava__(blackList: Boolean = false) =
public fun __rejectBlockingForJava__(blackList: Boolean = false): Unit =
runBlocking { reject(blackList) }
}
@ -107,7 +107,7 @@ data class NewFriendRequestEvent internal constructor(
/**
* [Friend] 头像被修改. 在此事件广播前就已经修改完毕.
*/
data class FriendAvatarChangedEvent internal constructor(
override val friend: Friend
public data class FriendAvatarChangedEvent internal constructor(
public override val friend: Friend
) : FriendEvent, Packet, AbstractEvent()

View File

@ -31,82 +31,85 @@ import kotlin.jvm.*
/**
* 机器人被踢出群或在其他客户端主动退出一个群. 在事件广播前 [Bot.groups] 就已删除这个群.
*/
sealed class BotLeaveEvent : BotEvent, Packet, AbstractEvent() {
abstract val group: Group
public sealed class BotLeaveEvent : BotEvent, Packet, AbstractEvent() {
public abstract val group: Group
/**
* 机器人主动退出一个群.
*/
@MiraiExperimentalAPI("目前此事件类型不一定正确. 部分被踢出情况也会广播此事件.")
data class Active internal constructor(override val group: Group) : BotLeaveEvent() {
override fun toString(): String = "BotLeaveEvent.Active(group=${group.id})"
public data class Active internal constructor(
public override val group: Group
) : BotLeaveEvent() {
public override fun toString(): String = "BotLeaveEvent.Active(group=${group.id})"
}
/**
* 机器人被管理员或群主踢出群.
*/
@MiraiExperimentalAPI("BotLeaveEvent 的子类可能在将来改动. 使用 BotLeaveEvent 以保证兼容性.")
data class Kick internal constructor(override val operator: Member) : BotLeaveEvent(), GroupOperableEvent {
override val group: Group get() = operator.group
override val bot: Bot get() = super<BotLeaveEvent>.bot
override fun toString(): String = "BotLeaveEvent.Kick(group=${group.id},operator=${operator.id})"
public data class Kick internal constructor(
public override val operator: Member
) : BotLeaveEvent(),
GroupOperableEvent {
public override val group: Group get() = operator.group
public override val bot: Bot get() = super<BotLeaveEvent>.bot
public override fun toString(): String = "BotLeaveEvent.Kick(group=${group.id},operator=${operator.id})"
}
override val bot: Bot get() = group.bot
public override val bot: Bot get() = group.bot
}
/**
* Bot 在群里的权限被改变. 操作人一定是群主
*/
data class BotGroupPermissionChangeEvent internal constructor(
override val group: Group,
val origin: MemberPermission,
val new: MemberPermission
public data class BotGroupPermissionChangeEvent internal constructor(
public override val group: Group,
public val origin: MemberPermission,
public val new: MemberPermission
) : BotPassiveEvent, GroupEvent, Packet, AbstractEvent()
/**
* Bot 被禁言
*/
data class BotMuteEvent internal constructor(
val durationSeconds: Int,
public data class BotMuteEvent internal constructor(
public val durationSeconds: Int,
/**
* 操作人.
*/
val operator: Member
public val operator: Member
) : GroupEvent, Packet, BotPassiveEvent, AbstractEvent() {
override val group: Group
public override val group: Group
get() = operator.group
}
/**
* Bot 被取消禁言
*/
data class BotUnmuteEvent internal constructor(
public data class BotUnmuteEvent internal constructor(
/**
* 操作人.
*/
val operator: Member
public val operator: Member
) : GroupEvent, Packet, BotPassiveEvent, AbstractEvent() {
override val group: Group
public override val group: Group
get() = operator.group
}
/**
* Bot 成功加入了一个新群
*/
sealed class BotJoinGroupEvent : GroupEvent, Packet, AbstractEvent() {
abstract override val group: Group
public sealed class BotJoinGroupEvent : GroupEvent, Packet, AbstractEvent() {
public abstract override val group: Group
/**
* 不确定. 可能是主动加入
*/
@MiraiExperimentalAPI
data class Active internal constructor(
override val group: Group
public data class Active internal constructor(
public override val group: Group
) : BotPassiveEvent, GroupEvent, Packet, AbstractEvent() {
override fun toString(): String {
return "BotJoinGroupEvent.Active(group=$group)"
}
public override fun toString(): String = "BotJoinGroupEvent.Active(group=$group)"
}
/**
@ -115,15 +118,15 @@ sealed class BotJoinGroupEvent : GroupEvent, Packet, AbstractEvent() {
* 此时服务器基于 Bot QQ 设置自动同意了请求.
*/
@MiraiExperimentalAPI
data class Invite internal constructor(
public data class Invite internal constructor(
/**
* 邀请人
*/
val invitor: Member
public val invitor: Member
) : BotPassiveEvent, GroupEvent, Packet, AbstractEvent() {
override val group: Group get() = invitor.group
public override val group: Group get() = invitor.group
override fun toString(): String {
public override fun toString(): String {
return "BotJoinGroupEvent.Invite(invitor=$invitor)"
}
}
@ -134,95 +137,95 @@ sealed class BotJoinGroupEvent : GroupEvent, Packet, AbstractEvent() {
/**
* 群设置改变. 此事件广播前修改就已经完成.
*/
interface GroupSettingChangeEvent<T> : GroupEvent, BotPassiveEvent, BroadcastControllable {
val origin: T
val new: T
public interface GroupSettingChangeEvent<T> : GroupEvent, BotPassiveEvent, BroadcastControllable {
public val origin: T
public val new: T
override val shouldBroadcast: Boolean
public override val shouldBroadcast: Boolean
get() = origin != new
}
/**
* 群名改变. 此事件广播前修改就已经完成.
*/
data class GroupNameChangeEvent internal constructor(
override val origin: String,
override val new: String,
override val group: Group,
public data class GroupNameChangeEvent internal constructor(
public override val origin: String,
public override val new: String,
public override val group: Group,
/**
* 操作人. null 时则是机器人操作
*/
override val operator: Member?
public override val operator: Member?
) : GroupSettingChangeEvent<String>, Packet, GroupOperableEvent, AbstractEvent() {
@LowPriorityInOverloadResolution
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
val isByBot: Boolean
internal val isByBot: Boolean
get() = operator == null
}
/**
* 入群公告改变. 此事件广播前修改就已经完成.
*/
data class GroupEntranceAnnouncementChangeEvent internal constructor(
override val origin: String,
override val new: String,
override val group: Group,
public data class GroupEntranceAnnouncementChangeEvent internal constructor(
public override val origin: String,
public override val new: String,
public override val group: Group,
/**
* 操作人. null 时则是机器人操作
*/
override val operator: Member?
public override val operator: Member?
) : GroupSettingChangeEvent<String>, Packet, GroupOperableEvent, AbstractEvent()
/**
* "全员禁言" 功能状态改变. 此事件广播前修改就已经完成.
*/
data class GroupMuteAllEvent internal constructor(
override val origin: Boolean,
override val new: Boolean,
override val group: Group,
public data class GroupMuteAllEvent internal constructor(
public override val origin: Boolean,
public override val new: Boolean,
public override val group: Group,
/**
* 操作人. null 时则是机器人操作
*/
override val operator: Member?
public override val operator: Member?
) : GroupSettingChangeEvent<Boolean>, Packet, GroupOperableEvent, AbstractEvent()
/**
* "匿名聊天" 功能状态改变. 此事件广播前修改就已经完成.
*/
data class GroupAllowAnonymousChatEvent internal constructor(
override val origin: Boolean,
override val new: Boolean,
override val group: Group,
public data class GroupAllowAnonymousChatEvent internal constructor(
public override val origin: Boolean,
public override val new: Boolean,
public override val group: Group,
/**
* 操作人. null 时则是机器人操作
*/
override val operator: Member?
public override val operator: Member?
) : GroupSettingChangeEvent<Boolean>, Packet, GroupOperableEvent, AbstractEvent()
/**
* "坦白说" 功能状态改变. 此事件广播前修改就已经完成.
*/
data class GroupAllowConfessTalkEvent internal constructor(
override val origin: Boolean,
override val new: Boolean,
override val group: Group,
val isByBot: Boolean // 无法获取操作人
public data class GroupAllowConfessTalkEvent internal constructor(
public override val origin: Boolean,
public override val new: Boolean,
public override val group: Group,
public val isByBot: Boolean // 无法获取操作人
) : GroupSettingChangeEvent<Boolean>, Packet, AbstractEvent()
/**
* "允许群员邀请好友加群" 功能状态改变. 此事件广播前修改就已经完成.
*/
data class GroupAllowMemberInviteEvent internal constructor(
override val origin: Boolean,
override val new: Boolean,
override val group: Group,
public data class GroupAllowMemberInviteEvent internal constructor(
public override val origin: Boolean,
public override val new: Boolean,
public override val group: Group,
/**
* 操作人. null 时则是机器人操作
*/
override val operator: Member?
public override val operator: Member?
) : GroupSettingChangeEvent<Boolean>, Packet, GroupOperableEvent, AbstractEvent()
@ -236,45 +239,53 @@ data class GroupAllowMemberInviteEvent internal constructor(
/**
* 成员已经加入群的事件
*/
sealed class MemberJoinEvent(override val member: Member) : GroupMemberEvent, BotPassiveEvent, Packet,
public sealed class MemberJoinEvent(
public override val member: Member
) : GroupMemberEvent, BotPassiveEvent, Packet,
AbstractEvent() {
/**
* 被邀请加入群
*/
data class Invite internal constructor(override val member: Member) : MemberJoinEvent(member) {
override fun toString(): String = "MemberJoinEvent.Invite(member=${member.id})"
public data class Invite internal constructor(
public override val member: Member
) : MemberJoinEvent(member) {
public override fun toString(): String = "MemberJoinEvent.Invite(member=${member.id})"
}
/**
* 成员主动加入群
*/
data class Active internal constructor(override val member: Member) : MemberJoinEvent(member) {
override fun toString(): String = "MemberJoinEvent.Active(member=${member.id})"
public data class Active internal constructor(
public override val member: Member
) : MemberJoinEvent(member) {
public override fun toString(): String = "MemberJoinEvent.Active(member=${member.id})"
}
}
/**
* 成员已经离开群的事件. 在事件广播前成员就已经从 [Group.members] 中删除
*/
sealed class MemberLeaveEvent : GroupMemberEvent, AbstractEvent() {
public sealed class MemberLeaveEvent : GroupMemberEvent, AbstractEvent() {
/**
* 成员被踢出群. 成员不可能是机器人自己.
*/
data class Kick(
override val member: Member,
public data class Kick(
public override val member: Member,
/**
* 操作人. null 则是机器人操作.
*/
override val operator: Member?
public override val operator: Member?
) : MemberLeaveEvent(), Packet, GroupOperableEvent {
override fun toString(): String = "MemberLeaveEvent.Kick(member=${member.id}, operator=${operator?.id})"
public override fun toString(): String = "MemberLeaveEvent.Kick(member=${member.id}, operator=${operator?.id})"
}
/**
* 成员主动离开
*/
data class Quit(override val member: Member) : MemberLeaveEvent(), Packet {
override fun toString(): String = "MemberLeaveEvent.Quit(member=${member.id})"
public data class Quit(
public override val member: Member
) : MemberLeaveEvent(), Packet {
public override fun toString(): String = "MemberLeaveEvent.Quit(member=${member.id})"
}
}
@ -282,42 +293,42 @@ sealed class MemberLeaveEvent : GroupMemberEvent, AbstractEvent() {
* [Bot] 被邀请加入一个群.
*/
@Suppress("DEPRECATION")
data class BotInvitedJoinGroupRequestEvent internal constructor(
override val bot: Bot,
public data class BotInvitedJoinGroupRequestEvent internal constructor(
public override val bot: Bot,
/**
* 事件唯一识别号
*/
val eventId: Long,
public val eventId: Long,
/**
* 邀请入群的账号的 id
*/
val invitorId: Long,
val groupId: Long,
val groupName: String,
public val invitorId: Long,
public val groupId: Long,
public val groupName: String,
/**
* 邀请人昵称
*/
val invitorNick: String
public val invitorNick: String
) : BotEvent, Packet, AbstractEvent() {
val invitor: Friend get() = this.bot.getFriend(invitorId)
public val invitor: Friend get() = this.bot.getFriend(invitorId)
@JvmField
internal val responded: MiraiAtomicBoolean = MiraiAtomicBoolean(false)
@JvmSynthetic
suspend fun accept() = bot.acceptInvitedJoinGroupRequest(this)
public suspend fun accept(): Unit = bot.acceptInvitedJoinGroupRequest(this)
@JvmSynthetic
suspend fun ignore() = bot.ignoreInvitedJoinGroupRequest(this)
public suspend fun ignore(): Unit = bot.ignoreInvitedJoinGroupRequest(this)
@JavaFriendlyAPI
@JvmName("accept")
fun __acceptBlockingForJava__() =
public fun __acceptBlockingForJava__(): Unit =
runBlocking { bot.acceptInvitedJoinGroupRequest(this@BotInvitedJoinGroupRequestEvent) }
@JavaFriendlyAPI
@JvmName("ignore")
fun __ignoreBlockingForJava__() =
public fun __ignoreBlockingForJava__(): Unit =
runBlocking { bot.ignoreInvitedJoinGroupRequest(this@BotInvitedJoinGroupRequestEvent) }
}
@ -325,7 +336,7 @@ data class BotInvitedJoinGroupRequestEvent internal constructor(
* 一个账号请求加入群事件, [Bot] 在此群中是管理员或群主.
*/
@Suppress("DEPRECATION")
data class MemberJoinRequestEvent internal constructor(
public data class MemberJoinRequestEvent internal constructor(
override val bot: Bot,
/**
* 事件唯一识别号
@ -346,37 +357,38 @@ data class MemberJoinRequestEvent internal constructor(
*/
val fromNick: String
) : BotEvent, Packet, AbstractEvent() {
val group: Group get() = this.bot.getGroup(groupId)
public val group: Group get() = this.bot.getGroup(groupId)
@JvmField
internal val responded: MiraiAtomicBoolean = MiraiAtomicBoolean(false)
@JvmSynthetic
suspend fun accept() = bot.acceptMemberJoinRequest(this)
public suspend fun accept(): Unit = bot.acceptMemberJoinRequest(this)
@JvmSynthetic
@JvmOverloads
suspend fun reject(blackList: Boolean = false, message: String = "") =
public suspend fun reject(blackList: Boolean = false, message: String = ""): Unit =
bot.rejectMemberJoinRequest(this, blackList, message)
@JvmSynthetic
suspend fun ignore(blackList: Boolean = false) = bot.ignoreMemberJoinRequest(this, blackList)
public suspend fun ignore(blackList: Boolean = false): Unit = bot.ignoreMemberJoinRequest(this, blackList)
@JavaFriendlyAPI
@JvmName("accept")
fun __acceptBlockingForJava__() = runBlocking { bot.acceptMemberJoinRequest(this@MemberJoinRequestEvent) }
public fun __acceptBlockingForJava__(): Unit =
runBlocking { bot.acceptMemberJoinRequest(this@MemberJoinRequestEvent) }
@JavaFriendlyAPI
@JvmOverloads
@JvmName("reject")
fun __rejectBlockingForJava__(blackList: Boolean = false, message: String = "") =
public fun __rejectBlockingForJava__(blackList: Boolean = false, message: String = ""): Unit =
runBlocking { bot.rejectMemberJoinRequest(this@MemberJoinRequestEvent, blackList, message) }
@JavaFriendlyAPI
@JvmOverloads
@JvmName("ignore")
fun __ignoreBlockingForJava__(blackList: Boolean = false) =
public fun __ignoreBlockingForJava__(blackList: Boolean = false): Unit =
runBlocking { bot.ignoreMemberJoinRequest(this@MemberJoinRequestEvent, blackList) }
}
@ -389,42 +401,42 @@ data class MemberJoinRequestEvent internal constructor(
*
* 由于服务器并不会告知名片变动, 此事件只能由 mirai 在发现变动时才广播. 不要依赖于这个事件.
*/
data class MemberCardChangeEvent internal constructor(
public data class MemberCardChangeEvent internal constructor(
/**
* 修改前
*/
val origin: String,
public val origin: String,
/**
* 修改后
*/
val new: String,
public val new: String,
override val member: Member
public override val member: Member
) : GroupMemberEvent, Packet, AbstractEvent()
/**
* 成员群头衔改动. 一定为群主操作
*/
data class MemberSpecialTitleChangeEvent internal constructor(
public data class MemberSpecialTitleChangeEvent internal constructor(
/**
* 修改前
*/
val origin: String,
public val origin: String,
/**
* 修改后
*/
val new: String,
public val new: String,
override val member: Member,
public override val member: Member,
/**
* 操作人.
* 不为 null 时一定为群主. 可能与 [member] 引用相同, 此时为群员自己修改.
* null 时则是机器人操作.
*/
override val operator: Member?
public override val operator: Member?
) : GroupMemberEvent, GroupOperableEvent, AbstractEvent()
// endregion
@ -435,10 +447,10 @@ data class MemberSpecialTitleChangeEvent internal constructor(
/**
* 成员权限改变的事件. 成员不可能是机器人自己.
*/
data class MemberPermissionChangeEvent internal constructor(
override val member: Member,
val origin: MemberPermission,
val new: MemberPermission
public data class MemberPermissionChangeEvent internal constructor(
public override val member: Member,
public val origin: MemberPermission,
public val new: MemberPermission
) : GroupMemberEvent, BotPassiveEvent, Packet, AbstractEvent()
// endregion
@ -451,13 +463,13 @@ data class MemberPermissionChangeEvent internal constructor(
*
* @see BotMuteEvent 机器人被禁言的事件
*/
data class MemberMuteEvent internal constructor(
override val member: Member,
val durationSeconds: Int,
public data class MemberMuteEvent internal constructor(
public override val member: Member,
public val durationSeconds: Int,
/**
* 操作人. null 则为机器人操作
*/
override val operator: Member?
public override val operator: Member?
) : GroupMemberEvent, Packet, GroupOperableEvent, AbstractEvent()
/**
@ -465,12 +477,12 @@ data class MemberMuteEvent internal constructor(
*
* @see BotUnmuteEvent 机器人被取消禁言的事件
*/
data class MemberUnmuteEvent internal constructor(
override val member: Member,
public data class MemberUnmuteEvent internal constructor(
public override val member: Member,
/**
* 操作人. null 则为机器人操作
*/
override val operator: Member?
public override val operator: Member?
) : GroupMemberEvent, Packet, GroupOperableEvent, AbstractEvent()
// endregion

View File

@ -49,13 +49,13 @@ import kotlin.jvm.JvmSynthetic
* @see Contact.sendMessage 发送消息. 为广播这个事件的唯一途径
*/
@SinceMirai("1.1.0")
sealed class MessagePreSendEvent : BotEvent, BotActiveEvent, AbstractEvent(), CancellableEvent {
public sealed class MessagePreSendEvent : BotEvent, BotActiveEvent, AbstractEvent(), CancellableEvent {
/** 发信目标. */
abstract val target: Contact
final override val bot: Bot get() = target.bot
public abstract val target: Contact
public final override val bot: Bot get() = target.bot
/** 待发送的消息. 修改后将会同时应用于发送. */
abstract var message: Message
public abstract var message: Message
}
/**
@ -63,11 +63,11 @@ sealed class MessagePreSendEvent : BotEvent, BotActiveEvent, AbstractEvent(), Ca
* @see MessagePreSendEvent
*/
@SinceMirai("1.1.0")
data class GroupMessagePreSendEvent internal constructor(
public data class GroupMessagePreSendEvent internal constructor(
/** 发信目标. */
override val target: Group,
public override val target: Group,
/** 待发送的消息. 修改后将会同时应用于发送. */
override var message: Message
public override var message: Message
) : MessagePreSendEvent()
/**
@ -75,9 +75,9 @@ data class GroupMessagePreSendEvent internal constructor(
* @see MessagePreSendEvent
*/
@SinceMirai("1.1.0")
sealed class UserMessagePreSendEvent : MessagePreSendEvent() {
public sealed class UserMessagePreSendEvent : MessagePreSendEvent() {
/** 发信目标. */
abstract override val target: User
public abstract override val target: User
}
/**
@ -85,11 +85,11 @@ sealed class UserMessagePreSendEvent : MessagePreSendEvent() {
* @see MessagePreSendEvent
*/
@SinceMirai("1.1.0")
data class FriendMessagePreSendEvent internal constructor(
public data class FriendMessagePreSendEvent internal constructor(
/** 发信目标. */
override val target: Friend,
public override val target: Friend,
/** 待发送的消息. 修改后将会同时应用于发送. */
override var message: Message
public override var message: Message
) : UserMessagePreSendEvent()
/**
@ -97,13 +97,13 @@ data class FriendMessagePreSendEvent internal constructor(
* @see MessagePreSendEvent
*/
@SinceMirai("1.1.0")
data class TempMessagePreSendEvent internal constructor(
public data class TempMessagePreSendEvent internal constructor(
/** 发信目标. */
override val target: Member,
public override val target: Member,
/** 待发送的消息. 修改后将会同时应用于发送. */
override var message: Message
public override var message: Message
) : UserMessagePreSendEvent() {
val group get() = target.group
public val group: Group get() = target.group
}
@ -122,25 +122,25 @@ data class TempMessagePreSendEvent internal constructor(
* @see MessagePreSendEvent
*/
@SinceMirai("1.1.0")
sealed class MessagePostSendEvent<C : Contact> : BotEvent, BotActiveEvent, AbstractEvent() {
public sealed class MessagePostSendEvent<C : Contact> : BotEvent, BotActiveEvent, AbstractEvent() {
/** 发信目标. */
abstract val target: C
final override val bot: Bot get() = target.bot
public abstract val target: C
public final override val bot: Bot get() = target.bot
/** 待发送的消息. 此为 [MessagePreSendEvent.message] 的最终值. */
abstract val message: MessageChain
public abstract val message: MessageChain
/**
* 发送消息时抛出的异常. `null` 表示消息成功发送.
* @see result
*/
abstract val exception: Throwable?
public abstract val exception: Throwable?
/**
* 发送消息成功时的回执. `null` 表示消息发送失败.
* @see result
*/
abstract val receipt: MessageReceipt<C>?
public abstract val receipt: MessageReceipt<C>?
}
/**
@ -149,7 +149,7 @@ sealed class MessagePostSendEvent<C : Contact> : BotEvent, BotActiveEvent, Abstr
*/
@get:JvmSynthetic
@SinceMirai("1.1.0")
inline val MessagePostSendEvent<*>.source: MessageSource?
public inline val MessagePostSendEvent<*>.source: MessageSource?
get() = receipt?.source
/**
@ -158,7 +158,7 @@ inline val MessagePostSendEvent<*>.source: MessageSource?
*/
@get:JvmSynthetic
@SinceMirai("1.1.0")
inline val MessagePostSendEvent<*>.sourceResult: Result<MessageSource>
public inline val MessagePostSendEvent<*>.sourceResult: Result<MessageSource>
get() = result.map { it.source }
/**
@ -168,7 +168,7 @@ inline val MessagePostSendEvent<*>.sourceResult: Result<MessageSource>
*/
@get:JvmSynthetic
@SinceMirai("1.1.0")
inline val MessagePostSendEvent<*>.isSuccess: Boolean
public inline val MessagePostSendEvent<*>.isSuccess: Boolean
get() = exception == null
/**
@ -178,7 +178,7 @@ inline val MessagePostSendEvent<*>.isSuccess: Boolean
*/
@get:JvmSynthetic
@SinceMirai("1.1.0")
inline val MessagePostSendEvent<*>.isFailure: Boolean
public inline val MessagePostSendEvent<*>.isFailure: Boolean
get() = exception != null
/**
@ -186,7 +186,7 @@ inline val MessagePostSendEvent<*>.isFailure: Boolean
*/
@InlineOnly
@SinceMirai("1.1.0")
inline val <C : Contact> MessagePostSendEvent<C>.result: Result<MessageReceipt<C>>
public inline val <C : Contact> MessagePostSendEvent<C>.result: Result<MessageReceipt<C>>
get() = exception.let { exception -> if (exception != null) Result.failure(exception) else Result.success(receipt!!) }
/**
@ -194,21 +194,21 @@ inline val <C : Contact> MessagePostSendEvent<C>.result: Result<MessageReceipt<C
* @see MessagePostSendEvent
*/
@SinceMirai("1.1.0")
data class GroupMessagePostSendEvent internal constructor(
public data class GroupMessagePostSendEvent internal constructor(
/** 发信目标. */
override val target: Group,
public override val target: Group,
/** 待发送的消息. 此为 [MessagePreSendEvent.message] 的最终值. */
override val message: MessageChain,
public override val message: MessageChain,
/**
* 发送消息时抛出的异常. `null` 表示消息成功发送.
* @see result
*/
override val exception: Throwable?,
public override val exception: Throwable?,
/**
* 发送消息成功时的回执. `null` 表示消息发送失败.
* @see result
*/
override val receipt: MessageReceipt<Group>?
public override val receipt: MessageReceipt<Group>?
) : MessagePostSendEvent<Group>()
/**
@ -216,28 +216,28 @@ data class GroupMessagePostSendEvent internal constructor(
* @see MessagePostSendEvent
*/
@SinceMirai("1.1.0")
sealed class UserMessagePostSendEvent<C : User> : MessagePostSendEvent<C>()
public sealed class UserMessagePostSendEvent<C : User> : MessagePostSendEvent<C>()
/**
* 在好友消息发送后广播的事件.
* @see MessagePostSendEvent
*/
@SinceMirai("1.1.0")
data class FriendMessagePostSendEvent internal constructor(
public data class FriendMessagePostSendEvent internal constructor(
/** 发信目标. */
override val target: Friend,
public override val target: Friend,
/** 待发送的消息. 此为 [MessagePreSendEvent.message] 的最终值. */
override val message: MessageChain,
public override val message: MessageChain,
/**
* 发送消息时抛出的异常. `null` 表示消息成功发送.
* @see result
*/
override val exception: Throwable?,
public override val exception: Throwable?,
/**
* 发送消息成功时的回执. `null` 表示消息发送失败.
* @see result
*/
override val receipt: MessageReceipt<Friend>?
public override val receipt: MessageReceipt<Friend>?
) : UserMessagePostSendEvent<Friend>()
/**
@ -245,23 +245,23 @@ data class FriendMessagePostSendEvent internal constructor(
* @see MessagePostSendEvent
*/
@SinceMirai("1.1.0")
data class TempMessagePostSendEvent internal constructor(
public data class TempMessagePostSendEvent internal constructor(
/** 发信目标. */
override val target: Member,
public override val target: Member,
/** 待发送的消息. 此为 [MessagePreSendEvent.message] 的最终值. */
override val message: MessageChain,
public override val message: MessageChain,
/**
* 发送消息时抛出的异常. `null` 表示消息成功发送.
* @see result
*/
override val exception: Throwable?,
public override val exception: Throwable?,
/**
* 发送消息成功时的回执. `null` 表示消息发送失败.
* @see result
*/
override val receipt: MessageReceipt<Member>?
public override val receipt: MessageReceipt<Member>?
) : UserMessagePostSendEvent<Member>() {
val group get() = target.group
public val group: Group get() = target.group
}
// endregion
@ -271,71 +271,71 @@ data class TempMessagePostSendEvent internal constructor(
*
* @see Contact.recall 撤回消息. 为广播这个事件的唯一途径
*/
sealed class MessageRecallEvent : BotEvent, AbstractEvent() {
public sealed class MessageRecallEvent : BotEvent, AbstractEvent() {
/**
* 消息原发送人
*/
abstract val authorId: Long
public abstract val authorId: Long
/**
* 消息 id.
* @see MessageSource.id
*/
abstract val messageId: Int
public abstract val messageId: Int
/**
* 消息内部 id.
* @see MessageSource.id
*/
abstract val messageInternalId: Int
public abstract val messageInternalId: Int
/**
* 原发送时间
*/
abstract val messageTime: Int // seconds
public abstract val messageTime: Int // seconds
/**
* 好友消息撤回事件, 暂不支持.
*/
data class FriendRecall internal constructor(
override val bot: Bot,
override val messageId: Int,
override val messageInternalId: Int,
override val messageTime: Int,
public data class FriendRecall internal constructor(
public override val bot: Bot,
public override val messageId: Int,
public override val messageInternalId: Int,
public override val messageTime: Int,
/**
* 撤回操作人, 好友的 [User.id]
*/
val operator: Long
public val operator: Long
) : MessageRecallEvent(), Packet {
override val authorId: Long
public override val authorId: Long
get() = bot.id
}
/**
* 群消息撤回事件.
*/
data class GroupRecall internal constructor(
override val bot: Bot,
override val authorId: Long,
override val messageId: Int,
override val messageInternalId: Int,
override val messageTime: Int,
public data class GroupRecall internal constructor(
public override val bot: Bot,
public override val authorId: Long,
public override val messageId: Int,
public override val messageInternalId: Int,
public override val messageTime: Int,
/**
* 操作人. null 时则为 [Bot] 操作.
*/
override val operator: Member?,
override val group: Group
public override val operator: Member?,
public override val group: Group
) : MessageRecallEvent(), GroupOperableEvent, Packet
}
val MessageRecallEvent.GroupRecall.author: Member
public val MessageRecallEvent.GroupRecall.author: Member
get() = if (authorId == bot.id) group.botAsMember else group[authorId]
val MessageRecallEvent.FriendRecall.isByBot: Boolean get() = this.operator == bot.id
public val MessageRecallEvent.FriendRecall.isByBot: Boolean get() = this.operator == bot.id
// val MessageRecallEvent.GroupRecall.isByBot: Boolean get() = (this as GroupOperableEvent).isByBot
// no need
val MessageRecallEvent.isByBot: Boolean
public val MessageRecallEvent.isByBot: Boolean
get() = when (this) {
is MessageRecallEvent.FriendRecall -> this.isByBot
is MessageRecallEvent.GroupRecall -> (this as GroupOperableEvent).isByBot
@ -350,11 +350,11 @@ val MessageRecallEvent.isByBot: Boolean
*
* @see Contact.uploadImage 上传图片. 为广播这个事件的唯一途径
*/
data class BeforeImageUploadEvent internal constructor(
val target: Contact,
val source: ExternalImage
public data class BeforeImageUploadEvent internal constructor(
public val target: Contact,
public val source: ExternalImage
) : BotEvent, BotActiveEvent, AbstractEvent(), CancellableEvent {
override val bot: Bot
public override val bot: Bot
get() = target.bot
}
@ -369,19 +369,19 @@ data class BeforeImageUploadEvent internal constructor(
* @see Succeed
* @see Failed
*/
sealed class ImageUploadEvent : BotEvent, BotActiveEvent, AbstractEvent() {
abstract val target: Contact
abstract val source: ExternalImage
override val bot: Bot
public sealed class ImageUploadEvent : BotEvent, BotActiveEvent, AbstractEvent() {
public abstract val target: Contact
public abstract val source: ExternalImage
public override val bot: Bot
get() = target.bot
data class Succeed internal constructor(
public data class Succeed internal constructor(
override val target: Contact,
override val source: ExternalImage,
val image: Image
) : ImageUploadEvent()
data class Failed internal constructor(
public data class Failed internal constructor(
override val target: Contact,
override val source: ExternalImage,
val errno: Int,
@ -406,9 +406,9 @@ sealed class ImageUploadEvent : BotEvent, BotActiveEvent, AbstractEvent() {
replaceWith = ReplaceWith("MessagePreSendEvent", "net.mamoe.mirai.event.events.MessagePreSendEvent"),
level = DeprecationLevel.WARNING
)
sealed class MessageSendEvent : BotEvent, BotActiveEvent, AbstractEvent() {
abstract val target: Contact
final override val bot: Bot
public sealed class MessageSendEvent : BotEvent, BotActiveEvent, AbstractEvent() {
public abstract val target: Contact
public final override val bot: Bot
get() = target.bot
@Deprecated(
@ -418,7 +418,7 @@ sealed class MessageSendEvent : BotEvent, BotActiveEvent, AbstractEvent() {
replaceWith = ReplaceWith("GroupMessagePreSendEvent", "net.mamoe.mirai.event.events.GroupMessagePreSendEvent"),
level = DeprecationLevel.WARNING
)
data class GroupMessageSendEvent internal constructor(
public data class GroupMessageSendEvent internal constructor(
override val target: Group,
var message: MessageChain
) : MessageSendEvent(), CancellableEvent
@ -433,7 +433,7 @@ sealed class MessageSendEvent : BotEvent, BotActiveEvent, AbstractEvent() {
),
level = DeprecationLevel.WARNING
)
data class FriendMessageSendEvent internal constructor(
public data class FriendMessageSendEvent internal constructor(
override val target: Friend,
var message: MessageChain
) : MessageSendEvent(), CancellableEvent
@ -445,7 +445,7 @@ sealed class MessageSendEvent : BotEvent, BotActiveEvent, AbstractEvent() {
replaceWith = ReplaceWith("TempMessagePreSendEvent", "net.mamoe.mirai.event.events.TempMessagePreSendEvent"),
level = DeprecationLevel.WARNING
)
data class TempMessageSendEvent internal constructor(
public data class TempMessageSendEvent internal constructor(
override val target: Member,
var message: MessageChain
) : MessageSendEvent(), CancellableEvent

View File

@ -22,26 +22,26 @@ import kotlin.jvm.JvmSynthetic
/**
* 有关一个 [Bot] 的事件
*/
interface BotEvent : Event {
val bot: Bot
public interface BotEvent : Event {
public val bot: Bot
}
/**
* [Bot] 被动接收的事件. 这些事件可能与机器人有关
*/
interface BotPassiveEvent : BotEvent
public interface BotPassiveEvent : BotEvent
/**
* [Bot] 主动发起的动作的事件
*/
interface BotActiveEvent : BotEvent
public interface BotActiveEvent : BotEvent
/**
* 有关群的事件
*/
interface GroupEvent : BotEvent {
val group: Group
public interface GroupEvent : BotEvent {
public val group: Group
override val bot: Bot
get() = group.bot
}
@ -49,8 +49,8 @@ interface GroupEvent : BotEvent {
/**
* 有关群成员的事件
*/
interface GroupMemberEvent : GroupEvent {
val member: Member
public interface GroupMemberEvent : GroupEvent {
public val member: Member
override val group: Group
get() = member.group
}
@ -60,11 +60,11 @@ interface GroupMemberEvent : GroupEvent {
* @see isByBot
* @see operatorOrBot
*/
interface GroupOperableEvent : GroupEvent {
public interface GroupOperableEvent : GroupEvent {
/**
* 操作人, `null` 时为 [Bot] 操作
*/
val operator: Member?
public val operator: Member?
}
/**
@ -72,7 +72,7 @@ interface GroupOperableEvent : GroupEvent {
*/
@HidesMembers
@get:JvmSynthetic // inline: planning to change to another file (1.2.0)
inline val GroupOperableEvent.isByBot: Boolean
public inline val GroupOperableEvent.isByBot: Boolean
get() = operator == null
/**
@ -80,14 +80,14 @@ inline val GroupOperableEvent.isByBot: Boolean
* 当操作人为 [Bot] 时获取 [Group.botAsMember]
*/
@get:JvmSynthetic // inline: planning to change to another file (1.2.0)
inline val GroupOperableEvent.operatorOrBot: Member
public inline val GroupOperableEvent.operatorOrBot: Member
get() = this.operator ?: this.group.botAsMember
/**
* 有关好友的事件
*/
interface FriendEvent : BotEvent {
val friend: Friend
public interface FriendEvent : BotEvent {
public val friend: Friend
final override val bot: Bot get() = friend.bot
}

View File

@ -33,7 +33,7 @@ import kotlin.reflect.KClass
* @throws Throwable [mapper] 抛出任何异常时, 本函数会抛出该异常
*/
@JvmSynthetic
suspend inline fun <reified E : Event, R : Any> syncFromEvent(
public suspend inline fun <reified E : Event, R : Any> syncFromEvent(
timeoutMillis: Long = -1,
priority: Listener.EventPriority = EventPriority.MONITOR,
crossinline mapper: suspend E.(E) -> R?
@ -66,7 +66,7 @@ suspend inline fun <reified E : Event, R : Any> syncFromEvent(
* @throws Throwable [mapper] 抛出任何异常时, 本函数会抛出该异常
*/
@JvmSynthetic
suspend inline fun <reified E : Event, R : Any> syncFromEventOrNull(
public suspend inline fun <reified E : Event, R : Any> syncFromEventOrNull(
timeoutMillis: Long,
priority: Listener.EventPriority = EventPriority.MONITOR,
crossinline mapper: suspend E.(E) -> R?
@ -94,7 +94,7 @@ suspend inline fun <reified E : Event, R : Any> syncFromEventOrNull(
*/
@JvmSynthetic
@Suppress("DeferredIsResult")
inline fun <reified E : Event, R : Any> CoroutineScope.asyncFromEventOrNull(
public inline fun <reified E : Event, R : Any> CoroutineScope.asyncFromEventOrNull(
timeoutMillis: Long,
coroutineContext: CoroutineContext = EmptyCoroutineContext,
priority: Listener.EventPriority = EventPriority.MONITOR,
@ -123,7 +123,7 @@ inline fun <reified E : Event, R : Any> CoroutineScope.asyncFromEventOrNull(
*/
@JvmSynthetic
@Suppress("DeferredIsResult")
inline fun <reified E : Event, R : Any> CoroutineScope.asyncFromEvent(
public inline fun <reified E : Event, R : Any> CoroutineScope.asyncFromEvent(
timeoutMillis: Long = -1,
coroutineContext: CoroutineContext = EmptyCoroutineContext,
priority: Listener.EventPriority = EventPriority.MONITOR,

View File

@ -31,7 +31,7 @@ import kotlin.reflect.KClass
* @throws TimeoutCancellationException 在超时后抛出.
*/
@JvmSynthetic
suspend inline fun <reified E : Event> nextEvent(
public suspend inline fun <reified E : Event> nextEvent(
timeoutMillis: Long = -1,
priority: Listener.EventPriority = EventPriority.MONITOR
): E {
@ -53,7 +53,7 @@ suspend inline fun <reified E : Event> nextEvent(
* @return 事件实例, 在超时后返回 `null`
*/
@JvmSynthetic
suspend inline fun <reified E : Event> nextEventOrNull(
public suspend inline fun <reified E : Event> nextEventOrNull(
timeoutMillis: Long,
priority: Listener.EventPriority = EventPriority.MONITOR
): E? {
@ -77,7 +77,7 @@ suspend inline fun <reified E : Event> nextEventOrNull(
level = DeprecationLevel.HIDDEN
)
@JvmSynthetic
suspend inline fun <reified E : BotEvent> Bot.nextEvent(
public suspend inline fun <reified E : BotEvent> Bot.nextEvent(
timeoutMillis: Long = -1,
priority: Listener.EventPriority = EventPriority.MONITOR
): E {

View File

@ -58,24 +58,24 @@ import kotlin.jvm.JvmSynthetic
* @see nextMessage 挂起协程并等待下一条消息
*/
@Suppress("unused")
suspend inline fun <reified T : MessageEvent> T.whileSelectMessages(
public suspend inline fun <reified T : MessageEvent> T.whileSelectMessages(
timeoutMillis: Long = -1,
filterContext: Boolean = true,
priority: Listener.EventPriority = EventPriority.MONITOR,
crossinline selectBuilder: @MessageDsl MessageSelectBuilder<T, Boolean>.() -> Unit
) = whileSelectMessagesImpl(timeoutMillis, filterContext, priority, selectBuilder)
): Unit = whileSelectMessagesImpl(timeoutMillis, filterContext, priority, selectBuilder)
/**
* [selectMessages] [Unit] 返回值捷径 (由于 Kotlin 无法推断 [Unit] 类型)
*/
@MiraiExperimentalAPI
@JvmName("selectMessages1")
suspend inline fun <reified T : MessageEvent> T.selectMessagesUnit(
public suspend inline fun <reified T : MessageEvent> T.selectMessagesUnit(
timeoutMillis: Long = -1,
filterContext: Boolean = true,
priority: Listener.EventPriority = EventPriority.MONITOR,
crossinline selectBuilder: @MessageDsl MessageSelectBuilderUnit<T, Unit>.() -> Unit
) = selectMessagesImpl(timeoutMillis, true, filterContext, priority, selectBuilder)
): Unit = selectMessagesImpl(timeoutMillis, true, filterContext, priority, selectBuilder)
/**
@ -100,17 +100,19 @@ suspend inline fun <reified T : MessageEvent> T.selectMessagesUnit(
*/
@Suppress("unused") // false positive
// @BuilderInference // https://youtrack.jetbrains.com/issue/KT-37716
suspend inline fun <reified T : MessageEvent, R> T.selectMessages(
public suspend inline fun <reified T : MessageEvent, R> T.selectMessages(
timeoutMillis: Long = -1,
filterContext: Boolean = true,
priority: Listener.EventPriority = EventPriority.MONITOR,
// @BuilderInference
crossinline selectBuilder: @MessageDsl MessageSelectBuilder<T, R>.() -> Unit
): R =
selectMessagesImpl(timeoutMillis,
selectMessagesImpl(
timeoutMillis,
false,
filterContext,
priority) { selectBuilder.invoke(this as MessageSelectBuilder<T, R>) }
priority
) { selectBuilder.invoke(this as MessageSelectBuilder<T, R>) }
/**
* [selectMessages] 时的 DSL 构建器.
@ -120,7 +122,7 @@ suspend inline fun <reified T : MessageEvent, R> T.selectMessages(
* @see MessageSelectBuilderUnit 查看上层 API
*/
@Suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE")
abstract class MessageSelectBuilder<M : MessageEvent, R> @PublishedApi internal constructor(
public abstract class MessageSelectBuilder<M : MessageEvent, R> @PublishedApi internal constructor(
ownerMessagePacket: M,
stub: Any?,
subscriber: (M.(String) -> Boolean, MessageListener<M, Any?>) -> Unit
@ -132,10 +134,10 @@ abstract class MessageSelectBuilder<M : MessageEvent, R> @PublishedApi internal
override fun <N : Any> mapping(
mapper: M.(String) -> N?,
onEvent: @MessageDsl suspend M.(N) -> R
) = error("prohibited")
): Nothing = error("prohibited")
@Deprecated("Use `default` instead", level = DeprecationLevel.HIDDEN)
override fun always(onEvent: MessageListener<M, Any?>) = error("prohibited")
override fun always(onEvent: MessageListener<M, Any?>): Nothing = error("prohibited")
@Deprecated("Using `reply` DSL in message selection is prohibited", level = DeprecationLevel.HIDDEN)
override infix fun MessageSelectionTimeoutChecker.reply(block: suspend () -> Any?): Nothing = error("prohibited")
@ -176,55 +178,55 @@ abstract class MessageSelectBuilder<M : MessageEvent, R> @PublishedApi internal
override fun String.containsReply(reply: String): Nothing = error("prohibited")
@Deprecated("Using `reply` DSL in message selection is prohibited", level = DeprecationLevel.HIDDEN)
override fun String.containsReply(replier: suspend M.(String) -> Any?) = error("prohibited")
override fun String.containsReply(replier: suspend M.(String) -> Any?): Nothing = error("prohibited")
@Deprecated("Using `reply` DSL in message selection is prohibited", level = DeprecationLevel.HIDDEN)
override fun Regex.matchingReply(replier: suspend M.(MatchResult) -> Any?) = error("prohibited")
override fun Regex.matchingReply(replier: suspend M.(MatchResult) -> Any?): Nothing = error("prohibited")
@Deprecated("Using `reply` DSL in message selection is prohibited", level = DeprecationLevel.HIDDEN)
override fun Regex.findingReply(replier: suspend M.(MatchResult) -> Any?) = error("prohibited")
override fun Regex.findingReply(replier: suspend M.(MatchResult) -> Any?): Nothing = error("prohibited")
@Deprecated("Using `reply` DSL in message selection is prohibited", level = DeprecationLevel.HIDDEN)
override fun String.endsWithReply(replier: suspend M.(String) -> Any?) = error("prohibited")
override fun String.endsWithReply(replier: suspend M.(String) -> Any?): Nothing = error("prohibited")
@Deprecated("Using `reply` DSL in message selection is prohibited", level = DeprecationLevel.HIDDEN)
override fun String.reply(reply: String) = error("prohibited")
override fun String.reply(reply: String): Nothing = error("prohibited")
@Deprecated("Using `reply` DSL in message selection is prohibited", level = DeprecationLevel.HIDDEN)
override fun String.reply(reply: Message) = error("prohibited")
override fun String.reply(reply: Message): Nothing = error("prohibited")
@Deprecated("Using `reply` DSL in message selection is prohibited", level = DeprecationLevel.HIDDEN)
override fun String.reply(replier: suspend M.(String) -> Any?) = error("prohibited")
override fun String.reply(replier: suspend M.(String) -> Any?): Nothing = error("prohibited")
@Deprecated("Using `reply` DSL in message selection is prohibited", level = DeprecationLevel.HIDDEN)
override fun ListeningFilter.reply(toReply: String) = error("prohibited")
override fun ListeningFilter.reply(toReply: String): Nothing = error("prohibited")
@Deprecated("Using `reply` DSL in message selection is prohibited", level = DeprecationLevel.HIDDEN)
override fun ListeningFilter.reply(message: Message) = error("prohibited")
override fun ListeningFilter.reply(message: Message): Nothing = error("prohibited")
@JvmName("reply3")
@Suppress("INAPPLICABLE_JVM_NAME", "INVALID_CHARACTERS", "NAME_CONTAINS_ILLEGAL_CHARS", "FunctionName")
@Deprecated("Using `reply` DSL in message selection is prohibited", level = DeprecationLevel.HIDDEN)
override fun ListeningFilter.`->`(toReply: String) = error("prohibited")
override fun ListeningFilter.`->`(toReply: String): Nothing = error("prohibited")
@JvmName("reply3")
@Suppress("INAPPLICABLE_JVM_NAME", "INVALID_CHARACTERS", "NAME_CONTAINS_ILLEGAL_CHARS", "FunctionName")
@Deprecated("Using `reply` DSL in message selection is prohibited", level = DeprecationLevel.HIDDEN)
override fun ListeningFilter.`->`(message: Message) = error("prohibited")
override fun ListeningFilter.`->`(message: Message): Nothing = error("prohibited")
@Deprecated("Using `reply` DSL in message selection is prohibited", level = DeprecationLevel.HIDDEN)
override fun ListeningFilter.reply(replier: suspend M.(String) -> Any?) =
override fun ListeningFilter.reply(replier: suspend M.(String) -> Any?): Nothing =
error("prohibited")
@Deprecated("Using `reply` DSL in message selection is prohibited", level = DeprecationLevel.HIDDEN)
override fun ListeningFilter.quoteReply(toReply: String) = error("prohibited")
override fun ListeningFilter.quoteReply(toReply: String): Nothing = error("prohibited")
@Deprecated("Using `reply` DSL in message selection is prohibited", level = DeprecationLevel.HIDDEN)
override fun ListeningFilter.quoteReply(toReply: Message) = error("prohibited")
override fun ListeningFilter.quoteReply(toReply: Message): Nothing = error("prohibited")
@Deprecated("Using `reply` DSL in message selection is prohibited", level = DeprecationLevel.HIDDEN)
override fun ListeningFilter.quoteReply(replier: suspend M.(String) -> Any?) = error("prohibited")
override fun ListeningFilter.quoteReply(replier: suspend M.(String) -> Any?): Nothing = error("prohibited")
}
/**
@ -234,7 +236,7 @@ abstract class MessageSelectBuilder<M : MessageEvent, R> @PublishedApi internal
*
* @see MessageSubscribersBuilder 查看上层 API
*/
abstract class MessageSelectBuilderUnit<M : MessageEvent, R> @PublishedApi internal constructor(
public abstract class MessageSelectBuilderUnit<M : MessageEvent, R> @PublishedApi internal constructor(
private val ownerMessagePacket: M,
stub: Any?,
subscriber: (M.(String) -> Boolean, MessageListener<M, Any?>) -> Unit
@ -243,17 +245,17 @@ abstract class MessageSelectBuilderUnit<M : MessageEvent, R> @PublishedApi inter
* 当其他条件都不满足时的默认处理.
*/
@MessageDsl
abstract fun default(onEvent: MessageListener<M, R>) // 需要后置默认监听器
public abstract fun default(onEvent: MessageListener<M, R>) // 需要后置默认监听器
@Deprecated("Use `default` instead", level = DeprecationLevel.HIDDEN)
override fun always(onEvent: MessageListener<M, Any?>) = error("prohibited")
override fun always(onEvent: MessageListener<M, Any?>): Nothing = error("prohibited")
/**
* 限制本次 select 的最长等待时间, 当超时后抛出 [TimeoutCancellationException]
*/
@Suppress("NOTHING_TO_INLINE")
@MessageDsl
fun timeoutException(
public fun timeoutException(
timeoutMillis: Long,
exception: () -> Throwable = { throw MessageSelectionTimeoutException() }
) {
@ -271,7 +273,7 @@ abstract class MessageSelectBuilderUnit<M : MessageEvent, R> @PublishedApi inter
* 限制本次 select 的最长等待时间, 当超时后执行 [block] 以完成 select
*/
@MessageDsl
fun timeout(timeoutMillis: Long, block: suspend () -> R) {
public fun timeout(timeoutMillis: Long, block: suspend () -> R) {
require(timeoutMillis > 0) { "timeoutMillis must be positive" }
obtainCurrentCoroutineScope().launch {
delay(timeoutMillis)
@ -290,7 +292,7 @@ abstract class MessageSelectBuilderUnit<M : MessageEvent, R> @PublishedApi inter
* @see reply
*/
@MessageDsl
fun timeout(timeoutMillis: Long): MessageSelectionTimeoutChecker {
public fun timeout(timeoutMillis: Long): MessageSelectionTimeoutChecker {
require(timeoutMillis > 0) { "timeoutMillis must be positive" }
return MessageSelectionTimeoutChecker(timeoutMillis)
}
@ -301,7 +303,7 @@ abstract class MessageSelectBuilderUnit<M : MessageEvent, R> @PublishedApi inter
* @see Deferred<Unit>.invoke
*/
@Suppress("unused")
fun MessageSelectionTimeoutChecker.invoke(block: suspend () -> R) {
public fun MessageSelectionTimeoutChecker.invoke(block: suspend () -> R) {
return timeout(this.timeoutMillis, block)
}
@ -314,7 +316,7 @@ abstract class MessageSelectBuilderUnit<M : MessageEvent, R> @PublishedApi inter
* @see quoteReply
*/
@Suppress("unused", "UNCHECKED_CAST")
open infix fun MessageSelectionTimeoutChecker.reply(block: suspend () -> Any?) {
public open infix fun MessageSelectionTimeoutChecker.reply(block: suspend () -> Any?) {
return timeout(this.timeoutMillis) {
executeAndReply(block)
Unit as R
@ -322,7 +324,7 @@ abstract class MessageSelectBuilderUnit<M : MessageEvent, R> @PublishedApi inter
}
@Suppress("unused", "UNCHECKED_CAST")
open infix fun MessageSelectionTimeoutChecker.reply(message: Message) {
public open infix fun MessageSelectionTimeoutChecker.reply(message: Message) {
return timeout(this.timeoutMillis) {
ownerMessagePacket.reply(message)
Unit as R
@ -330,7 +332,7 @@ abstract class MessageSelectBuilderUnit<M : MessageEvent, R> @PublishedApi inter
}
@Suppress("unused", "UNCHECKED_CAST")
open infix fun MessageSelectionTimeoutChecker.reply(message: String) {
public open infix fun MessageSelectionTimeoutChecker.reply(message: String) {
return timeout(this.timeoutMillis) {
ownerMessagePacket.reply(message)
Unit as R
@ -342,7 +344,7 @@ abstract class MessageSelectBuilderUnit<M : MessageEvent, R> @PublishedApi inter
"INAPPLICABLE_JVM_NAME", "unused", "UNCHECKED_CAST",
"INVALID_CHARACTERS", "NAME_CONTAINS_ILLEGAL_CHARS", "FunctionName"
)
open infix fun MessageSelectionTimeoutChecker.`->`(message: Message) {
public open infix fun MessageSelectionTimeoutChecker.`->`(message: Message) {
return this.reply(message)
}
@ -351,7 +353,7 @@ abstract class MessageSelectBuilderUnit<M : MessageEvent, R> @PublishedApi inter
"INAPPLICABLE_JVM_NAME", "unused", "UNCHECKED_CAST",
"INVALID_CHARACTERS", "NAME_CONTAINS_ILLEGAL_CHARS", "FunctionName"
)
open infix fun MessageSelectionTimeoutChecker.`->`(message: String) {
public open infix fun MessageSelectionTimeoutChecker.`->`(message: String) {
return this.reply(message)
}
@ -364,7 +366,7 @@ abstract class MessageSelectBuilderUnit<M : MessageEvent, R> @PublishedApi inter
* @see reply
*/
@Suppress("unused", "UNCHECKED_CAST")
open infix fun MessageSelectionTimeoutChecker.quoteReply(block: suspend () -> Any?) {
public open infix fun MessageSelectionTimeoutChecker.quoteReply(block: suspend () -> Any?) {
return timeout(this.timeoutMillis) {
executeAndQuoteReply(block)
Unit as R
@ -372,7 +374,7 @@ abstract class MessageSelectBuilderUnit<M : MessageEvent, R> @PublishedApi inter
}
@Suppress("unused", "UNCHECKED_CAST")
open infix fun MessageSelectionTimeoutChecker.quoteReply(message: Message) {
public open infix fun MessageSelectionTimeoutChecker.quoteReply(message: Message) {
return timeout(this.timeoutMillis) {
ownerMessagePacket.quoteReply(message)
Unit as R
@ -380,7 +382,7 @@ abstract class MessageSelectBuilderUnit<M : MessageEvent, R> @PublishedApi inter
}
@Suppress("unused", "UNCHECKED_CAST")
open infix fun MessageSelectionTimeoutChecker.quoteReply(message: String) {
public open infix fun MessageSelectionTimeoutChecker.quoteReply(message: String) {
return timeout(this.timeoutMillis) {
ownerMessagePacket.quoteReply(message)
Unit as R
@ -393,7 +395,7 @@ abstract class MessageSelectBuilderUnit<M : MessageEvent, R> @PublishedApi inter
* [block] 返回值为 [Unit] 时不回复, [Message] 时回复 [Message], 其他将 [toString] 后回复为 [PlainText]
*/
@MessageDsl
fun defaultReply(block: suspend () -> Any?): Unit = subscriber({ true }, {
public fun defaultReply(block: suspend () -> Any?): Unit = subscriber({ true }, {
this@MessageSelectBuilderUnit.executeAndReply(block)
})
@ -404,7 +406,7 @@ abstract class MessageSelectBuilderUnit<M : MessageEvent, R> @PublishedApi inter
* [block] 返回值为 [Unit] 时不回复, [Message] 时回复 [Message], 其他将 [toString] 后回复为 [PlainText]
*/
@MessageDsl
fun defaultQuoteReply(block: suspend () -> Any?): Unit = subscriber({ true }, {
public fun defaultQuoteReply(block: suspend () -> Any?): Unit = subscriber({ true }, {
this@MessageSelectBuilderUnit.executeAndQuoteReply(block)
})
@ -433,9 +435,9 @@ abstract class MessageSelectBuilderUnit<M : MessageEvent, R> @PublishedApi inter
}
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
inline class MessageSelectionTimeoutChecker internal constructor(val timeoutMillis: Long)
public inline class MessageSelectionTimeoutChecker internal constructor(public val timeoutMillis: Long)
class MessageSelectionTimeoutException : RuntimeException()
public class MessageSelectionTimeoutException : RuntimeException()
/////////////////////////

View File

@ -29,7 +29,7 @@ import kotlin.coroutines.EmptyCoroutineContext
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName
typealias MessagePacketSubscribersBuilder = MessageSubscribersBuilder<MessageEvent, Listener<MessageEvent>, Unit, Unit>
public typealias MessagePacketSubscribersBuilder = MessageSubscribersBuilder<MessageEvent, Listener<MessageEvent>, Unit, Unit>
/**
* 订阅来自所有 [Bot] 的所有联系人的消息事件. 联系人可以是任意群或任意好友或临时会话.
@ -39,7 +39,7 @@ typealias MessagePacketSubscribersBuilder = MessageSubscribersBuilder<MessageEve
* @see CoroutineScope.incoming 打开一个指定事件的接收通道
*/
fun <R> CoroutineScope.subscribeMessages(
public fun <R> CoroutineScope.subscribeMessages(
coroutineContext: CoroutineContext = EmptyCoroutineContext,
concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT,
priority: Listener.EventPriority = EventPriority.MONITOR,
@ -63,7 +63,7 @@ fun <R> CoroutineScope.subscribeMessages(
}.run(listeners)
}
typealias GroupMessageSubscribersBuilder = MessageSubscribersBuilder<GroupMessageEvent, Listener<GroupMessageEvent>, Unit, Unit>
public typealias GroupMessageSubscribersBuilder = MessageSubscribersBuilder<GroupMessageEvent, Listener<GroupMessageEvent>, Unit, Unit>
/**
* 订阅来自所有 [Bot] 的所有群消息事件
@ -72,7 +72,7 @@ typealias GroupMessageSubscribersBuilder = MessageSubscribersBuilder<GroupMessag
*
* @see CoroutineScope.incoming 打开一个指定事件的接收通道
*/
fun <R> CoroutineScope.subscribeGroupMessages(
public fun <R> CoroutineScope.subscribeGroupMessages(
coroutineContext: CoroutineContext = EmptyCoroutineContext,
concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT,
priority: Listener.EventPriority = EventPriority.MONITOR,
@ -90,7 +90,7 @@ fun <R> CoroutineScope.subscribeGroupMessages(
}.run(listeners)
}
typealias FriendMessageSubscribersBuilder = MessageSubscribersBuilder<FriendMessageEvent, Listener<FriendMessageEvent>, Unit, Unit>
public typealias FriendMessageSubscribersBuilder = MessageSubscribersBuilder<FriendMessageEvent, Listener<FriendMessageEvent>, Unit, Unit>
/**
* 订阅来自所有 [Bot] 的所有好友消息事件
@ -99,7 +99,7 @@ typealias FriendMessageSubscribersBuilder = MessageSubscribersBuilder<FriendMess
*
* @see CoroutineScope.incoming 打开一个指定事件的接收通道
*/
fun <R> CoroutineScope.subscribeFriendMessages(
public fun <R> CoroutineScope.subscribeFriendMessages(
coroutineContext: CoroutineContext = EmptyCoroutineContext,
concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT,
priority: Listener.EventPriority = EventPriority.MONITOR,
@ -117,7 +117,7 @@ fun <R> CoroutineScope.subscribeFriendMessages(
}.run(listeners)
}
typealias TempMessageSubscribersBuilder = MessageSubscribersBuilder<TempMessageEvent, Listener<TempMessageEvent>, Unit, Unit>
public typealias TempMessageSubscribersBuilder = MessageSubscribersBuilder<TempMessageEvent, Listener<TempMessageEvent>, Unit, Unit>
/**
* 订阅来自所有 [Bot] 的所有临时会话消息事件
@ -126,7 +126,7 @@ typealias TempMessageSubscribersBuilder = MessageSubscribersBuilder<TempMessageE
*
* @see CoroutineScope.incoming 打开一个指定事件的接收通道
*/
fun <R> CoroutineScope.subscribeTempMessages(
public fun <R> CoroutineScope.subscribeTempMessages(
coroutineContext: CoroutineContext = EmptyCoroutineContext,
concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT,
priority: Listener.EventPriority = EventPriority.MONITOR,
@ -159,7 +159,7 @@ fun <R> CoroutineScope.subscribeTempMessages(
* @see subscribeMessages
* @see subscribeGroupMessages
*/
inline fun <reified E : Event> CoroutineScope.incoming(
public inline fun <reified E : Event> CoroutineScope.incoming(
coroutineContext: CoroutineContext = EmptyCoroutineContext,
concurrencyKind: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT,
priority: Listener.EventPriority = EventPriority.MONITOR,

View File

@ -42,7 +42,7 @@ import kotlin.reflect.KClass
/**
* 订阅者的状态
*/
enum class ListeningStatus {
public enum class ListeningStatus {
/**
* 表示继续监听
*/
@ -65,9 +65,9 @@ enum class ListeningStatus {
*
* 取消监听: [complete]
*/
interface Listener<in E : Event> : CompletableJob {
public interface Listener<in E : Event> : CompletableJob {
enum class ConcurrencyKind {
public enum class ConcurrencyKind {
/**
* 并发地同时处理多个事件, 但无法保证 [onEvent] 返回 [ListeningStatus.STOPPED] 后立即停止事件监听.
*/
@ -82,7 +82,7 @@ interface Listener<in E : Event> : CompletableJob {
/**
* 并发类型
*/
val concurrencyKind: ConcurrencyKind
public val concurrencyKind: ConcurrencyKind
/**
* 事件优先级.
@ -96,7 +96,7 @@ interface Listener<in E : Event> : CompletableJob {
*
* 当事件被 [拦截][Event.intercept] , 优先级较低 (靠右) 的监听器将不会被调用.
*/
enum class EventPriority {
public enum class EventPriority {
HIGHEST, HIGH, NORMAL, LOW, LOWEST,
@ -108,7 +108,7 @@ interface Listener<in E : Event> : CompletableJob {
*/
MONITOR;
companion object {
internal companion object {
@JvmStatic
internal val valuesExceptMonitor: Array<EventPriority> = arrayOf(HIGHEST, HIGH, NORMAL, LOW, LOWEST)
}
@ -118,17 +118,17 @@ interface Listener<in E : Event> : CompletableJob {
* 事件优先级
* @see [EventPriority]
*/
val priority: EventPriority get() = NORMAL
public val priority: EventPriority get() = NORMAL
/**
* 这个方法将会调用 [CoroutineScope.subscribe] 时提供的参数 `noinline handler: suspend E.(E) -> ListeningStatus`.
*
* 这个函数不会抛出任何异常, 详见 [CoroutineScope.subscribe]
*/
suspend fun onEvent(event: E): ListeningStatus
public suspend fun onEvent(event: E): ListeningStatus
}
typealias EventPriority = Listener.EventPriority
public typealias EventPriority = Listener.EventPriority
// region subscribe / subscribeAlways / subscribeOnce
@ -210,7 +210,7 @@ typealias EventPriority = Listener.EventPriority
* @see subscribeFriendMessages 监听好友消息 DSL
* @see subscribeTempMessages 监听临时会话消息 DSL
*/
inline fun <reified E : Event> CoroutineScope.subscribe(
public inline fun <reified E : Event> CoroutineScope.subscribe(
coroutineContext: CoroutineContext = EmptyCoroutineContext,
concurrency: Listener.ConcurrencyKind = LOCKED,
priority: Listener.EventPriority = NORMAL,
@ -224,7 +224,7 @@ inline fun <reified E : Event> CoroutineScope.subscribe(
*
* @return 监听器实例. 此监听器已经注册到指定事件上, 在事件广播时将会调用 [handler]
*/
fun <E : Event> CoroutineScope.subscribe(
public fun <E : Event> CoroutineScope.subscribe(
eventClass: KClass<out E>,
coroutineContext: CoroutineContext = EmptyCoroutineContext,
concurrency: Listener.ConcurrencyKind = LOCKED,
@ -247,7 +247,7 @@ fun <E : Event> CoroutineScope.subscribe(
*
* @see CoroutineScope.subscribe 获取更多说明
*/
inline fun <reified E : Event> CoroutineScope.subscribeAlways(
public inline fun <reified E : Event> CoroutineScope.subscribeAlways(
coroutineContext: CoroutineContext = EmptyCoroutineContext,
concurrency: Listener.ConcurrencyKind = CONCURRENT,
priority: Listener.EventPriority = NORMAL,
@ -259,7 +259,7 @@ inline fun <reified E : Event> CoroutineScope.subscribeAlways(
* @see CoroutineScope.subscribe
* @see CoroutineScope.subscribeAlways
*/
fun <E : Event> CoroutineScope.subscribeAlways(
public fun <E : Event> CoroutineScope.subscribeAlways(
eventClass: KClass<out E>,
coroutineContext: CoroutineContext = EmptyCoroutineContext,
concurrency: Listener.ConcurrencyKind = CONCURRENT,
@ -282,7 +282,7 @@ fun <E : Event> CoroutineScope.subscribeAlways(
* @see CoroutineScope.subscribe 获取更多说明
*/
@JvmSynthetic
inline fun <reified E : Event> CoroutineScope.subscribeOnce(
public inline fun <reified E : Event> CoroutineScope.subscribeOnce(
coroutineContext: CoroutineContext = EmptyCoroutineContext,
priority: Listener.EventPriority = NORMAL,
noinline handler: suspend E.(E) -> Unit
@ -291,7 +291,7 @@ inline fun <reified E : Event> CoroutineScope.subscribeOnce(
/**
* @see CoroutineScope.subscribeOnce
*/
fun <E : Event> CoroutineScope.subscribeOnce(
public fun <E : Event> CoroutineScope.subscribeOnce(
eventClass: KClass<out E>,
coroutineContext: CoroutineContext = EmptyCoroutineContext,
priority: Listener.EventPriority = NORMAL,
@ -321,7 +321,7 @@ fun <E : Event> CoroutineScope.subscribeOnce(
@JvmSynthetic
@LowPriorityInOverloadResolution
@JvmName("subscribe1")
inline fun <reified E : Event> CoroutineScope.subscribe(
public inline fun <reified E : Event> CoroutineScope.subscribe(
crossinline handler: (E) -> ListeningStatus,
priority: Listener.EventPriority = NORMAL,
concurrency: Listener.ConcurrencyKind = CONCURRENT,
@ -342,7 +342,7 @@ inline fun <reified E : Event> CoroutineScope.subscribe(
@JvmSynthetic
@LowPriorityInOverloadResolution
@JvmName("subscribe2")
inline fun <reified E : Event> CoroutineScope.subscribe(
public inline fun <reified E : Event> CoroutineScope.subscribe(
crossinline handler: E.(E) -> ListeningStatus,
priority: Listener.EventPriority = NORMAL,
concurrency: Listener.ConcurrencyKind = CONCURRENT,
@ -363,7 +363,7 @@ inline fun <reified E : Event> CoroutineScope.subscribe(
@JvmSynthetic
@LowPriorityInOverloadResolution
@JvmName("subscribe1")
inline fun <reified E : Event> CoroutineScope.subscribe(
public inline fun <reified E : Event> CoroutineScope.subscribe(
crossinline handler: suspend (E) -> ListeningStatus,
priority: Listener.EventPriority = NORMAL,
concurrency: Listener.ConcurrencyKind = CONCURRENT,
@ -384,7 +384,7 @@ inline fun <reified E : Event> CoroutineScope.subscribe(
@JvmSynthetic
@LowPriorityInOverloadResolution
@JvmName("subscribe3")
inline fun <reified E : Event> CoroutineScope.subscribe(
public inline fun <reified E : Event> CoroutineScope.subscribe(
crossinline handler: suspend E.(E) -> ListeningStatus,
priority: Listener.EventPriority = NORMAL,
concurrency: Listener.ConcurrencyKind = CONCURRENT,
@ -410,7 +410,7 @@ inline fun <reified E : Event> CoroutineScope.subscribe(
@JvmSynthetic
@LowPriorityInOverloadResolution
@JvmName("subscribeAlways1")
inline fun <reified E : Event> CoroutineScope.subscribeAlways(
public inline fun <reified E : Event> CoroutineScope.subscribeAlways(
crossinline handler: (E) -> Unit,
priority: Listener.EventPriority = NORMAL,
concurrency: Listener.ConcurrencyKind = CONCURRENT,
@ -429,7 +429,7 @@ inline fun <reified E : Event> CoroutineScope.subscribeAlways(
@JvmSynthetic
@LowPriorityInOverloadResolution
@JvmName("subscribeAlways1")
inline fun <reified E : Event> CoroutineScope.subscribeAlways(
public inline fun <reified E : Event> CoroutineScope.subscribeAlways(
crossinline handler: E.(E) -> Unit,
priority: Listener.EventPriority = NORMAL,
concurrency: Listener.ConcurrencyKind = CONCURRENT,
@ -448,7 +448,7 @@ inline fun <reified E : Event> CoroutineScope.subscribeAlways(
@JvmSynthetic
@LowPriorityInOverloadResolution
@JvmName("subscribe4")
inline fun <reified E : Event> CoroutineScope.subscribeAlways(
public inline fun <reified E : Event> CoroutineScope.subscribeAlways(
crossinline handler: suspend (E) -> Unit,
priority: Listener.EventPriority = NORMAL,
concurrency: Listener.ConcurrencyKind = CONCURRENT,
@ -467,7 +467,7 @@ inline fun <reified E : Event> CoroutineScope.subscribeAlways(
@JvmSynthetic
@LowPriorityInOverloadResolution
@JvmName("subscribe1")
inline fun <reified E : Event> CoroutineScope.subscribeAlways(
public inline fun <reified E : Event> CoroutineScope.subscribeAlways(
crossinline handler: suspend E.(E) -> Unit,
priority: Listener.EventPriority = NORMAL,
concurrency: Listener.ConcurrencyKind = CONCURRENT,

View File

@ -45,7 +45,7 @@ import kotlin.reflect.KClass
"Deprecated for better Coroutine life cycle management. Please filter bot instance on your own.",
level = DeprecationLevel.HIDDEN
)
inline fun <reified E : BotEvent> Bot.subscribe(
public inline fun <reified E : BotEvent> Bot.subscribe(
coroutineContext: CoroutineContext = EmptyCoroutineContext,
concurrency: Listener.ConcurrencyKind = LOCKED,
priority: Listener.EventPriority = NORMAL,
@ -59,7 +59,7 @@ inline fun <reified E : BotEvent> Bot.subscribe(
"Deprecated for better Coroutine life cycle management. Please filter bot instance on your own.",
level = DeprecationLevel.HIDDEN
)
fun <E : BotEvent> Bot.subscribe(
public fun <E : BotEvent> Bot.subscribe(
eventClass: KClass<E>,
coroutineContext: CoroutineContext = EmptyCoroutineContext,
concurrency: Listener.ConcurrencyKind = LOCKED,
@ -82,7 +82,7 @@ fun <E : BotEvent> Bot.subscribe(
"Deprecated for better Coroutine life cycle management. Please filter bot instance on your own.",
level = DeprecationLevel.HIDDEN
)
inline fun <reified E : BotEvent> Bot.subscribeAlways(
public inline fun <reified E : BotEvent> Bot.subscribeAlways(
coroutineContext: CoroutineContext = EmptyCoroutineContext,
concurrency: Listener.ConcurrencyKind = CONCURRENT,
priority: Listener.EventPriority = NORMAL,
@ -95,7 +95,7 @@ inline fun <reified E : BotEvent> Bot.subscribeAlways(
"Deprecated for better Coroutine life cycle management. Please filter bot instance on your own.",
level = DeprecationLevel.HIDDEN
)
fun <E : BotEvent> Bot.subscribeAlways(
public fun <E : BotEvent> Bot.subscribeAlways(
eventClass: KClass<E>,
coroutineContext: CoroutineContext = EmptyCoroutineContext,
concurrency: Listener.ConcurrencyKind = CONCURRENT,
@ -114,7 +114,7 @@ fun <E : BotEvent> Bot.subscribeAlways(
"Deprecated for better Coroutine life cycle management. Please filter bot instance on your own.",
level = DeprecationLevel.HIDDEN
)
inline fun <reified E : BotEvent> Bot.subscribeOnce(
public inline fun <reified E : BotEvent> Bot.subscribeOnce(
coroutineContext: CoroutineContext = EmptyCoroutineContext,
priority: Listener.EventPriority = NORMAL,
noinline listener: suspend E.(E) -> Unit
@ -126,7 +126,7 @@ inline fun <reified E : BotEvent> Bot.subscribeOnce(
"Deprecated for better Coroutine life cycle management. Please filter bot instance on your own.",
level = DeprecationLevel.HIDDEN
)
fun <E : BotEvent> Bot.subscribeOnce(
public fun <E : BotEvent> Bot.subscribeOnce(
eventClass: KClass<E>,
coroutineContext: CoroutineContext = EmptyCoroutineContext,
priority: Listener.EventPriority = NORMAL,
@ -149,7 +149,7 @@ fun <E : BotEvent> Bot.subscribeOnce(
@JvmSynthetic
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
@Suppress("unused")
inline fun <reified E : Event> CoroutineScope.subscribeDeprecated(
public inline fun <reified E : Event> CoroutineScope.subscribeDeprecated(
coroutineContext: CoroutineContext = EmptyCoroutineContext,
concurrency: Listener.ConcurrencyKind = LOCKED,
noinline handler: suspend E.(E) -> ListeningStatus
@ -165,7 +165,7 @@ inline fun <reified E : Event> CoroutineScope.subscribeDeprecated(
@JvmSynthetic
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
@Suppress("unused")
fun <E : Event> CoroutineScope.subscribeDeprecated(
public fun <E : Event> CoroutineScope.subscribeDeprecated(
eventClass: KClass<E>,
coroutineContext: CoroutineContext = EmptyCoroutineContext,
concurrency: Listener.ConcurrencyKind = LOCKED,
@ -183,7 +183,7 @@ fun <E : Event> CoroutineScope.subscribeDeprecated(
@JvmSynthetic
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
@Suppress("unused")
inline fun <reified E : Event> CoroutineScope.subscribeAlwaysDeprecated(
public inline fun <reified E : Event> CoroutineScope.subscribeAlwaysDeprecated(
coroutineContext: CoroutineContext = EmptyCoroutineContext,
concurrency: Listener.ConcurrencyKind = LOCKED,
noinline listener: suspend E.(E) -> Unit
@ -199,7 +199,7 @@ inline fun <reified E : Event> CoroutineScope.subscribeAlwaysDeprecated(
@JvmSynthetic
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
@Suppress("unused")
fun <E : Event> CoroutineScope.subscribeAlwaysDeprecated(
public fun <E : Event> CoroutineScope.subscribeAlwaysDeprecated(
eventClass: KClass<E>,
coroutineContext: CoroutineContext = EmptyCoroutineContext,
concurrency: Listener.ConcurrencyKind = LOCKED,
@ -217,7 +217,7 @@ fun <E : Event> CoroutineScope.subscribeAlwaysDeprecated(
@JvmSynthetic
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
@Suppress("unused")
inline fun <reified E : Event> CoroutineScope.subscribeOnceDeprecated(
public inline fun <reified E : Event> CoroutineScope.subscribeOnceDeprecated(
coroutineContext: CoroutineContext = EmptyCoroutineContext,
noinline listener: suspend E.(E) -> Unit
): Listener<E> = subscribeOnce(
@ -231,7 +231,7 @@ inline fun <reified E : Event> CoroutineScope.subscribeOnceDeprecated(
@JvmSynthetic
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
@Suppress("unused")
fun <E : Event> CoroutineScope.subscribeOnceDeprecated(
public fun <E : Event> CoroutineScope.subscribeOnceDeprecated(
eventClass: KClass<E>,
coroutineContext: CoroutineContext = EmptyCoroutineContext,
listener: suspend E.(E) -> Unit
@ -247,7 +247,7 @@ fun <E : Event> CoroutineScope.subscribeOnceDeprecated(
@JvmName("subscribeAlwaysForBot")
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
@Suppress("unused")
inline fun <reified E : BotEvent> Bot.subscribeDeprecated(
public inline fun <reified E : BotEvent> Bot.subscribeDeprecated(
coroutineContext: CoroutineContext = EmptyCoroutineContext,
concurrency: Listener.ConcurrencyKind = LOCKED,
noinline handler: suspend E.(E) -> ListeningStatus
@ -263,7 +263,7 @@ inline fun <reified E : BotEvent> Bot.subscribeDeprecated(
@JvmName("subscribe")
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
@Suppress("unused")
fun <E : BotEvent> Bot.subscribeDeprecated(
public fun <E : BotEvent> Bot.subscribeDeprecated(
eventClass: KClass<E>,
coroutineContext: CoroutineContext = EmptyCoroutineContext,
concurrency: Listener.ConcurrencyKind = LOCKED,
@ -281,7 +281,7 @@ fun <E : BotEvent> Bot.subscribeDeprecated(
@JvmName("subscribeAlwaysForBot1")
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
@Suppress("unused")
inline fun <reified E : BotEvent> Bot.subscribeAlwaysDeprecated(
public inline fun <reified E : BotEvent> Bot.subscribeAlwaysDeprecated(
coroutineContext: CoroutineContext = EmptyCoroutineContext,
concurrency: Listener.ConcurrencyKind = CONCURRENT,
noinline listener: suspend E.(E) -> Unit
@ -297,7 +297,7 @@ inline fun <reified E : BotEvent> Bot.subscribeAlwaysDeprecated(
@JvmName("subscribeAlways")
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
@Suppress("unused")
fun <E : BotEvent> Bot.subscribeAlwaysDeprecated(
public fun <E : BotEvent> Bot.subscribeAlwaysDeprecated(
eventClass: KClass<E>,
coroutineContext: CoroutineContext = EmptyCoroutineContext,
concurrency: Listener.ConcurrencyKind = CONCURRENT,
@ -315,7 +315,7 @@ fun <E : BotEvent> Bot.subscribeAlwaysDeprecated(
@JvmName("subscribeOnceForBot2")
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
@Suppress("unused")
inline fun <reified E : BotEvent> Bot.subscribeOnceDeprecated(
public inline fun <reified E : BotEvent> Bot.subscribeOnceDeprecated(
coroutineContext: CoroutineContext = EmptyCoroutineContext,
noinline listener: suspend E.(E) -> Unit
): Listener<E> = subscribeOnce(
@ -329,7 +329,7 @@ inline fun <reified E : BotEvent> Bot.subscribeOnceDeprecated(
@JvmName("subscribeOnce")
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
@Suppress("unused")
fun <E : BotEvent> Bot.subscribeOnceDeprecated(
public fun <E : BotEvent> Bot.subscribeOnceDeprecated(
eventClass: KClass<E>,
coroutineContext: CoroutineContext = EmptyCoroutineContext,
listener: suspend E.(E) -> Unit

View File

@ -13,10 +13,6 @@ import kotlinx.coroutines.Job
import net.mamoe.mirai.contact.Friend
import net.mamoe.mirai.contact.Group
import net.mamoe.mirai.data.*
import net.mamoe.mirai.event.events.BotInvitedJoinGroupRequestEvent
import net.mamoe.mirai.event.events.MemberJoinRequestEvent
import net.mamoe.mirai.event.events.NewFriendRequestEvent
import net.mamoe.mirai.message.data.Voice
import net.mamoe.mirai.utils.MiraiExperimentalAPI
import net.mamoe.mirai.utils.WeakRef
@ -30,7 +26,7 @@ import net.mamoe.mirai.utils.WeakRef
@RequiresOptIn
@Retention(AnnotationRetention.BINARY)
@Target(AnnotationTarget.CLASS, AnnotationTarget.TYPE, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY)
annotation class LowLevelAPI
public annotation class LowLevelAPI
/**
* [Bot] 相关协议层低级 API.
@ -42,7 +38,7 @@ annotation class LowLevelAPI
@MiraiExperimentalAPI
@Suppress("FunctionName", "unused")
@LowLevelAPI
interface LowLevelBotAPIAccessor {
public interface LowLevelBotAPIAccessor {
/**
* 构造一个 [Friend] 对象. 它持有对 [Bot] 的弱引用([WeakRef]).
*
@ -50,20 +46,20 @@ interface LowLevelBotAPIAccessor {
* 因此, [Bot] 被关闭后, 这个对象也会被关闭.
*/
@LowLevelAPI
fun _lowLevelNewFriend(friendInfo: FriendInfo): Friend
public fun _lowLevelNewFriend(friendInfo: FriendInfo): Friend
/**
* 向服务器查询群列表. 返回值高 32 bits uin, 32 bits groupCode
*/
@LowLevelAPI
suspend fun _lowLevelQueryGroupList(): Sequence<Long>
public suspend fun _lowLevelQueryGroupList(): Sequence<Long>
/**
* 向服务器查询群资料. 获得的仅为当前时刻的资料.
* 请优先使用 [Bot.getGroup] 然后查看群资料.
*/
@LowLevelAPI
suspend fun _lowLevelQueryGroupInfo(groupCode: Long): GroupInfo
public suspend fun _lowLevelQueryGroupInfo(groupCode: Long): GroupInfo
/**
* 向服务器查询群成员列表.
@ -74,7 +70,11 @@ interface LowLevelBotAPIAccessor {
* @see Group.calculateGroupUinByGroupCode 使用 groupCode 计算 groupUin
*/
@LowLevelAPI
suspend fun _lowLevelQueryGroupMemberList(groupUin: Long, groupCode: Long, ownerId: Long): Sequence<MemberInfo>
public suspend fun _lowLevelQueryGroupMemberList(
groupUin: Long,
groupCode: Long,
ownerId: Long
): Sequence<MemberInfo>
/**
* 获取群公告列表
@ -82,7 +82,7 @@ interface LowLevelBotAPIAccessor {
*/
@LowLevelAPI
@MiraiExperimentalAPI
suspend fun _lowLevelGetAnnouncements(groupId: Long, page: Int = 1, amount: Int = 10): GroupAnnouncementList
public suspend fun _lowLevelGetAnnouncements(groupId: Long, page: Int = 1, amount: Int = 10): GroupAnnouncementList
/**
* 发送群公告
@ -91,7 +91,7 @@ interface LowLevelBotAPIAccessor {
*/
@LowLevelAPI
@MiraiExperimentalAPI
suspend fun _lowLevelSendAnnouncement(groupId: Long, announcement: GroupAnnouncement): String
public suspend fun _lowLevelSendAnnouncement(groupId: Long, announcement: GroupAnnouncement): String
/**
@ -100,7 +100,7 @@ interface LowLevelBotAPIAccessor {
*/
@LowLevelAPI
@MiraiExperimentalAPI
suspend fun _lowLevelDeleteAnnouncement(groupId: Long, fid: String)
public suspend fun _lowLevelDeleteAnnouncement(groupId: Long, fid: String)
/**
* 获取一条群公告
@ -108,7 +108,7 @@ interface LowLevelBotAPIAccessor {
*/
@LowLevelAPI
@MiraiExperimentalAPI
suspend fun _lowLevelGetAnnouncement(groupId: Long, fid: String): GroupAnnouncement
public suspend fun _lowLevelGetAnnouncement(groupId: Long, fid: String): GroupAnnouncement
/**
@ -118,7 +118,7 @@ interface LowLevelBotAPIAccessor {
*/
@LowLevelAPI
@MiraiExperimentalAPI
suspend fun _lowLevelGetGroupActiveData(groupId: Long, page: Int = -1): GroupActiveData
public suspend fun _lowLevelGetGroupActiveData(groupId: Long, page: Int = -1): GroupActiveData
/**
@ -126,7 +126,7 @@ interface LowLevelBotAPIAccessor {
*/
@LowLevelAPI
@MiraiExperimentalAPI
suspend fun _lowLevelSolveNewFriendRequestEvent(
public suspend fun _lowLevelSolveNewFriendRequestEvent(
eventId: Long,
fromId: Long,
fromNick: String,
@ -139,7 +139,7 @@ interface LowLevelBotAPIAccessor {
*/
@LowLevelAPI
@MiraiExperimentalAPI
suspend fun _lowLevelSolveBotInvitedJoinGroupRequestEvent(
public suspend fun _lowLevelSolveBotInvitedJoinGroupRequestEvent(
eventId: Long,
invitorId: Long,
groupId: Long,
@ -151,7 +151,7 @@ interface LowLevelBotAPIAccessor {
*/
@LowLevelAPI
@MiraiExperimentalAPI
suspend fun _lowLevelSolveMemberJoinRequestEvent(
public suspend fun _lowLevelSolveMemberJoinRequestEvent(
eventId: Long,
fromId: Long,
fromNick: String,
@ -163,10 +163,8 @@ interface LowLevelBotAPIAccessor {
/**
* 查询语音的下载连接
*
* */
*/
@LowLevelAPI
@MiraiExperimentalAPI
suspend fun _lowLevelQueryGroupVoiceDownloadUrl(md5: ByteArray, groupId: Long, dstUin: Long): String
public suspend fun _lowLevelQueryGroupVoiceDownloadUrl(md5: ByteArray, groupId: Long, dstUin: Long): String
}

View File

@ -25,10 +25,10 @@ import net.mamoe.mirai.utils.PlannedRemoval
*
* @see MessageEvent
*/
class FriendMessageEvent constructor(
override val sender: Friend,
override val message: MessageChain,
override val time: Int
public class FriendMessageEvent constructor(
public override val sender: Friend,
public override val message: MessageChain,
public override val time: Int
) : @PlannedRemoval("1.2.0") FriendMessage(), BroadcastControllable {
init {
val source =
@ -36,10 +36,10 @@ class FriendMessageEvent constructor(
check(source is OnlineMessageSource.Incoming.FromFriend) { "source provided to a FriendMessage must be an instance of OnlineMessageSource.Incoming.FromFriend" }
}
override val bot: Bot get() = sender.bot
override val subject: Friend get() = sender
override val senderName: String get() = sender.nick
override val source: OnlineMessageSource.Incoming.FromFriend get() = message.source as OnlineMessageSource.Incoming.FromFriend
public override val bot: Bot get() = sender.bot
public override val subject: Friend get() = sender
public override val senderName: String get() = sender.nick
public override val source: OnlineMessageSource.Incoming.FromFriend get() = message.source as OnlineMessageSource.Incoming.FromFriend
override fun toString(): String = "FriendMessageEvent(sender=${sender.id}, message=$message)"
public override fun toString(): String = "FriendMessageEvent(sender=${sender.id}, message=$message)"
}

View File

@ -7,7 +7,7 @@
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
@file:Suppress("DEPRECATION_ERROR", "unused", "NOTHING_TO_INLINE")
@file:Suppress("DEPRECATION_ERROR", "unused", "NOTHING_TO_INLINE", "MemberVisibilityCanBePrivate")
package net.mamoe.mirai.message
@ -24,30 +24,30 @@ import net.mamoe.mirai.utils.PlannedRemoval
*
* @see MessageEvent
*/
class GroupMessageEvent(
override val senderName: String,
public class GroupMessageEvent(
public override val senderName: String,
/**
* 发送方权限.
*/
val permission: MemberPermission,
override val sender: Member,
override val message: MessageChain,
override val time: Int
public val permission: MemberPermission,
public override val sender: Member,
public override val message: MessageChain,
public override val time: Int
) : @PlannedRemoval("1.2.0") GroupMessage(), Event {
init {
val source = message[MessageSource] ?: error("Cannot find MessageSource from message")
check(source is OnlineMessageSource.Incoming.FromGroup) { "source provided to a GroupMessage must be an instance of OnlineMessageSource.Incoming.FromGroup" }
}
override val group: Group get() = sender.group
override val bot: Bot get() = sender.bot
public override val group: Group get() = sender.group
public override val bot: Bot get() = sender.bot
override val subject: Group get() = group
public override val subject: Group get() = group
override val source: OnlineMessageSource.Incoming.FromGroup get() = message.source as OnlineMessageSource.Incoming.FromGroup
public override val source: OnlineMessageSource.Incoming.FromGroup get() = message.source as OnlineMessageSource.Incoming.FromGroup
inline fun At.asMember(): Member = group[this.target]
public inline fun At.asMember(): Member = group[this.target]
override fun toString(): String =
public override fun toString(): String =
"GroupMessageEvent(group=${group.id}, senderName=$senderName, sender=${sender.id}, permission=${permission.name}, message=$message)"
}

View File

@ -46,13 +46,13 @@ import kotlin.jvm.JvmSynthetic
* @see isContextIdenticalWith 判断语境是否相同
*/
@Suppress("DEPRECATION_ERROR")
abstract class MessageEvent : @PlannedRemoval("1.2.0") ContactMessage(),
public abstract class MessageEvent : @PlannedRemoval("1.2.0") ContactMessage(),
BotEvent, MessageEventExtensions<User, Contact> {
/**
* 与这个消息事件相关的 [Bot]
*/
abstract override val bot: Bot
public abstract override val bot: Bot
/**
* 消息事件主体.
@ -63,19 +63,19 @@ abstract class MessageEvent : @PlannedRemoval("1.2.0") ContactMessage(),
*
* 在回复消息时, 可通过 [subject] 作为回复对象
*/
abstract override val subject: Contact
public abstract override val subject: Contact
/**
* 发送人.
*
* 在好友消息时为 [Friend] 的实例, 在群消息时为 [Member] 的实例
*/
abstract override val sender: User
public abstract override val sender: User
/**
* 发送人名称
*/
abstract override val senderName: String
public abstract override val senderName: String
/**
* 消息内容.
@ -83,20 +83,20 @@ abstract class MessageEvent : @PlannedRemoval("1.2.0") ContactMessage(),
* 第一个元素一定为 [MessageSource], 存储此消息的发送人, 发送时间, 收信人, 消息 id 等数据.
* 随后的元素为拥有顺序的真实消息内容.
*/
abstract override val message: MessageChain
public abstract override val message: MessageChain
/** 消息发送时间 (由服务器提供, 可能与本地有时差) */
abstract override val time: Int
public abstract override val time: Int
/**
* 消息源. 来自 [message] 的第一个元素,
*/
override val source: OnlineMessageSource.Incoming get() = message.source as OnlineMessageSource.Incoming
public override val source: OnlineMessageSource.Incoming get() = message.source as OnlineMessageSource.Incoming
}
/** 消息事件的扩展函数 */
@Suppress("EXPOSED_SUPER_INTERFACE") // Functions are visible
interface MessageEventExtensions<out TSender : User, out TSubject : Contact> :
public interface MessageEventExtensions<out TSender : User, out TSubject : Contact> :
MessageEventPlatformExtensions<TSender, TSubject> {
// region 发送 Message
@ -107,29 +107,29 @@ interface MessageEventExtensions<out TSender : User, out TSubject : Contact> :
* 对于群消息事件, 这个方法将会给群 ([subject]) 发送消息
*/
@JvmSynthetic
suspend inline fun reply(message: Message): MessageReceipt<TSubject> =
public suspend inline fun reply(message: Message): MessageReceipt<TSubject> =
subject.sendMessage(message.asMessageChain()) as MessageReceipt<TSubject>
@JvmSynthetic
suspend inline fun reply(plain: String): MessageReceipt<TSubject> =
public suspend inline fun reply(plain: String): MessageReceipt<TSubject> =
subject.sendMessage(plain.toMessage().asMessageChain()) as MessageReceipt<TSubject>
// endregion
@JvmSynthetic
suspend inline fun ExternalImage.upload(): Image = this.upload(subject)
public suspend inline fun ExternalImage.upload(): Image = this.upload(subject)
@JvmSynthetic
suspend inline fun ExternalImage.send(): MessageReceipt<TSubject> = this.sendTo(subject)
public suspend inline fun ExternalImage.send(): MessageReceipt<TSubject> = this.sendTo(subject)
@JvmSynthetic
suspend inline fun Image.send(): MessageReceipt<TSubject> = this.sendTo(subject)
public suspend inline fun Image.send(): MessageReceipt<TSubject> = this.sendTo(subject)
@JvmSynthetic
suspend inline fun Message.send(): MessageReceipt<TSubject> = this.sendTo(subject)
public suspend inline fun Message.send(): MessageReceipt<TSubject> = this.sendTo(subject)
@JvmSynthetic
suspend inline fun String.send(): MessageReceipt<TSubject> = this.toMessage().sendTo(subject)
public suspend inline fun String.send(): MessageReceipt<TSubject> = this.toMessage().sendTo(subject)
// region 引用回复
/**
@ -138,17 +138,18 @@ interface MessageEventExtensions<out TSender : User, out TSubject : Contact> :
* 对于群消息事件, 这个方法将会给群 ([subject]) 发送消息
*/
@JvmSynthetic
suspend inline fun quoteReply(message: MessageChain): MessageReceipt<TSubject> =
public suspend inline fun quoteReply(message: MessageChain): MessageReceipt<TSubject> =
reply(this.message.quote() + message)
@JvmSynthetic
suspend inline fun quoteReply(message: Message): MessageReceipt<TSubject> = reply(this.message.quote() + message)
public suspend inline fun quoteReply(message: Message): MessageReceipt<TSubject> =
reply(this.message.quote() + message)
@JvmSynthetic
suspend inline fun quoteReply(plain: String): MessageReceipt<TSubject> = reply(this.message.quote() + plain)
public suspend inline fun quoteReply(plain: String): MessageReceipt<TSubject> = reply(this.message.quote() + plain)
@JvmSynthetic
inline fun At.isBot(): Boolean = target == bot.id
public inline fun At.isBot(): Boolean = target == bot.id
/**
@ -156,7 +157,7 @@ interface MessageEventExtensions<out TSender : User, out TSubject : Contact> :
* @return "http://gchat.qpic.cn/gchatpic_new/..."
*/
@JvmSynthetic
suspend inline fun Image.url(): String = this@url.queryUrl()
public suspend inline fun Image.url(): String = this@url.queryUrl()
}
/** 一个消息事件在各平台的相关扩展. 请使用 [MessageEventExtensions] */
@ -177,14 +178,15 @@ internal expect interface MessageEventPlatformExtensions<out TSender : User, out
replaceWith = ReplaceWith("MessageEvent", "net.mamoe.mirai.message.MessageEvent"),
level = DeprecationLevel.HIDDEN
)
abstract class MessagePacketBase<out TSender : User, out TSubject : Contact> : Packet, BotEvent, AbstractEvent() {
public abstract class MessagePacketBase<out TSender : User, out TSubject : Contact> : Packet, BotEvent,
AbstractEvent() {
abstract override val bot: Bot
abstract val sender: User
abstract val subject: Contact
abstract val message: MessageChain
abstract val time: Int
abstract val source: OnlineMessageSource.Incoming
abstract val senderName: String
public abstract val sender: User
public abstract val subject: Contact
public abstract val message: MessageChain
public abstract val time: Int
public abstract val source: OnlineMessageSource.Incoming
public abstract val senderName: String
}
@PlannedRemoval("1.2.0")
@ -194,7 +196,7 @@ abstract class MessagePacketBase<out TSender : User, out TSubject : Contact> : P
level = DeprecationLevel.HIDDEN
)
@Suppress("DEPRECATION_ERROR")
abstract class MessagePacket : MessagePacketBase<User, Contact>(),
public abstract class MessagePacket : MessagePacketBase<User, Contact>(),
BotEvent, MessageEventExtensions<User, Contact> {
abstract override val bot: Bot
abstract override val sender: User
@ -212,7 +214,7 @@ abstract class MessagePacket : MessagePacketBase<User, Contact>(),
level = DeprecationLevel.HIDDEN
)
@Suppress("DEPRECATION_ERROR")
abstract class ContactMessage : MessagePacket(),
public abstract class ContactMessage : MessagePacket(),
BotEvent, MessageEventExtensions<User, Contact> {
abstract override val bot: Bot
abstract override val sender: User
@ -230,7 +232,7 @@ abstract class ContactMessage : MessagePacket(),
level = DeprecationLevel.HIDDEN
)
@Suppress("DEPRECATION_ERROR")
abstract class FriendMessage : MessageEvent() {
public abstract class FriendMessage : MessageEvent() {
abstract override val bot: Bot
abstract override val sender: Friend
abstract override val subject: Friend
@ -247,8 +249,8 @@ abstract class FriendMessage : MessageEvent() {
level = DeprecationLevel.HIDDEN
)
@Suppress("DEPRECATION_ERROR")
abstract class GroupMessage : MessageEvent() {
abstract val group: Group
public abstract class GroupMessage : MessageEvent() {
public abstract val group: Group
abstract override val bot: Bot
abstract override val sender: Member
abstract override val subject: Group
@ -264,13 +266,13 @@ abstract class GroupMessage : MessageEvent() {
replaceWith = ReplaceWith("TempMessageEvent", "net.mamoe.mirai.message.TempMessageEvent"),
level = DeprecationLevel.HIDDEN
)
abstract class TempMessage : MessageEvent() {
public abstract class TempMessage : MessageEvent() {
abstract override val bot: Bot
abstract override val sender: Member
abstract override val subject: Member
abstract override val message: MessageChain
abstract override val time: Int
abstract override val source: OnlineMessageSource.Incoming.FromTemp
abstract val group: Group
public abstract val group: Group
abstract override val senderName: String
}

View File

@ -41,26 +41,26 @@ import kotlin.jvm.JvmSynthetic
* @see MessageReceipt.sourceId id
* @see MessageReceipt.sourceTime 源时间
*/
open class MessageReceipt<out C : Contact> @MiraiExperimentalAPI("The constructor is subject to change.") constructor(
public open class MessageReceipt<out C : Contact> @MiraiExperimentalAPI("The constructor is subject to change.") constructor(
/**
* 指代发送出去的消息.
*/
val source: OnlineMessageSource.Outgoing,
public val source: OnlineMessageSource.Outgoing,
/**
* 发送目标, [Group] [Friend] [Member]
*/
val target: C,
public val target: C,
/**
* @see Group.botAsMember
*/
@MiraiExperimentalAPI("This is subject to change.")
val botAsMember: Member?
public val botAsMember: Member?
) {
/**
* 是否为发送给群的消息的回执
*/
val isToGroup: Boolean get() = target is Group
public val isToGroup: Boolean get() = target is Group
/**
* 引用这条消息并回复.
@ -71,7 +71,7 @@ open class MessageReceipt<out C : Contact> @MiraiExperimentalAPI("The constructo
*/
@JavaFriendlyAPI
@JvmName("quoteReply")
fun __quoteReplyBlockingForJava__(message: Message): MessageReceipt<C> {
public fun __quoteReplyBlockingForJava__(message: Message): MessageReceipt<C> {
return runBlocking { return@runBlocking quoteReply(message) }
}
@ -82,7 +82,7 @@ open class MessageReceipt<out C : Contact> @MiraiExperimentalAPI("The constructo
*/
@JavaFriendlyAPI
@JvmName("quoteReply")
fun __quoteReplyBlockingForJava__(message: String): MessageReceipt<C> {
public fun __quoteReplyBlockingForJava__(message: String): MessageReceipt<C> {
return runBlocking { quoteReply(message) }
}
@ -93,7 +93,7 @@ open class MessageReceipt<out C : Contact> @MiraiExperimentalAPI("The constructo
*/
@JavaFriendlyAPI
@JvmName("recall")
fun __recallBlockingForJava__() {
public fun __recallBlockingForJava__() {
return runBlocking { recall() }
}
@ -104,7 +104,7 @@ open class MessageReceipt<out C : Contact> @MiraiExperimentalAPI("The constructo
*/
@JavaFriendlyAPI
@JvmName("recallIn")
fun __recallInBlockingForJava__(timeMillis: Long): Job {
public fun __recallInBlockingForJava__(timeMillis: Long): Job {
return recallIn(timeMillis = timeMillis)
}
@ -115,7 +115,7 @@ open class MessageReceipt<out C : Contact> @MiraiExperimentalAPI("The constructo
*/
@JavaFriendlyAPI
@JvmName("quote")
fun __quoteBlockingForJava__(): QuoteReply {
public fun __quoteBlockingForJava__(): QuoteReply {
return this.quote()
}
}
@ -126,7 +126,7 @@ open class MessageReceipt<out C : Contact> @MiraiExperimentalAPI("The constructo
* @see Bot.recall
* @throws IllegalStateException 当此消息已经被撤回或正计划撤回时
*/
suspend inline fun MessageReceipt<*>.recall() {
public suspend inline fun MessageReceipt<*>.recall() {
return target.bot.recall(source)
}
@ -136,7 +136,7 @@ suspend inline fun MessageReceipt<*>.recall() {
* @param timeMillis 延迟时间, 单位为毫秒
* @throws IllegalStateException 当此消息已经被撤回或正计划撤回时
*/
inline fun MessageReceipt<*>.recallIn(
public inline fun MessageReceipt<*>.recallIn(
timeMillis: Long,
coroutineContext: CoroutineContext = EmptyCoroutineContext
): Job = source.recallIn(timeMillis, coroutineContext)
@ -147,14 +147,14 @@ inline fun MessageReceipt<*>.recallIn(
* @see MessageChain.quote 引用一条消息
*/
@JvmSynthetic
inline fun MessageReceipt<*>.quote(): QuoteReply = this.source.quote()
public inline fun MessageReceipt<*>.quote(): QuoteReply = this.source.quote()
/**
* 引用这条消息并回复.
* @see MessageChain.quote 引用一条消息
*/
@JvmSynthetic
suspend inline fun <C : Contact> MessageReceipt<C>.quoteReply(message: Message): MessageReceipt<C> {
public suspend inline fun <C : Contact> MessageReceipt<C>.quoteReply(message: Message): MessageReceipt<C> {
@Suppress("UNCHECKED_CAST")
return target.sendMessage(this.quote() + message) as MessageReceipt<C>
}
@ -164,7 +164,7 @@ suspend inline fun <C : Contact> MessageReceipt<C>.quoteReply(message: Message):
* @see MessageChain.quote 引用一条消息
*/
@JvmSynthetic
suspend inline fun <C : Contact> MessageReceipt<C>.quoteReply(message: String): MessageReceipt<C> {
public suspend inline fun <C : Contact> MessageReceipt<C>.quoteReply(message: String): MessageReceipt<C> {
return this.quoteReply(message.toMessage())
}
@ -175,7 +175,7 @@ suspend inline fun <C : Contact> MessageReceipt<C>.quoteReply(message: String):
* @see MessageSource.id
*/
@get:JvmSynthetic
inline val MessageReceipt<*>.sourceId: Int
public inline val MessageReceipt<*>.sourceId: Int
get() = this.source.id
@ -185,7 +185,7 @@ inline val MessageReceipt<*>.sourceId: Int
* @see MessageSource.id
*/
@get:JvmSynthetic
inline val MessageReceipt<*>.sourceInternalId: Int
public inline val MessageReceipt<*>.sourceInternalId: Int
get() = this.source.internalId
/**
@ -194,6 +194,6 @@ inline val MessageReceipt<*>.sourceInternalId: Int
* @see MessageSource.time
*/
@get:JvmSynthetic
inline val MessageReceipt<*>.sourceTime: Int
public inline val MessageReceipt<*>.sourceTime: Int
get() = this.source.time

View File

@ -17,22 +17,22 @@ import net.mamoe.mirai.message.data.source
*
* @see MessageEvent
*/
class TempMessageEvent(
override val sender: Member,
override val message: MessageChain,
override val time: Int
public class TempMessageEvent(
public override val sender: Member,
public override val message: MessageChain,
public override val time: Int
) : TempMessage(), BroadcastControllable {
init {
val source = message[MessageSource] ?: error("Cannot find MessageSource from message")
check(source is OnlineMessageSource.Incoming.FromTemp) { "source provided to a TempMessage must be an instance of OnlineMessageSource.Incoming.FromTemp" }
}
override val bot: Bot get() = sender.bot
override val subject: Member get() = sender
override val group: Group get() = sender.group
override val senderName: String get() = sender.nameCardOrNick
override val source: OnlineMessageSource.Incoming.FromTemp get() = message.source as OnlineMessageSource.Incoming.FromTemp
public override val bot: Bot get() = sender.bot
public override val subject: Member get() = sender
public override val group: Group get() = sender.group
public override val senderName: String get() = sender.nameCardOrNick
public override val source: OnlineMessageSource.Incoming.FromTemp get() = message.source as OnlineMessageSource.Incoming.FromTemp
override fun toString(): String =
public override fun toString(): String =
"TempMessageEvent(sender=${sender.id} from group(${sender.group.id}), message=$message)"
}

View File

@ -33,12 +33,12 @@ import net.mamoe.mirai.utils.SinceMirai
*/
@MiraiExperimentalAPI
@SinceMirai("1.1.0")
interface CodableMessage : Message {
public interface CodableMessage : Message {
/**
* 转换为 mirai .
*
* @suppress 警告: API 可能在任何时刻被改变
*/
@MiraiExperimentalAPI
fun toMiraiCode(): String = this.toString()
public fun toMiraiCode(): String = this.toString()
}

View File

@ -32,30 +32,30 @@ import kotlin.jvm.JvmSynthetic
*
* @see AtAll 全体成员
*/
data class At
public data class At
@Suppress("DataClassPrivateConstructor")
private constructor(
val target: Long,
public val target: Long,
/**
* "@群员名片"
*/
val display: String
public val display: String
) : MessageContent, CodableMessage {
/**
* 构造一个 [At] 实例. 这是唯一的公开的构造方式.
*/
constructor(member: Member) : this(member.id, "@${member.nameCardOrNick}")
public constructor(member: Member) : this(member.id, "@${member.nameCardOrNick}")
override fun equals(other: Any?): Boolean {
public override fun equals(other: Any?): Boolean {
return other is At && other.target == this.target && other.display == this.display
}
override fun toString(): String = "[mirai:at:$target,$display]"
override fun contentToString(): String = this.display
public override fun toString(): String = "[mirai:at:$target,$display]"
public override fun contentToString(): String = this.display
companion object Key : Message.Key<At> {
override val typeName: String
public companion object Key : Message.Key<At> {
public override val typeName: String
get() = "At"
/**
@ -64,18 +64,18 @@ private constructor(
@Suppress("FunctionName")
@JvmStatic
@LowLevelAPI
fun _lowLevelConstructAtInstance(target: Long, display: String): At = At(target, display)
public fun _lowLevelConstructAtInstance(target: Long, display: String): At = At(target, display)
}
// 自动为消息补充 " "
override fun followedBy(tail: Message): MessageChain {
public override fun followedBy(tail: Message): MessageChain {
if (tail is PlainText && tail.content.startsWith(' ')) {
return super<MessageContent>.followedBy(tail)
}
return super<MessageContent>.followedBy(PlainText(" ")) + tail
}
override fun hashCode(): Int {
public override fun hashCode(): Int {
var result = target.hashCode()
result = 31 * result + display.hashCode()
return result
@ -88,4 +88,4 @@ private constructor(
*/
@JvmSynthetic
@Suppress("NOTHING_TO_INLINE")
inline fun Member.at(): At = At(this)
public inline fun Member.at(): At = At(this)

View File

@ -9,6 +9,7 @@
@file:JvmMultifileClass
@file:JvmName("MessageUtils")
@file:Suppress("MemberVisibilityCanBePrivate")
package net.mamoe.mirai.message.data
@ -28,26 +29,26 @@ private const val displayA = "@全体成员"
*
* @see At at 单个群成员
*/
object AtAll :
public object AtAll :
Message.Key<AtAll>,
MessageContent, CodableMessage {
const val display = displayA
override val typeName: String
public const val display: String = displayA
public override val typeName: String
get() = "AtAll"
@Suppress("SpellCheckingInspection")
override fun toString(): String = "[mirai:atall]"
override fun contentToString(): String = display
override fun equals(other: Any?): Boolean {
public override fun toString(): String = "[mirai:atall]"
public override fun contentToString(): String = display
public override fun equals(other: Any?): Boolean {
return other === this
}
override fun hashCode(): Int {
public override fun hashCode(): Int {
return display.hashCode()
}
// 自动为消息补充 " "
override fun followedBy(tail: Message): MessageChain {
public override fun followedBy(tail: Message): MessageChain {
if (tail is PlainText && tail.content.startsWith(' ')) {
return super<MessageContent>.followedBy(tail)
}

View File

@ -37,11 +37,11 @@ import kotlin.jvm.JvmOverloads
* @see CustomMessageMetadata 自定义消息元数据
*/
@MiraiExperimentalAPI
sealed class CustomMessage : SingleMessage {
public sealed class CustomMessage : SingleMessage {
/**
* 获取这个消息的工厂
*/
abstract fun getFactory(): Factory<out CustomMessage>
public abstract fun getFactory(): Factory<out CustomMessage>
/**
* 序列化和反序列化此消息的工厂, 将会自动注册.
@ -51,13 +51,13 @@ sealed class CustomMessage : SingleMessage {
* @see ProtoBufSerializerFactory 使用 [ProtoBuf] 作为序列模式的 [Factory]
*/
@MiraiExperimentalAPI
abstract class Factory<M : CustomMessage>(
public abstract class Factory<M : CustomMessage>(
/**
* 此类型消息的名称.
* 在发往服务器时使用此名称.
* 应确保唯一且不变.
*/
final override val typeName: String
public final override val typeName: String
) : Message.Key<M> {
init {
@ -69,51 +69,51 @@ sealed class CustomMessage : SingleMessage {
* 序列化此消息.
*/
@Throws(Exception::class)
abstract fun dump(message: @UnsafeVariance M): ByteArray
public abstract fun dump(message: @UnsafeVariance M): ByteArray
/**
* [input] 读取此消息.
*/
@Throws(Exception::class)
abstract fun load(input: ByteArray): @UnsafeVariance M
public abstract fun load(input: ByteArray): @UnsafeVariance M
}
/**
* 使用 [ProtoBuf] 作为序列模式的 [Factory].
* 推荐使用此工厂
*/
abstract class ProtoBufSerializerFactory<M : CustomMessage>(typeName: String) :
public abstract class ProtoBufSerializerFactory<M : CustomMessage>(typeName: String) :
Factory<M>(typeName) {
/**
* 得到 [M] [KSerializer].
*/
abstract fun serializer(): KSerializer<M>
public abstract fun serializer(): KSerializer<M>
override fun dump(message: M): ByteArray = ProtoBuf.dump(serializer(), message)
override fun load(input: ByteArray): M = ProtoBuf.load(serializer(), input)
public override fun dump(message: M): ByteArray = ProtoBuf.dump(serializer(), message)
public override fun load(input: ByteArray): M = ProtoBuf.load(serializer(), input)
}
/**
* 使用 [Json] 作为序列模式的 [Factory]
* 推荐在调试时使用此工厂
*/
abstract class JsonSerializerFactory<M : CustomMessage>(typeName: String) :
public abstract class JsonSerializerFactory<M : CustomMessage>(typeName: String) :
Factory<M>(typeName) {
/**
* 得到 [M] [KSerializer].
*/
abstract fun serializer(): KSerializer<M>
public abstract fun serializer(): KSerializer<M>
@OptIn(UnstableDefault::class)
open val json = Json(JsonConfiguration.Default)
public open val json: Json = Json(JsonConfiguration.Default)
override fun dump(message: M): ByteArray = json.stringify(serializer(), message).toByteArray()
override fun load(input: ByteArray): M = json.parse(serializer(), String(input))
public override fun dump(message: M): ByteArray = json.stringify(serializer(), message).toByteArray()
public override fun load(input: ByteArray): M = json.parse(serializer(), String(input))
}
companion object Key : Message.Key<CustomMessage> {
public companion object Key : Message.Key<CustomMessage> {
override val typeName: String get() = "CustomMessage"
private val factories: LockFreeLinkedList<Factory<*>> = LockFreeLinkedList()
@ -127,14 +127,14 @@ sealed class CustomMessage : SingleMessage {
}
@Serializable
class CustomMessageFullData(
private class CustomMessageFullData(
@ProtoId(1) val miraiVersionFlag: Int,
@ProtoId(2) val typeName: String,
@ProtoId(3) val data: ByteArray
)
class CustomMessageFullDataDeserializeInternalException(cause: Throwable?) : RuntimeException(cause)
class CustomMessageFullDataDeserializeUserException(val body: ByteArray, cause: Throwable?) :
public class CustomMessageFullDataDeserializeInternalException(cause: Throwable?) : RuntimeException(cause)
public class CustomMessageFullDataDeserializeUserException(public val body: ByteArray, cause: Throwable?) :
RuntimeException(cause)
internal fun load(fullData: ByteReadPacket): CustomMessage? {
@ -177,7 +177,7 @@ sealed class CustomMessage : SingleMessage {
*/
@MiraiExperimentalAPI
@SinceMirai("1.1.0")
fun <T : CustomMessage> T.toByteArray(): ByteArray {
public fun <T : CustomMessage> T.toByteArray(): ByteArray {
@Suppress("UNCHECKED_CAST")
return (this.getFactory() as CustomMessage.Factory<T>).dump(this)
}
@ -194,12 +194,12 @@ fun <T : CustomMessage> T.toByteArray(): ByteArray {
* @see ConstrainSingle 可实现此接口以保证消息链中只存在一个元素
*/
@MiraiExperimentalAPI
abstract class CustomMessageMetadata : CustomMessage(), MessageMetadata {
companion object Key : Message.Key<CustomMessageMetadata> {
public abstract class CustomMessageMetadata : CustomMessage(), MessageMetadata {
public companion object Key : Message.Key<CustomMessageMetadata> {
override val typeName: String get() = "CustomMessageMetadata"
}
open fun customToString(): ByteArray = customToStringImpl(this.getFactory())
public open fun customToString(): ByteArray = customToStringImpl(this.getFactory())
final override fun toString(): String =
"[mirai:custom:${getFactory().typeName}:${String(customToString())}]"

View File

@ -24,219 +24,219 @@ import kotlin.jvm.JvmSynthetic
* ## mirai 码支持
* 格式: &#91;mirai:face:*[id]*&#93;
*/
data class Face(val id: Int) : // used in delegation
public data class Face(public val id: Int) : // used in delegation
MessageContent, CodableMessage {
override fun toString(): String = "[mirai:face:$id]"
override fun contentToString(): String =
if (id >= 0 && id <= 255)
FaceName.names[id]
else "[表情]"
public override fun toString(): String = "[mirai:face:$id]"
public override fun contentToString(): String =
if (id >= 0 && id <= 255)
FaceName.names[id]
else "[表情]"
override fun equals(other: Any?): Boolean = other is Face && other.id == this.id
override fun hashCode(): Int = id
public override fun equals(other: Any?): Boolean = other is Face && other.id == this.id
public override fun hashCode(): Int = id
/**
* @author LamGC
*/
@Suppress("SpellCheckingInspection", "unused")
companion object IdList : Message.Key<Face> {
override val typeName: String
public companion object IdList : Message.Key<Face> {
public override val typeName: String
get() = "Face"
const val unknown: Int = 0xff
const val jingya: Int = 0
const val piezui: Int = 1
const val se: Int = 2
const val fadai: Int = 3
const val deyi: Int = 4
const val liulei: Int = 5
const val haixiu: Int = 6
const val bizui: Int = 7
const val shui: Int = 8
const val daku: Int = 9
const val ganga: Int = 10
const val fanu: Int = 11
const val tiaopi: Int = 12
const val ciya: Int = 13
const val weixiao: Int = 14
const val nanguo: Int = 15
const val ku: Int = 16
const val zhuakuang: Int = 18
const val tu: Int = 19
const val touxiao: Int = 20
const val keai: Int = 21
const val baiyan: Int = 22
const val aoman: Int = 23
const val ji_e: Int = 24
const val kun: Int = 25
const val jingkong: Int = 26
const val liuhan: Int = 27
const val hanxiao: Int = 28
const val dabing: Int = 29
const val fendou: Int = 30
const val zhouma: Int = 31
const val yiwen: Int = 32
const val yun: Int = 34
const val zhemo: Int = 35
const val shuai: Int = 36
const val kulou: Int = 37
const val qiaoda: Int = 38
const val zaijian: Int = 39
const val fadou: Int = 41
const val aiqing: Int = 42
const val tiaotiao: Int = 43
const val zhutou: Int = 46
const val yongbao: Int = 49
const val dan_gao: Int = 53
const val shandian: Int = 54
const val zhadan: Int = 55
const val dao: Int = 56
const val zuqiu: Int = 57
const val bianbian: Int = 59
const val kafei: Int = 60
const val fan: Int = 61
const val meigui: Int = 63
const val diaoxie: Int = 64
const val aixin: Int = 66
const val xinsui: Int = 67
const val liwu: Int = 69
const val taiyang: Int = 74
const val yueliang: Int = 75
const val qiang: Int = 76
const val ruo: Int = 77
const val woshou: Int = 78
const val shengli: Int = 79
const val feiwen: Int = 85
const val naohuo: Int = 86
const val xigua: Int = 89
const val lenghan: Int = 96
const val cahan: Int = 97
const val koubi: Int = 98
const val guzhang: Int = 99
const val qiudale: Int = 100
const val huaixiao: Int = 101
const val zuohengheng: Int = 102
const val youhengheng: Int = 103
const val haqian: Int = 104
const val bishi: Int = 105
const val weiqu: Int = 106
const val kuaikule: Int = 107
const val yinxian: Int = 108
const val qinqin: Int = 109
const val xia: Int = 110
const val kelian: Int = 111
const val caidao: Int = 112
const val pijiu: Int = 113
const val lanqiu: Int = 114
const val pingpang: Int = 115
const val shiai: Int = 116
const val piaochong: Int = 117
const val baoquan: Int = 118
const val gouyin: Int = 119
const val quantou: Int = 120
const val chajin: Int = 121
const val aini: Int = 122
const val bu: Int = 123
const val hao: Int = 124
const val zhuanquan: Int = 125
const val ketou: Int = 126
const val huitou: Int = 127
const val tiaosheng: Int = 128
const val huishou: Int = 129
const val jidong: Int = 130
const val jiewu: Int = 131
const val xianwen: Int = 132
const val zuotaiji: Int = 133
const val youtaiji: Int = 134
const val shuangxi: Int = 136
const val bianpao: Int = 137
const val denglong: Int = 138
const val facai: Int = 139
const val K_ge: Int = 140
const val gouwu: Int = 141
const val youjian: Int = 142
const val shuai_qi: Int = 143
const val hecai: Int = 144
const val qidao: Int = 145
const val baojin: Int = 146
const val bangbangtang: Int = 147
const val he_nai: Int = 148
const val xiamian: Int = 149
const val xiangjiao: Int = 150
const val feiji: Int = 151
const val kaiche: Int = 152
const val gaotiezuochetou: Int = 153
const val chexiang: Int = 154
const val gaotieyouchetou: Int = 155
const val duoyun: Int = 156
const val xiayu: Int = 157
const val chaopiao: Int = 158
const val xiongmao: Int = 159
const val dengpao: Int = 160
const val fengche: Int = 161
const val naozhong: Int = 162
const val dasan: Int = 163
const val caiqiu: Int = 164
const val zuanjie: Int = 165
const val shafa: Int = 166
const val zhijin: Int = 167
const val yao: Int = 168
const val shouqiang: Int = 169
const val qingwa: Int = 170
const val hexie: Int = 184
const val yangtuo: Int = 185
const val youling: Int = 187
const val dan: Int = 188
const val juhua: Int = 190
const val hongbao: Int = 192
const val daxiao: Int = 193
const val bukaixin: Int = 194
const val lengmo: Int = 197
const val e: Int = 198
const val haobang: Int = 199
const val baituo: Int = 200
const val dianzan: Int = 201
const val wuliao: Int = 202
const val tuolian: Int = 203
const val chi: Int = 204
const val songhua: Int = 205
const val haipa: Int = 206
const val huachi: Int = 207
const val xiaoyanger: Int = 208
const val biaolei: Int = 210
const val wobukan: Int = 211
const val bobo: Int = 214
const val hulian: Int = 215
const val paitou: Int = 216
const val cheyiche: Int = 217
const val tianyitian: Int = 218
const val cengyiceng: Int = 219
const val zhuaizhatian: Int = 220
const val dingguagua: Int = 221
const val baobao: Int = 222
const val baoji: Int = 223
const val kaiqiang: Int = 224
const val liaoyiliao: Int = 225
const val paizhuo: Int = 226
const val paishou: Int = 227
const val gongxi: Int = 228
const val ganbei: Int = 229
const val chaofeng: Int = 230
const val heng: Int = 231
const val foxi: Int = 232
const val qiaoyiqioa: Int = 233
const val jingdai: Int = 234
const val chandou: Int = 235
const val kentou: Int = 236
const val toukan: Int = 237
const val shanlian: Int = 238
const val yuanliang: Int = 239
const val penlian: Int = 240
const val shengrikuaile: Int = 241
const val touzhuangji: Int = 242
const val shuaitou: Int = 243
const val rengou: Int = 244
public const val unknown: Int = 0xff
public const val jingya: Int = 0
public const val piezui: Int = 1
public const val se: Int = 2
public const val fadai: Int = 3
public const val deyi: Int = 4
public const val liulei: Int = 5
public const val haixiu: Int = 6
public const val bizui: Int = 7
public const val shui: Int = 8
public const val daku: Int = 9
public const val ganga: Int = 10
public const val fanu: Int = 11
public const val tiaopi: Int = 12
public const val ciya: Int = 13
public const val weixiao: Int = 14
public const val nanguo: Int = 15
public const val ku: Int = 16
public const val zhuakuang: Int = 18
public const val tu: Int = 19
public const val touxiao: Int = 20
public const val keai: Int = 21
public const val baiyan: Int = 22
public const val aoman: Int = 23
public const val ji_e: Int = 24
public const val kun: Int = 25
public const val jingkong: Int = 26
public const val liuhan: Int = 27
public const val hanxiao: Int = 28
public const val dabing: Int = 29
public const val fendou: Int = 30
public const val zhouma: Int = 31
public const val yiwen: Int = 32
public const val yun: Int = 34
public const val zhemo: Int = 35
public const val shuai: Int = 36
public const val kulou: Int = 37
public const val qiaoda: Int = 38
public const val zaijian: Int = 39
public const val fadou: Int = 41
public const val aiqing: Int = 42
public const val tiaotiao: Int = 43
public const val zhutou: Int = 46
public const val yongbao: Int = 49
public const val dan_gao: Int = 53
public const val shandian: Int = 54
public const val zhadan: Int = 55
public const val dao: Int = 56
public const val zuqiu: Int = 57
public const val bianbian: Int = 59
public const val kafei: Int = 60
public const val fan: Int = 61
public const val meigui: Int = 63
public const val diaoxie: Int = 64
public const val aixin: Int = 66
public const val xinsui: Int = 67
public const val liwu: Int = 69
public const val taiyang: Int = 74
public const val yueliang: Int = 75
public const val qiang: Int = 76
public const val ruo: Int = 77
public const val woshou: Int = 78
public const val shengli: Int = 79
public const val feiwen: Int = 85
public const val naohuo: Int = 86
public const val xigua: Int = 89
public const val lenghan: Int = 96
public const val cahan: Int = 97
public const val koubi: Int = 98
public const val guzhang: Int = 99
public const val qiudale: Int = 100
public const val huaixiao: Int = 101
public const val zuohengheng: Int = 102
public const val youhengheng: Int = 103
public const val haqian: Int = 104
public const val bishi: Int = 105
public const val weiqu: Int = 106
public const val kuaikule: Int = 107
public const val yinxian: Int = 108
public const val qinqin: Int = 109
public const val xia: Int = 110
public const val kelian: Int = 111
public const val caidao: Int = 112
public const val pijiu: Int = 113
public const val lanqiu: Int = 114
public const val pingpang: Int = 115
public const val shiai: Int = 116
public const val piaochong: Int = 117
public const val baoquan: Int = 118
public const val gouyin: Int = 119
public const val quantou: Int = 120
public const val chajin: Int = 121
public const val aini: Int = 122
public const val bu: Int = 123
public const val hao: Int = 124
public const val zhuanquan: Int = 125
public const val ketou: Int = 126
public const val huitou: Int = 127
public const val tiaosheng: Int = 128
public const val huishou: Int = 129
public const val jidong: Int = 130
public const val jiewu: Int = 131
public const val xianwen: Int = 132
public const val zuotaiji: Int = 133
public const val youtaiji: Int = 134
public const val shuangxi: Int = 136
public const val bianpao: Int = 137
public const val denglong: Int = 138
public const val facai: Int = 139
public const val K_ge: Int = 140
public const val gouwu: Int = 141
public const val youjian: Int = 142
public const val shuai_qi: Int = 143
public const val hecai: Int = 144
public const val qidao: Int = 145
public const val baojin: Int = 146
public const val bangbangtang: Int = 147
public const val he_nai: Int = 148
public const val xiamian: Int = 149
public const val xiangjiao: Int = 150
public const val feiji: Int = 151
public const val kaiche: Int = 152
public const val gaotiezuochetou: Int = 153
public const val chexiang: Int = 154
public const val gaotieyouchetou: Int = 155
public const val duoyun: Int = 156
public const val xiayu: Int = 157
public const val chaopiao: Int = 158
public const val xiongmao: Int = 159
public const val dengpao: Int = 160
public const val fengche: Int = 161
public const val naozhong: Int = 162
public const val dasan: Int = 163
public const val caiqiu: Int = 164
public const val zuanjie: Int = 165
public const val shafa: Int = 166
public const val zhijin: Int = 167
public const val yao: Int = 168
public const val shouqiang: Int = 169
public const val qingwa: Int = 170
public const val hexie: Int = 184
public const val yangtuo: Int = 185
public const val youling: Int = 187
public const val dan: Int = 188
public const val juhua: Int = 190
public const val hongbao: Int = 192
public const val daxiao: Int = 193
public const val bukaixin: Int = 194
public const val lengmo: Int = 197
public const val e: Int = 198
public const val haobang: Int = 199
public const val baituo: Int = 200
public const val dianzan: Int = 201
public const val wuliao: Int = 202
public const val tuolian: Int = 203
public const val chi: Int = 204
public const val songhua: Int = 205
public const val haipa: Int = 206
public const val huachi: Int = 207
public const val xiaoyanger: Int = 208
public const val biaolei: Int = 210
public const val wobukan: Int = 211
public const val bobo: Int = 214
public const val hulian: Int = 215
public const val paitou: Int = 216
public const val cheyiche: Int = 217
public const val tianyitian: Int = 218
public const val cengyiceng: Int = 219
public const val zhuaizhatian: Int = 220
public const val dingguagua: Int = 221
public const val baobao: Int = 222
public const val baoji: Int = 223
public const val kaiqiang: Int = 224
public const val liaoyiliao: Int = 225
public const val paizhuo: Int = 226
public const val paishou: Int = 227
public const val gongxi: Int = 228
public const val ganbei: Int = 229
public const val chaofeng: Int = 230
public const val heng: Int = 231
public const val foxi: Int = 232
public const val qiaoyiqioa: Int = 233
public const val jingdai: Int = 234
public const val chandou: Int = 235
public const val kentou: Int = 236
public const val toukan: Int = 237
public const val shanlian: Int = 238
public const val yuanliang: Int = 239
public const val penlian: Int = 240
public const val shengrikuaile: Int = 241
public const val touzhuangji: Int = 242
public const val shuaitou: Int = 243
public const val rengou: Int = 244
}
@ -249,13 +249,13 @@ data class Face(val id: Int) : // used in delegation
@PlannedRemoval("1.2.0")
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
@Suppress("unused", "UNUSED_PARAMETER")
fun copy(id: Int = this.id, stringValue: String = "") = this.copy(id = id)
public fun copy(id: Int = this.id, stringValue: String = ""): Face = this.copy(id = id)
@JvmSynthetic
@PlannedRemoval("1.2.0")
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
@Suppress("unused", "UNUSED_PARAMETER")
operator fun component2(): String = toString()
public operator fun component2(): String = toString()
}
@ -264,7 +264,7 @@ data class Face(val id: Int) : // used in delegation
*/
@Suppress("SpellCheckingInspection")
private object FaceName {
val names = Array<String>(256, { "[表情]" })
val names = Array(256) { "[表情]" }
init {
names[Face.jingya] = "[惊讶]"

View File

@ -83,12 +83,12 @@ import kotlin.jvm.Transient
*
* @see buildForwardMessage
*/
class ForwardMessage @JvmOverloads constructor(
public class ForwardMessage @JvmOverloads constructor(
/**
* 消息列表
*/
val nodeList: Collection<INode>,
@Transient val displayStrategy: DisplayStrategy = DisplayStrategy.Default
public val nodeList: Collection<INode>,
@Transient public val displayStrategy: DisplayStrategy = DisplayStrategy.Default
) : MessageContent {
init {
require(nodeList.isNotEmpty()) {
@ -99,37 +99,37 @@ class ForwardMessage @JvmOverloads constructor(
/**
* @see ForwardMessage
*/
abstract class DisplayStrategy {
public abstract class DisplayStrategy {
/**
* 修改后卡片标题会变为 "转发的聊天记录", 而此函数的返回值会显示在 preview
*/
open fun generateTitle(forward: ForwardMessage): String = "群聊的聊天记录"
public open fun generateTitle(forward: ForwardMessage): String = "群聊的聊天记录"
/**
* 显示在消息列表中的预览.
*/
open fun generateBrief(forward: ForwardMessage): String = "[聊天记录]"
public open fun generateBrief(forward: ForwardMessage): String = "[聊天记录]"
/**
* 目前未发现在哪能显示
*/
open fun generateSource(forward: ForwardMessage): String = "聊天记录"
public open fun generateSource(forward: ForwardMessage): String = "聊天记录"
/**
* 显示在卡片 body , 只会显示 sequence 前四个元素.
* Java 用户: 使用 [sequenceOf] (`SequenceKt.sequenceOf`) [asSequence] (`SequenceKt.asSequence`)
*/
open fun generatePreview(forward: ForwardMessage): Sequence<String> =
public open fun generatePreview(forward: ForwardMessage): Sequence<String> =
forward.nodeList.asSequence().map { it.senderName + ": " + it.message.contentToString() }
/**
* 显示在卡片底部
*/
open fun generateSummary(forward: ForwardMessage): String = "查看 ${forward.nodeList.size} 条转发消息"
public open fun generateSummary(forward: ForwardMessage): String = "查看 ${forward.nodeList.size} 条转发消息"
companion object Default : DisplayStrategy() {
public companion object Default : DisplayStrategy() {
@JvmSynthetic
inline operator fun invoke(
public inline operator fun invoke(
crossinline generateTitle: (forward: ForwardMessage) -> String = Default::generateTitle,
crossinline generateBrief: (forward: ForwardMessage) -> String = Default::generateBrief,
crossinline generateSource: (forward: ForwardMessage) -> String = Default::generateSource,
@ -146,44 +146,44 @@ class ForwardMessage @JvmOverloads constructor(
}
data class Node(
public data class Node(
override val senderId: Long,
override val time: Int,
override val senderName: String,
override val message: Message
) : INode
interface INode {
public interface INode {
/**
* 发送人 [User.id]
*/
val senderId: Long
public val senderId: Long
/**
* 时间戳秒
*/
val time: Int
public val time: Int
/**
* 发送人名称
*/
val senderName: String
public val senderName: String
/**
* 消息内容
*/
val message: Message
public val message: Message
}
companion object Key : Message.Key<ForwardMessage> {
override val typeName: String get() = "ForwardMessage"
public companion object Key : Message.Key<ForwardMessage> {
public override val typeName: String get() = "ForwardMessage"
}
override fun toString(): String = "[mirai:forward:$nodeList]"
public override fun toString(): String = "[mirai:forward:$nodeList]"
private val contentToString: String by lazy { nodeList.joinToString("\n") }
@MiraiExperimentalAPI
override fun contentToString(): String = contentToString
public override fun contentToString(): String = contentToString
}
@ -191,7 +191,7 @@ class ForwardMessage @JvmOverloads constructor(
* 转换为 [ForwardMessage]
*/
@JvmOverloads
fun Iterable<MessageEvent>.toForwardMessage(displayStrategy: DisplayStrategy = DisplayStrategy): ForwardMessage {
public fun Iterable<MessageEvent>.toForwardMessage(displayStrategy: DisplayStrategy = DisplayStrategy): ForwardMessage {
val iterator = this.iterator()
if (!iterator.hasNext()) return ForwardMessage(emptyList(), displayStrategy)
return ForwardMessage(
@ -203,7 +203,7 @@ fun Iterable<MessageEvent>.toForwardMessage(displayStrategy: DisplayStrategy = D
* 转换为 [ForwardMessage]
*/
@JvmOverloads
fun Message.toForwardMessage(
public fun Message.toForwardMessage(
sender: User,
time: Int = currentTimeSeconds.toInt(),
displayStrategy: DisplayStrategy = DisplayStrategy
@ -213,7 +213,7 @@ fun Message.toForwardMessage(
* 转换为 [ForwardMessage]
*/
@JvmOverloads
fun Message.toForwardMessage(
public fun Message.toForwardMessage(
senderId: Long,
senderName: String,
time: Int = currentTimeSeconds.toInt(),
@ -227,7 +227,7 @@ fun Message.toForwardMessage(
* @see ForwardMessage 查看转发消息说明
*/
@JvmSynthetic
inline fun buildForwardMessage(
public inline fun buildForwardMessage(
context: Contact,
displayStrategy: DisplayStrategy = DisplayStrategy,
block: ForwardMessageBuilder.() -> Unit
@ -240,7 +240,7 @@ inline fun buildForwardMessage(
* @see ForwardMessage 查看转发消息说明
*/
@JvmSynthetic
inline fun MessageEvent.buildForwardMessage(
public inline fun MessageEvent.buildForwardMessage(
context: Contact = this.subject,
displayStrategy: DisplayStrategy = DisplayStrategy,
block: ForwardMessageBuilder.() -> Unit
@ -253,7 +253,7 @@ inline fun MessageEvent.buildForwardMessage(
*/
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.TYPE)
@DslMarker
annotation class ForwardMessageDsl
public annotation class ForwardMessageDsl
/**
* 转发消息 DSL 构建器.
@ -315,114 +315,115 @@ annotation class ForwardMessageDsl
*
* `S named "name1" named "name2" says M` 最终的发送人名称为 `"name2"`
*/
class ForwardMessageBuilder private constructor(
public class ForwardMessageBuilder private constructor(
/**
* 消息语境. 可为 [Group] [User]
*/
val context: Contact,
public val context: Contact,
private val container: MutableList<ForwardMessage.INode>
) : MutableList<ForwardMessage.INode> by container {
/**
* @see ForwardMessage.displayStrategy
*/
var displayStrategy: DisplayStrategy = DisplayStrategy
public var displayStrategy: DisplayStrategy = DisplayStrategy
private var built: Boolean = false
private fun checkBuilt() {
check(!built) { "ForwardMessageBuilder is already built therefore can't be modified" }
}
constructor(context: Contact) : this(context, mutableListOf())
constructor(context: Contact, initialSize: Int) : this(context, ArrayList<ForwardMessage.INode>(initialSize))
public constructor(context: Contact) : this(context, mutableListOf())
public constructor(context: Contact, initialSize: Int) : this(context, ArrayList<ForwardMessage.INode>(initialSize))
/**
* 当前时间.
* 在使用 [says] 时若不指定时间, 则会使用 [currentTime] 自增 1 的时间.
*/
var currentTime: Int = currentTimeSeconds.toInt()
public var currentTime: Int = currentTimeSeconds.toInt()
inner class BuilderNode : ForwardMessage.INode {
public inner class BuilderNode : ForwardMessage.INode {
/**
* 发送人 [User.id]
*/
override var senderId: Long = 0
public override var senderId: Long = 0
/**
* 时间戳秒
*/
override var time: Int = currentTime++
public override var time: Int = currentTime++
/**
* 发送人名称
*/
override var senderName: String = ""
public override var senderName: String = ""
/**
* 消息内容
*/
override lateinit var message: Message
public override lateinit var message: Message
/**
* 指定发送人 id 和名称.
*/
@ForwardMessageDsl
infix fun sender(user: User): BuilderNode = apply { this.senderId(user.id); this.named(user.nameCardOrNick) }
public infix fun sender(user: User): BuilderNode =
apply { this.senderId(user.id); this.named(user.nameCardOrNick) }
/**
* 指定发送人 id.
*/
@ForwardMessageDsl
infix fun senderId(id: Int): BuilderNode = apply { this.senderId = id.toLongUnsigned() }
public infix fun senderId(id: Int): BuilderNode = apply { this.senderId = id.toLongUnsigned() }
/**
* 指定发送人 id.
*/
@ForwardMessageDsl
infix fun senderId(id: Long): BuilderNode = apply { this.senderId = id }
public infix fun senderId(id: Long): BuilderNode = apply { this.senderId = id }
/**
* 指定发送人名称.
*/
@ForwardMessageDsl
infix fun named(name: String): BuilderNode = apply { this.senderName = name }
public infix fun named(name: String): BuilderNode = apply { this.senderName = name }
/**
* 指定发送人名称.
*/
@ForwardMessageDsl
infix fun senderName(name: String): BuilderNode = apply { this.senderName = name }
public infix fun senderName(name: String): BuilderNode = apply { this.senderName = name }
/**
* 指定时间.
* @time 时间戳, 单位为秒
*/
@ForwardMessageDsl
infix fun at(time: Int): BuilderNode = this.apply { this.time = time }
public infix fun at(time: Int): BuilderNode = this.apply { this.time = time }
/**
* 指定时间.
* @time 时间戳, 单位为秒
*/
@ForwardMessageDsl
infix fun time(time: Int): BuilderNode = this.apply { this.time = time }
public infix fun time(time: Int): BuilderNode = this.apply { this.time = time }
/**
* 指定消息内容
*/
@ForwardMessageDsl
infix fun message(message: Message): BuilderNode = this.apply { this.message = message }
public infix fun message(message: Message): BuilderNode = this.apply { this.message = message }
/**
* 指定消息内容
*/
@ForwardMessageDsl
infix fun message(message: String): BuilderNode = this.apply { this.message = message.toMessage() }
public infix fun message(message: String): BuilderNode = this.apply { this.message = message.toMessage() }
/** 添加一条消息 */
@ForwardMessageDsl
infix fun says(message: Message): ForwardMessageBuilder = this@ForwardMessageBuilder.apply {
public infix fun says(message: Message): ForwardMessageBuilder = this@ForwardMessageBuilder.apply {
checkBuilt()
this@BuilderNode.message = message
add(this@BuilderNode)
@ -430,11 +431,11 @@ class ForwardMessageBuilder private constructor(
/** 添加一条消息 */
@ForwardMessageDsl
infix fun says(message: String): ForwardMessageBuilder = this.says(message.toMessage())
public infix fun says(message: String): ForwardMessageBuilder = this.says(message.toMessage())
/** 构造并添加一个 [MessageChain] */
@ForwardMessageDsl
inline infix fun says(chain: @ForwardMessageDsl MessageChainBuilder.() -> Unit): ForwardMessageBuilder =
public inline infix fun says(chain: @ForwardMessageDsl MessageChainBuilder.() -> Unit): ForwardMessageBuilder =
says(MessageChainBuilder().apply(chain).asMessageChain())
}
@ -442,16 +443,16 @@ class ForwardMessageBuilder private constructor(
/** 添加一条消息, 自动按顺序调整时间 */
@ForwardMessageDsl
infix fun Long.says(message: String): ForwardMessageBuilder = says(message.toMessage())
public infix fun Long.says(message: String): ForwardMessageBuilder = says(message.toMessage())
/** 添加一条消息, 自动按顺序调整时间 */
@ForwardMessageDsl
infix fun Int.says(message: String): ForwardMessageBuilder =
public infix fun Int.says(message: String): ForwardMessageBuilder =
this.toLong().and(0xFFFF_FFFF).says(message.toMessage())
/** 添加一条消息, 自动按顺序调整时间 */
@ForwardMessageDsl
infix fun Long.says(message: Message): ForwardMessageBuilder =
public infix fun Long.says(message: Message): ForwardMessageBuilder =
this@ForwardMessageBuilder.apply {
checkBuilt()
add(BuilderNode().apply {
@ -462,43 +463,43 @@ class ForwardMessageBuilder private constructor(
/** 添加一条消息, 自动按顺序调整时间 */
@ForwardMessageDsl
infix fun Int.says(message: Message): ForwardMessageBuilder = this.toLong().and(0xFFFF_FFFF).says(message)
public infix fun Int.says(message: Message): ForwardMessageBuilder = this.toLong().and(0xFFFF_FFFF).says(message)
/** 构造并添加一个 [MessageChain], 自动按顺序调整时间 */
@ForwardMessageDsl
inline infix fun Long.says(chain: @ForwardMessageDsl MessageChainBuilder.() -> Unit): ForwardMessageBuilder =
public inline infix fun Long.says(chain: @ForwardMessageDsl MessageChainBuilder.() -> Unit): ForwardMessageBuilder =
says(MessageChainBuilder().apply(chain).asMessageChain())
/** 添加一条消息, 自动按顺序调整时间 */
@ForwardMessageDsl
inline infix fun Int.says(chain: @ForwardMessageDsl MessageChainBuilder.() -> Unit): ForwardMessageBuilder =
public inline infix fun Int.says(chain: @ForwardMessageDsl MessageChainBuilder.() -> Unit): ForwardMessageBuilder =
this.toLong().and(0xFFFF_FFFF).says(chain)
/** 添加一条消息, 自动按顺序调整时间 */
@ForwardMessageDsl
infix fun Bot.says(message: String): ForwardMessageBuilder = this.id named this.smartName() says message
public infix fun Bot.says(message: String): ForwardMessageBuilder = this.id named this.smartName() says message
/** 添加一条消息, 自动按顺序调整时间 */
@ForwardMessageDsl
infix fun User.says(message: String): ForwardMessageBuilder = this.id named this.nameCardOrNick says message
public infix fun User.says(message: String): ForwardMessageBuilder = this.id named this.nameCardOrNick says message
/** 添加一条消息, 自动按顺序调整时间 */
@ForwardMessageDsl
infix fun User.says(message: Message): ForwardMessageBuilder = this.id named this.nameCardOrNick says message
public infix fun User.says(message: Message): ForwardMessageBuilder = this.id named this.nameCardOrNick says message
/** 添加一条消息, 自动按顺序调整时间 */
@ForwardMessageDsl
infix fun Bot.says(message: Message): ForwardMessageBuilder = this.id named this.smartName() says message
public infix fun Bot.says(message: Message): ForwardMessageBuilder = this.id named this.smartName() says message
/** 构造并添加一个 [MessageChain], 自动按顺序调整时间 */
@ForwardMessageDsl
inline infix fun User.says(chain: @ForwardMessageDsl MessageChainBuilder.() -> Unit): ForwardMessageBuilder =
public inline infix fun User.says(chain: @ForwardMessageDsl MessageChainBuilder.() -> Unit): ForwardMessageBuilder =
this says (MessageChainBuilder().apply(chain).asMessageChain())
/** 构造并添加一个 [MessageChain], 自动按顺序调整时间 */
@ForwardMessageDsl
inline infix fun Bot.says(chain: @ForwardMessageDsl MessageChainBuilder.() -> Unit): ForwardMessageBuilder =
public inline infix fun Bot.says(chain: @ForwardMessageDsl MessageChainBuilder.() -> Unit): ForwardMessageBuilder =
this says (MessageChainBuilder().apply(chain).asMessageChain())
// endregion
@ -511,21 +512,21 @@ class ForwardMessageBuilder private constructor(
* @time 时间戳, 单位为秒
*/
@ForwardMessageDsl
infix fun Int.at(time: Int): BuilderNode = this.toLongUnsigned() at time
public infix fun Int.at(time: Int): BuilderNode = this.toLongUnsigned() at time
/**
* 为一条消息指定时间.
* @time 时间戳, 单位为秒
*/
@ForwardMessageDsl
infix fun Long.at(time: Int): BuilderNode = BuilderNode().apply { senderId = this@at;this.time = time }
public infix fun Long.at(time: Int): BuilderNode = BuilderNode().apply { senderId = this@at;this.time = time }
/**
* 为一条消息指定时间和发送人名称.
* @time 时间戳, 单位为秒
*/
@ForwardMessageDsl
infix fun User.at(time: Int): BuilderNode = this.id named this.nameCardOrNick at time
public infix fun User.at(time: Int): BuilderNode = this.id named this.nameCardOrNick at time
// endregion
@ -534,21 +535,21 @@ class ForwardMessageBuilder private constructor(
/** 为一条消息指定发送人名称. */
@ForwardMessageDsl
infix fun Int.named(name: String): BuilderNode = this.toLongUnsigned().named(name)
public infix fun Int.named(name: String): BuilderNode = this.toLongUnsigned().named(name)
/** 为一条消息指定发送人名称. */
@ForwardMessageDsl
infix fun Long.named(name: String): BuilderNode =
public infix fun Long.named(name: String): BuilderNode =
BuilderNode().apply { senderId = this@named;this.senderName = name }
/** 为一条消息指定发送人名称. */
@ForwardMessageDsl
infix fun User.named(name: String): BuilderNode = this.id.named(name)
public infix fun User.named(name: String): BuilderNode = this.id.named(name)
// endregion
/** 构造 [ForwardMessage] */
fun build(): ForwardMessage = ForwardMessage(container.toList(), this.displayStrategy)
public fun build(): ForwardMessage = ForwardMessage(container.toList(), this.displayStrategy)
internal fun Bot.smartName(): String = when (val c = this@ForwardMessageBuilder.context) {
is Group -> c.botAsMember.nameCardOrNick
else -> nick

View File

@ -17,7 +17,6 @@ import net.mamoe.mirai.message.code.CodableMessage
import net.mamoe.mirai.message.data.PokeMessage.Types
import net.mamoe.mirai.message.data.VipFace.Companion
import net.mamoe.mirai.message.data.VipFace.Kind
import net.mamoe.mirai.utils.PlannedRemoval
import kotlin.jvm.*
/**
@ -26,9 +25,9 @@ import kotlin.jvm.*
* @see PokeMessage 戳一戳
* @see FlashImage 闪照
*/
sealed class HummerMessage : MessageContent {
companion object Key : Message.Key<HummerMessage> {
override val typeName: String
public sealed class HummerMessage : MessageContent {
public companion object Key : Message.Key<HummerMessage> {
public override val typeName: String
get() = "HummerMessage"
}
// has service type etc.
@ -46,90 +45,90 @@ sealed class HummerMessage : MessageContent {
*
* @see Types 使用伴生对象中的常量
*/
data class PokeMessage internal constructor(
public data class PokeMessage internal constructor(
/**
* mirai, 显示的名称
*/
val name: String,
public val name: String,
val type: Int,
val id: Int
public val type: Int,
public val id: Int
) : HummerMessage(), CodableMessage {
@Suppress("DEPRECATION_ERROR", "DEPRECATION", "INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
companion object Types : Message.Key<PokeMessage> {
override val typeName: String
public companion object Types : Message.Key<PokeMessage> {
public override val typeName: String
get() = "PokeMessage"
/** 戳一戳 */
@JvmField
val Poke = PokeMessage("戳一戳", 1, -1)
public val Poke: PokeMessage = PokeMessage("戳一戳", 1, -1)
/** 比心 */
@JvmField
val ShowLove = PokeMessage("比心", 2, -1)
public val ShowLove: PokeMessage = PokeMessage("比心", 2, -1)
/** 点赞 */
@JvmField
val Like = PokeMessage("点赞", 3, -1)
public val Like: PokeMessage = PokeMessage("点赞", 3, -1)
/** 心碎 */
@JvmField
val Heartbroken = PokeMessage("心碎", 4, -1)
public val Heartbroken: PokeMessage = PokeMessage("心碎", 4, -1)
/** 666 */
@JvmField
val SixSixSix = PokeMessage("666", 5, -1)
public val SixSixSix: PokeMessage = PokeMessage("666", 5, -1)
/** 放大招 */
@JvmField
val FangDaZhao = PokeMessage("放大招", 6, -1)
public val FangDaZhao: PokeMessage = PokeMessage("放大招", 6, -1)
/** 宝贝球 (SVIP) */
@JvmField
val BaoBeiQiu = PokeMessage("宝贝球", 126, 2011)
public val BaoBeiQiu: PokeMessage = PokeMessage("宝贝球", 126, 2011)
/** 玫瑰花 (SVIP) */
@JvmField
val Rose = PokeMessage("玫瑰花", 126, 2007)
public val Rose: PokeMessage = PokeMessage("玫瑰花", 126, 2007)
/** 召唤术 (SVIP) */
@JvmField
val ZhaoHuanShu = PokeMessage("召唤术", 126, 2006)
public val ZhaoHuanShu: PokeMessage = PokeMessage("召唤术", 126, 2006)
/** 让你皮 (SVIP) */
@JvmField
val RangNiPi = PokeMessage("让你皮", 126, 2009)
public val RangNiPi: PokeMessage = PokeMessage("让你皮", 126, 2009)
/** 结印 (SVIP) */
@JvmField
val JieYin = PokeMessage("结印", 126, 2005)
public val JieYin: PokeMessage = PokeMessage("结印", 126, 2005)
/** 手雷 (SVIP) */
@JvmField
val ShouLei = PokeMessage("手雷", 126, 2004)
public val ShouLei: PokeMessage = PokeMessage("手雷", 126, 2004)
/** 勾引 */
@JvmField
val GouYin = PokeMessage("勾引", 126, 2003)
public val GouYin: PokeMessage = PokeMessage("勾引", 126, 2003)
/** 抓一下 (SVIP) */
@JvmField
val ZhuaYiXia = PokeMessage("抓一下", 126, 2001)
public val ZhuaYiXia: PokeMessage = PokeMessage("抓一下", 126, 2001)
/** 碎屏 (SVIP) */
@JvmField
val SuiPing = PokeMessage("碎屏", 126, 2002)
public val SuiPing: PokeMessage = PokeMessage("碎屏", 126, 2002)
/** 敲门 (SVIP) */
@JvmField
val QiaoMen = PokeMessage("敲门", 126, 2002)
public val QiaoMen: PokeMessage = PokeMessage("敲门", 126, 2002)
/**
* 所有类型数组
*/
@JvmStatic
val values: Array<PokeMessage> = arrayOf(
public val values: Array<PokeMessage> = arrayOf(
Poke, ShowLove, Like, Heartbroken, SixSixSix,
FangDaZhao, BaoBeiQiu, Rose, ZhaoHuanShu, RangNiPi,
JieYin, ShouLei, GouYin, ZhuaYiXia, SuiPing
@ -161,64 +160,64 @@ data class PokeMessage internal constructor(
*
* @see Types 使用伴生对象中的常量
*/
data class VipFace internal constructor(
public data class VipFace internal constructor(
/**
* 使用 [Companion] 中常量.
*/
val kind: Kind,
val count: Int
public val kind: Kind,
public val count: Int
) : HummerMessage(), CodableMessage {
data class Kind(
public data class Kind(
val id: Int,
val name: String
) {
override fun toString(): String {
public override fun toString(): String {
return "$id,$name"
}
}
@Suppress("DEPRECATION_ERROR", "DEPRECATION", "INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
companion object : Message.Key<VipFace> {
public companion object : Message.Key<VipFace> {
override val typeName: String get() = "VipFace"
@JvmStatic
val LiuLian = 9 to "榴莲"
public val LiuLian: Kind = 9 to "榴莲"
@JvmStatic
val PingDiGuo = 1 to "平底锅"
public val PingDiGuo: Kind = 1 to "平底锅"
@JvmStatic
val ChaoPiao = 12 to "钞票"
public val ChaoPiao: Kind = 12 to "钞票"
@JvmStatic
val LueLueLue = 10 to "略略略"
public val LueLueLue: Kind = 10 to "略略略"
@JvmStatic
val ZhuTou = 4 to "猪头"
public val ZhuTou: Kind = 4 to "猪头"
@JvmStatic
val BianBian = 6 to "便便"
public val BianBian: Kind = 6 to "便便"
@JvmStatic
val ZhaDan = 5 to "炸弹"
public val ZhaDan: Kind = 5 to "炸弹"
@JvmStatic
val AiXin = 2 to "爱心"
public val AiXin: Kind = 2 to "爱心"
@JvmStatic
val HaHa = 3 to "哈哈"
public val HaHa: Kind = 3 to "哈哈"
@JvmStatic
val DianZan = 1 to "点赞"
public val DianZan: Kind = 1 to "点赞"
@JvmStatic
val QinQin = 7 to "亲亲"
public val QinQin: Kind = 7 to "亲亲"
@JvmStatic
val YaoWan = 8 to "药丸"
public val YaoWan: Kind = 8 to "药丸"
@JvmStatic
val values: Array<Kind> = arrayOf(
public val values: Array<Kind> = arrayOf(
LiuLian, PingDiGuo, ChaoPiao, LueLueLue, ZhuTou,
BianBian, ZhaDan, AiXin, HaHa, DianZan, QinQin, YaoWan
)
@ -249,14 +248,14 @@ data class VipFace internal constructor(
*
* @see Image 查看图片相关信息
*/
sealed class FlashImage : MessageContent, HummerMessage(), CodableMessage {
companion object Key : Message.Key<FlashImage> {
public sealed class FlashImage : MessageContent, HummerMessage(), CodableMessage {
public companion object Key : Message.Key<FlashImage> {
/**
* 将普通图片转换为闪照.
*/
@JvmStatic
@JvmName("from")
operator fun invoke(image: Image): FlashImage {
public operator fun invoke(image: Image): FlashImage {
return when (image) {
is GroupImage -> GroupFlashImage(image)
@ -272,18 +271,18 @@ sealed class FlashImage : MessageContent, HummerMessage(), CodableMessage {
*/
@JvmStatic
@JvmName("from")
operator fun invoke(imageId: String): FlashImage {
public operator fun invoke(imageId: String): FlashImage {
return invoke(Image(imageId))
}
override val typeName: String
public override val typeName: String
get() = "FlashImage"
}
/**
* 闪照的内容图片, 即一个普通图片.
*/
abstract val image: Image
public abstract val image: Image
private var stringValue: String? = null
get() {
@ -293,23 +292,24 @@ sealed class FlashImage : MessageContent, HummerMessage(), CodableMessage {
}
}
final override fun toString(): String = stringValue!!
override fun contentToString(): String = "[闪照]"
public final override fun toString(): String = stringValue!!
public override fun contentToString(): String = "[闪照]"
}
inline fun Image.flash(): FlashImage = FlashImage(this)
public inline fun Image.flash(): FlashImage = FlashImage(this)
@JvmSynthetic
inline fun GroupImage.flash(): GroupFlashImage = FlashImage(this) as GroupFlashImage
public inline fun GroupImage.flash(): GroupFlashImage = FlashImage(this) as GroupFlashImage
@JvmSynthetic
inline fun FriendImage.flash(): FriendFlashImage = FlashImage(this) as FriendFlashImage
public inline fun FriendImage.flash(): FriendFlashImage = FlashImage(this) as FriendFlashImage
/**
* @see FlashImage.invoke
*/
data class GroupFlashImage(override val image: GroupImage) : FlashImage() {
companion object Key : Message.Key<GroupFlashImage> {
override val typeName: String
public data class GroupFlashImage(public override val image: GroupImage) : FlashImage() {
public companion object Key : Message.Key<GroupFlashImage> {
public override val typeName: String
get() = "GroupFlashImage"
}
}
@ -317,9 +317,9 @@ data class GroupFlashImage(override val image: GroupImage) : FlashImage() {
/**
* @see FlashImage.invoke
*/
data class FriendFlashImage(override val image: FriendImage) : FlashImage() {
companion object Key : Message.Key<FriendFlashImage> {
override val typeName: String
public data class FriendFlashImage(public override val image: FriendImage) : FlashImage() {
public companion object Key : Message.Key<FriendFlashImage> {
public override val typeName: String
get() = "FriendFlashImage"
}
}

View File

@ -61,9 +61,9 @@ import kotlin.jvm.JvmSynthetic
* @see FlashImage 闪照
* @see Image.flash 转换普通图片为闪照
*/
expect interface Image : Message, MessageContent, CodableMessage {
companion object Key : Message.Key<Image> {
override val typeName: String
public expect interface Image : Message, MessageContent, CodableMessage {
public companion object Key : Message.Key<Image> {
public override val typeName: String
}
/**
@ -82,7 +82,7 @@ expect interface Image : Message, MessageContent, CodableMessage {
* @see Image 使用 id 构造图片
* @see md5 得到图片文件 MD5
*/
val imageId: String
public val imageId: String
/* 实现:
final override fun toString(): String = _stringValue!!
@ -106,7 +106,7 @@ expect interface Image : Message, MessageContent, CodableMessage {
* Java 使用: `MessageUtils.calculateImageMd5(image)`
*/
@get:JvmName("calculateImageMd5")
val Image.md5: ByteArray
public val Image.md5: ByteArray
get() = calculateImageMd5ByImageId(imageId)
@ -116,9 +116,9 @@ val Image.md5: ByteArray
* [imageId] 形如 `/f8f1ab55-bf8e-4236-b55e-955848d7069f` (37 长度) `/000000000-3814297509-BFB7027B9354B8F899A062061D74E206` (54 长度)
*/
// NotOnlineImage
abstract class FriendImage internal constructor() : AbstractImage() { // change to sealed in the future.
companion object Key : Message.Key<FriendImage> {
override val typeName: String get() = "FriendImage"
public abstract class FriendImage internal constructor() : AbstractImage() { // change to sealed in the future.
public companion object Key : Message.Key<FriendImage> {
public override val typeName: String get() = "FriendImage"
}
}
@ -129,9 +129,9 @@ abstract class FriendImage internal constructor() : AbstractImage() { // change
* @see Image 查看更多说明
*/
// CustomFace
abstract class GroupImage internal constructor() : AbstractImage() { // change to sealed in the future.
companion object Key : Message.Key<GroupImage> {
override val typeName: String get() = "GroupImage"
public abstract class GroupImage internal constructor() : AbstractImage() { // change to sealed in the future.
public companion object Key : Message.Key<GroupImage> {
public override val typeName: String get() = "GroupImage"
}
}
@ -142,7 +142,7 @@ abstract class GroupImage internal constructor() : AbstractImage() { // change t
* @see FRIEND_IMAGE_ID_REGEX_2
*/
// Java: MessageUtils.FRIEND_IMAGE_ID_REGEX_1
val FRIEND_IMAGE_ID_REGEX_1 = Regex("""/[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}""")
public val FRIEND_IMAGE_ID_REGEX_1: Regex = Regex("""/[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}""")
/**
* 好友图片 ID 正则表达式 2
@ -151,16 +151,17 @@ val FRIEND_IMAGE_ID_REGEX_1 = Regex("""/[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a
* @see FRIEND_IMAGE_ID_REGEX_1
*/
// Java: MessageUtils.FRIEND_IMAGE_ID_REGEX_2
val FRIEND_IMAGE_ID_REGEX_2 = Regex("""/[0-9]*-[0-9]*-[0-9a-fA-F]{32}""")
public val FRIEND_IMAGE_ID_REGEX_2: Regex = Regex("""/[0-9]*-[0-9]*-[0-9a-fA-F]{32}""")
/**
* 群图片 ID 正则表达式
*
* `{01E9451B-70ED-EAE3-B37C-101F1EEBF5B5}.ext`
*/
@Suppress("RegExpRedundantEscape") // This is required on Android
@Suppress("RegExpRedundantEscape")
// This is required on Android
// Java: MessageUtils.GROUP_IMAGE_ID_REGEX
val GROUP_IMAGE_ID_REGEX = Regex("""\{[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}\}\..{3,5}""")
public val GROUP_IMAGE_ID_REGEX: Regex = Regex("""\{[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}\}\..{3,5}""")
/**
* 通过 [Image.imageId] 构造一个 [Image] 以便发送.
@ -175,7 +176,7 @@ val GROUP_IMAGE_ID_REGEX = Regex("""\{[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-f
@Suppress("FunctionName", "DEPRECATION")
@JsName("newImage")
@JvmName("newImage")
fun Image(imageId: String): OfflineImage = when {
public fun Image(imageId: String): OfflineImage = when {
imageId matches FRIEND_IMAGE_ID_REGEX_1 -> OfflineFriendImage(imageId)
imageId matches FRIEND_IMAGE_ID_REGEX_2 -> OfflineFriendImage(imageId)
imageId matches GROUP_IMAGE_ID_REGEX -> OfflineGroupImage(imageId)
@ -192,7 +193,7 @@ fun Image(imageId: String): OfflineImage = when {
* @throws IllegalStateException 当无任何 [Bot] 在线时抛出 (因为无法获取相关协议)
*/
@JvmSynthetic
suspend fun Image.queryUrl(): String {
public suspend fun Image.queryUrl(): String {
@Suppress("DEPRECATION")
return when (this) {
is ConstOriginUrlAware -> this.originUrl

View File

@ -75,7 +75,7 @@ import kotlin.jvm.JvmSynthetic
*
* @see Contact.sendMessage 发送消息
*/
interface Message { // must be interface. Don't consider any changes.
public interface Message { // must be interface. Don't consider any changes.
/**
* 类型 Key. 由伴生对象实现, 表示一个 [Message] 对象的类型.
*
@ -87,11 +87,11 @@ interface Message { // must be interface. Don't consider any changes.
*
* @param M 指代持有这个 Key 的消息类型
*/
interface Key<out M : Message> {
public interface Key<out M : Message> {
/**
* [Key] 指代的 [Message] 类型名. 一般为 `class.simpleName`, "QuoteReply", "PlainText"
*/
val typeName: String
public val typeName: String
}
/**
@ -112,7 +112,7 @@ interface Message { // must be interface. Don't consider any changes.
* @see plus `+` 操作符重载
*/
@JvmSynthetic // in java they should use `plus` instead
fun followedBy(tail: Message): MessageChain = followedByImpl(tail)
public fun followedBy(tail: Message): MessageChain = followedByImpl(tail)
/**
* 得到包含 mirai 消息元素代码的, 易读的字符串. `At(member) + "test"` 将转为 `"[mirai:at:qqId]test"`
@ -129,7 +129,7 @@ interface Message { // must be interface. Don't consider any changes.
*
* @see contentToString 转为最接近官方格式的字符串
*/
override fun toString(): String
public override fun toString(): String
/**
* 转为最接近官方格式的字符串. `At(member) + "test"` 将转为 `"@群名片 test"`.
@ -145,7 +145,7 @@ interface Message { // must be interface. Don't consider any changes.
*
* @see toString 得到包含 mirai 消息元素代码的, 易读的字符串
*/
fun contentToString(): String
public fun contentToString(): String
/**
@ -155,7 +155,7 @@ interface Message { // must be interface. Don't consider any changes.
* - `this` [another] [contentToString] 相等
* - `this` [another] 的所有 [MessageContent] [相等][Message.equals] 且有同样的排列顺序.
*/
/* final */ fun contentEquals(another: Message, ignoreCase: Boolean = false): Boolean =
public /* final */ fun contentEquals(another: Message, ignoreCase: Boolean = false): Boolean =
contentEqualsImpl(another, ignoreCase)
/**
@ -165,7 +165,7 @@ interface Message { // must be interface. Don't consider any changes.
* - [contentToString] [another] 相等
* - `this` [MessageChain], 则只包含 [MessageMetadata] [PlainText]
*/
/* final */ fun contentEquals(another: String, ignoreCase: Boolean = false): Boolean {
public /* final */ fun contentEquals(another: String, ignoreCase: Boolean = false): Boolean {
if (!this.contentToString().equals(another, ignoreCase = ignoreCase)) return false
return when (this) {
is SingleMessage -> true
@ -175,44 +175,45 @@ interface Message { // must be interface. Don't consider any changes.
}
/** 将 [another] 按顺序连接到这个消息的尾部. */
/* final */ operator fun plus(another: MessageChain): MessageChain = this + another as Message
public /* final */ operator fun plus(another: MessageChain): MessageChain = this + another as Message
/** 将 [another] 按顺序连接到这个消息的尾部. */
/* final */ operator fun plus(another: Message): MessageChain = this.followedBy(another)
public /* final */ operator fun plus(another: Message): MessageChain = this.followedBy(another)
/** 将 [another] 连接到这个消息的尾部. */
/* final */ operator fun plus(another: SingleMessage): MessageChain = this.followedBy(another)
public /* final */ operator fun plus(another: SingleMessage): MessageChain = this.followedBy(another)
/** 将 [another] 作为 [PlainText] 连接到这个消息的尾部. */
/* final */ operator fun plus(another: String): MessageChain = this.followedBy(another.toMessage())
public /* final */ operator fun plus(another: String): MessageChain = this.followedBy(another.toMessage())
/** 将 [another] 作为 [PlainText] 连接到这个消息的尾部. */
/* final */ operator fun plus(another: CharSequence): MessageChain = this.followedBy(another.toString().toMessage())
public /* final */ operator fun plus(another: CharSequence): MessageChain =
this.followedBy(another.toString().toMessage())
/** 将 [another] 按顺序连接到这个消息的尾部. */
/* final */ operator fun plus(another: Iterable<Message>): MessageChain =
public /* final */ operator fun plus(another: Iterable<Message>): MessageChain =
another.fold(this, Message::plus).asMessageChain()
/** 将 [another] 按顺序连接到这个消息的尾部. */
@JvmName("plusIterableString")
/* final */ operator fun plus(another: Iterable<String>): MessageChain =
public /* final */ operator fun plus(another: Iterable<String>): MessageChain =
another.fold(this, Message::plus).asMessageChain()
/** 将 [another] 按顺序连接到这个消息的尾部. */
/* final */ operator fun plus(another: Sequence<Message>): MessageChain =
public /* final */ operator fun plus(another: Sequence<Message>): MessageChain =
another.fold(this, Message::plus).asMessageChain()
}
@MiraiExperimentalAPI
@JvmSynthetic
suspend inline operator fun Message.plus(another: Flow<Message>): MessageChain =
public suspend inline operator fun Message.plus(another: Flow<Message>): MessageChain =
another.fold(this) { acc, it -> acc + it }.asMessageChain()
/**
* [Message.contentToString] 的捷径
*/
@get:JvmSynthetic
inline val Message.content: String
public inline val Message.content: String
get() = contentToString()
@ -225,7 +226,7 @@ inline val Message.content: String
* - [PlainText] 长度为 0
* - [MessageChain] 所有元素都满足 [isContentEmpty]
*/
fun Message.isContentEmpty(): Boolean {
public fun Message.isContentEmpty(): Boolean {
return when (this) {
is MessageMetadata -> true
is PlainText -> this.content.isEmpty()
@ -234,9 +235,9 @@ fun Message.isContentEmpty(): Boolean {
}
}
inline fun Message.isContentNotEmpty(): Boolean = !this.isContentEmpty()
public inline fun Message.isContentNotEmpty(): Boolean = !this.isContentEmpty()
inline fun Message.isPlain(): Boolean {
public inline fun Message.isPlain(): Boolean {
contract {
returns(true) implies (this@isPlain is PlainText)
returns(false) implies (this@isPlain !is PlainText)
@ -244,7 +245,7 @@ inline fun Message.isPlain(): Boolean {
return this is PlainText
}
inline fun Message.isNotPlain(): Boolean {
public inline fun Message.isNotPlain(): Boolean {
contract {
returns(false) implies (this@isNotPlain is PlainText)
returns(true) implies (this@isNotPlain !is PlainText)
@ -256,7 +257,7 @@ inline fun Message.isNotPlain(): Boolean {
* 将此消息元素按顺序重复 [count] .
*/
// inline: for future removal
inline fun Message.repeat(count: Int): MessageChain {
public inline fun Message.repeat(count: Int): MessageChain {
if (this is ConstrainSingle<*>) {
// fast-path
return this.asMessageChain()
@ -272,26 +273,26 @@ inline fun Message.repeat(count: Int): MessageChain {
* 将此消息元素按顺序重复 [count] .
*/
@JvmSynthetic
inline operator fun Message.times(count: Int): MessageChain = this.repeat(count)
public inline operator fun Message.times(count: Int): MessageChain = this.repeat(count)
/**
* 单个消息元素. 与之相对的是 [MessageChain], 是多个 [SingleMessage] 的集合.
*/
interface SingleMessage : Message {
public interface SingleMessage : Message {
@PlannedRemoval("1.2.0")
@JvmSynthetic
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
fun length(): Int = this.toString().length
public fun length(): Int = this.toString().length
@PlannedRemoval("1.2.0")
@JvmSynthetic
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
fun charAt(index: Int): Char = this.toString()[index]
public fun charAt(index: Int): Char = this.toString()[index]
@PlannedRemoval("1.2.0")
@JvmSynthetic
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
fun subSequence(start: Int, end: Int): CharSequence = this.toString().subSequence(start, end)
public fun subSequence(start: Int, end: Int): CharSequence = this.toString().subSequence(start, end)
}
/**
@ -307,7 +308,7 @@ interface SingleMessage : Message {
*
* @see ConstrainSingle 约束一个 [MessageChain] 中只存在这一种类型的元素
*/
interface MessageMetadata : SingleMessage {
public interface MessageMetadata : SingleMessage {
/**
* 返回空字符串
*/
@ -319,12 +320,12 @@ interface MessageMetadata : SingleMessage {
*
* 实现此接口的元素将会在连接时自动处理替换.
*/
interface ConstrainSingle<out M : Message> : MessageMetadata {
public interface ConstrainSingle<out M : Message> : MessageMetadata {
/**
* 用于判断是否为同一种元素的 [Key]
* @see Key 查看更多信息
*/
val key: Key<M>
public val key: Key<M>
}
/**
@ -341,17 +342,17 @@ interface ConstrainSingle<out M : Message> : MessageMetadata {
* @see ForwardMessage 合并转发
* @see Voice 语音
*/
interface MessageContent : SingleMessage
public interface MessageContent : SingleMessage
/**
* [this] 发送给指定联系人
*/
@JvmSynthetic
@Suppress("UNCHECKED_CAST")
suspend inline fun <C : Contact> MessageChain.sendTo(contact: C): MessageReceipt<C> =
public suspend inline fun <C : Contact> MessageChain.sendTo(contact: C): MessageReceipt<C> =
contact.sendMessage(this) as MessageReceipt<C>
@JvmSynthetic
@Suppress("UNCHECKED_CAST")
suspend inline fun <C : Contact> Message.sendTo(contact: C): MessageReceipt<C> =
public suspend inline fun <C : Contact> Message.sendTo(contact: C): MessageReceipt<C> =
contact.sendMessage(this) as MessageReceipt<C>

View File

@ -50,11 +50,11 @@ import kotlin.reflect.KProperty
* @see flatten 扁平化
*/
@Suppress("FunctionName", "DeprecatedCallableAddReplaceWith", "INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
interface MessageChain : Message, List<SingleMessage>, RandomAccess {
public interface MessageChain : Message, List<SingleMessage>, RandomAccess {
/**
* 元素数量. [EmptyMessageChain] 不参加计数.
*/
override val size: Int
public override val size: Int
/**
* 获取第一个类型为 [key] [Message] 实例. 若不存在此实例, 返回 `null`
@ -77,7 +77,7 @@ interface MessageChain : Message, List<SingleMessage>, RandomAccess {
* @see MessageChain.getOrFail 在找不到此类型的元素时抛出 [NoSuchElementException]
*/
@JvmName("first")
operator fun <M : Message> get(key: Message.Key<M>): M? = firstOrNull(key)
public operator fun <M : Message> get(key: Message.Key<M>): M? = firstOrNull(key)
/**
* 遍历每一个有内容的消息, [At], [AtAll], [PlainText], [Image], [Face]
@ -85,7 +85,7 @@ interface MessageChain : Message, List<SingleMessage>, RandomAccess {
*/
@JvmName("forEachContent")
@JavaFriendlyAPI
fun __forEachContentForJava__(block: (Message) -> Unit) = this.forEachContent(block)
public fun __forEachContentForJava__(block: (Message) -> Unit): Unit = this.forEachContent(block)
@PlannedRemoval("1.2.0")
@JvmName("firstOrNull")
@ -94,7 +94,7 @@ interface MessageChain : Message, List<SingleMessage>, RandomAccess {
ReplaceWith("get(key)"),
level = DeprecationLevel.ERROR
)
fun <M : Message> getOrNull(key: Message.Key<M>): M? = get(key)
public fun <M : Message> getOrNull(key: Message.Key<M>): M? = get(key)
}
// region accessors
@ -105,7 +105,7 @@ interface MessageChain : Message, List<SingleMessage>, RandomAccess {
* @param key 由各个类型消息的伴生对象持有. [PlainText.Key]
*/
@JvmOverloads
inline fun <M : Message> MessageChain.getOrFail(
public inline fun <M : Message> MessageChain.getOrFail(
key: Message.Key<M>,
crossinline lazyMessage: (key: Message.Key<M>) -> String = { key.typeName }
): M = firstOrNull(key) ?: throw NoSuchElementException(lazyMessage(key))
@ -115,7 +115,7 @@ inline fun <M : Message> MessageChain.getOrFail(
* 遍历每一个 [消息内容][MessageContent]
*/
@JvmSynthetic
inline fun MessageChain.forEachContent(block: (MessageContent) -> Unit) {
public inline fun MessageChain.forEachContent(block: (MessageContent) -> Unit) {
for (element in this) {
if (element !is MessageMetadata) {
check(element is MessageContent) { "internal error: Message must be either MessageMetaData or MessageContent" }
@ -128,7 +128,7 @@ inline fun MessageChain.forEachContent(block: (MessageContent) -> Unit) {
* 如果每一个 [消息内容][MessageContent] 都满足 [block], 返回 `true`
*/
@JvmSynthetic
inline fun MessageChain.allContent(block: (MessageContent) -> Boolean): Boolean {
public inline fun MessageChain.allContent(block: (MessageContent) -> Boolean): Boolean {
this.forEach {
if (it !is MessageMetadata) {
check(it is MessageContent) { "internal error: Message must be either MessageMetaData or MessageContent" }
@ -142,7 +142,7 @@ inline fun MessageChain.allContent(block: (MessageContent) -> Boolean): Boolean
* 如果每一个 [消息内容][MessageContent] 都不满足 [block], 返回 `true`
*/
@JvmSynthetic
inline fun MessageChain.noneContent(block: (MessageContent) -> Boolean): Boolean {
public inline fun MessageChain.noneContent(block: (MessageContent) -> Boolean): Boolean {
this.forEach {
if (it !is MessageMetadata) {
check(it is MessageContent) { "internal error: Message must be either MessageMetaData or MessageContent" }
@ -157,20 +157,20 @@ inline fun MessageChain.noneContent(block: (MessageContent) -> Boolean): Boolean
* 获取第一个 [M] 类型的 [Message] 实例
*/
@JvmSynthetic
inline fun <reified M : Message?> MessageChain.firstIsInstanceOrNull(): M? = this.firstOrNull { it is M } as M?
public inline fun <reified M : Message?> MessageChain.firstIsInstanceOrNull(): M? = this.firstOrNull { it is M } as M?
/**
* 获取第一个 [M] 类型的 [Message] 实例
* @throws [NoSuchElementException] 如果找不到该类型的实例
*/
@JvmSynthetic
inline fun <reified M : Message> MessageChain.firstIsInstance(): M = this.first { it is M } as M
public inline fun <reified M : Message> MessageChain.firstIsInstance(): M = this.first { it is M } as M
/**
* 判断 [this] 中是否存在 [Message] 的实例
*/
@JvmSynthetic
inline fun <reified M : Message> MessageChain.anyIsInstance(): Boolean = this.any { it is M }
public inline fun <reified M : Message> MessageChain.anyIsInstance(): Boolean = this.any { it is M }
/**
@ -178,7 +178,7 @@ inline fun <reified M : Message> MessageChain.anyIsInstance(): Boolean = this.an
*/
@JvmSynthetic
@Suppress("UNCHECKED_CAST")
fun <M : Message> MessageChain.firstOrNull(key: Message.Key<M>): M? = firstOrNullImpl(key)
public fun <M : Message> MessageChain.firstOrNull(key: Message.Key<M>): M? = firstOrNullImpl(key)
/**
* 获取第一个 [M] 类型的 [Message] 实例
@ -186,7 +186,7 @@ fun <M : Message> MessageChain.firstOrNull(key: Message.Key<M>): M? = firstOrNul
*/
@JvmSynthetic
@Suppress("UNCHECKED_CAST")
inline fun <M : Message> MessageChain.first(key: Message.Key<M>): M =
public inline fun <M : Message> MessageChain.first(key: Message.Key<M>): M =
firstOrNull(key) ?: throw NoSuchElementException("Message type ${key.typeName} not found in chain $this")
/**
@ -194,7 +194,7 @@ inline fun <M : Message> MessageChain.first(key: Message.Key<M>): M =
*/
@JvmSynthetic
@Suppress("UNCHECKED_CAST")
inline fun <M : Message> MessageChain.any(key: Message.Key<M>): Boolean = firstOrNull(key) != null
public inline fun <M : Message> MessageChain.any(key: Message.Key<M>): Boolean = firstOrNull(key) != null
// endregion accessors
@ -212,7 +212,7 @@ inline fun <M : Message> MessageChain.any(key: Message.Key<M>): Boolean = firstO
* val image: Image by message
*/
@JvmSynthetic
inline operator fun <reified T : Message> MessageChain.getValue(thisRef: Any?, property: KProperty<*>): T =
public inline operator fun <reified T : Message> MessageChain.getValue(thisRef: Any?, property: KProperty<*>): T =
this.firstIsInstance()
/**
@ -220,9 +220,9 @@ inline operator fun <reified T : Message> MessageChain.getValue(thisRef: Any?, p
* @see orNull
*/
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
inline class OrNullDelegate<out R> @PublishedApi internal constructor(@JvmField @PublishedApi internal val value: Any?) {
public inline class OrNullDelegate<out R> @PublishedApi internal constructor(@JvmField @PublishedApi internal val value: Any?) {
@Suppress("UNCHECKED_CAST")
operator fun getValue(thisRef: Any?, property: KProperty<*>): R = value as R
public operator fun getValue(thisRef: Any?, property: KProperty<*>): R = value as R
}
/**
@ -238,7 +238,7 @@ inline class OrNullDelegate<out R> @PublishedApi internal constructor(@JvmField
* @see orElse 提供一个不存在则使用默认值的委托
*/
@JvmSynthetic
inline fun <reified T : Message> MessageChain.orNull(): OrNullDelegate<T?> =
public inline fun <reified T : Message> MessageChain.orNull(): OrNullDelegate<T?> =
OrNullDelegate(this.firstIsInstanceOrNull<T>())
/**
@ -255,7 +255,7 @@ inline fun <reified T : Message> MessageChain.orNull(): OrNullDelegate<T?> =
*/
@Suppress("RemoveExplicitTypeArguments")
@JvmSynthetic
inline fun <reified T : R, R : Message?> MessageChain.orElse(
public inline fun <reified T : R, R : Message?> MessageChain.orElse(
lazyDefault: () -> R
): OrNullDelegate<R> = OrNullDelegate<R>(this.firstIsInstanceOrNull<T>() ?: lazyDefault())
@ -268,7 +268,7 @@ inline fun <reified T : R, R : Message?> MessageChain.orElse(
* 返回一个包含 [messages] 所有元素的消息链, 保留顺序.
*/
@JvmName("newChain")
inline fun messageChainOf(vararg messages: Message): MessageChain = messages.asMessageChain()
public inline fun messageChainOf(vararg messages: Message): MessageChain = messages.asMessageChain()
/**
* 得到包含 [this] [MessageChain].
@ -280,7 +280,7 @@ inline fun messageChainOf(vararg messages: Message): MessageChain = messages.asM
@JvmName("newChain")
@JsName("newChain")
@Suppress("UNCHECKED_CAST")
fun Message.asMessageChain(): MessageChain = when (this) {
public fun Message.asMessageChain(): MessageChain = when (this) {
is MessageChain -> this
is CombinedMessage -> (this as Iterable<Message>).asMessageChain()
else -> SingleMessageChainImpl(this as SingleMessage)
@ -290,13 +290,13 @@ fun Message.asMessageChain(): MessageChain = when (this) {
* 直接将 [this] 委托为一个 [MessageChain]
*/
@JvmSynthetic
fun SingleMessage.asMessageChain(): MessageChain = SingleMessageChainImpl(this)
public fun SingleMessage.asMessageChain(): MessageChain = SingleMessageChainImpl(this)
/**
* 直接将 [this] 委托为一个 [MessageChain]
*/
@JvmSynthetic
fun Collection<SingleMessage>.asMessageChain(): MessageChain =
public fun Collection<SingleMessage>.asMessageChain(): MessageChain =
MessageChainImplByCollection(this.constrainSingleMessages())
/**
@ -305,48 +305,48 @@ fun Collection<SingleMessage>.asMessageChain(): MessageChain =
@JvmSynthetic
@JvmName("newChain1")
// @JsName("newChain")
fun Array<out Message>.asMessageChain(): MessageChain = MessageChainImplBySequence(this.flatten())
public fun Array<out Message>.asMessageChain(): MessageChain = MessageChainImplBySequence(this.flatten())
@JvmSynthetic
@JvmName("newChain2")
fun Array<out SingleMessage>.asMessageChain(): MessageChain = MessageChainImplBySequence(this.asSequence())
public fun Array<out SingleMessage>.asMessageChain(): MessageChain = MessageChainImplBySequence(this.asSequence())
/**
* [this] [扁平化后][flatten] 委托为一个 [MessageChain]
*/
@JvmName("newChain")
// @JsName("newChain")
fun Collection<Message>.asMessageChain(): MessageChain = MessageChainImplBySequence(this.flatten())
public fun Collection<Message>.asMessageChain(): MessageChain = MessageChainImplBySequence(this.flatten())
/**
* 直接将 [this] 委托为一个 [MessageChain]
*/
@JvmSynthetic
fun Iterable<SingleMessage>.asMessageChain(): MessageChain =
public fun Iterable<SingleMessage>.asMessageChain(): MessageChain =
MessageChainImplByCollection(this.constrainSingleMessages())
@JvmSynthetic
inline fun MessageChain.asMessageChain(): MessageChain = this // 避免套娃
public inline fun MessageChain.asMessageChain(): MessageChain = this // 避免套娃
/**
* [this] [扁平化后][flatten] 委托为一个 [MessageChain]
*/
@JvmName("newChain")
// @JsName("newChain")
fun Iterable<Message>.asMessageChain(): MessageChain = MessageChainImplBySequence(this.flatten())
public fun Iterable<Message>.asMessageChain(): MessageChain = MessageChainImplBySequence(this.flatten())
/**
* 直接将 [this] 委托为一个 [MessageChain]
*/
@JvmSynthetic
fun Sequence<SingleMessage>.asMessageChain(): MessageChain = MessageChainImplBySequence(this)
public fun Sequence<SingleMessage>.asMessageChain(): MessageChain = MessageChainImplBySequence(this)
/**
* [this] [扁平化后][flatten] 委托为一个 [MessageChain]
*/
@JvmName("newChain")
// @JsName("newChain")
fun Sequence<Message>.asMessageChain(): MessageChain = MessageChainImplBySequence(this.flatten())
public fun Sequence<Message>.asMessageChain(): MessageChain = MessageChainImplBySequence(this.flatten())
/**
@ -355,7 +355,7 @@ fun Sequence<Message>.asMessageChain(): MessageChain = MessageChainImplBySequenc
*/
@Suppress("FunctionName")
@JvmName("newChain")
fun _____newChain______(messages: String): MessageChain {
public fun _____newChain______(messages: String): MessageChain {
return messages.toMessage().asMessageChain()
}
@ -371,12 +371,12 @@ fun _____newChain______(messages: String): MessageChain {
* A <- B <- C <- D <- E <- F <- G
* ```
*/
inline fun Iterable<Message>.flatten(): Sequence<SingleMessage> = asSequence().flatten()
public inline fun Iterable<Message>.flatten(): Sequence<SingleMessage> = asSequence().flatten()
// @JsName("flatten1")
@JvmName("flatten1")// avoid platform declare clash
@JvmSynthetic
inline fun Iterable<SingleMessage>.flatten(): Sequence<SingleMessage> = this.asSequence() // fast path
public inline fun Iterable<SingleMessage>.flatten(): Sequence<SingleMessage> = this.asSequence() // fast path
/**
* 扁平化消息序列.
@ -390,16 +390,16 @@ inline fun Iterable<SingleMessage>.flatten(): Sequence<SingleMessage> = this.asS
* A <- B <- C <- D <- E <- F <- G
* ```
*/
inline fun Sequence<Message>.flatten(): Sequence<SingleMessage> = flatMap { it.flatten() }
public inline fun Sequence<Message>.flatten(): Sequence<SingleMessage> = flatMap { it.flatten() }
@JsName("flatten1") // avoid platform declare clash
@JvmName("flatten1")
@JvmSynthetic
inline fun Sequence<SingleMessage>.flatten(): Sequence<SingleMessage> = this // fast path
public inline fun Sequence<SingleMessage>.flatten(): Sequence<SingleMessage> = this // fast path
inline fun Array<out Message>.flatten(): Sequence<SingleMessage> = this.asSequence().flatten()
public inline fun Array<out Message>.flatten(): Sequence<SingleMessage> = this.asSequence().flatten()
inline fun Array<out SingleMessage>.flatten(): Sequence<SingleMessage> = this.asSequence() // fast path
public inline fun Array<out SingleMessage>.flatten(): Sequence<SingleMessage> = this.asSequence() // fast path
/**
* 扁平化 [Message]
@ -409,7 +409,7 @@ inline fun Array<out SingleMessage>.flatten(): Sequence<SingleMessage> = this.as
* - `[MessageChain](E, F, G)` 返回 `E <- F <- G`
* - 其他: 返回 `sequenceOf(this)`
*/
fun Message.flatten(): Sequence<SingleMessage> {
public fun Message.flatten(): Sequence<SingleMessage> {
return when (this) {
is MessageChain -> this.asSequence()
is CombinedMessage -> this.asSequence() // already constrained single.
@ -418,7 +418,7 @@ fun Message.flatten(): Sequence<SingleMessage> {
}
@JvmSynthetic // make Java user happier with less methods
inline fun MessageChain.flatten(): Sequence<SingleMessage> = this.asSequence() // fast path
public inline fun MessageChain.flatten(): Sequence<SingleMessage> = this.asSequence() // fast path
// endregion converters
@ -426,14 +426,14 @@ inline fun MessageChain.flatten(): Sequence<SingleMessage> = this.asSequence() /
/**
* 不含任何元素的 [MessageChain].
*/
object EmptyMessageChain : MessageChain, Iterator<SingleMessage>, List<SingleMessage> by emptyList() {
public object EmptyMessageChain : MessageChain, Iterator<SingleMessage>, List<SingleMessage> by emptyList() {
override val size: Int get() = 0
override fun toString(): String = ""
override fun contentToString(): String = ""
override fun equals(other: Any?): Boolean = other === this
public override val size: Int get() = 0
public override fun toString(): String = ""
public override fun contentToString(): String = ""
public override fun equals(other: Any?): Boolean = other === this
override fun iterator(): Iterator<SingleMessage> = this
override fun hasNext(): Boolean = false
override fun next(): SingleMessage = throw NoSuchElementException("EmptyMessageChain is empty.")
public override fun iterator(): Iterator<SingleMessage> = this
public override fun hasNext(): Boolean = false
public override fun next(): SingleMessage = throw NoSuchElementException("EmptyMessageChain is empty.")
}

View File

@ -23,7 +23,7 @@ import kotlin.jvm.JvmSynthetic
* @see MessageChainBuilder
*/
@JvmSynthetic
inline fun buildMessageChain(block: MessageChainBuilder.() -> Unit): MessageChain {
public inline fun buildMessageChain(block: MessageChainBuilder.() -> Unit): MessageChain {
return MessageChainBuilder().apply(block).asMessageChain()
}
@ -33,7 +33,7 @@ inline fun buildMessageChain(block: MessageChainBuilder.() -> Unit): MessageChai
* @see MessageChainBuilder
*/
@JvmSynthetic
inline fun buildMessageChain(initialSize: Int, block: MessageChainBuilder.() -> Unit): MessageChain {
public inline fun buildMessageChain(initialSize: Int, block: MessageChainBuilder.() -> Unit): MessageChain {
return MessageChainBuilder(initialSize).apply(block).asMessageChain()
}
@ -47,19 +47,19 @@ inline fun buildMessageChain(initialSize: Int, block: MessageChainBuilder.() ->
* @see buildMessageChain 推荐使用
* @see asMessageChain 完成构建
*/
open class MessageChainBuilder private constructor(
public open class MessageChainBuilder private constructor(
private val container: MutableList<SingleMessage>
) : MutableList<SingleMessage> by container, Appendable {
constructor() : this(mutableListOf())
constructor(initialSize: Int) : this(ArrayList<SingleMessage>(initialSize))
public constructor() : this(mutableListOf())
public constructor(initialSize: Int) : this(ArrayList<SingleMessage>(initialSize))
final override fun add(element: SingleMessage): Boolean {
public final override fun add(element: SingleMessage): Boolean {
checkBuilt()
flushCache()
return addAndCheckConstrainSingle(element)
}
fun add(element: Message): Boolean {
public fun add(element: Message): Boolean {
checkBuilt()
flushCache()
@Suppress("UNCHECKED_CAST")
@ -71,27 +71,27 @@ open class MessageChainBuilder private constructor(
}
}
final override fun addAll(elements: Collection<SingleMessage>): Boolean {
public final override fun addAll(elements: Collection<SingleMessage>): Boolean {
checkBuilt()
flushCache()
return addAll(elements.flatten())
}
fun addAll(elements: Iterable<SingleMessage>): Boolean {
public fun addAll(elements: Iterable<SingleMessage>): Boolean {
checkBuilt()
flushCache()
return addAll(elements.flatten())
}
@JvmName("addAllFlatten") // erased generic type cause declaration clash
fun addAll(elements: Iterable<Message>): Boolean {
public fun addAll(elements: Iterable<Message>): Boolean {
checkBuilt()
flushCache()
return addAll(elements.flatten())
}
@JvmSynthetic
operator fun Message.unaryPlus() {
public operator fun Message.unaryPlus() {
checkBuilt()
flushCache()
add(this)
@ -99,91 +99,91 @@ open class MessageChainBuilder private constructor(
@JvmSynthetic
operator fun String.unaryPlus() {
public operator fun String.unaryPlus() {
checkBuilt()
add(this)
}
@JvmSynthetic // they should use add
operator fun plusAssign(plain: String) {
public operator fun plusAssign(plain: String) {
checkBuilt()
withCache { append(plain) }
}
@JvmSynthetic // they should use add
operator fun plusAssign(message: Message) {
public operator fun plusAssign(message: Message) {
checkBuilt()
flushCache()
this.add(message)
}
@JvmSynthetic // they should use add
operator fun plusAssign(message: SingleMessage) { // avoid resolution ambiguity
public operator fun plusAssign(message: SingleMessage) { // avoid resolution ambiguity
checkBuilt()
flushCache()
this.add(message)
}
fun add(plain: String) {
public fun add(plain: String) {
checkBuilt()
withCache { append(plain) }
}
@JvmSynthetic // they should use add
operator fun plusAssign(charSequence: CharSequence) {
public operator fun plusAssign(charSequence: CharSequence) {
checkBuilt()
withCache { append(charSequence) }
}
final override fun append(value: Char): MessageChainBuilder = withCache { append(value) }
final override fun append(value: CharSequence?): MessageChainBuilder = withCache { append(value) }
final override fun append(value: CharSequence?, startIndex: Int, endIndex: Int): MessageChainBuilder =
public final override fun append(value: Char): MessageChainBuilder = withCache { append(value) }
public final override fun append(value: CharSequence?): MessageChainBuilder = withCache { append(value) }
public final override fun append(value: CharSequence?, startIndex: Int, endIndex: Int): MessageChainBuilder =
withCache { append(value, startIndex, endIndex) }
fun append(message: Message): MessageChainBuilder = apply { add(message) }
fun append(message: SingleMessage): MessageChainBuilder = apply { add(message) }
public fun append(message: Message): MessageChainBuilder = apply { add(message) }
public fun append(message: SingleMessage): MessageChainBuilder = apply { add(message) }
// avoid resolution to extensions
fun asMessageChain(): MessageChain {
public fun asMessageChain(): MessageChain {
built = true
this.flushCache()
return MessageChainImplByCollection(this) // fast-path, no need to constrain
}
/** 同 [asMessageChain] */
fun build(): MessageChain = asMessageChain()
public fun build(): MessageChain = asMessageChain()
/**
* 将所有已有元素引用复制到一个新的 [MessageChainBuilder]
*/
fun copy(): MessageChainBuilder {
public fun copy(): MessageChainBuilder {
return MessageChainBuilder(container.toMutableList())
}
///////
// FOR IMMUTABLE SAFETY
final override fun remove(element: SingleMessage): Boolean {
public final override fun remove(element: SingleMessage): Boolean {
checkBuilt()
return container.remove(element)
}
final override fun removeAll(elements: Collection<SingleMessage>): Boolean {
public final override fun removeAll(elements: Collection<SingleMessage>): Boolean {
checkBuilt()
return container.removeAll(elements)
}
final override fun removeAt(index: Int): SingleMessage {
public final override fun removeAt(index: Int): SingleMessage {
checkBuilt()
return container.removeAt(index)
}
final override fun clear() {
public final override fun clear() {
checkBuilt()
return container.clear()
}
final override fun set(index: Int, element: SingleMessage): SingleMessage {
public final override fun set(index: Int, element: SingleMessage): SingleMessage {
checkBuilt()
return container.set(index, element)
}

View File

@ -63,17 +63,17 @@ import kotlin.jvm.JvmSynthetic
*
* @see buildMessageSource 构造一个 [OfflineMessageSource]
*/
sealed class MessageSource : Message, MessageMetadata, ConstrainSingle<MessageSource> {
companion object Key : Message.Key<MessageSource> {
public sealed class MessageSource : Message, MessageMetadata, ConstrainSingle<MessageSource> {
public companion object Key : Message.Key<MessageSource> {
override val typeName: String get() = "MessageSource"
}
final override val key: Message.Key<MessageSource> get() = Key
public final override val key: Message.Key<MessageSource> get() = Key
/**
* 所属 [Bot]
*/
abstract val bot: Bot
public abstract val bot: Bot
/**
* 消息 id (序列号). 在获取失败时 (概率很低) `-1`.
@ -88,7 +88,7 @@ sealed class MessageSource : Message, MessageMetadata, ConstrainSingle<MessageSo
* - 在同一个群的消息中此值随每条消息递增 1, 但此行为由服务器决定, mirai 不保证自增顺序.
* - 在好友消息中无法保证每次都递增 1. 也可能会产生大幅跳过的情况.
*/
abstract val id: Int
public abstract val id: Int
/**
* 内部 id. **仅用于协议模块使用**
@ -97,14 +97,14 @@ sealed class MessageSource : Message, MessageMetadata, ConstrainSingle<MessageSo
*
* 在事件中和在引用中无法保证同一条消息的 [internalId] 相同.
*/
abstract val internalId: Int
public abstract val internalId: Int
/**
* 发送时间时间戳, 单位为秒.
*
* 时间戳可能来自服务器, 也可能来自 mirai, 且无法保证两者时间同步.
*/
abstract val time: Int
public abstract val time: Int
/**
* 发送人.
@ -113,7 +113,7 @@ sealed class MessageSource : Message, MessageMetadata, ConstrainSingle<MessageSo
* - [OnlineMessageSource.Incoming] 时为发信 [目标好友][Friend.id] [][Group.id]
* - [OfflineMessageSource] 时为 [机器人][Bot.id], 发信 [目标好友][Friend.id] [][Group.id] (取决于 [OfflineMessageSource.kind])
*/
abstract val fromId: Long
public abstract val fromId: Long
/**
* 消息发送目标.
@ -122,7 +122,7 @@ sealed class MessageSource : Message, MessageMetadata, ConstrainSingle<MessageSo
* - [OnlineMessageSource.Incoming] 时为 [机器人][Bot.id]
* - [OfflineMessageSource] 时为 [机器人][Bot.id], 发信 [目标好友][Friend.id] [][Group.id] [临时消息][Member.id] (取决于 [OfflineMessageSource.kind])
*/
abstract val targetId: Long // groupCode / friendUin / memberUin
public abstract val targetId: Long // groupCode / friendUin / memberUin
/**
* 原消息内容.
@ -130,12 +130,12 @@ sealed class MessageSource : Message, MessageMetadata, ConstrainSingle<MessageSo
* 此属性是 **lazy** : 它只会在第一次调用时初始化, 因为需要反序列化服务器发来的整个包, 相当于接收了一条新消息.
*/
@LazyProperty
abstract val originalMessage: MessageChain
public abstract val originalMessage: MessageChain
/**
* 返回 `"[mirai:source:$id,$internalId]"`
*/
final override fun toString(): String = "[mirai:source:$id,$internalId]"
public final override fun toString(): String = "[mirai:source:$id,$internalId]"
}
@ -160,28 +160,28 @@ sealed class MessageSource : Message, MessageMetadata, ConstrainSingle<MessageSo
*
* @see OnlineMessageSource.toOffline 转为 [OfflineMessageSource]
*/
sealed class OnlineMessageSource : MessageSource() {
companion object Key : Message.Key<OnlineMessageSource> {
override val typeName: String get() = "OnlineMessageSource"
public sealed class OnlineMessageSource : MessageSource() {
public companion object Key : Message.Key<OnlineMessageSource> {
public override val typeName: String get() = "OnlineMessageSource"
}
/**
* 消息发送人. 可能为 [机器人][Bot] [好友][Friend] [群员][Member].
* 即类型必定为 [Bot], [Friend] [Member]
*/
abstract val sender: ContactOrBot
public abstract val sender: ContactOrBot
/**
* 消息发送目标. 可能为 [机器人][Bot] [好友][Friend] [][Group].
* 即类型必定为 [Bot], [Friend] [Group]
*/
abstract val target: ContactOrBot
public abstract val target: ContactOrBot
/**
* 消息主体. 群消息时为 [Group]. 好友消息时为 [Friend], 临时消息为 [Member]
* 不论是机器人接收的消息还是发送的消息, 此属性都指向机器人能进行回复的目标.
*/
abstract val subject: Contact
public abstract val subject: Contact
/*
* 以下子类型仅是覆盖了 [target], [subject], [sender] 等的类型
@ -190,91 +190,91 @@ sealed class OnlineMessageSource : MessageSource() {
/**
* [机器人主动发送消息][Contact.sendMessage] 产生的 [MessageSource], 可通过 [MessageReceipt] 获得.
*/
sealed class Outgoing : OnlineMessageSource() {
companion object Key : Message.Key<Outgoing> {
override val typeName: String get() = "OnlineMessageSource.Outgoing"
public sealed class Outgoing : OnlineMessageSource() {
public companion object Key : Message.Key<Outgoing> {
public override val typeName: String get() = "OnlineMessageSource.Outgoing"
}
abstract override val sender: Bot
abstract override val target: Contact
public abstract override val sender: Bot
public abstract override val target: Contact
final override val fromId: Long get() = sender.id
final override val targetId: Long get() = target.id
public final override val fromId: Long get() = sender.id
public final override val targetId: Long get() = target.id
abstract class ToFriend : Outgoing() {
companion object Key : Message.Key<ToFriend> {
override val typeName: String get() = "OnlineMessageSource.Outgoing.ToFriend"
public abstract class ToFriend : Outgoing() {
public companion object Key : Message.Key<ToFriend> {
public override val typeName: String get() = "OnlineMessageSource.Outgoing.ToFriend"
}
abstract override val target: Friend
final override val subject: Friend get() = target
public abstract override val target: Friend
public final override val subject: Friend get() = target
// final override fun toString(): String = "OnlineMessageSource.ToFriend(target=${target.id})"
}
abstract class ToTemp : Outgoing() {
companion object Key : Message.Key<ToTemp> {
override val typeName: String get() = "OnlineMessageSource.Outgoing.ToTemp"
public abstract class ToTemp : Outgoing() {
public companion object Key : Message.Key<ToTemp> {
public override val typeName: String get() = "OnlineMessageSource.Outgoing.ToTemp"
}
abstract override val target: Member
val group: Group get() = target.group
final override val subject: Member get() = target
public abstract override val target: Member
public val group: Group get() = target.group
public final override val subject: Member get() = target
}
abstract class ToGroup : Outgoing() {
companion object Key : Message.Key<ToGroup> {
override val typeName: String get() = "OnlineMessageSource.Outgoing.ToGroup"
public abstract class ToGroup : Outgoing() {
public companion object Key : Message.Key<ToGroup> {
public override val typeName: String get() = "OnlineMessageSource.Outgoing.ToGroup"
}
abstract override val target: Group
final override val subject: Group get() = target
public abstract override val target: Group
public final override val subject: Group get() = target
}
}
/**
* 接收到的一条消息的 [MessageSource]
*/
sealed class Incoming : OnlineMessageSource() {
companion object Key : Message.Key<Incoming> {
override val typeName: String get() = "OnlineMessageSource.Incoming"
public sealed class Incoming : OnlineMessageSource() {
public companion object Key : Message.Key<Incoming> {
public override val typeName: String get() = "OnlineMessageSource.Incoming"
}
abstract override val sender: User
public abstract override val sender: User
final override val fromId: Long get() = sender.id
final override val targetId: Long get() = target.id
public final override val fromId: Long get() = sender.id
public final override val targetId: Long get() = target.id
abstract class FromFriend : Incoming() {
companion object Key : Message.Key<FromFriend> {
override val typeName: String get() = "OnlineMessageSource.Incoming.FromFriend"
public abstract class FromFriend : Incoming() {
public companion object Key : Message.Key<FromFriend> {
public override val typeName: String get() = "OnlineMessageSource.Incoming.FromFriend"
}
abstract override val sender: Friend
final override val subject: Friend get() = sender
final override val target: Bot get() = sender.bot
public abstract override val sender: Friend
public final override val subject: Friend get() = sender
public final override val target: Bot get() = sender.bot
// final override fun toString(): String = "OnlineMessageSource.FromFriend(from=${sender.id})"
}
abstract class FromTemp : Incoming() {
companion object Key : Message.Key<FromTemp> {
override val typeName: String get() = "OnlineMessageSource.Incoming.FromTemp"
public abstract class FromTemp : Incoming() {
public companion object Key : Message.Key<FromTemp> {
public override val typeName: String get() = "OnlineMessageSource.Incoming.FromTemp"
}
abstract override val sender: Member
inline val group: Group get() = sender.group
final override val subject: Member get() = sender
final override val target: Bot get() = sender.bot
public abstract override val sender: Member
public inline val group: Group get() = sender.group
public final override val subject: Member get() = sender
public final override val target: Bot get() = sender.bot
}
abstract class FromGroup : Incoming() {
companion object Key : Message.Key<FromGroup> {
override val typeName: String get() = "OnlineMessageSource.Incoming.FromGroup"
public abstract class FromGroup : Incoming() {
public companion object Key : Message.Key<FromGroup> {
public override val typeName: String get() = "OnlineMessageSource.Incoming.FromGroup"
}
abstract override val sender: Member
final override val subject: Group get() = sender.group
final override val target: Group get() = group
inline val group: Group get() = sender.group
public abstract override val sender: Member
public final override val subject: Group get() = sender.group
public final override val target: Group get() = group
public inline val group: Group get() = sender.group
}
}
}
@ -285,12 +285,12 @@ sealed class OnlineMessageSource : MessageSource() {
*
* @see buildMessageSource 构建一个 [OfflineMessageSource]
*/
abstract class OfflineMessageSource : MessageSource() {
companion object Key : Message.Key<OfflineMessageSource> {
override val typeName: String get() = "OfflineMessageSource"
public abstract class OfflineMessageSource : MessageSource() {
public companion object Key : Message.Key<OfflineMessageSource> {
public override val typeName: String get() = "OfflineMessageSource"
}
enum class Kind {
public enum class Kind {
GROUP,
FRIEND,
TEMP
@ -299,14 +299,14 @@ abstract class OfflineMessageSource : MessageSource() {
/**
* 消息种类
*/
abstract val kind: Kind
public abstract val kind: Kind
}
/**
* 判断是否是发送给群, 或从群接收的消息的消息源
*/
// inline for future removal
inline fun MessageSource.isAboutGroup(): Boolean {
public inline fun MessageSource.isAboutGroup(): Boolean {
return when (this) {
is OnlineMessageSource -> subject is Group
is OfflineMessageSource -> kind == OfflineMessageSource.Kind.GROUP
@ -316,7 +316,7 @@ inline fun MessageSource.isAboutGroup(): Boolean {
/**
* 判断是否是发送给临时会话, 或从临时会话接收的消息的消息源
*/
inline fun MessageSource.isAboutTemp(): Boolean {
public inline fun MessageSource.isAboutTemp(): Boolean {
return when (this) {
is OnlineMessageSource -> subject is Member
is OfflineMessageSource -> kind == OfflineMessageSource.Kind.TEMP
@ -327,7 +327,7 @@ inline fun MessageSource.isAboutTemp(): Boolean {
* 判断是否是发送给好友, 或从好友接收的消息的消息源
*/
// inline for future removal
inline fun MessageSource.isAboutFriend(): Boolean {
public inline fun MessageSource.isAboutFriend(): Boolean {
return when (this) {
is OnlineMessageSource -> subject !is Group && subject !is Member
is OfflineMessageSource -> kind == OfflineMessageSource.Kind.FRIEND
@ -339,14 +339,14 @@ inline fun MessageSource.isAboutFriend(): Boolean {
* @see QuoteReply
*/
@JvmSynthetic
inline fun MessageSource.quote(): QuoteReply = QuoteReply(this)
public inline fun MessageSource.quote(): QuoteReply = QuoteReply(this)
/**
* 引用这条消息. 仅从服务器接收的消息 (即来自 [MessageEvent]) 才可以通过这个方式被引用.
* @see QuoteReply
*/
@JvmSynthetic
inline fun MessageChain.quote(): QuoteReply = QuoteReply(this.source)
public inline fun MessageChain.quote(): QuoteReply = QuoteReply(this.source)
/**
* 撤回这条消息. 可撤回自己 2 分钟内发出的消息, 和任意时间的群成员的消息.
@ -364,7 +364,7 @@ inline fun MessageChain.quote(): QuoteReply = QuoteReply(this.source)
* @see Bot.recall
*/
@JvmSynthetic
suspend inline fun MessageSource.recall() = bot.recall(this)
public suspend inline fun MessageSource.recall(): Unit = bot.recall(this)
/**
* 在一段时间后撤回这条消息. 可撤回自己 2 分钟内发出的消息, 和任意时间的群成员的消息.
@ -378,7 +378,7 @@ suspend inline fun MessageSource.recall() = bot.recall(this)
* @see Bot.recall
*/
@JvmSynthetic
inline fun MessageSource.recallIn(
public inline fun MessageSource.recallIn(
timeMillis: Long,
coroutineContext: CoroutineContext = EmptyCoroutineContext
): Job = bot.recallIn(this, timeMillis, coroutineContext)
@ -393,7 +393,7 @@ inline fun MessageSource.recallIn(
* @see MessageSource.id
*/
@get:JvmSynthetic
val MessageChain.id: Int
public val MessageChain.id: Int
get() = this.source.id
/**
@ -404,7 +404,7 @@ val MessageChain.id: Int
* @see MessageSource.id
*/
@get:JvmSynthetic
val MessageChain.internalId: Int
public val MessageChain.internalId: Int
get() = this.source.internalId
/**
@ -415,7 +415,7 @@ val MessageChain.internalId: Int
* @see MessageSource.id
*/
@get:JvmSynthetic
val MessageChain.time: Int
public val MessageChain.time: Int
get() = this.source.time
/**
@ -426,7 +426,7 @@ val MessageChain.time: Int
* @see MessageSource.id
*/
@get:JvmSynthetic
val MessageChain.bot: Bot
public val MessageChain.bot: Bot
get() = this.source.bot
/**
@ -435,7 +435,7 @@ val MessageChain.bot: Bot
* 仅从服务器接收的消息 (即来自 [MessageEvent.message]), 或手动添加了 [MessageSource] 元素的 [MessageChain] 才可以获取消息源, 否则将抛出异常 [NoSuchElementException]
*/
@get:JvmSynthetic
val MessageChain.source: MessageSource
public val MessageChain.source: MessageSource
get() = this.getOrFail(MessageSource)
/**
@ -454,7 +454,7 @@ val MessageChain.source: MessageSource
* @see Bot.recall
*/
@JvmSynthetic
suspend inline fun MessageChain.recall() = this.source.recall()
public suspend inline fun MessageChain.recall(): Unit = this.source.recall()
/**
* 在一段时间后撤回这条消息. 可撤回自己 2 分钟内发出的消息, 和任意时间的群成员的消息.
@ -472,7 +472,7 @@ suspend inline fun MessageChain.recall() = this.source.recall()
* @see Bot.recall
*/
@JvmSynthetic
inline fun MessageChain.recallIn(
public inline fun MessageChain.recallIn(
millis: Long,
coroutineContext: CoroutineContext = EmptyCoroutineContext
): Job = source.recallIn(millis, coroutineContext)

View File

@ -28,7 +28,7 @@ import kotlin.jvm.JvmSynthetic
* 将在线消息源转换为离线消息源.
*/
@JvmName("toOfflineMessageSource")
fun OnlineMessageSource.toOffline(): OfflineMessageSource =
public fun OnlineMessageSource.toOffline(): OfflineMessageSource =
OfflineMessageSourceByOnline(this)
///////////////
@ -43,25 +43,25 @@ fun OnlineMessageSource.toOffline(): OfflineMessageSource =
*/
@MiraiExperimentalAPI
@JvmName("copySource")
fun MessageSource.copyAmend(
public fun MessageSource.copyAmend(
block: MessageSourceAmender.() -> Unit
): OfflineMessageSource = toMutableOffline().apply(block)
/**
* 仅于 [copyAmend] 中修改 [MessageSource]
*/
interface MessageSourceAmender {
var kind: OfflineMessageSource.Kind
var fromUin: Long
var targetUin: Long
var id: Int
var time: Int
var internalId: Int
public interface MessageSourceAmender {
public var kind: OfflineMessageSource.Kind
public var fromUin: Long
public var targetUin: Long
public var id: Int
public var time: Int
public var internalId: Int
var originalMessage: MessageChain
public var originalMessage: MessageChain
/** 从另一个 [MessageSource] 中复制 [id], [internalId], [time]*/
fun metadataFrom(another: MessageSource) {
public fun metadataFrom(another: MessageSource) {
this.id = another.id
this.internalId = another.internalId
this.time = another.time
@ -104,7 +104,7 @@ interface MessageSourceAmender {
*/
@JvmSynthetic
@MiraiExperimentalAPI
fun Bot.buildMessageSource(block: MessageSourceBuilder.() -> Unit): MessageSource {
public fun Bot.buildMessageSource(block: MessageSourceBuilder.() -> Unit): MessageSource {
val builder = MessageSourceBuilderImpl().apply(block)
return constructMessageSource(
builder.kind ?: error("You must call `Contact.sendTo(Contact)` when `buildMessageSource`"),
@ -120,7 +120,7 @@ fun Bot.buildMessageSource(block: MessageSourceBuilder.() -> Unit): MessageSourc
/**
* @see buildMessageSource
*/
abstract class MessageSourceBuilder {
public abstract class MessageSourceBuilder {
internal abstract var kind: OfflineMessageSource.Kind?
internal abstract var fromUin: Long
internal abstract var targetUin: Long
@ -132,22 +132,22 @@ abstract class MessageSourceBuilder {
@PublishedApi
internal val originalMessages: MessageChainBuilder = MessageChainBuilder()
fun time(from: MessageSource): MessageSourceBuilder = apply { this.time = from.time }
val now: Int get() = currentTimeSeconds.toInt()
fun time(value: Int) = apply { this.time = value }
public fun time(from: MessageSource): MessageSourceBuilder = apply { this.time = from.time }
public val now: Int get() = currentTimeSeconds.toInt()
public fun time(value: Int): MessageSourceBuilder = apply { this.time = value }
fun internalId(from: MessageSource): MessageSourceBuilder = apply { this.internalId = from.internalId }
fun internalId(value: Int): MessageSourceBuilder = apply { this.internalId = value }
public fun internalId(from: MessageSource): MessageSourceBuilder = apply { this.internalId = from.internalId }
public fun internalId(value: Int): MessageSourceBuilder = apply { this.internalId = value }
fun id(from: MessageSource): MessageSourceBuilder = apply { this.id = from.id }
fun id(value: Int): MessageSourceBuilder = apply { this.id = value }
public fun id(from: MessageSource): MessageSourceBuilder = apply { this.id = from.id }
public fun id(value: Int): MessageSourceBuilder = apply { this.id = value }
/**
* 从另一个 [MessageSource] 复制 [id], [time], [internalId].
* 这三个数据决定官方客户端能 "定位" 到的原消息
*/
fun metadata(from: MessageSource): MessageSourceBuilder = apply {
public fun metadata(from: MessageSource): MessageSourceBuilder = apply {
id(from)
internalId(from)
time(from)
@ -156,7 +156,7 @@ abstract class MessageSourceBuilder {
/**
* 从另一个 [MessageSource] 复制所有信息, 包括消息内容. 不会清空已有消息.
*/
fun allFrom(source: MessageSource): MessageSourceBuilder {
public fun allFrom(source: MessageSource): MessageSourceBuilder {
this.kind = determineKind(source)
this.id = source.id
this.time = source.time
@ -171,34 +171,35 @@ abstract class MessageSourceBuilder {
/**
* 从另一个 [MessageSource] 复制 [消息内容][MessageSource.originalMessage]. 不会清空已有消息.
*/
fun messagesFrom(source: MessageSource): MessageSourceBuilder = apply {
public fun messagesFrom(source: MessageSource): MessageSourceBuilder = apply {
this.originalMessages.addAll(source.originalMessage)
}
fun messages(messages: Iterable<Message>): MessageSourceBuilder = apply {
public fun messages(messages: Iterable<Message>): MessageSourceBuilder = apply {
this.originalMessages.addAll(messages)
}
fun messages(vararg message: Message): MessageSourceBuilder = apply {
public fun messages(vararg message: Message): MessageSourceBuilder = apply {
for (it in message) {
this.originalMessages.add(it)
}
}
@JvmSynthetic
inline fun messages(block: MessageChainBuilder.() -> Unit): MessageSourceBuilder = apply {
public inline fun messages(block: MessageChainBuilder.() -> Unit): MessageSourceBuilder = apply {
this.originalMessages.apply(block)
}
fun clearMessages(): MessageSourceBuilder = apply { this.originalMessages.clear() }
public fun clearMessages(): MessageSourceBuilder = apply { this.originalMessages.clear() }
/**
* 设置 [发送人][this] [发送目标][target], 并自动判断 [kind]
*/
@JvmSynthetic
abstract infix fun ContactOrBot.sendTo(target: ContactOrBot): MessageSourceBuilder
public abstract infix fun ContactOrBot.sendTo(target: ContactOrBot): MessageSourceBuilder
fun setSenderAndTarget(sender: ContactOrBot, target: ContactOrBot) = sender sendTo target
public fun setSenderAndTarget(sender: ContactOrBot, target: ContactOrBot): MessageSourceBuilder =
sender sendTo target
}

View File

@ -23,8 +23,8 @@ import kotlin.jvm.JvmSynthetic
*
* 一般不需要主动构造 [PlainText], [Message] 可直接与 [String] 相加. Java 用户请使用 [Message.plus]
*/
data class PlainText(
val content: String
public data class PlainText(
public val content: String
) : MessageContent {
@PlannedRemoval("1.2.0")
@ -33,17 +33,17 @@ data class PlainText(
level = DeprecationLevel.ERROR,
replaceWith = ReplaceWith("content")
)
val stringValue: String
public val stringValue: String
get() = content
@Suppress("unused")
constructor(charSequence: CharSequence) : this(charSequence.toString())
public constructor(charSequence: CharSequence) : this(charSequence.toString())
override fun toString(): String = content
override fun contentToString(): String = content
public override fun toString(): String = content
public override fun contentToString(): String = content
companion object Key : Message.Key<PlainText> {
override val typeName: String get() = "PlainText"
public companion object Key : Message.Key<PlainText> {
public override val typeName: String get() = "PlainText"
}
}
@ -52,4 +52,4 @@ data class PlainText(
*/
@JvmSynthetic
@Suppress("NOTHING_TO_INLINE")
inline fun String.toMessage(): PlainText = PlainText(this)
public inline fun String.toMessage(): PlainText = PlainText(this)

View File

@ -44,37 +44,37 @@ import kotlin.jvm.JvmSynthetic
*
* @see MessageSource 获取有关消息源的更多信息
*/
class QuoteReply(val source: MessageSource) : Message, MessageMetadata, ConstrainSingle<QuoteReply> {
companion object Key : Message.Key<QuoteReply> {
override val typeName: String
public class QuoteReply(public val source: MessageSource) : Message, MessageMetadata, ConstrainSingle<QuoteReply> {
public companion object Key : Message.Key<QuoteReply> {
public override val typeName: String
get() = "QuoteReply"
}
override val key: Message.Key<QuoteReply> get() = Key
public override val key: Message.Key<QuoteReply> get() = Key
override fun toString(): String = "[mirai:quote:${source.id},${source.internalId}]"
override fun equals(other: Any?): Boolean = other is QuoteReply && other.source == this.source
override fun hashCode(): Int = source.hashCode()
public override fun toString(): String = "[mirai:quote:${source.id},${source.internalId}]"
public override fun equals(other: Any?): Boolean = other is QuoteReply && other.source == this.source
public override fun hashCode(): Int = source.hashCode()
}
/**
* @see MessageSource.bot
*/
@get:JvmSynthetic
inline val QuoteReply.bot: Bot
public inline val QuoteReply.bot: Bot
get() = source.bot
/**
* 撤回引用的源消息
*/
@JvmSynthetic
suspend inline fun QuoteReply.recallSource() = this.source.recall()
public suspend inline fun QuoteReply.recallSource(): Unit = this.source.recall()
/**
* 在一段时间后撤回引用的源消息
*/
@JvmOverloads
inline fun QuoteReply.recallSourceIn(
public inline fun QuoteReply.recallSourceIn(
millis: Long,
coroutineContext: CoroutineContext = EmptyCoroutineContext
): Job = this.source.recallIn(millis, coroutineContext)
@ -85,43 +85,43 @@ inline fun QuoteReply.recallSourceIn(
@PlannedRemoval("1.3.0")
@get:JvmSynthetic
@Deprecated("use source.id for clearer semantics", ReplaceWith("source.id"))
inline val QuoteReply.id: Int
public inline val QuoteReply.id: Int
get() = source.id
@PlannedRemoval("1.3.0")
@get:JvmSynthetic
@Deprecated("use source.internalId for clearer semantics", ReplaceWith("source.internalId"))
inline val QuoteReply.internalId: Int
public inline val QuoteReply.internalId: Int
get() = source.internalId
@PlannedRemoval("1.3.0")
@get:JvmSynthetic
@Deprecated("use source.fromId for clearer semantics", ReplaceWith("source.fromId"))
inline val QuoteReply.fromId: Long
public inline val QuoteReply.fromId: Long
get() = source.fromId
@PlannedRemoval("1.3.0")
@get:JvmSynthetic
@Deprecated("use source.targetId for clearer semantics", ReplaceWith("source.targetId"))
inline val QuoteReply.targetId: Long
public inline val QuoteReply.targetId: Long
get() = source.targetId
@PlannedRemoval("1.3.0")
@get:JvmSynthetic
@Deprecated("use source.originalMessage for clearer semantics", ReplaceWith("source.originalMessage"))
inline val QuoteReply.originalMessage: MessageChain
public inline val QuoteReply.originalMessage: MessageChain
get() = source.originalMessage
@PlannedRemoval("1.3.0")
@get:JvmSynthetic
@Deprecated("use source.time for clearer semantics", ReplaceWith("source.time"))
inline val QuoteReply.time: Int
public inline val QuoteReply.time: Int
get() = source.time
@PlannedRemoval("1.3.0")
@Deprecated("use recallSourceIn for clearer semantics", ReplaceWith("recallSourceIn(millis, coroutineContext)"))
@JvmOverloads
inline fun QuoteReply.recallIn(
public inline fun QuoteReply.recallIn(
millis: Long,
coroutineContext: CoroutineContext = EmptyCoroutineContext
): Job = recallSourceIn(millis, coroutineContext)
@ -129,4 +129,4 @@ inline fun QuoteReply.recallIn(
@PlannedRemoval("1.3.0")
@Deprecated("use recallSource for clearer semantics", ReplaceWith("this.recallSource()"))
@JvmSynthetic
suspend inline fun QuoteReply.recall() = recallSource()
public suspend inline fun QuoteReply.recall(): Unit = recallSource()

View File

@ -29,31 +29,31 @@ import kotlin.jvm.JvmSynthetic
* @see LightApp 小程序 (JSON)
*/
// not using sealed class for customized implementations
interface RichMessage : MessageContent {
public interface RichMessage : MessageContent {
/**
* **注意**: 富文本消息的 [RichMessage.contentEquals] [RichMessage.toString] 都不稳定. 将来可能在没有任何警告的情况下改变格式.
*/
@MiraiExperimentalAPI
override fun contentToString(): String = this.content
public override fun contentToString(): String = this.content
/**
* 消息内容. 可为 JSON 文本或 XML 文本
*/
val content: String
public val content: String
/**
* 一些模板
* @suppress API 不稳定, 可能在任意时刻被删除
*/
@MiraiExperimentalAPI
companion object Templates : Message.Key<RichMessage> {
public companion object Templates : Message.Key<RichMessage> {
/**
* @suppress API 不稳定, 可能在任意时刻被删除
*/
@MiraiExperimentalAPI
fun share(
public fun share(
url: String,
title: String? = null,
content: String? = null,
@ -93,12 +93,12 @@ interface RichMessage : MessageContent {
*
* @see ServiceMessage 服务消息
*/
data class LightApp(override val content: String) : RichMessage {
companion object Key : Message.Key<LightApp> {
override val typeName: String get() = "LightApp"
public data class LightApp(override val content: String) : RichMessage {
public companion object Key : Message.Key<LightApp> {
public override val typeName: String get() = "LightApp"
}
override fun toString(): String = "[mirai:app:$content]"
public override fun toString(): String = "[mirai:app:$content]"
}
/**
@ -111,21 +111,24 @@ data class LightApp(override val content: String) : RichMessage {
*
* @see LightApp 小程序类型消息
*/
open class ServiceMessage(val serviceId: Int, final override val content: String) : RichMessage {
companion object Key : Message.Key<ServiceMessage> {
override val typeName: String get() = "ServiceMessage"
public open class ServiceMessage(
public val serviceId: Int,
public final override val content: String
) : RichMessage {
public companion object Key : Message.Key<ServiceMessage> {
public override val typeName: String get() = "ServiceMessage"
}
final override fun toString(): String = "[mirai:service:$serviceId,$content]"
public final override fun toString(): String = "[mirai:service:$serviceId,$content]"
final override fun equals(other: Any?): Boolean {
public final override fun equals(other: Any?): Boolean {
if (other == null) return false
if (other::class != this::class) return false
other as ServiceMessage
return other.serviceId == this.serviceId && other.content == this.content
}
final override fun hashCode(): Int {
public final override fun hashCode(): Int {
var result = serviceId
result = 31 * result + content.hashCode()
return result
@ -148,40 +151,40 @@ commonElem=CommonElem#750141174 {
@Suppress("DEPRECATION_ERROR")
@JvmSynthetic
@MiraiExperimentalAPI
inline fun buildXmlMessage(serviceId: Int, block: @XmlMessageDsl XmlMessageBuilder.() -> Unit): ServiceMessage =
public inline fun buildXmlMessage(serviceId: Int, block: @XmlMessageDsl XmlMessageBuilder.() -> Unit): ServiceMessage =
ServiceMessage(serviceId, XmlMessageBuilder().apply(block).text)
@MiraiExperimentalAPI
@Target(CLASS, FUNCTION, TYPE)
@DslMarker
annotation class XmlMessageDsl
public annotation class XmlMessageDsl
/**
* @suppress API 不稳定
*/
@MiraiExperimentalAPI
@XmlMessageDsl
class XmlMessageBuilder(
var templateId: Int = 1,
var serviceId: Int = 1,
var action: String = "plugin",
public class XmlMessageBuilder(
public var templateId: Int = 1,
public var serviceId: Int = 1,
public var action: String = "plugin",
/**
* 一般为点击这条消息后跳转的链接
*/
var actionData: String = "",
public var actionData: String = "",
/**
* 摘要, 在官方客户端内消息列表中显示
*/
var brief: String = "",
var flag: Int = 3,
var url: String = "", // TODO: 2019/12/3 unknown
var sourceName: String = "",
var sourceIconURL: String = ""
public var brief: String = "",
public var flag: Int = 3,
public var url: String = "", // TODO: 2019/12/3 unknown
public var sourceName: String = "",
public var sourceIconURL: String = ""
) {
@PublishedApi
internal val builder: StringBuilder = StringBuilder()
val text: String
public val text: String
get() = "<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>" +
"<msg templateID='$templateId' serviceID='$serviceId' action='$action' actionData='$actionData' brief='$brief' flag='$flag' url='$url'>" +
builder.toString() +
@ -190,36 +193,38 @@ class XmlMessageBuilder(
@JvmOverloads
@XmlMessageDsl
inline fun item(bg: Int = 0, layout: Int = 4, block: @XmlMessageDsl ItemBuilder.() -> Unit) {
public inline fun item(bg: Int = 0, layout: Int = 4, block: @XmlMessageDsl ItemBuilder.() -> Unit) {
builder.append(ItemBuilder(bg, layout).apply(block).text)
}
fun source(name: String, iconURL: String = "") {
public fun source(name: String, iconURL: String = "") {
sourceName = name
sourceIconURL = iconURL
}
@XmlMessageDsl
class ItemBuilder @PublishedApi internal constructor(
var bg: Int = 0,
var layout: Int = 4
public class ItemBuilder @PublishedApi internal constructor(
public var bg: Int = 0,
public var layout: Int = 4
) {
@PublishedApi
internal val builder: StringBuilder = StringBuilder()
val text: String get() = "<item bg='$bg' layout='$layout'>$builder</item>"
public val text: String get() = "<item bg='$bg' layout='$layout'>$builder</item>"
fun summary(text: String, color: String = "#000000") {
public fun summary(text: String, color: String = "#000000") {
this.builder.append("<summary color='$color'>$text</summary>")
}
fun title(text: String, size: Int = 25, color: String = "#000000") {
public fun title(text: String, size: Int = 25, color: String = "#000000") {
this.builder.append("<title size='$size' color='$color'>$text</title>")
}
fun picture(coverUrl: String) {
public fun picture(coverUrl: String) {
this.builder.append("<picture cover='$coverUrl'/>")
}
}
}
@MiraiExperimentalAPI
internal class LongMessage internal constructor(content: String, val resId: String) : ServiceMessage(35, content) {
companion object Key : Message.Key<LongMessage> {

View File

@ -6,16 +6,16 @@ import net.mamoe.mirai.utils.MiraiExperimentalAPI
* 需要通过上传到服务器的消息如语音文件
*/
@MiraiExperimentalAPI
abstract class PttMessage : MessageContent {
public abstract class PttMessage : MessageContent {
companion object Key : Message.Key<PttMessage> {
override val typeName: String
public companion object Key : Message.Key<PttMessage> {
public override val typeName: String
get() = "PttMessage"
}
abstract val fileName: String
abstract val md5: ByteArray
abstract val fileSize: Long
public abstract val fileName: String
public abstract val md5: ByteArray
public abstract val fileSize: Long
}
@ -23,21 +23,22 @@ abstract class PttMessage : MessageContent {
* 语音消息, 目前只支持接收和转发
*/
@MiraiExperimentalAPI
class Voice(
override val fileName: String,
override val md5: ByteArray,
override val fileSize: Long,
public class Voice(
public override val fileName: String,
public override val md5: ByteArray,
public override val fileSize: Long,
private val _url: String
) : PttMessage() {
companion object Key : Message.Key<Voice> {
public companion object Key : Message.Key<Voice> {
override val typeName: String
get() = "Voice"
}
val url: String?
get() = if (_url.startsWith("http")) _url
else null
public val url: String?
get() =
if (_url.startsWith("http")) _url
else null
private var _stringValue: String? = null
get() = field ?: kotlin.run {
@ -45,7 +46,7 @@ class Voice(
field
}
override fun toString(): String = _stringValue!!
public override fun toString(): String = _stringValue!!
override fun contentToString(): String = "[语音]"
public override fun contentToString(): String = "[语音]"
}

View File

@ -52,12 +52,12 @@ internal const val ONLINE_OFFLINE_DEPRECATION_MESSAGE = """
replaceWith = ReplaceWith("Image", "net.mamoe.mirai.message.data.Image")
)
@Suppress("EXPOSED_SUPER_INTERFACE")
interface OnlineImage : Image, ConstOriginUrlAware {
companion object Key : Message.Key<OnlineImage> {
override val typeName: String get() = "OnlineImage"
public interface OnlineImage : Image, ConstOriginUrlAware {
public companion object Key : Message.Key<OnlineImage> {
public override val typeName: String get() = "OnlineImage"
}
override val originUrl: String
public override val originUrl: String
}
/**
@ -72,9 +72,9 @@ interface OnlineImage : Image, ConstOriginUrlAware {
level = DeprecationLevel.ERROR,
replaceWith = ReplaceWith("Image", "net.mamoe.mirai.message.data.Image")
)
interface OfflineImage : Image {
companion object Key : Message.Key<OfflineImage> {
override val typeName: String get() = "OfflineImage"
public interface OfflineImage : Image {
public companion object Key : Message.Key<OfflineImage> {
public override val typeName: String get() = "OfflineImage"
}
}
@ -84,7 +84,7 @@ interface OfflineImage : Image {
level = DeprecationLevel.HIDDEN
)
@JvmSynthetic
suspend fun OfflineImage.queryUrl(): String {
public suspend fun OfflineImage.queryUrl(): String {
return Bot._instances.peekFirst()?.get()?.queryImageUrl(this) ?: error("No Bot available to query image url")
}
@ -100,12 +100,14 @@ suspend fun OfflineImage.queryUrl(): String {
replaceWith = ReplaceWith("Image", "net.mamoe.mirai.message.data.Image")
)
@Serializable
data class OfflineGroupImage(
override val imageId: String
public data class OfflineGroupImage(
public override val imageId: String
) : GroupImage(), OfflineImage, DeferredOriginUrlAware {
override fun getUrl(bot: Bot): String {
return "http://gchat.qpic.cn/gchatpic_new/${bot.id}/0-0-${imageId.substring(1..36)
.replace("-", "")}/0?term=2"
public override fun getUrl(bot: Bot): String {
return "http://gchat.qpic.cn/gchatpic_new/${bot.id}/0-0-${
imageId.substring(1..36)
.replace("-", "")
}/0?term=2"
}
init {
@ -125,7 +127,7 @@ data class OfflineGroupImage(
level = DeprecationLevel.ERROR,
replaceWith = ReplaceWith("Image", "net.mamoe.mirai.message.data.Image")
)
abstract class OnlineGroupImage : GroupImage(), OnlineImage
public abstract class OnlineGroupImage : GroupImage(), OnlineImage
/**
* 通过 [Group.uploadImage] 上传得到的 [GroupImage]. 它的链接需要查询 [Bot.queryImageUrl]
@ -139,10 +141,10 @@ abstract class OnlineGroupImage : GroupImage(), OnlineImage
replaceWith = ReplaceWith("Image", "net.mamoe.mirai.message.data.Image")
)
@Serializable
data class OfflineFriendImage(
override val imageId: String
public data class OfflineFriendImage(
public override val imageId: String
) : FriendImage(), OfflineImage, DeferredOriginUrlAware {
override fun getUrl(bot: Bot): String {
public override fun getUrl(bot: Bot): String {
return "http://c2cpicdw.qpic.cn/offpic_new/${bot.id}/${this.imageId}/0?term=2"
}
@ -162,6 +164,6 @@ data class OfflineFriendImage(
level = DeprecationLevel.ERROR,
replaceWith = ReplaceWith("Image", "net.mamoe.mirai.message.data.Image")
)
abstract class OnlineFriendImage : FriendImage(), OnlineImage
public abstract class OnlineFriendImage : FriendImage(), OnlineImage
// endregion

View File

@ -31,7 +31,7 @@ import kotlin.jvm.JvmSynthetic
/**
* 判断两个 [MessageEvent] [MessageEvent.sender] [MessageEvent.subject] 是否相同
*/
fun MessageEvent.isContextIdenticalWith(another: MessageEvent): Boolean {
public fun MessageEvent.isContextIdenticalWith(another: MessageEvent): Boolean {
return this.sender == another.sender && this.subject == another.subject
}
@ -47,7 +47,7 @@ fun MessageEvent.isContextIdenticalWith(another: MessageEvent): Boolean {
* @see syncFromEvent 实现原理
*/
@JvmSynthetic
suspend inline fun <reified P : MessageEvent> P.nextMessage(
public suspend inline fun <reified P : MessageEvent> P.nextMessage(
timeoutMillis: Long = -1,
priority: Listener.EventPriority = EventPriority.MONITOR,
noinline filter: suspend P.(P) -> Boolean = { true }
@ -69,7 +69,7 @@ suspend inline fun <reified P : MessageEvent> P.nextMessage(
* @see syncFromEventOrNull 实现原理
*/
@JvmSynthetic
suspend inline fun <reified P : MessageEvent> P.nextMessageOrNull(
public suspend inline fun <reified P : MessageEvent> P.nextMessageOrNull(
timeoutMillis: Long,
priority: Listener.EventPriority = EventPriority.MONITOR,
noinline filter: suspend P.(P) -> Boolean = { true }
@ -84,7 +84,7 @@ suspend inline fun <reified P : MessageEvent> P.nextMessageOrNull(
* @see nextMessage
*/
@JvmSynthetic
inline fun <reified P : MessageEvent> P.nextMessageAsync(
public inline fun <reified P : MessageEvent> P.nextMessageAsync(
timeoutMillis: Long = -1,
coroutineContext: CoroutineContext = EmptyCoroutineContext,
priority: Listener.EventPriority = EventPriority.MONITOR,
@ -101,7 +101,7 @@ inline fun <reified P : MessageEvent> P.nextMessageAsync(
* @see nextMessageOrNull
*/
@JvmSynthetic
inline fun <reified P : MessageEvent> P.nextMessageOrNullAsync(
public inline fun <reified P : MessageEvent> P.nextMessageOrNullAsync(
timeoutMillis: Long,
coroutineContext: CoroutineContext = EmptyCoroutineContext,
priority: Listener.EventPriority = EventPriority.MONITOR,
@ -118,6 +118,6 @@ inline fun <reified P : MessageEvent> P.nextMessageOrNullAsync(
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
@Suppress("DEPRECATION_ERROR")
@JvmSynthetic
fun ContactMessage.isContextIdenticalWith(another: ContactMessage): Boolean {
public fun ContactMessage.isContextIdenticalWith(another: ContactMessage): Boolean {
return this.sender == another.sender && this.subject == another.subject && this.bot == another.bot
}

View File

@ -7,4 +7,4 @@ import net.mamoe.mirai.Bot
/**
* [Bot] 被迫下线时抛出, 作为 [Job.cancel] `cause`
*/
class ForceOfflineException(override val message: String?) : CancellationException(message)
public class ForceOfflineException(public override val message: String?) : CancellationException(message)

View File

@ -19,11 +19,11 @@ import net.mamoe.mirai.utils.SinceMirai
/**
* [登录][Bot.login] 失败时抛出, 可正常地中断登录过程.
*/
sealed class LoginFailedException constructor(
public sealed class LoginFailedException(
/**
* 是否可因此登录失败而关闭 [Bot]. 一般是密码错误, 被冻结等异常时.
*/
val killBot: Boolean = false,
public val killBot: Boolean = false,
message: String? = null,
cause: Throwable? = null
) : RuntimeException(message, cause)
@ -31,38 +31,43 @@ sealed class LoginFailedException constructor(
/**
* 密码输入错误 (有时候也会是其他错误, `"当前上网环境异常,请更换网络环境或在常用设备上登录或稍后再试。"`)
*/
class WrongPasswordException @MiraiInternalAPI constructor(message: String?) : LoginFailedException(true, message)
public class WrongPasswordException @MiraiInternalAPI constructor(
message: String?
) : LoginFailedException(true, message)
/**
* 无可用服务器
*/
class NoServerAvailableException @MiraiInternalAPI constructor(override val cause: Throwable?) :
LoginFailedException(false, "no server available")
public class NoServerAvailableException @MiraiInternalAPI constructor(
public override val cause: Throwable?
) : LoginFailedException(false, "no server available")
/**
* 服务器要求稍后重试
*/
@SinceMirai("1.2.0")
class RetryLaterException @MiraiInternalAPI constructor() : LoginFailedException(false, "server requests retrial later")
public class RetryLaterException @MiraiInternalAPI constructor() :
LoginFailedException(false, "server requests retrial later")
/**
* 无标准输入或 Kotlin 不支持此输入.
*/
class NoStandardInputForCaptchaException @MiraiInternalAPI constructor(override val cause: Throwable?) :
LoginFailedException(true, "no standard input for captcha")
public class NoStandardInputForCaptchaException @MiraiInternalAPI constructor(
public override val cause: Throwable?
) : LoginFailedException(true, "no standard input for captcha")
/**
* 需要短信验证时抛出. mirai 目前还不支持短信验证.
*/
@MiraiExperimentalAPI
class UnsupportedSMSLoginException(message: String?) : LoginFailedException(true, message)
public class UnsupportedSMSLoginException(message: String?) : LoginFailedException(true, message)
/**
* mirai 实现的异常
*/
abstract class CustomLoginFailedException : LoginFailedException {
constructor(killBot: Boolean) : super(killBot)
constructor(killBot: Boolean, message: String?) : super(killBot, message)
constructor(killBot: Boolean, message: String?, cause: Throwable?) : super(killBot, message, cause)
constructor(killBot: Boolean, cause: Throwable?) : super(killBot, cause = cause)
public abstract class CustomLoginFailedException : LoginFailedException {
public constructor(killBot: Boolean) : super(killBot)
public constructor(killBot: Boolean, message: String?) : super(killBot, message)
public constructor(killBot: Boolean, message: String?, cause: Throwable?) : super(killBot, message, cause)
public constructor(killBot: Boolean, cause: Throwable?) : super(killBot, cause = cause)
}

View File

@ -10,14 +10,16 @@ import net.mamoe.mirai.utils.MiraiInternalAPI
* **InternalAPI**: 这是内部 API, 它随时都有可能被修改
*/
@MiraiInternalAPI
interface Packet {
public interface Packet {
/**
* 实现这个接口的包将不会被记录到日志中
*/
interface NoLog
@MiraiInternalAPI
public interface NoLog
/**
* 实现这个接口的 [Event] 不会被作为事件记录到日志中
*/
interface NoEventLog
@MiraiInternalAPI
public interface NoEventLog
}

View File

@ -24,8 +24,8 @@ import kotlin.annotation.AnnotationTarget.*
CLASS, FUNCTION, PROPERTY
)
@MustBeDocumented
annotation class MiraiInternalAPI(
val message: String = ""
public annotation class MiraiInternalAPI(
public val message: String = ""
)
/**
@ -38,8 +38,8 @@ annotation class MiraiInternalAPI(
@RequiresOptIn(level = RequiresOptIn.Level.WARNING)
@Target(CLASS, TYPEALIAS, FUNCTION, PROPERTY, FIELD, CONSTRUCTOR)
@MustBeDocumented
annotation class MiraiExperimentalAPI(
val message: String = ""
public annotation class MiraiExperimentalAPI(
public val message: String = ""
)
/**
@ -48,7 +48,9 @@ annotation class MiraiExperimentalAPI(
@Target(CLASS, PROPERTY, FIELD, CONSTRUCTOR, FUNCTION, PROPERTY_GETTER, PROPERTY_SETTER, TYPEALIAS)
@Retention(AnnotationRetention.BINARY)
@MustBeDocumented
annotation class SinceMirai(val version: String)
public annotation class SinceMirai(
public val version: String
)
/**
* 标记一个正计划在 [version] 版本时删除 (对外隐藏) API.

View File

@ -37,12 +37,12 @@ import kotlin.jvm.JvmSynthetic
* }
* ```
*/
expect open class BotConfiguration() : BotConfigurationBase {
public expect open class BotConfiguration() : BotConfigurationBase {
/**
* 设备信息覆盖. 在没有手动指定时将会通过日志警告, 并使用随机设备信息.
* @see randomDeviceInfo 使用随机设备信息
*/
var deviceInfo: ((Context) -> DeviceInfo)?
public var deviceInfo: ((Context) -> DeviceInfo)?
/**
* 使用随机设备信息.
@ -50,12 +50,12 @@ expect open class BotConfiguration() : BotConfigurationBase {
* @see deviceInfo
*/
@ConfigurationDsl
fun randomDeviceInfo()
public fun randomDeviceInfo()
/**
* 协议类型, 服务器仅允许使用不同协议同时登录.
*/
enum class MiraiProtocol {
public enum class MiraiProtocol {
/**
* Android 手机.
*/
@ -76,17 +76,17 @@ expect open class BotConfiguration() : BotConfigurationBase {
internal val id: Long
}
companion object {
public companion object {
/** 默认的配置实例. 可以进行修改 */
@JvmStatic
val Default: BotConfiguration
public val Default: BotConfiguration
}
fun copy(): BotConfiguration
public fun copy(): BotConfiguration
}
@SinceMirai("1.1.0")
open class BotConfigurationBase internal constructor() {
public open class BotConfigurationBase internal constructor() {
/**
* 日志记录器
*
@ -97,7 +97,7 @@ open class BotConfigurationBase internal constructor() {
*
* @see MiraiLogger
*/
var botLoggerSupplier: ((Bot) -> MiraiLogger) = { DefaultLogger("Bot ${it.id}") }
public var botLoggerSupplier: ((Bot) -> MiraiLogger) = { DefaultLogger("Bot ${it.id}") }
/**
* 网络层日志构造器
@ -109,46 +109,46 @@ open class BotConfigurationBase internal constructor() {
*
* @see MiraiLogger
*/
var networkLoggerSupplier: ((Bot) -> MiraiLogger) = { DefaultLogger("Net ${it.id}") }
public var networkLoggerSupplier: ((Bot) -> MiraiLogger) = { DefaultLogger("Net ${it.id}") }
/** 父 [CoroutineContext]. [Bot] 创建后会使用 [SupervisorJob] 覆盖其 [Job], 但会将这个 [Job] 作为父 [Job] */
var parentCoroutineContext: CoroutineContext = EmptyCoroutineContext
public var parentCoroutineContext: CoroutineContext = EmptyCoroutineContext
/** 心跳周期. 过长会导致被服务器断开连接. */
var heartbeatPeriodMillis: Long = 60.secondsToMillis
public var heartbeatPeriodMillis: Long = 60.secondsToMillis
/**
* 每次心跳时等待结果的时间.
* 一旦心跳超时, 整个网络服务将会重启 (将消耗约 1s). 除正在进行的任务 (如图片上传) 会被中断外, 事件和插件均不受影响.
*/
var heartbeatTimeoutMillis: Long = 5.secondsToMillis
public var heartbeatTimeoutMillis: Long = 5.secondsToMillis
/** 心跳失败后的第一次重连前的等待时间. */
var firstReconnectDelayMillis: Long = 5.secondsToMillis
public var firstReconnectDelayMillis: Long = 5.secondsToMillis
/** 重连失败后, 继续尝试的每次等待时间 */
var reconnectPeriodMillis: Long = 5.secondsToMillis
public var reconnectPeriodMillis: Long = 5.secondsToMillis
/** 最多尝试多少次重连 */
var reconnectionRetryTimes: Int = Int.MAX_VALUE
public var reconnectionRetryTimes: Int = Int.MAX_VALUE
/** 验证码处理器 */
var loginSolver: LoginSolver = LoginSolver.Default
public var loginSolver: LoginSolver = LoginSolver.Default
/** 使用协议类型 */
var protocol: MiraiProtocol = MiraiProtocol.ANDROID_PAD
public var protocol: MiraiProtocol = MiraiProtocol.ANDROID_PAD
/** 缓存策略 */
@SinceMirai("1.0.0")
@MiraiExperimentalAPI
var fileCacheStrategy: FileCacheStrategy = FileCacheStrategy.PlatformDefault
public var fileCacheStrategy: FileCacheStrategy = FileCacheStrategy.PlatformDefault
/**
* Json 序列化器, 使用 'kotlinx.serialization'
*/
@SinceMirai("1.1.0")
@MiraiExperimentalAPI
var json: Json = kotlin.runCatching {
public var json: Json = kotlin.runCatching {
@OptIn(UnstableDefault::class)
Json(JsonConfiguration(isLenient = true, ignoreUnknownKeys = true))
}.getOrElse { Json(JsonConfiguration.Stable) }
@ -158,7 +158,7 @@ open class BotConfigurationBase internal constructor() {
* @see networkLoggerSupplier 更多日志处理方式
*/
@ConfigurationDsl
fun noNetworkLog() {
public fun noNetworkLog() {
networkLoggerSupplier = { _ -> SilentLogger }
}
@ -167,7 +167,7 @@ open class BotConfigurationBase internal constructor() {
* @see botLoggerSupplier 更多日志处理方式
*/
@ConfigurationDsl
fun noBotLog() {
public fun noBotLog() {
botLoggerSupplier = { _ -> SilentLogger }
}
@ -225,14 +225,14 @@ open class BotConfigurationBase internal constructor() {
*/
@JvmSynthetic
@ConfigurationDsl
suspend inline fun inheritCoroutineContext() {
public suspend inline fun inheritCoroutineContext() {
parentCoroutineContext = coroutineContext
}
/** 标注一个配置 DSL 函数 */
@Target(AnnotationTarget.FUNCTION)
@DslMarker
annotation class ConfigurationDsl
public annotation class ConfigurationDsl
}
internal val deviceInfoStub: (Context) -> DeviceInfo = {

View File

@ -30,7 +30,7 @@ import kotlin.jvm.JvmName
*/
@OptIn(InternalSerializationApi::class)
@MiraiExperimentalAPI
suspend fun ByteReadChannel.copyTo(dst: OutputStream) {
public suspend fun ByteReadChannel.copyTo(dst: OutputStream) {
val buffer = ByteArray(2048)
var size: Int
while (this.readAvailable(buffer).also { size = it } > 0) {
@ -42,7 +42,7 @@ suspend fun ByteReadChannel.copyTo(dst: OutputStream) {
* 从接收者管道读取所有数据并写入 [dst]. 不会关闭 [dst]
*/
@MiraiExperimentalAPI
suspend fun ByteReadChannel.copyTo(dst: Output) {
public suspend fun ByteReadChannel.copyTo(dst: Output) {
val buffer = ByteArray(2048)
var size: Int
while (this.readAvailable(buffer).also { size = it } > 0) {
@ -54,7 +54,7 @@ suspend fun ByteReadChannel.copyTo(dst: Output) {
* 从接收者管道读取所有数据并写入 [dst]. 不会关闭 [dst]
*/
@MiraiExperimentalAPI
suspend fun ByteReadChannel.copyTo(dst: ByteWriteChannel) {
public suspend fun ByteReadChannel.copyTo(dst: ByteWriteChannel) {
val buffer = ByteArray(2048)
var size: Int
while (this.readAvailable(buffer).also { size = it } > 0) {
@ -70,7 +70,7 @@ suspend fun ByteReadChannel.copyTo(dst: ByteWriteChannel) {
*/
@MiraiExperimentalAPI
@OptIn(InternalSerializationApi::class)
suspend fun ByteReadChannel.copyAndClose(dst: OutputStream) { // 在 JVM 这个 API 不是 internal 的
public suspend fun ByteReadChannel.copyAndClose(dst: OutputStream) { // 在 JVM 这个 API 不是 internal 的
try {
val buffer = ByteArray(2048)
var size: Int
@ -86,7 +86,7 @@ suspend fun ByteReadChannel.copyAndClose(dst: OutputStream) { // 在 JVM 这个
* 从接收者管道读取所有数据并写入 [dst], 最终关闭 [dst]
*/
@MiraiExperimentalAPI
suspend fun ByteReadChannel.copyAndClose(dst: Output) {
public suspend fun ByteReadChannel.copyAndClose(dst: Output) {
try {
val buffer = ByteArray(2048)
var size: Int
@ -102,7 +102,7 @@ suspend fun ByteReadChannel.copyAndClose(dst: Output) {
* 从接收者管道读取所有数据并写入 [dst], 最终关闭 [dst]
*/
@MiraiExperimentalAPI
suspend fun ByteReadChannel.copyAndClose(dst: ByteWriteChannel) {
public suspend fun ByteReadChannel.copyAndClose(dst: ByteWriteChannel) {
@Suppress("DuplicatedCode")
try {
val buffer = ByteArray(2048)
@ -120,7 +120,7 @@ suspend fun ByteReadChannel.copyAndClose(dst: ByteWriteChannel) {
* 从接收者管道读取所有数据并写入 [dst], 最终关闭 [dst]
*/
@MiraiExperimentalAPI
suspend fun ByteReadChannel.copyAndClose(dst: io.ktor.utils.io.ByteWriteChannel) {
public suspend fun ByteReadChannel.copyAndClose(dst: io.ktor.utils.io.ByteWriteChannel) {
@Suppress("DuplicatedCode")
try {
val buffer = ByteArray(2048)

View File

@ -13,4 +13,4 @@ package net.mamoe.mirai.utils
* On Android, typealias to `android.content.Context`
* On JVM, empty class.
*/
expect abstract class Context
public expect abstract class Context

View File

@ -17,45 +17,45 @@ import kotlinx.serialization.protobuf.ProtoId
/**
* 设备信息. 可通过继承 [SystemDeviceInfo] 来在默认的基础上修改
*/
abstract class DeviceInfo {
public abstract class DeviceInfo {
@Transient
abstract val context: Context
public abstract val context: Context
abstract val display: ByteArray
abstract val product: ByteArray
abstract val device: ByteArray
abstract val board: ByteArray
public abstract val display: ByteArray
public abstract val product: ByteArray
public abstract val device: ByteArray
public abstract val board: ByteArray
abstract val brand: ByteArray
abstract val model: ByteArray
abstract val bootloader: ByteArray
abstract val fingerprint: ByteArray
abstract val bootId: ByteArray
public abstract val brand: ByteArray
public abstract val model: ByteArray
public abstract val bootloader: ByteArray
public abstract val fingerprint: ByteArray
public abstract val bootId: ByteArray
abstract val procVersion: ByteArray
abstract val baseBand: ByteArray
public abstract val procVersion: ByteArray
public abstract val baseBand: ByteArray
abstract val version: Version
public abstract val version: Version
abstract val simInfo: ByteArray
public abstract val simInfo: ByteArray
abstract val osType: ByteArray
public abstract val osType: ByteArray
abstract val macAddress: ByteArray
public abstract val macAddress: ByteArray
abstract val wifiBSSID: ByteArray?
abstract val wifiSSID: ByteArray?
public abstract val wifiBSSID: ByteArray?
public abstract val wifiSSID: ByteArray?
abstract val imsiMd5: ByteArray
abstract val imei: String
public abstract val imsiMd5: ByteArray
public abstract val imei: String
val ipAddress: ByteArray get() = byteArrayOf(192.toByte(), 168.toByte(), 1, 123)
public val ipAddress: ByteArray get() = byteArrayOf(192.toByte(), 168.toByte(), 1, 123)
abstract val androidId: ByteArray
public abstract val androidId: ByteArray
abstract val apn: ByteArray
public abstract val apn: ByteArray
fun generateDeviceInfoData(): ByteArray {
public fun generateDeviceInfoData(): ByteArray {
@Serializable
class DevInfo(
@ProtoId(1) val bootloader: ByteArray,
@ -84,48 +84,48 @@ abstract class DeviceInfo {
)
}
interface Version {
val incremental: ByteArray
val release: ByteArray
val codename: ByteArray
val sdk: Int
public interface Version {
public val incremental: ByteArray
public val release: ByteArray
public val codename: ByteArray
public val sdk: Int
}
}
@Serializable
class DeviceInfoData(
override val display: ByteArray,
override val product: ByteArray,
override val device: ByteArray,
override val board: ByteArray,
override val brand: ByteArray,
override val model: ByteArray,
override val bootloader: ByteArray,
override val fingerprint: ByteArray,
override val bootId: ByteArray,
override val procVersion: ByteArray,
override val baseBand: ByteArray,
override val version: VersionData,
override val simInfo: ByteArray,
override val osType: ByteArray,
override val macAddress: ByteArray,
override val wifiBSSID: ByteArray?,
override val wifiSSID: ByteArray?,
override val imsiMd5: ByteArray,
override val imei: String,
override val apn: ByteArray
public class DeviceInfoData(
public override val display: ByteArray,
public override val product: ByteArray,
public override val device: ByteArray,
public override val board: ByteArray,
public override val brand: ByteArray,
public override val model: ByteArray,
public override val bootloader: ByteArray,
public override val fingerprint: ByteArray,
public override val bootId: ByteArray,
public override val procVersion: ByteArray,
public override val baseBand: ByteArray,
public override val version: VersionData,
public override val simInfo: ByteArray,
public override val osType: ByteArray,
public override val macAddress: ByteArray,
public override val wifiBSSID: ByteArray?,
public override val wifiSSID: ByteArray?,
public override val imsiMd5: ByteArray,
public override val imei: String,
public override val apn: ByteArray
) : DeviceInfo() {
@Transient
override lateinit var context: Context
public override lateinit var context: Context
override val androidId: ByteArray get() = display
public override val androidId: ByteArray get() = display
@Serializable
class VersionData(
override val incremental: ByteArray = SystemDeviceInfo.Version.incremental,
override val release: ByteArray = SystemDeviceInfo.Version.release,
override val codename: ByteArray = SystemDeviceInfo.Version.codename,
override val sdk: Int = SystemDeviceInfo.Version.sdk
public class VersionData(
public override val incremental: ByteArray = SystemDeviceInfo.Version.incremental,
public override val release: ByteArray = SystemDeviceInfo.Version.release,
public override val codename: ByteArray = SystemDeviceInfo.Version.codename,
public override val sdk: Int = SystemDeviceInfo.Version.sdk
) : Version
}

View File

@ -33,12 +33,12 @@ import kotlin.jvm.JvmSynthetic
* @see ExternalImage.sendTo 上传图片并以纯图片消息发送给联系人
* @See ExternalImage.upload 上传图片并得到 [Image] 消息
*/
class ExternalImage internal constructor(
public class ExternalImage internal constructor(
@JvmField
internal val input: ReusableInput
) {
internal val md5: ByteArray get() = this.input.md5
val formatName: String by lazy {
public val formatName: String by lazy {
val hex = input.asInput().use {
it.readBytes(8).toUHexString("")
}
@ -51,22 +51,22 @@ class ExternalImage internal constructor(
}
}
companion object {
const val defaultFormatName = "mirai"
public companion object {
public const val defaultFormatName: String = "mirai"
@MiraiExperimentalAPI
fun generateUUID(md5: ByteArray): String {
public fun generateUUID(md5: ByteArray): String {
return "${md5[0, 3]}-${md5[4, 5]}-${md5[6, 7]}-${md5[8, 9]}-${md5[10, 15]}"
}
@MiraiExperimentalAPI
fun generateImageId(md5: ByteArray): String {
public fun generateImageId(md5: ByteArray): String {
return """{${generateUUID(md5)}}.$defaultFormatName"""
}
}
override fun toString(): String {
public override fun toString(): String {
if (input is DeferredReusableInput) {
if (!input.initialized) {
return "ExternalImage(uninitialized)"
@ -104,7 +104,7 @@ class ExternalImage internal constructor(
* @see Contact.sendMessage 最终调用, 发送消息.
*/
@JvmSynthetic
suspend fun <C : Contact> ExternalImage.sendTo(contact: C): MessageReceipt<C> = when (contact) {
public suspend fun <C : Contact> ExternalImage.sendTo(contact: C): MessageReceipt<C> = when (contact) {
is Group -> contact.uploadImage(this).sendTo(contact)
is User -> contact.uploadImage(this).sendTo(contact)
else -> error("unreachable")
@ -119,7 +119,7 @@ suspend fun <C : Contact> ExternalImage.sendTo(contact: C): MessageReceipt<C> =
* @see Contact.uploadImage 最终调用, 上传图片.
*/
@JvmSynthetic
suspend fun ExternalImage.upload(contact: Contact): Image = when (contact) {
public suspend fun ExternalImage.upload(contact: Contact): Image = when (contact) {
is Group -> contact.uploadImage(this)
is User -> contact.uploadImage(this)
else -> error("unreachable")
@ -131,7 +131,7 @@ suspend fun ExternalImage.upload(contact: Contact): Image = when (contact) {
* @see Contact.sendMessage 最终调用, 发送消息.
*/
@JvmSynthetic
suspend inline fun <C : Contact> C.sendImage(image: ExternalImage): MessageReceipt<C> = image.sendTo(this)
public suspend inline fun <C : Contact> C.sendImage(image: ExternalImage): MessageReceipt<C> = image.sendTo(this)
@JvmSynthetic

View File

@ -13,14 +13,14 @@ import kotlin.contracts.contract
* 图片上传时默认使用文件缓存.
*/
@MiraiExperimentalAPI
expect interface FileCacheStrategy {
public expect interface FileCacheStrategy {
/**
* [input] 缓存为 [ExternalImage].
* 此函数应 close 这个 [Input]
*/
@MiraiExperimentalAPI
@Throws(IOException::class)
fun newImageCache(input: Input): ExternalImage
public fun newImageCache(input: Input): ExternalImage
/**
* [input] 缓存为 [ExternalImage].
@ -28,25 +28,25 @@ expect interface FileCacheStrategy {
*/
@MiraiExperimentalAPI
@Throws(IOException::class)
fun newImageCache(input: ByteArray): ExternalImage
public fun newImageCache(input: ByteArray): ExternalImage
/**
* 默认的缓存方案. JVM 平台使用系统临时文件.
*/
@MiraiExperimentalAPI
object PlatformDefault : FileCacheStrategy
public object PlatformDefault : FileCacheStrategy
/**
* 使用内存直接存储所有图片文件.
*/
object MemoryCache : FileCacheStrategy {
public object MemoryCache : FileCacheStrategy {
@MiraiExperimentalAPI
@Throws(IOException::class)
override fun newImageCache(input: Input): ExternalImage
public override fun newImageCache(input: Input): ExternalImage
@MiraiExperimentalAPI
@Throws(IOException::class)
override fun newImageCache(input: ByteArray): ExternalImage
public override fun newImageCache(input: ByteArray): ExternalImage
}
}

View File

@ -40,12 +40,12 @@ import kotlin.reflect.KClass
@Retention(AnnotationRetention.SOURCE)
@OptIn(ExperimentalMultiplatform::class)
@OptionalExpectation
expect annotation class Throws(vararg val exceptionClasses: KClass<out Throwable>)
internal expect annotation class Throws(vararg val exceptionClasses: KClass<out Throwable>)
/**
* 验证码, 设备锁解决器
*/
expect abstract class LoginSolver {
public expect abstract class LoginSolver {
/**
* 处理图片验证码.
* 返回 null 以表示无法处理验证码, 将会刷新验证码或重试登录.
@ -53,7 +53,7 @@ expect abstract class LoginSolver {
*
* @throws LoginFailedException
*/
abstract suspend fun onSolvePicCaptcha(bot: Bot, data: ByteArray): String?
public abstract suspend fun onSolvePicCaptcha(bot: Bot, data: ByteArray): String?
/**
* 处理滑动验证码.
@ -63,7 +63,7 @@ expect abstract class LoginSolver {
* @throws LoginFailedException
* @return 验证码解决成功后获得的 ticket.
*/
abstract suspend fun onSolveSliderCaptcha(bot: Bot, url: String): String?
public abstract suspend fun onSolveSliderCaptcha(bot: Bot, url: String): String?
/**
* 处理不安全设备验证.
@ -73,9 +73,9 @@ expect abstract class LoginSolver {
* @return 任意内容. 返回值保留以供未来更新.
* @throws LoginFailedException
*/
abstract suspend fun onSolveUnsafeDeviceLoginVerify(bot: Bot, url: String): String?
public abstract suspend fun onSolveUnsafeDeviceLoginVerify(bot: Bot, url: String): String?
companion object {
val Default: LoginSolver
public companion object {
public val Default: LoginSolver
}
}

View File

@ -32,13 +32,13 @@ import kotlin.jvm.JvmOverloads
*
* Java 调用: `Utils.getDefaultLogger().invoke(identity)`
*/
var DefaultLogger: (identity: String?) -> MiraiLogger = { PlatformLogger(it) }
public var DefaultLogger: (identity: String?) -> MiraiLogger = { PlatformLogger(it) }
/**
* 给这个 logger 添加一个开关, 用于控制是否记录 log
*/
@JvmOverloads
fun MiraiLogger.withSwitch(default: Boolean = true): MiraiLoggerWithSwitch = MiraiLoggerWithSwitch(this, default)
public fun MiraiLogger.withSwitch(default: Boolean = true): MiraiLoggerWithSwitch = MiraiLoggerWithSwitch(this, default)
/**
* 日志记录器. 所有的输出均依赖于它.
@ -56,7 +56,7 @@ fun MiraiLogger.withSwitch(default: Boolean = true): MiraiLoggerWithSwitch = Mir
*
* @see MiraiLoggerPlatformBase 平台通用基础实现. Mirai 自带的日志系统无法满足需求, 请继承这个类并实现其抽象函数.
*/
interface MiraiLogger {
public interface MiraiLogger {
/**
* 顶层日志记录器.
*
@ -64,7 +64,7 @@ interface MiraiLogger {
* 请参考使用 [DefaultLogger]
*/
@Deprecated(message = "顶层日志会导致混乱并难以定位问题. 请自行构造 logger 实例并使用.", level = DeprecationLevel.WARNING)
companion object : MiraiLogger by DefaultLogger("Mirai")
public companion object : MiraiLogger by DefaultLogger("Mirai")
/**
* 日志的标记. Mirai , identity 可为
@ -74,14 +74,14 @@ interface MiraiLogger {
*
* 它只用于帮助调试或统计. 十分建议清晰定义 identity
*/
val identity: String?
public val identity: String?
/**
* 获取 [MiraiLogger] 是否已开启
*
* [MiraiLoggerWithSwitch] 可控制开关外, 其他的所有 [MiraiLogger] 均一直开启.
*/
val isEnabled: Boolean
public val isEnabled: Boolean
/**
* 随从. this 中调用所有方法后都应继续往 [follower] 传递调用.
@ -93,54 +93,54 @@ interface MiraiLogger {
*
* 当然, 多个 logger 也可以加在一起: `val logger = bot.logger + MynLogger() + MyLogger2()`
*/
var follower: MiraiLogger?
public var follower: MiraiLogger?
/**
* 记录一个 `verbose` 级别的日志.
* 无关紧要的, 经常大量输出的日志应使用它.
*/
fun verbose(message: String?)
public fun verbose(message: String?)
fun verbose(e: Throwable?) = verbose(null, e)
fun verbose(message: String?, e: Throwable?)
public fun verbose(e: Throwable?): Unit = verbose(null, e)
public fun verbose(message: String?, e: Throwable?)
/**
* 记录一个 _调试_ 级别的日志.
*/
fun debug(message: String?)
public fun debug(message: String?)
fun debug(e: Throwable?) = debug(null, e)
fun debug(message: String?, e: Throwable?)
public fun debug(e: Throwable?): Unit = debug(null, e)
public fun debug(message: String?, e: Throwable?)
/**
* 记录一个 _信息_ 级别的日志.
*/
fun info(message: String?)
public fun info(message: String?)
fun info(e: Throwable?) = info(null, e)
fun info(message: String?, e: Throwable?)
public fun info(e: Throwable?): Unit = info(null, e)
public fun info(message: String?, e: Throwable?)
/**
* 记录一个 _警告_ 级别的日志.
*/
fun warning(message: String?)
public fun warning(message: String?)
fun warning(e: Throwable?) = warning(null, e)
fun warning(message: String?, e: Throwable?)
public fun warning(e: Throwable?): Unit = warning(null, e)
public fun warning(message: String?, e: Throwable?)
/**
* 记录一个 _错误_ 级别的日志.
*/
fun error(message: String?)
public fun error(message: String?)
fun error(e: Throwable?) = error(null, e)
fun error(message: String?, e: Throwable?)
public fun error(e: Throwable?): Unit = error(null, e)
public fun error(message: String?, e: Throwable?)
/** 根据优先级调用对应函数 */
fun call(priority: SimpleLogger.LogPriority, message: String? = null, e: Throwable? = null) =
public fun call(priority: SimpleLogger.LogPriority, message: String? = null, e: Throwable? = null): Unit =
priority.correspondingFunction(this, message, e)
/**
@ -154,7 +154,7 @@ interface MiraiLogger {
*
* @return [follower]
*/
operator fun <T : MiraiLogger> plus(follower: T): T
public operator fun <T : MiraiLogger> plus(follower: T): T
/**
* 添加一个 [follower]
@ -162,47 +162,47 @@ interface MiraiLogger {
*
* @see follower
*/
operator fun plusAssign(follower: MiraiLogger)
public operator fun plusAssign(follower: MiraiLogger)
}
inline fun MiraiLogger.verbose(lazyMessage: () -> String) {
public inline fun MiraiLogger.verbose(lazyMessage: () -> String) {
if (isEnabled) verbose(lazyMessage())
}
inline fun MiraiLogger.verbose(lazyMessage: () -> String, e: Throwable?) {
public inline fun MiraiLogger.verbose(lazyMessage: () -> String, e: Throwable?) {
if (isEnabled) verbose(lazyMessage(), e)
}
inline fun MiraiLogger.debug(lazyMessage: () -> String?) {
public inline fun MiraiLogger.debug(lazyMessage: () -> String?) {
if (isEnabled) debug(lazyMessage())
}
inline fun MiraiLogger.debug(lazyMessage: () -> String?, e: Throwable?) {
public inline fun MiraiLogger.debug(lazyMessage: () -> String?, e: Throwable?) {
if (isEnabled) debug(lazyMessage(), e)
}
inline fun MiraiLogger.info(lazyMessage: () -> String?) {
public inline fun MiraiLogger.info(lazyMessage: () -> String?) {
if (isEnabled) info(lazyMessage())
}
inline fun MiraiLogger.info(lazyMessage: () -> String?, e: Throwable?) {
public inline fun MiraiLogger.info(lazyMessage: () -> String?, e: Throwable?) {
if (isEnabled) info(lazyMessage(), e)
}
inline fun MiraiLogger.warning(lazyMessage: () -> String?) {
public inline fun MiraiLogger.warning(lazyMessage: () -> String?) {
if (isEnabled) warning(lazyMessage())
}
inline fun MiraiLogger.warning(lazyMessage: () -> String?, e: Throwable?) {
public inline fun MiraiLogger.warning(lazyMessage: () -> String?, e: Throwable?) {
if (isEnabled) warning(lazyMessage(), e)
}
inline fun MiraiLogger.error(lazyMessage: () -> String?) {
public inline fun MiraiLogger.error(lazyMessage: () -> String?) {
if (isEnabled) error(lazyMessage())
}
inline fun MiraiLogger.error(lazyMessage: () -> String?, e: Throwable?) {
public inline fun MiraiLogger.error(lazyMessage: () -> String?, e: Throwable?) {
if (isEnabled) error(lazyMessage(), e)
}
@ -229,41 +229,41 @@ inline fun MiraiLogger.error(lazyMessage: () -> String?, e: Throwable?) {
*
* @see DefaultLogger
*/
expect open class PlatformLogger @JvmOverloads constructor(identity: String? = "Mirai") : MiraiLoggerPlatformBase
public expect open class PlatformLogger @JvmOverloads constructor(identity: String? = "Mirai") : MiraiLoggerPlatformBase
/**
* 不做任何事情的 logger, keep silent.
*/
@Suppress("unused")
object SilentLogger : PlatformLogger() {
override val identity: String? = null
public object SilentLogger : PlatformLogger() {
public override val identity: String? = null
override fun error0(message: String?) = Unit
override fun debug0(message: String?) = Unit
override fun warning0(message: String?) = Unit
override fun verbose0(message: String?) = Unit
override fun info0(message: String?) = Unit
public override fun error0(message: String?): Unit = Unit
public override fun debug0(message: String?): Unit = Unit
public override fun warning0(message: String?): Unit = Unit
public override fun verbose0(message: String?): Unit = Unit
public override fun info0(message: String?): Unit = Unit
override fun verbose0(message: String?, e: Throwable?) = Unit
override fun debug0(message: String?, e: Throwable?) = Unit
override fun info0(message: String?, e: Throwable?) = Unit
override fun warning0(message: String?, e: Throwable?) = Unit
override fun error0(message: String?, e: Throwable?) = Unit
public override fun verbose0(message: String?, e: Throwable?): Unit = Unit
public override fun debug0(message: String?, e: Throwable?): Unit = Unit
public override fun info0(message: String?, e: Throwable?): Unit = Unit
public override fun warning0(message: String?, e: Throwable?): Unit = Unit
public override fun error0(message: String?, e: Throwable?): Unit = Unit
}
/**
* 简易日志记录, 所有类型日志都会被重定向 [logger]
*/
open class SimpleLogger(
final override val identity: String?,
public open class SimpleLogger(
public final override val identity: String?,
protected open val logger: (priority: LogPriority, message: String?, e: Throwable?) -> Unit
) : MiraiLoggerPlatformBase() {
enum class LogPriority(
@MiraiExperimentalAPI val nameAligned: String,
val simpleName: String,
@MiraiExperimentalAPI val correspondingFunction: MiraiLogger.(message: String?, e: Throwable?) -> Unit
public enum class LogPriority(
@MiraiExperimentalAPI public val nameAligned: String,
public val simpleName: String,
@MiraiExperimentalAPI public val correspondingFunction: MiraiLogger.(message: String?, e: Throwable?) -> Unit
) {
VERBOSE("VERBOSE", "V", MiraiLogger::verbose),
DEBUG(" DEBUG ", "D", MiraiLogger::debug),
@ -272,11 +272,11 @@ open class SimpleLogger(
ERROR(" ERROR ", "E", MiraiLogger::error)
}
companion object {
inline operator fun invoke(crossinline logger: (message: String?, e: Throwable?) -> Unit): SimpleLogger =
public companion object {
public inline operator fun invoke(crossinline logger: (message: String?, e: Throwable?) -> Unit): SimpleLogger =
SimpleLogger(null, logger)
inline operator fun invoke(
public inline operator fun invoke(
identity: String?,
crossinline logger: (message: String?, e: Throwable?) -> Unit
): SimpleLogger =
@ -284,20 +284,20 @@ open class SimpleLogger(
logger(message, e)
}
operator fun invoke(logger: (priority: LogPriority, message: String?, e: Throwable?) -> Unit): SimpleLogger =
public operator fun invoke(logger: (priority: LogPriority, message: String?, e: Throwable?) -> Unit): SimpleLogger =
SimpleLogger(null, logger)
}
override fun verbose0(message: String?) = logger(LogPriority.VERBOSE, message, null)
override fun verbose0(message: String?, e: Throwable?) = logger(LogPriority.VERBOSE, message, e)
override fun debug0(message: String?) = logger(LogPriority.DEBUG, message, null)
override fun debug0(message: String?, e: Throwable?) = logger(LogPriority.DEBUG, message, e)
override fun info0(message: String?) = logger(LogPriority.INFO, message, null)
override fun info0(message: String?, e: Throwable?) = logger(LogPriority.INFO, message, e)
override fun warning0(message: String?) = logger(LogPriority.WARNING, message, null)
override fun warning0(message: String?, e: Throwable?) = logger(LogPriority.WARNING, message, e)
override fun error0(message: String?) = logger(LogPriority.ERROR, message, null)
override fun error0(message: String?, e: Throwable?) = logger(LogPriority.ERROR, message, e)
public override fun verbose0(message: String?): Unit = logger(LogPriority.VERBOSE, message, null)
public override fun verbose0(message: String?, e: Throwable?): Unit = logger(LogPriority.VERBOSE, message, e)
public override fun debug0(message: String?): Unit = logger(LogPriority.DEBUG, message, null)
public override fun debug0(message: String?, e: Throwable?): Unit = logger(LogPriority.DEBUG, message, e)
public override fun info0(message: String?): Unit = logger(LogPriority.INFO, message, null)
public override fun info0(message: String?, e: Throwable?): Unit = logger(LogPriority.INFO, message, e)
public override fun warning0(message: String?): Unit = logger(LogPriority.WARNING, message, null)
public override fun warning0(message: String?, e: Throwable?): Unit = logger(LogPriority.WARNING, message, e)
public override fun error0(message: String?): Unit = logger(LogPriority.ERROR, message, null)
public override fun error0(message: String?, e: Throwable?): Unit = logger(LogPriority.ERROR, message, e)
}
/**
@ -307,9 +307,9 @@ open class SimpleLogger(
* @see disable 关闭
*/
@Suppress("MemberVisibilityCanBePrivate")
class MiraiLoggerWithSwitch internal constructor(private val delegate: MiraiLogger, default: Boolean) :
public class MiraiLoggerWithSwitch internal constructor(private val delegate: MiraiLogger, default: Boolean) :
MiraiLoggerPlatformBase() {
override val identity: String? get() = delegate.identity
public override val identity: String? get() = delegate.identity
/**
* true 为开启.
@ -317,26 +317,26 @@ class MiraiLoggerWithSwitch internal constructor(private val delegate: MiraiLogg
@PublishedApi
internal var switch: Boolean = default
override val isEnabled: Boolean get() = switch
public override val isEnabled: Boolean get() = switch
fun enable() {
public fun enable() {
switch = true
}
fun disable() {
public fun disable() {
switch = false
}
override fun verbose0(message: String?) = delegate.verbose(message)
override fun verbose0(message: String?, e: Throwable?) = delegate.verbose(message, e)
override fun debug0(message: String?) = delegate.debug(message)
override fun debug0(message: String?, e: Throwable?) = delegate.debug(message, e)
override fun info0(message: String?) = delegate.info(message)
override fun info0(message: String?, e: Throwable?) = delegate.info(message, e)
override fun warning0(message: String?) = delegate.warning(message)
override fun warning0(message: String?, e: Throwable?) = delegate.warning(message, e)
override fun error0(message: String?) = delegate.error(message)
override fun error0(message: String?, e: Throwable?) = delegate.error(message, e)
public override fun verbose0(message: String?): Unit = delegate.verbose(message)
public override fun verbose0(message: String?, e: Throwable?): Unit = delegate.verbose(message, e)
public override fun debug0(message: String?): Unit = delegate.debug(message)
public override fun debug0(message: String?, e: Throwable?): Unit = delegate.debug(message, e)
public override fun info0(message: String?): Unit = delegate.info(message)
public override fun info0(message: String?, e: Throwable?): Unit = delegate.info(message, e)
public override fun warning0(message: String?): Unit = delegate.warning(message)
public override fun warning0(message: String?, e: Throwable?): Unit = delegate.warning(message, e)
public override fun error0(message: String?): Unit = delegate.error(message)
public override fun error0(message: String?, e: Throwable?): Unit = delegate.error(message, e)
}
/**
@ -349,87 +349,87 @@ class MiraiLoggerWithSwitch internal constructor(private val delegate: MiraiLogg
* @see PlatformLogger
* @see SimpleLogger
*/
abstract class MiraiLoggerPlatformBase : MiraiLogger {
override val isEnabled: Boolean get() = true
final override var follower: MiraiLogger? = null
public abstract class MiraiLoggerPlatformBase : MiraiLogger {
public override val isEnabled: Boolean get() = true
public final override var follower: MiraiLogger? = null
final override fun verbose(message: String?) {
public final override fun verbose(message: String?) {
if (!isEnabled) return
follower?.verbose(message)
verbose0(message)
}
final override fun verbose(message: String?, e: Throwable?) {
public final override fun verbose(message: String?, e: Throwable?) {
if (!isEnabled) return
follower?.verbose(message, e)
verbose0(message, e)
}
final override fun debug(message: String?) {
public final override fun debug(message: String?) {
if (!isEnabled) return
follower?.debug(message)
debug0(message)
}
final override fun debug(message: String?, e: Throwable?) {
public final override fun debug(message: String?, e: Throwable?) {
if (!isEnabled) return
follower?.debug(message, e)
debug0(message, e)
}
final override fun info(message: String?) {
public final override fun info(message: String?) {
if (!isEnabled) return
follower?.info(message)
info0(message)
}
final override fun info(message: String?, e: Throwable?) {
public final override fun info(message: String?, e: Throwable?) {
if (!isEnabled) return
follower?.info(message, e)
info0(message, e)
}
final override fun warning(message: String?) {
public final override fun warning(message: String?) {
if (!isEnabled) return
follower?.warning(message)
warning0(message)
}
final override fun warning(message: String?, e: Throwable?) {
public final override fun warning(message: String?, e: Throwable?) {
if (!isEnabled) return
follower?.warning(message, e)
warning0(message, e)
}
final override fun error(message: String?) {
public final override fun error(message: String?) {
if (!isEnabled) return
follower?.error(message)
error0(message)
}
final override fun error(message: String?, e: Throwable?) {
public final override fun error(message: String?, e: Throwable?) {
if (!isEnabled) return
follower?.error(message, e)
error0(message, e)
}
protected open fun verbose0(message: String?) = verbose0(message, null)
protected open fun verbose0(message: String?): Unit = verbose0(message, null)
protected abstract fun verbose0(message: String?, e: Throwable?)
protected open fun debug0(message: String?) = debug0(message, null)
protected open fun debug0(message: String?): Unit = debug0(message, null)
protected abstract fun debug0(message: String?, e: Throwable?)
protected open fun info0(message: String?) = info0(message, null)
protected open fun info0(message: String?): Unit = info0(message, null)
protected abstract fun info0(message: String?, e: Throwable?)
protected open fun warning0(message: String?) = warning0(message, null)
protected open fun warning0(message: String?): Unit = warning0(message, null)
protected abstract fun warning0(message: String?, e: Throwable?)
protected open fun error0(message: String?) = error0(message, null)
protected open fun error0(message: String?): Unit = error0(message, null)
protected abstract fun error0(message: String?, e: Throwable?)
override operator fun <T : MiraiLogger> plus(follower: T): T {
public override operator fun <T : MiraiLogger> plus(follower: T): T {
this.follower = follower
return follower
}
override fun plusAssign(follower: MiraiLogger) =
public override fun plusAssign(follower: MiraiLogger): Unit =
if (this.follower == null) this.follower = follower
else this.follower!! += follower
}

View File

@ -18,4 +18,4 @@ import kotlin.jvm.JvmName
/**
* 图片文件过大
*/ // 不要删除多平台结构, 这是 kotlin 的 bug
expect class OverFileSizeMaxException() : IllegalStateException
public expect class OverFileSizeMaxException() : IllegalStateException

View File

@ -15,9 +15,9 @@ package net.mamoe.mirai.utils
* Android: 获取手机信息, QQ 官方相同.
* JVM: 部分为常量, 部分为随机
*/
expect open class SystemDeviceInfo : DeviceInfo {
constructor()
constructor(context: Context)
public expect open class SystemDeviceInfo : DeviceInfo {
public constructor()
public constructor(context: Context)
object Version : DeviceInfo.Version
public object Version : DeviceInfo.Version
}

View File

@ -23,10 +23,10 @@ import kotlin.time.ExperimentalTime
/**
* 时间戳
*/
expect val currentTimeMillis: Long
public expect val currentTimeMillis: Long
@get:JvmSynthetic
inline val currentTimeSeconds: Long
public inline val currentTimeSeconds: Long
get() = currentTimeMillis / 1000
@ -34,57 +34,57 @@ inline val currentTimeSeconds: Long
// 内联属性, 则将来删除这些 API 将不会导致二进制不兼容.
@get:JvmSynthetic
inline val Int.secondsToMillis: Long
public inline val Int.secondsToMillis: Long
get() = this * 1000L
@get:JvmSynthetic
inline val Int.minutesToMillis: Long
public inline val Int.minutesToMillis: Long
get() = this * 60.secondsToMillis
@get:JvmSynthetic
inline val Int.hoursToMillis: Long
public inline val Int.hoursToMillis: Long
get() = this * 60.minutesToMillis
@get:JvmSynthetic
inline val Int.daysToMillis: Long
public inline val Int.daysToMillis: Long
get() = this * 24.hoursToMillis
@get:JvmSynthetic
inline val Int.weeksToMillis: Long
public inline val Int.weeksToMillis: Long
get() = this * 7.daysToMillis
@get:JvmSynthetic
inline val Int.monthsToMillis: Long
public inline val Int.monthsToMillis: Long
get() = this * 30.daysToMillis
@get:JvmSynthetic
inline val Int.millisToSeconds: Long
public inline val Int.millisToSeconds: Long
get() = (this / 1000).toLong()
@get:JvmSynthetic
inline val Int.minutesToSeconds: Long
public inline val Int.minutesToSeconds: Long
get() = (this * 60).toLong()
@get:JvmSynthetic
inline val Int.hoursToSeconds: Long
public inline val Int.hoursToSeconds: Long
get() = this * 60.minutesToSeconds
@get:JvmSynthetic
inline val Int.daysToSeconds: Long
public inline val Int.daysToSeconds: Long
get() = this * 24.hoursToSeconds
@get:JvmSynthetic
inline val Int.weeksToSeconds: Long
public inline val Int.weeksToSeconds: Long
get() = this * 7.daysToSeconds
@get:JvmSynthetic
inline val Int.monthsToSeconds: Long
public inline val Int.monthsToSeconds: Long
get() = this * 30.daysToSeconds
@MiraiExperimentalAPI
@ExperimentalTime
val Duration.asHumanReadable: String
public val Duration.asHumanReadable: String
get() {
val days = toInt(DurationUnit.DAYS)
val hours = toInt(DurationUnit.HOURS) % 24

View File

@ -19,9 +19,9 @@ import kotlin.reflect.KProperty
/**
* WeakRef that `getValue` for delegation throws an [IllegalStateException] if the referent is released by GC. Therefore it returns notnull value only
*/
class UnsafeWeakRef<T>(private val weakRef: WeakRef<T>) {
fun get(): T = weakRef.get() ?: error("WeakRef is released")
fun clear() = weakRef.clear()
public class UnsafeWeakRef<T>(private val weakRef: WeakRef<T>) {
public fun get(): T = weakRef.get() ?: error("WeakRef is released")
public fun clear(): Unit = weakRef.clear()
}
/**
@ -32,7 +32,7 @@ class UnsafeWeakRef<T>(private val weakRef: WeakRef<T>) {
* ```
*/
@JvmSynthetic
inline operator fun <T> UnsafeWeakRef<T>.getValue(thisRef: Any?, property: KProperty<*>): T = get()
public inline operator fun <T> UnsafeWeakRef<T>.getValue(thisRef: Any?, property: KProperty<*>): T = get()
/**
* Weak Reference.
@ -46,9 +46,9 @@ inline operator fun <T> UnsafeWeakRef<T>.getValue(thisRef: Any?, property: KProp
* @see weakRef provides a WeakRef
* @see unsafeWeakRef provides a UnsafeWeakRef
*/
expect class WeakRef<T>(referent: T) {
fun get(): T?
fun clear()
public expect class WeakRef<T>(referent: T) {
public fun get(): T?
public fun clear()
}
/**
@ -58,20 +58,20 @@ expect class WeakRef<T>(referent: T) {
*/
@Target(AnnotationTarget.PROPERTY)
@Retention(AnnotationRetention.SOURCE)
annotation class WeakRefProperty
public annotation class WeakRefProperty
/**
* Provides a weak reference to [this]
* The `getValue` for delegation returns [this] when [this] is not released by GC
*/
@JvmSynthetic
inline fun <T> T.weakRef(): WeakRef<T> = WeakRef(this)
public inline fun <T> T.weakRef(): WeakRef<T> = WeakRef(this)
/**
* Constructs an unsafe inline delegate for [this]
*/
@JvmSynthetic
inline fun <T> WeakRef<T>.unsafe(): UnsafeWeakRef<T> = UnsafeWeakRef(this)
public inline fun <T> WeakRef<T>.unsafe(): UnsafeWeakRef<T> = UnsafeWeakRef(this)
/**
* Provides a weak reference to [this].
@ -80,7 +80,7 @@ inline fun <T> WeakRef<T>.unsafe(): UnsafeWeakRef<T> = UnsafeWeakRef(this)
* **UNSTABLE API**: It is strongly suggested not to use this api
*/
@JvmSynthetic
inline fun <T> T.unsafeWeakRef(): UnsafeWeakRef<T> = UnsafeWeakRef(this.weakRef())
public inline fun <T> T.unsafeWeakRef(): UnsafeWeakRef<T> = UnsafeWeakRef(this.weakRef())
/**
* Provides delegate value.
@ -90,10 +90,10 @@ inline fun <T> T.unsafeWeakRef(): UnsafeWeakRef<T> = UnsafeWeakRef(this.weakRef(
* ```
*/
@JvmSynthetic
inline operator fun <T> WeakRef<T>.getValue(thisRef: Any?, property: KProperty<*>): T? = this.get()
public inline operator fun <T> WeakRef<T>.getValue(thisRef: Any?, property: KProperty<*>): T? = this.get()
/**
* Call the block if the referent is absent
*/
@JvmSynthetic
inline fun <T, R> WeakRef<T>.ifAbsent(block: (T) -> R): R? = this.get()?.let(block)
public inline fun <T, R> WeakRef<T>.ifAbsent(block: (T) -> R): R? = this.get()?.let(block)

View File

@ -20,12 +20,12 @@ import net.mamoe.mirai.utils.ContextImpl
* ### 手动选择协议模块并构造 [Bot]
* 引用 `net.mamoe.mirai.qqandroid.QQAndroid` 并使用其成员函数 [Bot]
*/
actual interface BotFactory {
public actual interface BotFactory {
/**
* 使用指定的 [配置][configuration] 构造 [Bot] 实例
*/
@JvmName("newBot")
actual fun Bot(
public actual fun Bot(
context: Context,
qq: Long,
password: String,
@ -36,7 +36,7 @@ actual interface BotFactory {
* 使用指定的 [配置][configuration] 构造 [Bot] 实例
*/
@JvmName("newBot")
actual fun Bot(
public actual fun Bot(
context: Context,
qq: Long,
passwordMd5: ByteArray,
@ -52,14 +52,14 @@ actual interface BotFactory {
*/
@JvmName("newBot")
@JvmOverloads
fun Bot(context: Context, qq: Long, password: String, configuration: BotConfiguration = BotConfiguration.Default): Bot =
public fun Bot(context: Context, qq: Long, password: String, configuration: BotConfiguration = BotConfiguration.Default): Bot =
factory.Bot(context, qq, password, configuration)
/**
* 自动加载现有协议的 [BotFactory], 并使用指定的 [配置][configuration] 构造 [Bot] 实例
*/
@JvmSynthetic
inline fun Bot(context: Context, qq: Long, password: String, configuration: (BotConfiguration.() -> Unit)): Bot =
public inline fun Bot(context: Context, qq: Long, password: String, configuration: (BotConfiguration.() -> Unit)): Bot =
factory.Bot(context, qq, password, configuration)
@ -70,14 +70,14 @@ inline fun Bot(context: Context, qq: Long, password: String, configuration: (Bot
*/
@JvmName("newBot")
@JvmOverloads
fun Bot(qq: Long, password: String, configuration: BotConfiguration = BotConfiguration.Default): Bot =
public fun Bot(qq: Long, password: String, configuration: BotConfiguration = BotConfiguration.Default): Bot =
factory.Bot(ContextImpl(), qq, password, configuration)
/**
* 自动加载现有协议的 [BotFactory], 并使用指定的 [配置][configuration] 构造 [Bot] 实例
*/
@JvmSynthetic
inline fun Bot(qq: Long, password: String, configuration: (BotConfiguration.() -> Unit)): Bot =
public inline fun Bot(qq: Long, password: String, configuration: (BotConfiguration.() -> Unit)): Bot =
factory.Bot(ContextImpl(), qq, password, configuration)
@ -88,7 +88,7 @@ inline fun Bot(qq: Long, password: String, configuration: (BotConfiguration.() -
*/
@JvmName("newBot")
@JvmOverloads
fun Bot(
public fun Bot(
context: Context,
qq: Long,
passwordMd5: ByteArray,
@ -100,7 +100,7 @@ fun Bot(
* 自动加载现有协议的 [BotFactory], 并使用指定的 [配置][configuration] 构造 [Bot] 实例
*/
@JvmSynthetic
inline fun Bot(context: Context, qq: Long, passwordMd5: ByteArray, configuration: (BotConfiguration.() -> Unit)): Bot =
public inline fun Bot(context: Context, qq: Long, passwordMd5: ByteArray, configuration: (BotConfiguration.() -> Unit)): Bot =
factory.Bot(context, qq, passwordMd5, BotConfiguration().apply(configuration))
@ -111,14 +111,14 @@ inline fun Bot(context: Context, qq: Long, passwordMd5: ByteArray, configuration
*/
@JvmName("newBot")
@JvmOverloads
fun Bot(qq: Long, passwordMd5: ByteArray, configuration: BotConfiguration = BotConfiguration.Default): Bot =
public fun Bot(qq: Long, passwordMd5: ByteArray, configuration: BotConfiguration = BotConfiguration.Default): Bot =
factory.Bot(ContextImpl(), qq, passwordMd5, configuration)
/**
* 自动加载现有协议的 [BotFactory], 并使用指定的 [配置][configuration] 构造 [Bot] 实例
*/
@JvmSynthetic
inline fun Bot(qq: Long, passwordMd5: ByteArray, configuration: (BotConfiguration.() -> Unit)): Bot =
public inline fun Bot(qq: Long, passwordMd5: ByteArray, configuration: (BotConfiguration.() -> Unit)): Bot =
factory.Bot(ContextImpl(), qq, passwordMd5, BotConfiguration().apply(configuration))

View File

@ -144,27 +144,27 @@ import kotlin.reflect.jvm.kotlinFunction
* Events.registerEvents(new MyEventHandlers())
* ```
*
* @sample net.mamoe.mirai.event.JvmMethodEventsTest
* //@sample net.mamoe.mirai.event.JvmMethodEventsTest
*/
@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
annotation class EventHandler(
public annotation class EventHandler(
/**
* 监听器优先级
* @see Listener.EventPriority 查看优先级相关信息
* @see Event.intercept 拦截事件
*/
val priority: Listener.EventPriority = EventPriority.NORMAL,
public val priority: Listener.EventPriority = EventPriority.NORMAL,
/**
* 是否自动忽略被 [取消][CancellableEvent.isCancelled]
* @see CancellableEvent
*/
val ignoreCancelled: Boolean = true,
public val ignoreCancelled: Boolean = true,
/**
* 并发类型
* @see Listener.ConcurrencyKind
*/
val concurrency: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT
public val concurrency: Listener.ConcurrencyKind = Listener.ConcurrencyKind.CONCURRENT
)
/**
@ -173,23 +173,23 @@ annotation class EventHandler(
* @see SimpleListenerHost 简单的实现
* @see EventHandler 查看更多信息
*/
interface ListenerHost
public interface ListenerHost
/**
* 携带一个异常处理器的 [ListenerHost].
* @see ListenerHost 查看更多信息
* @see EventHandler 查看更多信息
*/
abstract class SimpleListenerHost
public abstract class SimpleListenerHost
@JvmOverloads constructor(coroutineContext: CoroutineContext = EmptyCoroutineContext) : ListenerHost, CoroutineScope {
final override val coroutineContext: CoroutineContext =
public final override val coroutineContext: CoroutineContext =
CoroutineExceptionHandler(::handleException) + coroutineContext + SupervisorJob(coroutineContext[Job])
/**
* 处理事件处理中未捕获的异常. 在构造器中的 [coroutineContext] 未提供 [CoroutineExceptionHandler] 情况下必须继承此函数.
*/
open fun handleException(context: CoroutineContext, exception: Throwable) {
public open fun handleException(context: CoroutineContext, exception: Throwable) {
throw IllegalStateException(
"""
未找到异常处理器. 请继承 SimpleListenerHost 中的 handleException 方法, 或在构造 SimpleListenerHost 时提供 CoroutineExceptionHandler
@ -203,7 +203,7 @@ abstract class SimpleListenerHost
/**
* 停止所有事件监听
*/
fun cancelAll() {
public fun cancelAll() {
this.cancel()
}
}
@ -216,7 +216,7 @@ abstract class SimpleListenerHost
* @see EventHandler 获取更多信息
*/
@JvmOverloads
fun <T> T.registerEvents(coroutineContext: CoroutineContext = EmptyCoroutineContext)
public fun <T> T.registerEvents(coroutineContext: CoroutineContext = EmptyCoroutineContext): Unit
where T : CoroutineScope, T : ListenerHost = this.registerEvents(this, coroutineContext)
/**
@ -227,7 +227,7 @@ fun <T> T.registerEvents(coroutineContext: CoroutineContext = EmptyCoroutineCont
* @see EventHandler 获取更多信息
*/
@JvmOverloads
fun CoroutineScope.registerEvents(host: ListenerHost, coroutineContext: CoroutineContext = EmptyCoroutineContext) {
public fun CoroutineScope.registerEvents(host: ListenerHost, coroutineContext: CoroutineContext = EmptyCoroutineContext) {
for (method in host.javaClass.declaredMethods) {
method.getAnnotation(EventHandler::class.java)?.let {
method.registerEvent(host, this, it, coroutineContext)

View File

@ -36,7 +36,7 @@ import java.net.URL
* @throws OverFileSizeMaxException
*/
@Throws(OverFileSizeMaxException::class)
suspend fun <C : Contact> BufferedImage.sendTo(contact: C): MessageReceipt<C> =
public suspend fun <C : Contact> BufferedImage.sendTo(contact: C): MessageReceipt<C> =
toExternalImage().sendTo(contact)
/**
@ -44,7 +44,7 @@ suspend fun <C : Contact> BufferedImage.sendTo(contact: C): MessageReceipt<C> =
* @throws OverFileSizeMaxException
*/
@Throws(OverFileSizeMaxException::class)
suspend fun <C : Contact> URL.sendAsImageTo(contact: C): MessageReceipt<C> =
public suspend fun <C : Contact> URL.sendAsImageTo(contact: C): MessageReceipt<C> =
toExternalImage().sendTo(contact)
/**
@ -52,7 +52,7 @@ suspend fun <C : Contact> URL.sendAsImageTo(contact: C): MessageReceipt<C> =
* @throws OverFileSizeMaxException
*/
@Throws(OverFileSizeMaxException::class)
suspend fun <C : Contact> Input.sendAsImageTo(contact: C): MessageReceipt<C> =
public suspend fun <C : Contact> Input.sendAsImageTo(contact: C): MessageReceipt<C> =
toExternalImage().sendTo(contact)
/**
@ -60,7 +60,7 @@ suspend fun <C : Contact> Input.sendAsImageTo(contact: C): MessageReceipt<C> =
* @throws OverFileSizeMaxException
*/
@Throws(OverFileSizeMaxException::class)
suspend fun <C : Contact> InputStream.sendAsImageTo(contact: C): MessageReceipt<C> =
public suspend fun <C : Contact> InputStream.sendAsImageTo(contact: C): MessageReceipt<C> =
toExternalImage().sendTo(contact)
/**
@ -68,7 +68,7 @@ suspend fun <C : Contact> InputStream.sendAsImageTo(contact: C): MessageReceipt<
* @throws OverFileSizeMaxException
*/
@Throws(OverFileSizeMaxException::class)
suspend fun <C : Contact> File.sendAsImageTo(contact: C): MessageReceipt<C> {
public suspend fun <C : Contact> File.sendAsImageTo(contact: C): MessageReceipt<C> {
require(this.exists() && this.canRead())
return toExternalImage().sendTo(contact)
}
@ -83,7 +83,7 @@ suspend fun <C : Contact> File.sendAsImageTo(contact: C): MessageReceipt<C> {
*/
@JvmSynthetic
@Throws(OverFileSizeMaxException::class)
suspend fun BufferedImage.upload(contact: Contact): Image =
public suspend fun BufferedImage.upload(contact: Contact): Image =
toExternalImage().upload(contact)
/**
@ -91,7 +91,7 @@ suspend fun BufferedImage.upload(contact: Contact): Image =
* @throws OverFileSizeMaxException
*/
@Throws(OverFileSizeMaxException::class)
suspend fun URL.uploadAsImage(contact: Contact): Image =
public suspend fun URL.uploadAsImage(contact: Contact): Image =
toExternalImage().upload(contact)
/**
@ -99,7 +99,7 @@ suspend fun URL.uploadAsImage(contact: Contact): Image =
* @throws OverFileSizeMaxException
*/
@Throws(OverFileSizeMaxException::class)
suspend fun Input.uploadAsImage(contact: Contact): Image =
public suspend fun Input.uploadAsImage(contact: Contact): Image =
toExternalImage().upload(contact)
/**
@ -107,7 +107,7 @@ suspend fun Input.uploadAsImage(contact: Contact): Image =
* @throws OverFileSizeMaxException
*/
@Throws(OverFileSizeMaxException::class)
suspend fun InputStream.uploadAsImage(contact: Contact): Image =
public suspend fun InputStream.uploadAsImage(contact: Contact): Image =
toExternalImage().upload(contact)
/**
@ -115,7 +115,7 @@ suspend fun InputStream.uploadAsImage(contact: Contact): Image =
* @throws OverFileSizeMaxException
*/
@Throws(OverFileSizeMaxException::class)
suspend fun File.uploadAsImage(contact: Contact): Image {
public suspend fun File.uploadAsImage(contact: Contact): Image {
require(this.isFile && this.exists() && this.canRead()) { "file ${this.path} is not readable" }
return toExternalImage().upload(contact)
}
@ -129,7 +129,7 @@ suspend fun File.uploadAsImage(contact: Contact): Image {
* @throws OverFileSizeMaxException
*/
@Throws(OverFileSizeMaxException::class)
suspend inline fun <C : Contact> C.sendImage(bufferedImage: BufferedImage): MessageReceipt<C> =
public suspend inline fun <C : Contact> C.sendImage(bufferedImage: BufferedImage): MessageReceipt<C> =
bufferedImage.sendTo(this)
/**
@ -137,21 +137,21 @@ suspend inline fun <C : Contact> C.sendImage(bufferedImage: BufferedImage): Mess
* @throws OverFileSizeMaxException
*/
@Throws(OverFileSizeMaxException::class)
suspend inline fun <C : Contact> C.sendImage(imageUrl: URL): MessageReceipt<C> = imageUrl.sendAsImageTo(this)
public suspend inline fun <C : Contact> C.sendImage(imageUrl: URL): MessageReceipt<C> = imageUrl.sendAsImageTo(this)
/**
* [Dispatchers.IO] 中读取 [Input] 到临时文件并将其作为图片发送到指定联系人
* @throws OverFileSizeMaxException
*/
@Throws(OverFileSizeMaxException::class)
suspend inline fun <C : Contact> C.sendImage(imageInput: Input): MessageReceipt<C> = imageInput.sendAsImageTo(this)
public suspend inline fun <C : Contact> C.sendImage(imageInput: Input): MessageReceipt<C> = imageInput.sendAsImageTo(this)
/**
* [Dispatchers.IO] 中读取 [InputStream] 到临时文件并将其作为图片发送到指定联系人
* @throws OverFileSizeMaxException
*/
@Throws(OverFileSizeMaxException::class)
suspend inline fun <C : Contact> C.sendImage(imageStream: InputStream): MessageReceipt<C> =
public suspend inline fun <C : Contact> C.sendImage(imageStream: InputStream): MessageReceipt<C> =
imageStream.sendAsImageTo(this)
/**
@ -159,7 +159,7 @@ suspend inline fun <C : Contact> C.sendImage(imageStream: InputStream): MessageR
* @throws OverFileSizeMaxException
*/
@Throws(OverFileSizeMaxException::class)
suspend inline fun <C : Contact> C.sendImage(file: File): MessageReceipt<C> = file.sendAsImageTo(this)
public suspend inline fun <C : Contact> C.sendImage(file: File): MessageReceipt<C> = file.sendAsImageTo(this)
// endregion
@ -170,34 +170,34 @@ suspend inline fun <C : Contact> C.sendImage(file: File): MessageReceipt<C> = fi
* @throws OverFileSizeMaxException
*/
@Throws(OverFileSizeMaxException::class)
suspend inline fun Contact.uploadImage(bufferedImage: BufferedImage): Image = bufferedImage.upload(this)
public suspend inline fun Contact.uploadImage(bufferedImage: BufferedImage): Image = bufferedImage.upload(this)
/**
* [Dispatchers.IO] 中下载 [URL] 到临时文件并将其作为图片上传, 但不发送
* @throws OverFileSizeMaxException
*/
@Throws(OverFileSizeMaxException::class)
suspend inline fun Contact.uploadImage(imageUrl: URL): Image = imageUrl.uploadAsImage(this)
public suspend inline fun Contact.uploadImage(imageUrl: URL): Image = imageUrl.uploadAsImage(this)
/**
* [Dispatchers.IO] 中读取 [Input] 到临时文件并将其作为图片上传, 但不发送
* @throws OverFileSizeMaxException
*/
@Throws(OverFileSizeMaxException::class)
suspend inline fun Contact.uploadImage(imageInput: Input): Image = imageInput.uploadAsImage(this)
public suspend inline fun Contact.uploadImage(imageInput: Input): Image = imageInput.uploadAsImage(this)
/**
* [Dispatchers.IO] 中读取 [InputStream] 到临时文件并将其作为图片上传, 但不发送
* @throws OverFileSizeMaxException
*/
@Throws(OverFileSizeMaxException::class)
suspend inline fun Contact.uploadImage(imageStream: InputStream): Image = imageStream.uploadAsImage(this)
public suspend inline fun Contact.uploadImage(imageStream: InputStream): Image = imageStream.uploadAsImage(this)
/**
* [Dispatchers.IO] 中将文件作为图片上传, 但不发送
* @throws OverFileSizeMaxException
*/
@Throws(OverFileSizeMaxException::class)
suspend inline fun Contact.uploadImage(file: File): Image = file.uploadAsImage(this)
public suspend inline fun Contact.uploadImage(file: File): Image = file.uploadAsImage(this)
// endregion

View File

@ -61,8 +61,8 @@ import java.net.URL
* @see FlashImage 闪照
* @see Image.flash 转换普通图片为闪照
*/
actual interface Image : Message, MessageContent, CodableMessage {
actual companion object Key : Message.Key<Image> {
public actual interface Image : Message, MessageContent, CodableMessage {
public actual companion object Key : Message.Key<Image> {
actual override val typeName: String get() = "Image"
}
@ -82,7 +82,7 @@ actual interface Image : Message, MessageContent, CodableMessage {
*
* @see Image 使用 id 构造图片
*/
actual val imageId: String
public actual val imageId: String
@Deprecated(

View File

@ -37,13 +37,13 @@ import java.io.File
* ```
*/
@Suppress("PropertyName")
actual open class BotConfiguration : BotConfigurationBase() { // open for Java
public actual open class BotConfiguration : BotConfigurationBase() { // open for Java
/**
* 设备信息覆盖. 在没有手动指定时将会通过日志警告, 并使用随机设备信息.
* @see fileBasedDeviceInfo 使用指定文件存储设备信息
* @see randomDeviceInfo 使用随机设备信息
*/
actual var deviceInfo: ((Context) -> DeviceInfo)? = deviceInfoStub
public actual var deviceInfo: ((Context) -> DeviceInfo)? = deviceInfoStub
/**
* 使用随机设备信息.
@ -51,7 +51,7 @@ actual open class BotConfiguration : BotConfigurationBase() { // open for Java
* @see deviceInfo
*/
@ConfigurationDsl
actual fun randomDeviceInfo() {
public actual fun randomDeviceInfo() {
deviceInfo = null
}
@ -63,7 +63,7 @@ actual open class BotConfiguration : BotConfigurationBase() { // open for Java
@JvmOverloads
@ConfigurationDsl
@SinceMirai("1.1.0")
fun redirectNetworkLogToDirectory(
public fun redirectNetworkLogToDirectory(
dir: File = File("logs"),
retain: Long = 1.weeksToMillis,
identity: (bot: Bot) -> String = { "Net ${it.id}" }
@ -82,7 +82,7 @@ actual open class BotConfiguration : BotConfigurationBase() { // open for Java
@JvmOverloads
@SinceMirai("1.1.0")
@ConfigurationDsl
fun redirectNetworkLogToFile(
public fun redirectNetworkLogToFile(
file: File = File("mirai.log"),
identity: (bot: Bot) -> String = { "Net ${it.id}" }
) {
@ -99,7 +99,7 @@ actual open class BotConfiguration : BotConfigurationBase() { // open for Java
@JvmOverloads
@ConfigurationDsl
@SinceMirai("1.1.0")
fun redirectBotLogToDirectory(
public fun redirectBotLogToDirectory(
dir: File = File("logs"),
retain: Long = 1.weeksToMillis,
identity: (bot: Bot) -> String = { "Net ${it.id}" }
@ -118,7 +118,7 @@ actual open class BotConfiguration : BotConfigurationBase() { // open for Java
@JvmOverloads
@ConfigurationDsl
@SinceMirai("1.1.0")
fun redirectBotLogToFile(
public fun redirectBotLogToFile(
file: File = File("mirai.log"),
identity: (bot: Bot) -> String = { "Net ${it.id}" }
) {
@ -128,9 +128,9 @@ actual open class BotConfiguration : BotConfigurationBase() { // open for Java
}
@Suppress("ACTUAL_WITHOUT_EXPECT")
actual enum class MiraiProtocol actual constructor(
public actual enum class MiraiProtocol actual constructor(
/** 协议模块使用的 ID */
@JvmField actual internal val id: Long
@JvmField internal actual val id: Long
) {
/**
* Android 手机.
@ -149,10 +149,10 @@ actual open class BotConfiguration : BotConfigurationBase() { // open for Java
ANDROID_WATCH(537061176)
}
actual companion object {
public actual companion object {
/** 默认的配置实例. 可以进行修改 */
@JvmStatic
actual val Default = BotConfiguration()
public actual val Default: BotConfiguration = BotConfiguration()
}
/**
@ -164,11 +164,11 @@ actual open class BotConfiguration : BotConfigurationBase() { // open for Java
*/
@JvmOverloads
@ConfigurationDsl
fun fileBasedDeviceInfo(filepath: String = "device.json") {
public fun fileBasedDeviceInfo(filepath: String = "device.json") {
deviceInfo = getFileBasedDeviceInfoSupplier(filepath)
}
actual fun copy(): BotConfiguration {
public actual fun copy(): BotConfiguration {
return BotConfiguration().also { new ->
new.botLoggerSupplier = botLoggerSupplier
new.networkLoggerSupplier = networkLoggerSupplier

View File

@ -11,6 +11,6 @@ package net.mamoe.mirai.utils
import kotlinx.io.pool.DefaultPool
actual abstract class Context
public actual abstract class Context
open class ContextImpl : Context()
public open class ContextImpl : Context()

View File

@ -29,7 +29,7 @@ import java.net.URL
* [BufferedImage] 保存为临时文件, 然后构造 [ExternalImage]
*/
@JvmOverloads
fun BufferedImage.toExternalImage(formatName: String = "png"): ExternalImage =
public fun BufferedImage.toExternalImage(formatName: String = "png"): ExternalImage =
ExternalImage(DeferredReusableInput(this, formatName))
/**
@ -37,7 +37,7 @@ fun BufferedImage.toExternalImage(formatName: String = "png"): ExternalImage =
* @param deleteOnClose 若为 `true`, 图片发送后将会删除这个文件
*/
@JvmOverloads
fun File.toExternalImage(deleteOnClose: Boolean = false): ExternalImage {
public fun File.toExternalImage(deleteOnClose: Boolean = false): ExternalImage {
require(this.isFile) { "File must be a file" }
require(this.exists()) { "File must exist" }
require(this.canRead()) { "File must can be read" }
@ -48,42 +48,42 @@ fun File.toExternalImage(deleteOnClose: Boolean = false): ExternalImage {
* [URL] 委托为 [ExternalImage].
* 只会在上传图片时才读取 [URL] 的内容. 具体行为取决于相关 [Bot] [FileCacheStrategy]
*/
fun URL.toExternalImage(): ExternalImage = ExternalImage(DeferredReusableInput(this, null))
public fun URL.toExternalImage(): ExternalImage = ExternalImage(DeferredReusableInput(this, null))
/**
* [InputStream] 委托为 [ExternalImage].
* 只会在上传图片时才读取 [InputStream] 的内容. 具体行为取决于相关 [Bot] [FileCacheStrategy]
*/
fun InputStream.toExternalImage(): ExternalImage = ExternalImage(DeferredReusableInput(this, null))
public fun InputStream.toExternalImage(): ExternalImage = ExternalImage(DeferredReusableInput(this, null))
/**
* [Input] 委托为 [ExternalImage].
* 只会在上传图片时才读取 [Input] 的内容. 具体行为取决于相关 [Bot] [FileCacheStrategy]
*/
fun Input.toExternalImage(): ExternalImage = ExternalImage(DeferredReusableInput(this, null))
public fun Input.toExternalImage(): ExternalImage = ExternalImage(DeferredReusableInput(this, null))
@PlannedRemoval("1.2.0")
@Suppress("RedundantSuspendModifier")
@Deprecated("no need", ReplaceWith("toExternalImage()"), level = DeprecationLevel.ERROR)
suspend fun Input.suspendToExternalImage(): ExternalImage = toExternalImage()
public suspend fun Input.suspendToExternalImage(): ExternalImage = toExternalImage()
@Suppress("RedundantSuspendModifier")
@PlannedRemoval("1.2.0")
@Deprecated("no need", ReplaceWith("toExternalImage()"), level = DeprecationLevel.ERROR)
suspend fun InputStream.suspendToExternalImage(): ExternalImage = toExternalImage()
public suspend fun InputStream.suspendToExternalImage(): ExternalImage = toExternalImage()
@Suppress("RedundantSuspendModifier")
@PlannedRemoval("1.2.0")
@Deprecated("no need", ReplaceWith("toExternalImage()"), level = DeprecationLevel.ERROR)
suspend fun URL.suspendToExternalImage(): ExternalImage = toExternalImage()
public suspend fun URL.suspendToExternalImage(): ExternalImage = toExternalImage()
@Suppress("RedundantSuspendModifier")
@PlannedRemoval("1.2.0")
@Deprecated("no need", ReplaceWith("toExternalImage()"), level = DeprecationLevel.ERROR)
suspend fun File.suspendToExternalImage(): ExternalImage = toExternalImage()
public suspend fun File.suspendToExternalImage(): ExternalImage = toExternalImage()
@Suppress("RedundantSuspendModifier")
@PlannedRemoval("1.2.0")
@Deprecated("no need", ReplaceWith("toExternalImage()"), level = DeprecationLevel.ERROR)
suspend fun BufferedImage.suspendToExternalImage(): ExternalImage = toExternalImage()
public suspend fun BufferedImage.suspendToExternalImage(): ExternalImage = toExternalImage()

View File

@ -29,14 +29,14 @@ import kotlin.io.use
* @see BotConfiguration.fileCacheStrategy [Bot] 指定缓存策略
*/
@MiraiExperimentalAPI
actual interface FileCacheStrategy {
public actual interface FileCacheStrategy {
/**
* [input] 缓存为 [ExternalImage].
* 此函数应 close 这个 [Input]
*/
@MiraiExperimentalAPI
@Throws(IOException::class)
actual fun newImageCache(input: Input): ExternalImage
public actual fun newImageCache(input: Input): ExternalImage
/**
* [input] 缓存为 [ExternalImage].
@ -44,7 +44,7 @@ actual interface FileCacheStrategy {
*/
@MiraiExperimentalAPI
@Throws(IOException::class)
fun newImageCache(input: InputStream): ExternalImage
public fun newImageCache(input: InputStream): ExternalImage
/**
* [input] 缓存为 [ExternalImage].
@ -52,7 +52,7 @@ actual interface FileCacheStrategy {
*/
@MiraiExperimentalAPI
@Throws(IOException::class)
actual fun newImageCache(input: ByteArray): ExternalImage
public actual fun newImageCache(input: ByteArray): ExternalImage
/**
* [input] 缓存为 [ExternalImage].
@ -60,25 +60,25 @@ actual interface FileCacheStrategy {
*/
@MiraiExperimentalAPI
@Throws(IOException::class)
fun newImageCache(input: BufferedImage, format: String = "png"): ExternalImage
public fun newImageCache(input: BufferedImage, format: String = "png"): ExternalImage
/**
* [input] 缓存为 [ExternalImage].
*/
@MiraiExperimentalAPI
@Throws(IOException::class)
fun newImageCache(input: URL): ExternalImage
public fun newImageCache(input: URL): ExternalImage
/**
* 默认的缓存方案, 使用系统临时文件夹存储.
*/
@MiraiExperimentalAPI
actual object PlatformDefault : FileCacheStrategy by TempCache(null)
public actual object PlatformDefault : FileCacheStrategy by TempCache(null)
/**
* 使用内存直接存储所有图片文件.
*/
actual object MemoryCache : FileCacheStrategy {
public actual object MemoryCache : FileCacheStrategy {
@MiraiExperimentalAPI
@Throws(IOException::class)
actual override fun newImageCache(input: Input): ExternalImage {
@ -116,11 +116,11 @@ actual interface FileCacheStrategy {
* 使用系统临时文件夹缓存图片文件. 在图片使用完毕后删除临时文件.
*/
@MiraiExperimentalAPI
class TempCache @JvmOverloads constructor(
public class TempCache @JvmOverloads constructor(
/**
* 缓存图片存放位置. `null` 时使用主机系统的临时文件夹
*/
val directory: File? = null
public val directory: File? = null
) : FileCacheStrategy {
@MiraiExperimentalAPI
@Throws(IOException::class)

View File

@ -21,7 +21,7 @@ private val currentDate get() = SimpleDateFormat("yyyy-MM-dd").format(Date())
*
* @see PlatformLogger 查看格式信息
*/
class SingleFileLogger @JvmOverloads constructor(identity: String, file: File = File("$identity-$currentDate.log")) :
public class SingleFileLogger @JvmOverloads constructor(identity: String, file: File = File("$identity-$currentDate.log")) :
PlatformLogger(identity, { file.appendText(it + "\n") }, false) {
init {
@ -39,7 +39,7 @@ private val STUB: (priority: SimpleLogger.LogPriority, message: String?, e: Thro
*
* @see PlatformLogger 查看格式信息
*/
class DirectoryLogger @JvmOverloads constructor(
public class DirectoryLogger @JvmOverloads constructor(
identity: String,
private val directory: File = File(identity),
/**

View File

@ -30,15 +30,16 @@ import java.io.RandomAccessFile
import javax.imageio.ImageIO
import kotlin.coroutines.CoroutineContext
actual typealias Throws = kotlin.jvm.Throws
@Suppress("ACTUAL_WITHOUT_EXPECT")
internal actual typealias Throws = kotlin.jvm.Throws
/**
* 自动选择 [SwingSolver] [StandardCharImageLoginSolver]
*/
@MiraiExperimentalAPI
class DefaultLoginSolver(
val input: suspend () -> String,
val overrideLogger: MiraiLogger? = null
public class DefaultLoginSolver(
public val input: suspend () -> String,
public val overrideLogger: MiraiLogger? = null
) : LoginSolver() {
private val delegate: LoginSolver
@ -67,7 +68,7 @@ class DefaultLoginSolver(
* 使用字符图片展示验证码, 使用 [input] 获取输入, 使用 [overrideLogger] 输出
*/
@MiraiExperimentalAPI
class StandardCharImageLoginSolver(
public class StandardCharImageLoginSolver(
input: suspend () -> String,
/**
* `null` 时使用 [Bot.logger]
@ -138,13 +139,13 @@ class StandardCharImageLoginSolver(
/**
* 验证码, 设备锁解决器
*/
actual abstract class LoginSolver {
actual abstract suspend fun onSolvePicCaptcha(bot: Bot, data: ByteArray): String?
actual abstract suspend fun onSolveSliderCaptcha(bot: Bot, url: String): String?
actual abstract suspend fun onSolveUnsafeDeviceLoginVerify(bot: Bot, url: String): String?
public actual abstract class LoginSolver {
public actual abstract suspend fun onSolvePicCaptcha(bot: Bot, data: ByteArray): String?
public actual abstract suspend fun onSolveSliderCaptcha(bot: Bot, url: String): String?
public actual abstract suspend fun onSolveUnsafeDeviceLoginVerify(bot: Bot, url: String): String?
actual companion object {
actual val Default: LoginSolver =
public actual companion object {
public actual val Default: LoginSolver =
DefaultLoginSolver({ readLine() ?: throw NoStandardInputForCaptchaException(null) })
}

View File

@ -21,22 +21,22 @@ import javax.swing.JTextField
* @author Karlatemp <karlatemp@vip.qq.com> <https://github.com/Karlatemp>
*/
@MiraiExperimentalAPI
object SwingSolver : LoginSolver() {
override suspend fun onSolvePicCaptcha(bot: Bot, data: ByteArray): String? {
public object SwingSolver : LoginSolver() {
public override suspend fun onSolvePicCaptcha(bot: Bot, data: ByteArray): String? {
return openWindow("Mirai PicCaptcha(${bot.id})") {
val image = ImageIO.read(data.inputStream())
JLabel(ImageIcon(image)).append()
}
}
override suspend fun onSolveSliderCaptcha(bot: Bot, url: String): String? {
public override suspend fun onSolveSliderCaptcha(bot: Bot, url: String): String? {
return openWindow("Mirai SliderCaptcha(${bot.id})") {
JLabel("需要滑动验证码, 完成后请关闭该窗口").append()
Desktop.getDesktop().browse(URI(url))
}
}
override suspend fun onSolveUnsafeDeviceLoginVerify(bot: Bot, url: String): String? {
public override suspend fun onSolveUnsafeDeviceLoginVerify(bot: Bot, url: String): String? {
return openWindow("Mirai UnsafeDeviceLoginVerify(${bot.id})") {
JLabel(
"""

View File

@ -3,4 +3,4 @@ package net.mamoe.mirai.utils
/**
* 图片文件过大
*/
actual class OverFileSizeMaxException : IllegalStateException()
public actual class OverFileSizeMaxException : IllegalStateException()

View File

@ -15,6 +15,7 @@ package net.mamoe.mirai.utils
import java.io.ByteArrayOutputStream
import java.io.PrintStream
import java.text.DateFormat
import java.text.SimpleDateFormat
import java.util.*
@ -43,15 +44,15 @@ import java.util.*
* @see SingleFileLogger 使用单一文件记录日志
* @see DirectoryLogger 在一个目录中按日期存放文件记录日志, 自动清理过期日志
*/
actual open class PlatformLogger @JvmOverloads constructor(
override val identity: String? = "Mirai",
public actual open class PlatformLogger @JvmOverloads constructor(
public override val identity: String? = "Mirai",
/**
* 日志输出. 不会自动添加换行
*/
open val output: (String) -> Unit,
val isColored: Boolean = true
public open val output: (String) -> Unit,
public val isColored: Boolean = true
) : MiraiLoggerPlatformBase() {
actual constructor(identity: String?) : this(identity, ::println)
public actual constructor(identity: String?) : this(identity, ::println)
/**
* 输出一条日志. [message] 末尾可能不带换行符.
@ -75,39 +76,39 @@ actual open class PlatformLogger @JvmOverloads constructor(
SimpleLogger.LogPriority.DEBUG -> Color.LIGHT_CYAN
}
override fun verbose0(message: String?) = printLog(message, SimpleLogger.LogPriority.VERBOSE)
public override fun verbose0(message: String?): Unit = printLog(message, SimpleLogger.LogPriority.VERBOSE)
override fun verbose0(message: String?, e: Throwable?) {
public override fun verbose0(message: String?, e: Throwable?) {
if (e != null) verbose((message ?: e.toString()) + "\n${e.stackTraceString}")
else verbose(message.toString())
}
override fun info0(message: String?) = printLog(message, SimpleLogger.LogPriority.INFO)
override fun info0(message: String?, e: Throwable?) {
public override fun info0(message: String?): Unit = printLog(message, SimpleLogger.LogPriority.INFO)
public override fun info0(message: String?, e: Throwable?) {
if (e != null) info((message ?: e.toString()) + "\n${e.stackTraceString}")
else info(message.toString())
}
override fun warning0(message: String?) = printLog(message, SimpleLogger.LogPriority.WARNING)
override fun warning0(message: String?, e: Throwable?) {
public override fun warning0(message: String?): Unit = printLog(message, SimpleLogger.LogPriority.WARNING)
public override fun warning0(message: String?, e: Throwable?) {
if (e != null) warning((message ?: e.toString()) + "\n${e.stackTraceString}")
else warning(message.toString())
}
override fun error0(message: String?) = printLog(message, SimpleLogger.LogPriority.ERROR)
override fun error0(message: String?, e: Throwable?) {
public override fun error0(message: String?): Unit = printLog(message, SimpleLogger.LogPriority.ERROR)
public override fun error0(message: String?, e: Throwable?) {
if (e != null) error((message ?: e.toString()) + "\n${e.stackTraceString}")
else error(message.toString())
}
override fun debug0(message: String?) = printLog(message, SimpleLogger.LogPriority.DEBUG)
override fun debug0(message: String?, e: Throwable?) {
public override fun debug0(message: String?): Unit = printLog(message, SimpleLogger.LogPriority.DEBUG)
public override fun debug0(message: String?, e: Throwable?) {
if (e != null) debug((message ?: e.toString()) + "\n${e.stackTraceString}")
else debug(message.toString())
}
@SinceMirai("1.1.0")
protected open val timeFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.SIMPLIFIED_CHINESE)
protected open val timeFormat: DateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.SIMPLIFIED_CHINESE)
private val currentTimeFormatted get() = timeFormat.format(Date())

View File

@ -30,5 +30,5 @@ import java.util.zip.Inflater
/**
* 时间戳
*/
actual val currentTimeMillis: Long
public actual val currentTimeMillis: Long
get() = System.currentTimeMillis()

View File

@ -12,9 +12,7 @@ package net.mamoe.mirai.utils
import kotlinx.io.core.toByteArray
import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
import kotlinx.serialization.UnstableDefault
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonConfiguration
import net.mamoe.mirai.utils.internal.md5
import java.io.File
import kotlin.random.Random
@ -23,7 +21,7 @@ import kotlin.random.nextInt
/**
* 加载一个设备信息. 若文件不存在或为空则随机并创建一个设备信息保存.
*/
fun File.loadAsDeviceInfo(json: Json, context: Context = ContextImpl()): DeviceInfo {
public fun File.loadAsDeviceInfo(json: Json, context: Context = ContextImpl()): DeviceInfo {
if (!this.exists() || this.length() == 0L) {
return SystemDeviceInfo(context).also {
this.writeText(json.stringify(SystemDeviceInfo.serializer(), it))
@ -35,55 +33,57 @@ fun File.loadAsDeviceInfo(json: Json, context: Context = ContextImpl()): DeviceI
}
@Serializable
actual open class SystemDeviceInfo actual constructor() : DeviceInfo() {
actual constructor(context: Context) : this() {
public actual open class SystemDeviceInfo actual constructor() : DeviceInfo() {
public actual constructor(context: Context) : this() {
this.context = context
}
@Transient
final override lateinit var context: Context
public final override lateinit var context: Context
override val display: ByteArray = "MIRAI.${getRandomString(6, '0'..'9')}.001".toByteArray()
override val product: ByteArray = "mirai".toByteArray()
override val device: ByteArray = "mirai".toByteArray()
override val board: ByteArray = "mirai".toByteArray()
override val brand: ByteArray = "mamoe".toByteArray()
override val model: ByteArray = "mirai".toByteArray()
override val bootloader: ByteArray = "unknown".toByteArray()
override val fingerprint: ByteArray =
public override val display: ByteArray = "MIRAI.${getRandomString(6, '0'..'9')}.001".toByteArray()
public override val product: ByteArray = "mirai".toByteArray()
public override val device: ByteArray = "mirai".toByteArray()
public override val board: ByteArray = "mirai".toByteArray()
public override val brand: ByteArray = "mamoe".toByteArray()
public override val model: ByteArray = "mirai".toByteArray()
public override val bootloader: ByteArray = "unknown".toByteArray()
public override val fingerprint: ByteArray =
"mamoe/mirai/mirai:10/MIRAI.200122.001/${getRandomString(7, '0'..'9')}:user/release-keys".toByteArray()
override val bootId: ByteArray = ExternalImage.generateUUID(getRandomByteArray(16).md5()).toByteArray()
override val procVersion: ByteArray =
public override val bootId: ByteArray = ExternalImage.generateUUID(getRandomByteArray(16).md5()).toByteArray()
public override val procVersion: ByteArray =
"Linux version 3.0.31-${getRandomString(8)} (android-build@xxx.xxx.xxx.xxx.com)".toByteArray()
override val baseBand: ByteArray = byteArrayOf()
override val version: Version = Version
override val simInfo: ByteArray = "T-Mobile".toByteArray()
override val osType: ByteArray = "android".toByteArray()
override val macAddress: ByteArray = "02:00:00:00:00:00".toByteArray()
override val wifiBSSID: ByteArray? = "02:00:00:00:00:00".toByteArray()
override val wifiSSID: ByteArray? = "<unknown ssid>".toByteArray()
override val imsiMd5: ByteArray = getRandomByteArray(16).md5()
override val imei: String = getRandomString(15, '0'..'9')
override val androidId: ByteArray get() = display
override val apn: ByteArray = "wifi".toByteArray()
public override val baseBand: ByteArray = byteArrayOf()
public override val version: Version = Version
public override val simInfo: ByteArray = "T-Mobile".toByteArray()
public override val osType: ByteArray = "android".toByteArray()
public override val macAddress: ByteArray = "02:00:00:00:00:00".toByteArray()
public override val wifiBSSID: ByteArray? = "02:00:00:00:00:00".toByteArray()
public override val wifiSSID: ByteArray? = "<unknown ssid>".toByteArray()
public override val imsiMd5: ByteArray = getRandomByteArray(16).md5()
public override val imei: String = getRandomString(15, '0'..'9')
public override val androidId: ByteArray get() = display
public override val apn: ByteArray = "wifi".toByteArray()
@Serializable
actual object Version : DeviceInfo.Version {
override val incremental: ByteArray = "5891938".toByteArray()
override val release: ByteArray = "10".toByteArray()
override val codename: ByteArray = "REL".toByteArray()
override val sdk: Int = 29
public actual object Version : DeviceInfo.Version {
public override val incremental: ByteArray = "5891938".toByteArray()
public override val release: ByteArray = "10".toByteArray()
public override val codename: ByteArray = "REL".toByteArray()
public override val sdk: Int = 29
}
}
/**
* 生成长度为 [length], 元素为随机 `0..255` [ByteArray]
*/
@JvmSynthetic
internal fun getRandomByteArray(length: Int): ByteArray = ByteArray(length) { Random.nextInt(0..255).toByte() }
/**
* 随机生成长度为 [length] [String].
*/
@JvmSynthetic
internal fun getRandomString(length: Int): String =
getRandomString(length, *defaultRanges)
@ -92,11 +92,13 @@ private val defaultRanges: Array<CharRange> = arrayOf('a'..'z', 'A'..'Z', '0'..'
/**
* 根据所给 [charRange] 随机生成长度为 [length] [String].
*/
@JvmSynthetic
internal fun getRandomString(length: Int, charRange: CharRange): String =
String(CharArray(length) { charRange.random() })
/**
* 根据所给 [charRanges] 随机生成长度为 [length] [String].
*/
@JvmSynthetic
internal fun getRandomString(length: Int, vararg charRanges: CharRange): String =
String(CharArray(length) { charRanges[Random.Default.nextInt(0..charRanges.lastIndex)].random() })

View File

@ -11,4 +11,4 @@ package net.mamoe.mirai.utils
import java.lang.ref.WeakReference
actual typealias WeakRef<T> = WeakReference<T>
public actual typealias WeakRef<T> = WeakReference<T>

View File

@ -14,6 +14,8 @@ description = "Mirai serialization module"
val isAndroidSDKAvailable: Boolean by project
kotlin {
explicitApi()
if (isAndroidSDKAvailable) {
apply(from = rootProject.file("gradle/android.gradle"))
android("android") {
@ -36,7 +38,7 @@ kotlin {
jvm()
sourceSets {
sourceSets.apply {
all {
languageSettings.enableLanguageFeature("InlineClasses")
languageSettings.useExperimentalAnnotation("kotlin.Experimental")
@ -47,12 +49,16 @@ kotlin {
languageSettings.useExperimentalAnnotation("kotlin.experimental.ExperimentalTypeInference")
languageSettings.useExperimentalAnnotation("kotlin.time.ExperimentalTime")
languageSettings.useExperimentalAnnotation("kotlin.contracts.ExperimentalContracts")
languageSettings.languageVersion = "1.3"
languageSettings.apiVersion = "1.3"
languageSettings.progressiveMode = true
}
val commonMain by getting {
dependencies {
api(kotlin("stdlib"))
api(kotlin("stdlib", Versions.Kotlin.stdlib))
api(project(":mirai-core"))
}
}

View File

@ -22,8 +22,9 @@ pluginManagement {
rootProject.name = 'mirai'
include(':mirai-core')
include(':mirai-core-qqandroid')
include(':mirai-serialization')
//include(':mirai-core-qqandroid')
//include(':mirai-serialization')
//include(':compatibility-validator') // THIS WILL CAUSE A DEPENDENCY RESOLUTION BUG
//include(':java-compatibility-validator')