mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-21 12:32:23 +08:00
Add docs
This commit is contained in:
parent
52dc100b19
commit
7973858bd7
@ -17,16 +17,26 @@ import net.mamoe.mirai.qqandroid.network.protocol.packet.chat.image.ImgStore
|
|||||||
import net.mamoe.mirai.qqandroid.network.protocol.packet.chat.receive.MessageSvc
|
import net.mamoe.mirai.qqandroid.network.protocol.packet.chat.receive.MessageSvc
|
||||||
import net.mamoe.mirai.qqandroid.network.protocol.packet.withUse
|
import net.mamoe.mirai.qqandroid.network.protocol.packet.withUse
|
||||||
import net.mamoe.mirai.qqandroid.utils.toIpV4AddressString
|
import net.mamoe.mirai.qqandroid.utils.toIpV4AddressString
|
||||||
import net.mamoe.mirai.utils.ExternalImage
|
import net.mamoe.mirai.utils.*
|
||||||
import net.mamoe.mirai.utils.MiraiInternalAPI
|
|
||||||
import net.mamoe.mirai.utils.getValue
|
|
||||||
import net.mamoe.mirai.utils.io.PlatformSocket
|
import net.mamoe.mirai.utils.io.PlatformSocket
|
||||||
import net.mamoe.mirai.utils.io.discardExact
|
import net.mamoe.mirai.utils.io.discardExact
|
||||||
import net.mamoe.mirai.utils.unsafeWeakRef
|
|
||||||
import kotlin.coroutines.CoroutineContext
|
import kotlin.coroutines.CoroutineContext
|
||||||
import kotlin.properties.Delegates
|
import kotlin.properties.Delegates
|
||||||
|
|
||||||
internal abstract class ContactImpl : Contact
|
internal abstract class ContactImpl : Contact {
|
||||||
|
override fun hashCode(): Int {
|
||||||
|
var result = bot.hashCode()
|
||||||
|
result = 31 * result + id.hashCode()
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
if (this === other) return true
|
||||||
|
if (other !is Contact) return false
|
||||||
|
if (this::class != other::class) return false
|
||||||
|
return this.id == other.id && this.bot == other.bot
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
internal class QQImpl(bot: QQAndroidBot, override val coroutineContext: CoroutineContext, override val id: Long) : ContactImpl(), QQ {
|
internal class QQImpl(bot: QQAndroidBot, override val coroutineContext: CoroutineContext, override val id: Long) : ContactImpl(), QQ {
|
||||||
override val bot: QQAndroidBot by bot.unsafeWeakRef()
|
override val bot: QQAndroidBot by bot.unsafeWeakRef()
|
||||||
@ -60,8 +70,11 @@ internal class QQImpl(bot: QQAndroidBot, override val coroutineContext: Coroutin
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
|
if (this === other) return true
|
||||||
return other is QQ && other.id == this.id
|
return other is QQ && other.id == this.id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int = super.hashCode()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -78,10 +91,8 @@ internal class MemberImpl(
|
|||||||
|
|
||||||
|
|
||||||
override var groupCard: String by Delegates.observable(initGroupCard) { _, old, new ->
|
override var groupCard: String by Delegates.observable(initGroupCard) { _, old, new ->
|
||||||
check(group.botPermission != MemberPermission.MEMBER) {
|
group.checkBotPermissionOperator()
|
||||||
"Permission Denied when trying to edit group card for $this"
|
if (new != old) {
|
||||||
}
|
|
||||||
if (group.botPermission != MemberPermission.MEMBER && new != old) {
|
|
||||||
|
|
||||||
launch {
|
launch {
|
||||||
bot.network.run {
|
bot.network.run {
|
||||||
@ -96,9 +107,7 @@ internal class MemberImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override var specialTitle: String by Delegates.observable(initSpecialTitle) { _, old, new ->
|
override var specialTitle: String by Delegates.observable(initSpecialTitle) { _, old, new ->
|
||||||
check(group.botPermission == MemberPermission.OWNER) {
|
group.checkBotPermissionOperator()
|
||||||
"Permission Denied when trying to edit special title for $this, need to be OWNER"
|
|
||||||
}
|
|
||||||
if (new != old) {
|
if (new != old) {
|
||||||
launch {
|
launch {
|
||||||
bot.network.run {
|
bot.network.run {
|
||||||
@ -148,8 +157,11 @@ internal class MemberImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
|
if (this === other) return true
|
||||||
return other is Member && other.id == this.id
|
return other is Member && other.id == this.id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int = super.hashCode()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -169,12 +181,13 @@ internal class GroupImpl(
|
|||||||
initMuteAll: Boolean,
|
initMuteAll: Boolean,
|
||||||
initAutoApprove: Boolean,
|
initAutoApprove: Boolean,
|
||||||
initAnonymousChat: Boolean,
|
initAnonymousChat: Boolean,
|
||||||
override var members: ContactList<Member>
|
override val members: ContactList<Member>
|
||||||
) : ContactImpl(), Group {
|
) : ContactImpl(), Group {
|
||||||
|
|
||||||
override var name by Delegates.observable(initName) { _, oldValue, newValue ->
|
override var name by Delegates.observable(initName) { _, oldValue, newValue ->
|
||||||
if (this.botPermission != MemberPermission.MEMBER && oldValue != newValue) {
|
this.checkBotPermissionOperator()
|
||||||
this.bot.launch {
|
if (oldValue != newValue) {
|
||||||
|
launch {
|
||||||
bot.network.run {
|
bot.network.run {
|
||||||
TroopManagement.GroupOperation.name(
|
TroopManagement.GroupOperation.name(
|
||||||
client = bot.client,
|
client = bot.client,
|
||||||
@ -187,8 +200,9 @@ internal class GroupImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override var announcement: String by Delegates.observable(initAnnouncement) { _, oldValue, newValue ->
|
override var announcement: String by Delegates.observable(initAnnouncement) { _, oldValue, newValue ->
|
||||||
if (this.botPermission != MemberPermission.MEMBER && oldValue != newValue) {
|
this.checkBotPermissionOperator()
|
||||||
this.bot.launch {
|
if (oldValue != newValue) {
|
||||||
|
launch {
|
||||||
bot.network.run {
|
bot.network.run {
|
||||||
TroopManagement.GroupOperation.memo(
|
TroopManagement.GroupOperation.memo(
|
||||||
client = bot.client,
|
client = bot.client,
|
||||||
@ -202,8 +216,9 @@ internal class GroupImpl(
|
|||||||
|
|
||||||
|
|
||||||
override var allowMemberInvite: Boolean by Delegates.observable(initAllowMemberInvite) { _, oldValue, newValue ->
|
override var allowMemberInvite: Boolean by Delegates.observable(initAllowMemberInvite) { _, oldValue, newValue ->
|
||||||
if (this.botPermission != MemberPermission.MEMBER && oldValue != newValue) {
|
this.checkBotPermissionOperator()
|
||||||
this.bot.launch {
|
if (oldValue != newValue) {
|
||||||
|
launch {
|
||||||
bot.network.run {
|
bot.network.run {
|
||||||
TroopManagement.GroupOperation.allowMemberInvite(
|
TroopManagement.GroupOperation.allowMemberInvite(
|
||||||
client = bot.client,
|
client = bot.client,
|
||||||
@ -216,16 +231,17 @@ internal class GroupImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override var autoApprove: Boolean by Delegates.observable(initAutoApprove) { _, oldValue, newValue ->
|
override var autoApprove: Boolean by Delegates.observable(initAutoApprove) { _, oldValue, newValue ->
|
||||||
//暂时也不能改
|
TODO("Group.autoApprove implementation")
|
||||||
}
|
}
|
||||||
|
|
||||||
override val anonymousChat: Boolean by Delegates.observable(initAnonymousChat) { _, oldValue, newValue ->
|
override val anonymousChat: Boolean by Delegates.observable(initAnonymousChat) { _, oldValue, newValue ->
|
||||||
//暂时不能改
|
TODO("Group.anonymousChat implementation")
|
||||||
}
|
}
|
||||||
|
|
||||||
override var confessTalk: Boolean by Delegates.observable(initConfessTalk) { _, oldValue, newValue ->
|
override var confessTalk: Boolean by Delegates.observable(initConfessTalk) { _, oldValue, newValue ->
|
||||||
if (this.botPermission != MemberPermission.MEMBER && oldValue != newValue) {
|
this.checkBotPermissionOperator()
|
||||||
this.bot.launch {
|
if (oldValue != newValue) {
|
||||||
|
launch {
|
||||||
bot.network.run {
|
bot.network.run {
|
||||||
TroopManagement.GroupOperation.confessTalk(
|
TroopManagement.GroupOperation.confessTalk(
|
||||||
client = bot.client,
|
client = bot.client,
|
||||||
@ -239,8 +255,9 @@ internal class GroupImpl(
|
|||||||
|
|
||||||
|
|
||||||
override var muteAll: Boolean by Delegates.observable(initMuteAll) { _, oldValue, newValue ->
|
override var muteAll: Boolean by Delegates.observable(initMuteAll) { _, oldValue, newValue ->
|
||||||
if (this.botPermission != MemberPermission.MEMBER && oldValue != newValue) {
|
this.checkBotPermissionOperator()
|
||||||
this.bot.launch {
|
if (oldValue != newValue) {
|
||||||
|
launch {
|
||||||
bot.network.run {
|
bot.network.run {
|
||||||
TroopManagement.GroupOperation.muteAll(
|
TroopManagement.GroupOperation.muteAll(
|
||||||
client = bot.client,
|
client = bot.client,
|
||||||
@ -254,6 +271,7 @@ internal class GroupImpl(
|
|||||||
|
|
||||||
|
|
||||||
override lateinit var owner: Member
|
override lateinit var owner: Member
|
||||||
|
@UseExperimental(MiraiExperimentalAPI::class)
|
||||||
override var botPermission: MemberPermission = MemberPermission.MEMBER
|
override var botPermission: MemberPermission = MemberPermission.MEMBER
|
||||||
|
|
||||||
override suspend fun quit(): Boolean {
|
override suspend fun quit(): Boolean {
|
||||||
@ -369,6 +387,9 @@ internal class GroupImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
|
if (this === other) return true
|
||||||
return other is Group && other.id == this.id
|
return other is Group && other.id == this.id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int = super.hashCode()
|
||||||
}
|
}
|
@ -5,6 +5,7 @@ import net.mamoe.mirai.BotAccount
|
|||||||
import net.mamoe.mirai.BotImpl
|
import net.mamoe.mirai.BotImpl
|
||||||
import net.mamoe.mirai.contact.*
|
import net.mamoe.mirai.contact.*
|
||||||
import net.mamoe.mirai.data.AddFriendResult
|
import net.mamoe.mirai.data.AddFriendResult
|
||||||
|
import net.mamoe.mirai.event.events.BotEvent
|
||||||
import net.mamoe.mirai.message.data.Image
|
import net.mamoe.mirai.message.data.Image
|
||||||
import net.mamoe.mirai.qqandroid.network.QQAndroidBotNetworkHandler
|
import net.mamoe.mirai.qqandroid.network.QQAndroidBotNetworkHandler
|
||||||
import net.mamoe.mirai.qqandroid.network.QQAndroidClient
|
import net.mamoe.mirai.qqandroid.network.QQAndroidClient
|
||||||
@ -28,6 +29,7 @@ internal abstract class QQAndroidBotBase constructor(
|
|||||||
configuration: BotConfiguration
|
configuration: BotConfiguration
|
||||||
) : BotImpl<QQAndroidBotNetworkHandler>(account, configuration) {
|
) : BotImpl<QQAndroidBotNetworkHandler>(account, configuration) {
|
||||||
val client: QQAndroidClient = QQAndroidClient(context, account, bot = @Suppress("LeakingThis") this as QQAndroidBot)
|
val client: QQAndroidClient = QQAndroidClient(context, account, bot = @Suppress("LeakingThis") this as QQAndroidBot)
|
||||||
|
internal var firstLoginSucceed: Boolean = false
|
||||||
override val uin: Long get() = client.uin
|
override val uin: Long get() = client.uin
|
||||||
override val qqs: ContactList<QQ> = ContactList(LockFreeLinkedList())
|
override val qqs: ContactList<QQ> = ContactList(LockFreeLinkedList())
|
||||||
|
|
||||||
@ -56,6 +58,10 @@ internal abstract class QQAndroidBotBase constructor(
|
|||||||
?: throw NoSuchElementException("Can not found group with GroupCode=${id}")
|
?: throw NoSuchElementException("Can not found group with GroupCode=${id}")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onEvent(event: BotEvent): Boolean {
|
||||||
|
return firstLoginSucceed
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun addFriend(id: Long, message: String?, remark: String?): AddFriendResult {
|
override suspend fun addFriend(id: Long, message: String?, remark: String?): AddFriendResult {
|
||||||
TODO("not implemented")
|
TODO("not implemented")
|
||||||
}
|
}
|
||||||
@ -64,6 +70,7 @@ internal abstract class QQAndroidBotBase constructor(
|
|||||||
TODO("not implemented")
|
TODO("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("OverridingDeprecatedMember")
|
||||||
override suspend fun Image.downloadAsByteArray(): ByteArray {
|
override suspend fun Image.downloadAsByteArray(): ByteArray {
|
||||||
TODO("not implemented")
|
TODO("not implemented")
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ package net.mamoe.mirai
|
|||||||
|
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import net.mamoe.mirai.event.broadcast
|
import net.mamoe.mirai.event.broadcast
|
||||||
|
import net.mamoe.mirai.event.events.BotEvent
|
||||||
import net.mamoe.mirai.event.events.BotOfflineEvent
|
import net.mamoe.mirai.event.events.BotOfflineEvent
|
||||||
import net.mamoe.mirai.network.BotNetworkHandler
|
import net.mamoe.mirai.network.BotNetworkHandler
|
||||||
import net.mamoe.mirai.network.closeAndJoin
|
import net.mamoe.mirai.network.closeAndJoin
|
||||||
@ -56,6 +57,11 @@ abstract class BotImpl<N : BotNetworkHandler> constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 可阻止事件广播
|
||||||
|
*/
|
||||||
|
abstract fun onEvent(event: BotEvent): Boolean
|
||||||
|
|
||||||
// region network
|
// region network
|
||||||
|
|
||||||
final override val network: N get() = _network
|
final override val network: N get() = _network
|
||||||
|
@ -2,7 +2,10 @@
|
|||||||
|
|
||||||
package net.mamoe.mirai.event
|
package net.mamoe.mirai.event
|
||||||
|
|
||||||
|
import net.mamoe.mirai.BotImpl
|
||||||
|
import net.mamoe.mirai.event.events.BotEvent
|
||||||
import net.mamoe.mirai.event.internal.broadcastInternal
|
import net.mamoe.mirai.event.internal.broadcastInternal
|
||||||
|
import net.mamoe.mirai.utils.MiraiInternalAPI
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 可被监听的.
|
* 可被监听的.
|
||||||
@ -47,7 +50,7 @@ abstract class Event : Subscribable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 实现这个接口的事件可以被取消. 在广播中取消不会影响广播过程.
|
* 实现这个接口的事件([Event])可以被取消. 在广播中取消不会影响广播过程.
|
||||||
*/
|
*/
|
||||||
interface Cancellable : Subscribable {
|
interface Cancellable : Subscribable {
|
||||||
val cancelled: Boolean
|
val cancelled: Boolean
|
||||||
@ -58,9 +61,12 @@ interface Cancellable : Subscribable {
|
|||||||
/**
|
/**
|
||||||
* 广播一个事件的唯一途径.
|
* 广播一个事件的唯一途径.
|
||||||
*/
|
*/
|
||||||
suspend fun <E : Subscribable> E.broadcast(): E {
|
@UseExperimental(MiraiInternalAPI::class)
|
||||||
|
suspend fun <E : Subscribable> E.broadcast(): E = apply {
|
||||||
|
if (this is BotEvent && !(this.bot as BotImpl<*>).onEvent(this)) {
|
||||||
|
return@apply
|
||||||
|
}
|
||||||
this@broadcast.broadcastInternal() // inline, no extra cost
|
this@broadcast.broadcastInternal() // inline, no extra cost
|
||||||
return this
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -98,7 +98,7 @@ abstract class MessagePacketBase<TSender : QQ, TSubject : Contact>(_bot: Bot) :
|
|||||||
|
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
// region Image download
|
// region 下载图片
|
||||||
/**
|
/**
|
||||||
* 将图片下载到内存.
|
* 将图片下载到内存.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user