Update docs

This commit is contained in:
Him188 2020-02-10 16:01:59 +08:00
parent d1b1c76588
commit fda2040de9
11 changed files with 33 additions and 91 deletions

View File

@ -1,23 +0,0 @@
/*
* Copyright 2020 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
package net.mamoe.mirai.qqandroid.event
import net.mamoe.mirai.Bot
import net.mamoe.mirai.data.Packet
import net.mamoe.mirai.event.events.BotEvent
/**
* 被挤下线
*/
data class ForceOfflineEvent(
override val bot: Bot,
val title: String,
val tips: String
) : BotEvent(), Packet

View File

@ -21,6 +21,7 @@ import kotlinx.io.core.use
import net.mamoe.mirai.contact.ContactList
import net.mamoe.mirai.contact.Member
import net.mamoe.mirai.contact.MemberPermission
import net.mamoe.mirai.event.events.ForceOfflineEvent
import net.mamoe.mirai.data.MultiPacket
import net.mamoe.mirai.data.Packet
import net.mamoe.mirai.event.*
@ -29,7 +30,6 @@ import net.mamoe.mirai.qqandroid.GroupImpl
import net.mamoe.mirai.qqandroid.MemberImpl
import net.mamoe.mirai.qqandroid.QQAndroidBot
import net.mamoe.mirai.qqandroid.QQImpl
import net.mamoe.mirai.qqandroid.event.ForceOfflineEvent
import net.mamoe.mirai.qqandroid.event.PacketReceivedEvent
import net.mamoe.mirai.qqandroid.network.protocol.data.proto.MsgSvc
import net.mamoe.mirai.qqandroid.network.protocol.packet.*

View File

@ -11,13 +11,13 @@ package net.mamoe.mirai.qqandroid.network.protocol.packet.chat.receive
import kotlinx.io.core.ByteReadPacket
import kotlinx.io.core.discardExact
import net.mamoe.mirai.event.events.ForceOfflineEvent
import net.mamoe.mirai.data.MultiPacket
import net.mamoe.mirai.data.Packet
import net.mamoe.mirai.event.BroadcastControllable
import net.mamoe.mirai.message.FriendMessage
import net.mamoe.mirai.message.data.MessageChain
import net.mamoe.mirai.qqandroid.QQAndroidBot
import net.mamoe.mirai.qqandroid.event.ForceOfflineEvent
import net.mamoe.mirai.qqandroid.io.serialization.decodeUniPacket
import net.mamoe.mirai.qqandroid.io.serialization.readProtoBuf
import net.mamoe.mirai.qqandroid.io.serialization.toByteArray
@ -32,11 +32,7 @@ import net.mamoe.mirai.qqandroid.network.protocol.data.proto.MsgComm
import net.mamoe.mirai.qqandroid.network.protocol.data.proto.MsgSvc
import net.mamoe.mirai.qqandroid.network.protocol.data.proto.SyncCookie
import net.mamoe.mirai.qqandroid.network.protocol.packet.*
import net.mamoe.mirai.qqandroid.message.toMessageChain
import net.mamoe.mirai.qqandroid.message.toRichTextElems
import net.mamoe.mirai.utils.MiraiDebugAPI
import net.mamoe.mirai.utils.MiraiInternalAPI
import net.mamoe.mirai.utils.cryptor.contentToString
import net.mamoe.mirai.utils.currentTimeSeconds
import kotlin.math.absoluteValue
import kotlin.random.Random

View File

