Commit 719b5ac7 authored by Him188's avatar Him188

Explicit api mode

parent 0a7ebffd
......@@ -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}")
}
......
......@@ -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"
......
......@@ -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"))
......
......@@ -3,4 +3,5 @@ kotlin.code.style=official
# config
kotlin.incremental.multiplatform=true
kotlin.parallel.tasks.in.project=true
org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=512m -Dfile.encoding=UTF-8
\ No newline at end of file
org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=512m -Dfile.encoding=UTF-8
#kotlin.mpp.enableGranularSourceSetsMetadata=true
\ No newline at end of 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"))
......
......@@ -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
......
......@@ -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 {
dependencies {
api(kotlin("stdlib"))
api(kotlin("stdlib", Versions.Kotlin.stdlib))
api(kotlin("serialization"))
api(kotlin("reflect"))
......
......@@ -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,
......
......@@ -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
......
......@@ -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
) + "]"
......
......@@ -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
}
\ No newline at end of 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
\ No newline at end of file
public inline val BotIsBeingMutedException.botMuteRemaining: Int get() = target.botMuteRemaining
\ No newline at end of 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"
/**
......
......@@ -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 {
......
......@@ -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())
\ No newline at end of file
public suspend inline fun Member.mute(durationSeconds: Long): Unit = this.mute(durationSeconds.toInt())
\ No newline at end of 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)
\ No newline at end of file
): Unit = checkBotPermission(MemberPermission.ADMINISTRATOR, lazyMessage)
\ No newline at end of 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
}
\ No newline at end of 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
}
\ No newline at end of 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,
......
......@@ -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,
......
......@@ -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
/*
/**
......
......@@ -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
}
\ No newline at end of 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 }
}
}
\ No newline at end of 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
}
......@@ -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
......
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)
}
......@@ -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 图片
......
......@@ -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()
......@@ -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
}
\ No newline at end of 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,
......
......@@ -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 {
......
......@@ -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,
......
......@@ -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,
......
......@@ -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
......
......@@ -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
}
......@@ -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)"
}
......@@ -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)"
}
\ No newline at end of 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
}
\ No newline at end of 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
......@@ -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)"
}
\ No newline at end of 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()
}
\ No newline at end of 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)
\ No newline at end of file
public inline fun Member.at(): At = At(this)
\ No newline at end of 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)
}
......
......@@ -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())}]"
......
......@@ -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)
\ No newline at end of file
public inline fun String.toMessage(): PlainText = PlainText(this)
\ No newline at end of file
......@@ -7,4 +7,4 @@ import net.mamoe.mirai.Bot
/**
* 当 [Bot] 被迫下线时抛出, 作为 [Job.cancel] 的 `cause`
*/
class ForceOfflineException(override val message: String?) : CancellationException(message)
\ No newline at end of file
public class ForceOfflineException(public override val message: String?) : CancellationException(message)
\ No newline at end of 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
......@@ -18,4 +18,4 @@ import kotlin.jvm.JvmName
/**
* 图片文件过大
*/ // 不要删除多平台结构, 这是 kotlin 的 bug
expect class OverFileSizeMaxException() : IllegalStateException
\ No newline at end of file
public expect class OverFileSizeMaxException() : IllegalStateException
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment