diff --git a/mirai-japt/src/main/java/net/mamoe/mirai/japt/BlockingContact.java b/mirai-japt/src/main/java/net/mamoe/mirai/japt/BlockingContact.java index 26faed221..6ac2875b5 100644 --- a/mirai-japt/src/main/java/net/mamoe/mirai/japt/BlockingContact.java +++ b/mirai-japt/src/main/java/net/mamoe/mirai/japt/BlockingContact.java @@ -9,6 +9,7 @@ import net.mamoe.mirai.event.events.EventCancelledException; import net.mamoe.mirai.event.events.ImageUploadEvent; import net.mamoe.mirai.event.events.MessageSendEvent.FriendMessageSendEvent; import net.mamoe.mirai.event.events.MessageSendEvent.GroupMessageSendEvent; +import net.mamoe.mirai.message.MessageReceipt; import net.mamoe.mirai.message.data.Image; import net.mamoe.mirai.message.data.Message; import net.mamoe.mirai.message.data.MessageChain; @@ -42,8 +43,7 @@ public interface BlockingContact { * @see FriendMessageSendEvent 发送好友信息事件, cancellable * @see GroupMessageSendEvent 发送群消息事件. cancellable */ - // kotlin bug - void sendMessage(@NotNull MessageChain messages) throws EventCancelledException, IllegalStateException; + MessageReceipt sendMessage(@NotNull MessageChain messages) throws EventCancelledException, IllegalStateException; /** * 向这个对象发送消息. @@ -53,7 +53,7 @@ public interface BlockingContact { * @see FriendMessageSendEvent 发送好友信息事件, cancellable * @see GroupMessageSendEvent 发送群消息事件. cancellable */ - void sendMessage(@NotNull String message) throws EventCancelledException, IllegalStateException; + MessageReceipt sendMessage(@NotNull String message) throws EventCancelledException, IllegalStateException; /** * 向这个对象发送消息. @@ -63,7 +63,7 @@ public interface BlockingContact { * @see FriendMessageSendEvent 发送好友信息事件, cancellable * @see GroupMessageSendEvent 发送群消息事件. cancellable */ - void sendMessage(@NotNull Message message) throws EventCancelledException, IllegalStateException; + MessageReceipt sendMessage(@NotNull Message message) throws EventCancelledException, IllegalStateException; /** * 上传一个图片以备发送. diff --git a/mirai-japt/src/main/java/net/mamoe/mirai/japt/BlockingGroup.java b/mirai-japt/src/main/java/net/mamoe/mirai/japt/BlockingGroup.java index 2ebd58f6b..a70b70921 100644 --- a/mirai-japt/src/main/java/net/mamoe/mirai/japt/BlockingGroup.java +++ b/mirai-japt/src/main/java/net/mamoe/mirai/japt/BlockingGroup.java @@ -3,6 +3,9 @@ package net.mamoe.mirai.japt; import net.mamoe.mirai.contact.*; import net.mamoe.mirai.data.MemberInfo; import net.mamoe.mirai.event.events.*; +import net.mamoe.mirai.message.MessageReceipt; +import net.mamoe.mirai.message.data.Message; +import net.mamoe.mirai.message.data.MessageChain; import net.mamoe.mirai.utils.MiraiExperimentalAPI; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -152,6 +155,36 @@ public interface BlockingGroup extends BlockingContact { @Nullable BlockingMember getMemberOrNull(long id); + /** + * 向这个对象发送消息. + * + * @throws EventCancelledException 当发送消息事件被取消 + * @throws IllegalStateException 发送群消息时若 [Bot] 被禁言抛出 + * @see MessageSendEvent.FriendMessageSendEvent 发送好友信息事件, cancellable + * @see MessageSendEvent.GroupMessageSendEvent 发送群消息事件. cancellable + */ + MessageReceipt sendMessage(@NotNull MessageChain messages) throws EventCancelledException, IllegalStateException; + + /** + * 向这个对象发送消息. + * + * @throws EventCancelledException 当发送消息事件被取消 + * @throws IllegalStateException 发送群消息时若 [Bot] 被禁言抛出 + * @see MessageSendEvent.FriendMessageSendEvent 发送好友信息事件, cancellable + * @see MessageSendEvent.GroupMessageSendEvent 发送群消息事件. cancellable + */ + MessageReceipt sendMessage(@NotNull String message) throws EventCancelledException, IllegalStateException; + + /** + * 向这个对象发送消息. + * + * @throws EventCancelledException 当发送消息事件被取消 + * @throws IllegalStateException 发送群消息时若 [Bot] 被禁言抛出 + * @see MessageSendEvent.FriendMessageSendEvent 发送好友信息事件, cancellable + * @see MessageSendEvent.GroupMessageSendEvent 发送群消息事件. cancellable + */ + MessageReceipt sendMessage(@NotNull Message message) throws EventCancelledException, IllegalStateException; + /** * 检查此 id 的群成员是否存在 */ diff --git a/mirai-japt/src/main/java/net/mamoe/mirai/japt/BlockingQQ.java b/mirai-japt/src/main/java/net/mamoe/mirai/japt/BlockingQQ.java index 7fb7afc0e..4108a4384 100644 --- a/mirai-japt/src/main/java/net/mamoe/mirai/japt/BlockingQQ.java +++ b/mirai-japt/src/main/java/net/mamoe/mirai/japt/BlockingQQ.java @@ -1,8 +1,14 @@ package net.mamoe.mirai.japt; +import net.mamoe.mirai.contact.QQ; import net.mamoe.mirai.data.FriendNameRemark; import net.mamoe.mirai.data.PreviousNameList; import net.mamoe.mirai.data.Profile; +import net.mamoe.mirai.event.events.EventCancelledException; +import net.mamoe.mirai.event.events.MessageSendEvent; +import net.mamoe.mirai.message.MessageReceipt; +import net.mamoe.mirai.message.data.Message; +import net.mamoe.mirai.message.data.MessageChain; import net.mamoe.mirai.utils.MiraiExperimentalAPI; import org.jetbrains.annotations.NotNull; @@ -47,4 +53,35 @@ public interface BlockingQQ extends BlockingContact { @MiraiExperimentalAPI(message = "还未支持") @NotNull FriendNameRemark queryRemark(); + + /** + * 向这个对象发送消息. + * + * @throws EventCancelledException 当发送消息事件被取消 + * @throws IllegalStateException 发送群消息时若 [Bot] 被禁言抛出 + * @see MessageSendEvent.FriendMessageSendEvent 发送好友信息事件, cancellable + * @see MessageSendEvent.GroupMessageSendEvent 发送群消息事件. cancellable + */ + MessageReceipt sendMessage(@NotNull MessageChain messages) throws EventCancelledException, IllegalStateException; + + /** + * 向这个对象发送消息. + * + * @throws EventCancelledException 当发送消息事件被取消 + * @throws IllegalStateException 发送群消息时若 [Bot] 被禁言抛出 + * @see MessageSendEvent.FriendMessageSendEvent 发送好友信息事件, cancellable + * @see MessageSendEvent.GroupMessageSendEvent 发送群消息事件. cancellable + */ + MessageReceipt sendMessage(@NotNull String message) throws EventCancelledException, IllegalStateException; + + /** + * 向这个对象发送消息. + * + * @throws EventCancelledException 当发送消息事件被取消 + * @throws IllegalStateException 发送群消息时若 [Bot] 被禁言抛出 + * @see MessageSendEvent.FriendMessageSendEvent 发送好友信息事件, cancellable + * @see MessageSendEvent.GroupMessageSendEvent 发送群消息事件. cancellable + */ + MessageReceipt sendMessage(@NotNull Message message) throws EventCancelledException, IllegalStateException; + } diff --git a/mirai-japt/src/main/kotlin/net/mamoe/mirai/japt/internal/BlockingContactsImpl.kt b/mirai-japt/src/main/kotlin/net/mamoe/mirai/japt/internal/BlockingContactsImpl.kt index 193b57506..451d39d44 100644 --- a/mirai-japt/src/main/kotlin/net/mamoe/mirai/japt/internal/BlockingContactsImpl.kt +++ b/mirai-japt/src/main/kotlin/net/mamoe/mirai/japt/internal/BlockingContactsImpl.kt @@ -24,6 +24,7 @@ import net.mamoe.mirai.japt.BlockingBot import net.mamoe.mirai.japt.BlockingGroup import net.mamoe.mirai.japt.BlockingMember import net.mamoe.mirai.japt.BlockingQQ +import net.mamoe.mirai.message.MessageReceipt import net.mamoe.mirai.message.data.* import net.mamoe.mirai.utils.ExternalImage import net.mamoe.mirai.utils.MiraiExperimentalAPI @@ -35,9 +36,9 @@ internal class BlockingQQImpl(private val delegate: QQ) : BlockingQQ { override fun getId(): Long = delegate.id override fun getNick(): String = delegate.nick - override fun sendMessage(messages: MessageChain) = runBlocking { delegate.sendMessage(messages) } - override fun sendMessage(message: String) = runBlocking { delegate.sendMessage(message.toMessage().toChain()) } - override fun sendMessage(message: Message) = runBlocking { delegate.sendMessage(message.toChain()) } + override fun sendMessage(messages: MessageChain): MessageReceipt = runBlocking { delegate.sendMessage(messages) } + override fun sendMessage(message: String): MessageReceipt = runBlocking { delegate.sendMessage(message.toMessage().toChain()) } + override fun sendMessage(message: Message): MessageReceipt = runBlocking { delegate.sendMessage(message.toChain()) } override fun uploadImage(image: ExternalImage): Image = runBlocking { delegate.uploadImage(image) } @MiraiExperimentalAPI @@ -51,9 +52,9 @@ internal class BlockingQQImpl(private val delegate: QQ) : BlockingQQ { } internal class BlockingGroupImpl(private val delegate: Group) : BlockingGroup { - override fun sendMessage(messages: MessageChain) = runBlocking { delegate.sendMessage(messages) } - override fun sendMessage(message: String) = runBlocking { delegate.sendMessage(message.toMessage().toChain()) } - override fun sendMessage(message: Message) = runBlocking { delegate.sendMessage(message.toChain()) } + override fun sendMessage(messages: MessageChain): MessageReceipt = runBlocking { delegate.sendMessage(messages) } + override fun sendMessage(message: String): MessageReceipt = runBlocking { delegate.sendMessage(message.toMessage().toChain()) } + override fun sendMessage(message: Message): MessageReceipt = runBlocking { delegate.sendMessage(message.toChain()) } override fun getOwner(): BlockingMember = delegate.owner.blocking() @MiraiExperimentalAPI override fun newMember(memberInfo: MemberInfo): Member = delegate.Member(memberInfo)