Update japt

This commit is contained in:
Him188 2020-01-11 23:53:01 +08:00
parent 844d798f59
commit 3a5ec367cb
11 changed files with 59 additions and 38 deletions

View File

@ -39,7 +39,7 @@ interface Contact : CoroutineScope {
suspend fun uploadImage(image: ExternalImage): ImageId
}
suspend inline fun Contact.sendMessage(message: Message) = sendMessage(message.chain())
suspend inline fun Contact.sendMessage(message: Message) = sendMessage(message.toChain())
suspend inline fun Contact.sendMessage(plain: String) = sendMessage(plain.singleChain())

View File

@ -61,8 +61,6 @@ interface Group : Contact, CoroutineScope/*, Map<UInt, Member>*/ { // TODO: 2019
/**
* 让机器人退出这个群. 机器人必须为非群主才能退出. 否则将会失败
*
* @see QuitGroupResponse.isSuccess 判断是否成功
*/
suspend fun quit(): Boolean

View File

@ -10,7 +10,6 @@ import net.mamoe.mirai.data.ImageLink
import net.mamoe.mirai.event.events.BotEvent
import net.mamoe.mirai.message.data.*
import net.mamoe.mirai.utils.*
import net.mamoe.mirai.utils.coerceAtLeastOrFail
import kotlin.jvm.JvmName
/**
@ -50,7 +49,7 @@ abstract class MessagePacketBase<TSender : QQ, TSubject : Contact>(_bot: Bot) :
*/
suspend inline fun reply(message: MessageChain) = subject.sendMessage(message)
suspend inline fun reply(message: Message) = subject.sendMessage(message.chain())
suspend inline fun reply(message: Message) = subject.sendMessage(message.toChain())
suspend inline fun reply(plain: String) = subject.sendMessage(plain.toMessage())
@JvmName("reply1")

View File

@ -63,7 +63,7 @@ fun MessageChain(initialCapacity: Int): MessageChain =
/**
* 构造 [MessageChain]
* 若仅提供一个参数, 请考虑使用 [Message.chain] 以优化性能
* 若仅提供一个参数, 请考虑使用 [Message.toChain] 以优化性能
*/
@Suppress("FunctionName")
fun MessageChain(vararg messages: Message): MessageChain =
@ -81,12 +81,12 @@ fun MessageChain(messages: Iterable<Message>): MessageChain =
* 构造单元素的不可修改的 [MessageChain]. 内部类实现为 [SingleMessageChain]
*
* 参数 [delegate] 不能为 [MessageChain] 的实例, 否则将会抛出异常.
* 使用 [Message.chain] 将帮助提前处理这个问题.
* 使用 [Message.toChain] 将帮助提前处理这个问题.
*
* @param delegate 所构造的单元素 [MessageChain] 代表的 [Message]
* @throws IllegalArgumentException [delegate] [MessageChain] 的实例时
*
* @see Message.chain receiver 模式
* @see Message.toChain receiver 模式
*/
@MiraiExperimentalAPI
@UseExperimental(ExperimentalContracts::class)
@ -106,17 +106,13 @@ fun SingleMessageChain(delegate: Message): MessageChain {
* 否则将调用 [MessageChain] 构造一个 [MessageChainImpl]
*/
@Suppress("NOTHING_TO_INLINE")
inline fun Message.chain(): MessageChain = if (this is MessageChain) this else MessageChain(
this
)
inline fun Message.toChain(): MessageChain = if (this is MessageChain) this else MessageChain(this)
/**
* 构造 [MessageChain]
*/
@Suppress("unused", "NOTHING_TO_INLINE")
inline fun List<Message>.messageChain(): MessageChain =
MessageChain(this)
inline fun List<Message>.toMessageChain(): MessageChain = MessageChain(this)
/**
* 获取第一个 [M] 类型的 [Message] 实例
@ -327,6 +323,7 @@ internal inline class MessageChainImpl constructor(
*
* 在连接时将会把它当做一个普通 [Message] 看待, 但它不能被 [plusAssign]
*/
@PublishedApi
internal inline class SingleMessageChainImpl(
private val delegate: Message
) : Message, MutableList<Message>,

View File

@ -23,4 +23,4 @@ inline fun String.toMessage(): PlainText = PlainText(this)
* @see SingleMessageChainImpl
*/
@Suppress("NOTHING_TO_INLINE")
inline fun String.singleChain(): MessageChain = this.toMessage().chain()
inline fun String.singleChain(): MessageChain = SingleMessageChainImpl(this.toMessage())

View File

@ -1,4 +1,5 @@
# Contact
.blocking : 阻塞式包装
net.mamoe.mirai.contact.QQ [net.mamoe.mirai.japt.BlockingContacts] -> BlockingQQ. BlockingContacts.createBlocking($var$)
## Contact ##
.blocking : Blocking wrap
net.mamoe.mirai.contact.QQ → net.mamoe.mirai.japt.BlockingContacts.createBlocking($expr$)
net.mamoe.mirai.contact.QQ [net.mamoe.mirai.japt.BlockingContacts] → net.mamoe.mirai.japt.BlockingContacts.createBlocking($expr$)
net.mamoe.mirai.timpc.network.QQImpl [net.mamoe.mirai.japt.BlockingContacts] → net.mamoe.mirai.japt.BlockingContacts.createBlocking($expr$)

View File

@ -0,0 +1,4 @@
package net.mamoe.mirai.japt;
public interface BlockingBot {
}

View File

@ -1,7 +1,8 @@
package net.mamoe.mirai.japt;
import net.mamoe.mirai.Bot;
import net.mamoe.mirai.message.MessageChain;
import net.mamoe.mirai.message.data.Message;
import net.mamoe.mirai.message.data.MessageChain;
import org.jetbrains.annotations.NotNull;
@SuppressWarnings("unused")
@ -19,8 +20,16 @@ public interface BlockingContact {
/**
* 向这个对象发送消息.
* <p>
* 速度太快会被服务器屏蔽(无响应). 在测试中不延迟地发送 6 条消息就会被屏蔽之后的数据包 1 秒左右.
*/
void sendMessage(@NotNull MessageChain messages);
/**
* 向这个对象发送消息.
*/
void sendMessage(@NotNull String message);
/**
* 向这个对象发送消息.
*/
void sendMessage(@NotNull Message message);
}

View File

@ -1,6 +1,6 @@
package net.mamoe.mirai.japt;
import net.mamoe.mirai.network.protocol.tim.packet.action.GroupInfo;
import net.mamoe.mirai.data.GroupInfo;
import java.util.Map;
@ -9,7 +9,7 @@ public interface BlockingGroup extends BlockingContact {
/**
* 内部 ID. 内部 ID [GroupId] 的映射
*/
Long getInternalId();
long getInternalId();
/**
* 群主 (同步事件更新)

View File

@ -1,8 +1,8 @@
package net.mamoe.mirai.japt;
import net.mamoe.mirai.contact.data.Profile;
import net.mamoe.mirai.network.protocol.tim.packet.action.FriendNameRemark;
import net.mamoe.mirai.network.protocol.tim.packet.action.PreviousNameList;
import net.mamoe.mirai.data.FriendNameRemark;
import net.mamoe.mirai.data.PreviousNameList;
import net.mamoe.mirai.data.Profile;
import org.jetbrains.annotations.NotNull;
@SuppressWarnings("unused")

View File

@ -8,16 +8,24 @@ import net.mamoe.mirai.contact.Group
import net.mamoe.mirai.contact.Member
import net.mamoe.mirai.contact.MemberPermission
import net.mamoe.mirai.contact.QQ
import net.mamoe.mirai.contact.data.Profile
import net.mamoe.mirai.message.MessageChain
import net.mamoe.mirai.network.protocol.tim.packet.action.FriendNameRemark
import net.mamoe.mirai.network.protocol.tim.packet.action.GroupInfo
import net.mamoe.mirai.network.protocol.tim.packet.action.PreviousNameList
import net.mamoe.mirai.data.FriendNameRemark
import net.mamoe.mirai.data.GroupInfo
import net.mamoe.mirai.data.PreviousNameList
import net.mamoe.mirai.data.Profile
import net.mamoe.mirai.message.data.Message
import net.mamoe.mirai.message.data.MessageChain
import net.mamoe.mirai.message.data.toChain
import net.mamoe.mirai.message.data.toMessage
import net.mamoe.mirai.utils.MiraiInternalAPI
import net.mamoe.mirai.utils.toList
internal class BlockingQQImpl(private val delegate: QQ) : BlockingQQ {
override fun getBot(): Bot = delegate.bot
override fun getId(): Long = delegate.id.toLong()
override fun getId(): Long = delegate.id
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 queryProfile(): Profile = runBlocking { delegate.queryProfile() }
override fun queryPreviousNameList(): PreviousNameList = runBlocking { delegate.queryPreviousNameList() }
override fun queryRemark(): FriendNameRemark = runBlocking { delegate.queryRemark() }
@ -25,17 +33,22 @@ 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 getOwner(): BlockingMember = delegate.owner.blocking()
override fun getName(): String = delegate.name
override fun getId(): Long = delegate.id.toLong()
override fun getId(): Long = delegate.id
override fun updateGroupInfo(): GroupInfo = runBlocking { delegate.updateGroupInfo() }
override fun toFullString(): String = delegate.toFullString()
override fun getMember(id: Long): BlockingMember = delegate.getMember(id.toUInt()).blocking()
override fun getMember(id: Long): BlockingMember = delegate.getMember(id).blocking()
override fun getBot(): Bot = delegate.bot
override fun getAnnouncement(): String = delegate.announcement
override fun getMembers(): MutableMap<Long, BlockingMember> = delegate.members.mapKeys { it.key.toLong() }.mapValues { it.value.blocking() }.toMutableMap()
override fun getInternalId(): Long = delegate.internalId.value.toLong()
override fun quit(): Boolean = runBlocking { delegate.quit().isSuccess }
@UseExperimental(MiraiInternalAPI::class)
override fun getMembers(): Map<Long, BlockingMember> =
delegate.members.delegate.toList().associateBy { it.id }.mapValues { it.value.blocking() }
override fun getInternalId(): Long = delegate.internalId.value
override fun quit(): Boolean = runBlocking { delegate.quit() }
}
internal class BlockingMemberImpl(private val delegate: Member) : BlockingMember {