Skip to content

Commit

Permalink
fix: nudge doc and add to mock (#2790)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nambers authored Feb 22, 2024
1 parent b7eb6eb commit eeb3217
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
12 changes: 8 additions & 4 deletions mirai-core-api/src/commonMain/kotlin/message/action/Nudge.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ public sealed class Nudge {
/**
* 发送戳一戳消息到 [receiver].
*
* 需要使用支持的[协议][BotConfiguration.protocol] [MiraiProtocol.ANDROID_PHONE] 或 [MiraiProtocol.IPAD]. 自 2.10 起才支持使用 IPAD 协议发送.
* 需要使用支持的[协议][BotConfiguration.protocol] [MiraiProtocol.ANDROID_PHONE], [ANDROID_PAD 协议][MiraiProtocol.ANDROID_PAD] 或 [MiraiProtocol.IPAD].
* + 自 2.10 起才支持使用 IPAD 协议发送.
* + 自 2.16.0-RC 起才支持使用 PAD 协议发送.
*
* @param receiver 这条 "戳一戳" 消息的接收对象. (不是 "戳" 动作的对象, 而是接收 "A 戳了 B" 这条消息的对象)
* @return 成功发送时为 `true`. 若对方禁用 "戳一戳" 功能, 返回 `false`.
* @throws UnsupportedOperationException 当未使用 [ANDROID_PHONE 协议][MiraiProtocol.ANDROID_PHONE] 或 [IPAD 协议][MiraiProtocol.IPAD] 时抛出
* @throws UnsupportedOperationException 当未使用 [ANDROID_PHONE 协议][MiraiProtocol.ANDROID_PHONE], [ANDROID_PAD 协议][MiraiProtocol.ANDROID_PAD] 或 [IPAD 协议][MiraiProtocol.IPAD] 时抛出
*
* @see NudgeEvent 事件
* @see Contact.sendNudge
Expand All @@ -59,11 +61,13 @@ public sealed class Nudge {
/**
* 发送戳一戳消息.
*
* 需要使用支持的[协议][BotConfiguration.protocol] [MiraiProtocol.ANDROID_PHONE] 或 [MiraiProtocol.IPAD]. 自 2.10 起才支持使用 IPAD 协议发送.
* 需要使用支持的[协议][BotConfiguration.protocol] [MiraiProtocol.ANDROID_PHONE], [ANDROID_PAD 协议][MiraiProtocol.ANDROID_PAD] 或 [MiraiProtocol.IPAD].
* + 自 2.10 起才支持使用 IPAD 协议发送.
* + 自 2.16.0-RC 起才支持使用 PAD 协议发送.
*
* @return 成功发送时为 `true`. 若对方禁用 "戳一戳" 功能或今日 "戳一戳" 次数已达到上限, 返回 `false`.
*
* @throws UnsupportedOperationException 当未使用 [ANDROID_PHONE 协议][MiraiProtocol.ANDROID_PHONE] 或 [IPAD 协议][MiraiProtocol.IPAD] 时抛出
* @throws UnsupportedOperationException 当未使用 [ANDROID_PHONE 协议][MiraiProtocol.ANDROID_PHONE], [ANDROID_PAD 协议][MiraiProtocol.ANDROID_PAD] 或 [IPAD 协议][MiraiProtocol.IPAD] 时抛出
*
* @see NudgeEvent 事件
*/
Expand Down
6 changes: 6 additions & 0 deletions mirai-core-mock/src/internal/MockMiraiImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import net.mamoe.mirai.event.broadcast
import net.mamoe.mirai.event.events.*
import net.mamoe.mirai.internal.MiraiImpl
import net.mamoe.mirai.internal.network.components.EventDispatcher
import net.mamoe.mirai.internal.utils.MiraiProtocolInternal
import net.mamoe.mirai.message.action.Nudge
import net.mamoe.mirai.message.data.*
import net.mamoe.mirai.mock.MockActions
Expand Down Expand Up @@ -295,6 +296,11 @@ internal class MockMiraiImpl : MiraiImpl() {
}

override suspend fun sendNudge(bot: Bot, nudge: Nudge, receiver: Contact): Boolean {
if (!bot.configuration.protocol.isNudgeSupported) {
throw UnsupportedOperationException("nudge is supported only with protocol ${
MiraiProtocolInternal.protocols.filter { it.value.supportsNudge }.map { it.key }
}")
}
NudgeEvent(
from = bot,
target = nudge.target,
Expand Down

0 comments on commit eeb3217

Please sign in to comment.