@ -28,7 +28,7 @@ interface Contact : CoroutineScope {
* 这个联系人所属 [Bot].
*/
@WeakRefProperty
val bot: Bot // weak ref
val bot: Bot
/**
* 可以是 QQ 号码或者群号码.

View File

@ -1,17 +0,0 @@
/*
* Copyright 2020 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
package net.mamoe.mirai.data
/**
* 被挤下线. 只能获取到中文的消息
*/
inline class ConnectionOccupiedEvent(val message: String) : EventPacket {
override fun toString(): String = "ConnectionOccupiedEvent(${message.replace("\n", "").replace("\r", "")})"
}

View File

@ -1,36 +0,0 @@
/*
* Copyright 2020 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
package net.mamoe.mirai.data
import net.mamoe.mirai.contact.ContactList
import net.mamoe.mirai.contact.Group
import net.mamoe.mirai.contact.Member
import kotlin.jvm.JvmField
/**
* 群资料
*/
@Suppress("MemberVisibilityCanBePrivate") // 将来使用
class GroupInfo(
@JvmField internal var _group: Group,
@JvmField internal var _owner: Member,
@JvmField internal var _name: String,
@JvmField internal var _announcement: String,
@JvmField internal var _members: ContactList<Member>
) {
val group: Group get() = _group
val owner: Member get() = _owner
val name: String get() = _name
val announcement: String get() = _announcement
val members: ContactList<Member> get() = _members
override fun toString(): String =
"GroupInfo(id=${group.id}, owner=$owner, name=$name, announcement=$announcement, members=${members.idContentString}"
}

View File

@ -53,7 +53,7 @@ data class Profile(
/**
* 性别
*/ // 在 Android 中 enum 的使用被严格控制.
*/
enum class Gender(val value: Byte) {
SECRET(0),
MALE(1),

View File

@ -180,6 +180,12 @@ class MessageSubscribersBuilder<T : MessagePacket<*, *>>(
infix fun nand(another: ListeningFilter): ListeningFilter =
ListeningFilter { !filter.invoke(this, it) || !another.filter.invoke(this, it) }
/**
* 进行逻辑 `not`
*/
fun not(): ListeningFilter =
ListeningFilter { !filter.invoke(this, it) }
/**
* 启动事件监听.
*/
@ -359,7 +365,7 @@ class MessageSubscribersBuilder<T : MessagePacket<*, *>>(
*/
@MessageDsl
inline fun sentByFriend(crossinline onEvent: MessageListener<FriendMessage>): Listener<T> =
content({ this is FriendMessage }){
content({ this is FriendMessage }) {
onEvent(this as FriendMessage, it)
}

View File

@ -0,0 +1,13 @@
package net.mamoe.mirai.event.events
import net.mamoe.mirai.Bot
import net.mamoe.mirai.data.Packet
/**
* 被挤下线
*/
data class ForceOfflineEvent(
override val bot: Bot,
val title: String,
val tips: String
) : BotEvent(), Packet

View File

@ -42,6 +42,8 @@ fun MiraiLogger.withSwitch(default: Boolean = true): MiraiLoggerWithSwitch = Mir
*
* 在定义 logger 变量时, 请一直使用 [MiraiLogger] 或者 [MiraiLoggerWithSwitch].
*
* Mirai 内建三种日志实现, 分别是 [SimpleLogger], [PlatformLogger], [SilentLogger]
*
* @see SimpleLogger 简易 logger, 它将所有的日志记录操作都转移给 lambda `(String?, Throwable?) -> Unit`
* @see PlatformLogger 各个平台下的默认日志记录实现.
* @see SilentLogger 忽略任何日志记录操作的 logger 实例.

View File

@ -13,6 +13,8 @@ package net.mamoe.mirai.utils
import kotlin.reflect.KProperty
// TODO: 2020/2/10 添加中文 doc
/**
* WeakRef that `getValue` for delegation throws an [IllegalStateException] if the referent is released by GC. Therefore it returns notnull value only
*/
@ -32,13 +34,12 @@ operator fun <T> UnsafeWeakRef<T>.getValue(thisRef: Any?, property: KProperty<*>
/**
* Weak Reference.
* In JVM, this is implemented as a typealias to `WeakReference` from JDK.
* On JVM, it is implemented as a typealias referring to `WeakReference` from JDK.
*
* Reference details:
* In JVM, instances of objects are stored in the Heap and are accessed via references.
* GC can automatically collect and release the memory used by objects that are not directly referred by any other.
* WeakReference is not direct reference, therefore it does no influence on garbage collection.
* Using weak reference can help GC with that.
* Details:
* On JVM, instances of objects are stored in the JVM Heap and are accessed via references.
* GC(garbage collection) can automatically collect and release the memory used by objects that are not directly referred by any other.
* [WeakRef] is not a direct reference, therefore it doesn't hinder GC.
*
* @see weakRef provides a WeakRef
* @see unsafeWeakRef provides a UnsafeWeakRef