Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: nudge doc and add to mock #2790

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }
}")
}
Him188 marked this conversation as resolved.
Show resolved Hide resolved
NudgeEvent(
from = bot,
target = nudge.target,
Expand Down