mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-05 07:30:09 +08:00
Add blocking bridges to events
This commit is contained in:
parent
5459e1c577
commit
fefadad3f4
@ -13,8 +13,8 @@
|
|||||||
|
|
||||||
package net.mamoe.mirai.event.events
|
package net.mamoe.mirai.event.events
|
||||||
|
|
||||||
|
import net.mamoe.kjbb.JvmBlockingBridge
|
||||||
import net.mamoe.mirai.Bot
|
import net.mamoe.mirai.Bot
|
||||||
import net.mamoe.mirai.JavaFriendlyAPI
|
|
||||||
import net.mamoe.mirai.Mirai
|
import net.mamoe.mirai.Mirai
|
||||||
import net.mamoe.mirai.contact.Friend
|
import net.mamoe.mirai.contact.Friend
|
||||||
import net.mamoe.mirai.contact.Group
|
import net.mamoe.mirai.contact.Group
|
||||||
@ -23,8 +23,6 @@ import net.mamoe.mirai.event.AbstractEvent
|
|||||||
import net.mamoe.mirai.internal.network.Packet
|
import net.mamoe.mirai.internal.network.Packet
|
||||||
import net.mamoe.mirai.message.action.Nudge
|
import net.mamoe.mirai.message.action.Nudge
|
||||||
import net.mamoe.mirai.utils.MiraiExperimentalApi
|
import net.mamoe.mirai.utils.MiraiExperimentalApi
|
||||||
|
|
||||||
import net.mamoe.mirai.utils.internal.runBlocking
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
|
|
||||||
|
|
||||||
@ -89,22 +87,11 @@ public data class NewFriendRequestEvent internal constructor(
|
|||||||
*/
|
*/
|
||||||
public val fromGroup: Group? = if (fromGroupId == 0L) null else bot.getGroup(fromGroupId)
|
public val fromGroup: Group? = if (fromGroupId == 0L) null else bot.getGroup(fromGroupId)
|
||||||
|
|
||||||
@JvmSynthetic
|
@JvmBlockingBridge
|
||||||
public suspend fun accept(): Unit = Mirai.acceptNewFriendRequest(this)
|
public suspend fun accept(): Unit = Mirai.acceptNewFriendRequest(this)
|
||||||
|
|
||||||
@JvmSynthetic
|
@JvmBlockingBridge
|
||||||
public suspend fun reject(blackList: Boolean = false): Unit = Mirai.rejectNewFriendRequest(this, blackList)
|
public suspend fun reject(blackList: Boolean = false): Unit = Mirai.rejectNewFriendRequest(this, blackList)
|
||||||
|
|
||||||
|
|
||||||
@JavaFriendlyAPI
|
|
||||||
@JvmName("accept")
|
|
||||||
public fun __acceptBlockingForJava__(): Unit = runBlocking { accept() }
|
|
||||||
|
|
||||||
@JavaFriendlyAPI
|
|
||||||
@JvmOverloads
|
|
||||||
@JvmName("reject")
|
|
||||||
public fun __rejectBlockingForJava__(blackList: Boolean = false): Unit =
|
|
||||||
runBlocking { reject(blackList) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,8 +13,8 @@
|
|||||||
|
|
||||||
package net.mamoe.mirai.event.events
|
package net.mamoe.mirai.event.events
|
||||||
|
|
||||||
|
import net.mamoe.kjbb.JvmBlockingBridge
|
||||||
import net.mamoe.mirai.Bot
|
import net.mamoe.mirai.Bot
|
||||||
import net.mamoe.mirai.JavaFriendlyAPI
|
|
||||||
import net.mamoe.mirai.Mirai
|
import net.mamoe.mirai.Mirai
|
||||||
import net.mamoe.mirai.contact.Friend
|
import net.mamoe.mirai.contact.Friend
|
||||||
import net.mamoe.mirai.contact.Group
|
import net.mamoe.mirai.contact.Group
|
||||||
@ -25,9 +25,7 @@ import net.mamoe.mirai.event.BroadcastControllable
|
|||||||
import net.mamoe.mirai.internal.network.Packet
|
import net.mamoe.mirai.internal.network.Packet
|
||||||
import net.mamoe.mirai.message.action.Nudge
|
import net.mamoe.mirai.message.action.Nudge
|
||||||
import net.mamoe.mirai.utils.MiraiExperimentalApi
|
import net.mamoe.mirai.utils.MiraiExperimentalApi
|
||||||
import net.mamoe.mirai.utils.internal.runBlocking
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
import kotlin.jvm.*
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 机器人被踢出群或在其他客户端主动退出一个群. 在事件广播前 [Bot.groups] 就已删除这个群.
|
* 机器人被踢出群或在其他客户端主动退出一个群. 在事件广播前 [Bot.groups] 就已删除这个群.
|
||||||
@ -332,21 +330,11 @@ public data class BotInvitedJoinGroupRequestEvent internal constructor(
|
|||||||
@JvmField
|
@JvmField
|
||||||
internal val responded: AtomicBoolean = AtomicBoolean(false)
|
internal val responded: AtomicBoolean = AtomicBoolean(false)
|
||||||
|
|
||||||
@JvmSynthetic
|
@JvmBlockingBridge
|
||||||
public suspend fun accept(): Unit = Mirai.acceptInvitedJoinGroupRequest(this)
|
public suspend fun accept(): Unit = Mirai.acceptInvitedJoinGroupRequest(this)
|
||||||
|
|
||||||
@JvmSynthetic
|
@JvmBlockingBridge
|
||||||
public suspend fun ignore(): Unit = Mirai.ignoreInvitedJoinGroupRequest(this)
|
public suspend fun ignore(): Unit = Mirai.ignoreInvitedJoinGroupRequest(this)
|
||||||
|
|
||||||
@JavaFriendlyAPI
|
|
||||||
@JvmName("accept")
|
|
||||||
public fun __acceptBlockingForJava__(): Unit =
|
|
||||||
runBlocking { Mirai.acceptInvitedJoinGroupRequest(this@BotInvitedJoinGroupRequestEvent) }
|
|
||||||
|
|
||||||
@JavaFriendlyAPI
|
|
||||||
@JvmName("ignore")
|
|
||||||
public fun __ignoreBlockingForJava__(): Unit =
|
|
||||||
runBlocking { Mirai.ignoreInvitedJoinGroupRequest(this@BotInvitedJoinGroupRequestEvent) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -380,34 +368,16 @@ public data class MemberJoinRequestEvent internal constructor(
|
|||||||
@PublishedApi
|
@PublishedApi
|
||||||
internal val responded: AtomicBoolean = AtomicBoolean(false)
|
internal val responded: AtomicBoolean = AtomicBoolean(false)
|
||||||
|
|
||||||
@JvmSynthetic
|
@JvmBlockingBridge
|
||||||
public suspend fun accept(): Unit = Mirai.acceptMemberJoinRequest(this)
|
public suspend fun accept(): Unit = Mirai.acceptMemberJoinRequest(this)
|
||||||
|
|
||||||
@JvmSynthetic
|
@JvmBlockingBridge
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
public suspend fun reject(blackList: Boolean = false, message: String = ""): Unit =
|
public suspend fun reject(blackList: Boolean = false, message: String = ""): Unit =
|
||||||
Mirai.rejectMemberJoinRequest(this, blackList, message)
|
Mirai.rejectMemberJoinRequest(this, blackList, message)
|
||||||
|
|
||||||
@JvmSynthetic
|
@JvmBlockingBridge
|
||||||
public suspend fun ignore(blackList: Boolean = false): Unit = Mirai.ignoreMemberJoinRequest(this, blackList)
|
public suspend fun ignore(blackList: Boolean = false): Unit = Mirai.ignoreMemberJoinRequest(this, blackList)
|
||||||
|
|
||||||
|
|
||||||
@JavaFriendlyAPI
|
|
||||||
@JvmName("accept")
|
|
||||||
public fun __acceptBlockingForJava__(): Unit =
|
|
||||||
runBlocking { Mirai.acceptMemberJoinRequest(this@MemberJoinRequestEvent) }
|
|
||||||
|
|
||||||
@JavaFriendlyAPI
|
|
||||||
@JvmOverloads
|
|
||||||
@JvmName("reject")
|
|
||||||
public fun __rejectBlockingForJava__(blackList: Boolean = false, message: String = ""): Unit =
|
|
||||||
runBlocking { Mirai.rejectMemberJoinRequest(this@MemberJoinRequestEvent, blackList, message) }
|
|
||||||
|
|
||||||
@JavaFriendlyAPI
|
|
||||||
@JvmOverloads
|
|
||||||
@JvmName("ignore")
|
|
||||||
public fun __ignoreBlockingForJava__(blackList: Boolean = false): Unit =
|
|
||||||
runBlocking { Mirai.ignoreMemberJoinRequest(this@MemberJoinRequestEvent, blackList) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// endregion
|
// endregion
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
package net.mamoe.mirai.event.events
|
package net.mamoe.mirai.event.events
|
||||||
|
|
||||||
|
import net.mamoe.kjbb.JvmBlockingBridge
|
||||||
import net.mamoe.mirai.Bot
|
import net.mamoe.mirai.Bot
|
||||||
import net.mamoe.mirai.contact.*
|
import net.mamoe.mirai.contact.*
|
||||||
import net.mamoe.mirai.event.*
|
import net.mamoe.mirai.event.*
|
||||||
@ -592,6 +593,7 @@ public interface MessageEvent : Event, Packet, BotEvent, MessageEventExtensions<
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** 消息事件的扩展函数 */
|
/** 消息事件的扩展函数 */
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
public interface MessageEventExtensions<out TSender : User, out TSubject : Contact> :
|
public interface MessageEventExtensions<out TSender : User, out TSubject : Contact> :
|
||||||
MessageEventPlatformExtensions<TSender, TSubject> {
|
MessageEventPlatformExtensions<TSender, TSubject> {
|
||||||
|
|
||||||
@ -602,11 +604,11 @@ public interface MessageEventExtensions<out TSender : User, out TSubject : Conta
|
|||||||
* 对于好友消息事件, 这个方法将会给好友 ([subject]) 发送消息
|
* 对于好友消息事件, 这个方法将会给好友 ([subject]) 发送消息
|
||||||
* 对于群消息事件, 这个方法将会给群 ([subject]) 发送消息
|
* 对于群消息事件, 这个方法将会给群 ([subject]) 发送消息
|
||||||
*/
|
*/
|
||||||
@JvmSynthetic
|
@JvmBlockingBridge
|
||||||
public suspend fun reply(message: Message): MessageReceipt<TSubject> =
|
public suspend fun reply(message: Message): MessageReceipt<TSubject> =
|
||||||
subject.sendMessage(message.asMessageChain()) as MessageReceipt<TSubject>
|
subject.sendMessage(message.asMessageChain()) as MessageReceipt<TSubject>
|
||||||
|
|
||||||
@JvmSynthetic
|
@JvmBlockingBridge
|
||||||
public suspend fun reply(plain: String): MessageReceipt<TSubject> =
|
public suspend fun reply(plain: String): MessageReceipt<TSubject> =
|
||||||
subject.sendMessage(PlainText(plain).asMessageChain()) as MessageReceipt<TSubject>
|
subject.sendMessage(PlainText(plain).asMessageChain()) as MessageReceipt<TSubject>
|
||||||
|
|
||||||
@ -633,15 +635,15 @@ public interface MessageEventExtensions<out TSender : User, out TSubject : Conta
|
|||||||
* 对于好友消息事件, 这个方法将会给好友 ([subject]) 发送消息
|
* 对于好友消息事件, 这个方法将会给好友 ([subject]) 发送消息
|
||||||
* 对于群消息事件, 这个方法将会给群 ([subject]) 发送消息
|
* 对于群消息事件, 这个方法将会给群 ([subject]) 发送消息
|
||||||
*/
|
*/
|
||||||
@JvmSynthetic
|
@JvmBlockingBridge
|
||||||
public suspend fun quoteReply(message: MessageChain): MessageReceipt<TSubject> =
|
public suspend fun quoteReply(message: MessageChain): MessageReceipt<TSubject> =
|
||||||
reply(this.message.quote() + message)
|
reply(this.message.quote() + message)
|
||||||
|
|
||||||
@JvmSynthetic
|
@JvmBlockingBridge
|
||||||
public suspend fun quoteReply(message: Message): MessageReceipt<TSubject> =
|
public suspend fun quoteReply(message: Message): MessageReceipt<TSubject> =
|
||||||
reply(this.message.quote() + message)
|
reply(this.message.quote() + message)
|
||||||
|
|
||||||
@JvmSynthetic
|
@JvmBlockingBridge
|
||||||
public suspend fun quoteReply(plain: String): MessageReceipt<TSubject> = reply(this.message.quote() + plain)
|
public suspend fun quoteReply(plain: String): MessageReceipt<TSubject> = reply(this.message.quote() + plain)
|
||||||
|
|
||||||
@JvmSynthetic
|
@JvmSynthetic
|
||||||
@ -670,24 +672,24 @@ public interface MessageEventPlatformExtensions<out TSender : User, out TSubject
|
|||||||
|
|
||||||
// region 上传图片
|
// region 上传图片
|
||||||
|
|
||||||
@JvmSynthetic
|
@JvmBlockingBridge
|
||||||
public suspend fun uploadImage(image: BufferedImage): Image = subject.uploadImage(image)
|
public suspend fun uploadImage(image: BufferedImage): Image = subject.uploadImage(image)
|
||||||
|
|
||||||
@JvmSynthetic
|
@JvmBlockingBridge
|
||||||
public suspend fun uploadImage(image: InputStream): Image = subject.uploadImage(image)
|
public suspend fun uploadImage(image: InputStream): Image = subject.uploadImage(image)
|
||||||
|
|
||||||
@JvmSynthetic
|
@JvmBlockingBridge
|
||||||
public suspend fun uploadImage(image: File): Image = subject.uploadImage(image)
|
public suspend fun uploadImage(image: File): Image = subject.uploadImage(image)
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
// region 发送图片
|
// region 发送图片
|
||||||
@JvmSynthetic
|
@JvmBlockingBridge
|
||||||
public suspend fun sendImage(image: BufferedImage): MessageReceipt<TSubject> = subject.sendImage(image)
|
public suspend fun sendImage(image: BufferedImage): MessageReceipt<TSubject> = subject.sendImage(image)
|
||||||
|
|
||||||
@JvmSynthetic
|
@JvmBlockingBridge
|
||||||
public suspend fun sendImage(image: InputStream): MessageReceipt<TSubject> = subject.sendImage(image)
|
public suspend fun sendImage(image: InputStream): MessageReceipt<TSubject> = subject.sendImage(image)
|
||||||
|
|
||||||
@JvmSynthetic
|
@JvmBlockingBridge
|
||||||
public suspend fun sendImage(image: File): MessageReceipt<TSubject> = subject.sendImage(image)
|
public suspend fun sendImage(image: File): MessageReceipt<TSubject> = subject.sendImage(image)
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user