mirror of
https://github.com/mamoe/mirai.git
synced 2025-02-07 06:56:58 +08:00
Nugde stability update
This commit is contained in:
parent
16623aec65
commit
c1f609d0de
@ -262,7 +262,12 @@ private object Transformers732 : Map<Int, Lambda732> by mapOf(
|
||||
}
|
||||
}
|
||||
if (target.id == bot.id) {
|
||||
return@lambda732 sequenceOf(BotNudgedEvent(from, action, suffix))
|
||||
return@lambda732 sequenceOf(
|
||||
if (from.id == bot.id)
|
||||
BotNudgedEvent.InGroup.ByBot(action, suffix, group)
|
||||
else
|
||||
BotNudgedEvent.InGroup.ByMember(action, suffix, from)
|
||||
)
|
||||
}
|
||||
return@lambda732 sequenceOf(MemberNudgedEvent(from, target, action, suffix))
|
||||
}
|
||||
@ -519,8 +524,20 @@ internal object Transformers528 : Map<Long, Lambda528> by mapOf(
|
||||
"suffix_str" -> suffix = value
|
||||
}
|
||||
}
|
||||
return@lambda528 sequenceOf(BotNudgedEvent(from, action, suffix))
|
||||
|
||||
return@lambda528 sequenceOf(
|
||||
if (target.id == bot.id) {
|
||||
if (from.id == bot.id)
|
||||
BotNudgedEvent.InPrivateSession.ByBot(target, action, suffix)
|
||||
else
|
||||
BotNudgedEvent.InPrivateSession.ByFriend(target, action, suffix)
|
||||
} else {
|
||||
if (from.id == bot.id)
|
||||
FriendNudgedEvent.NudgedByBot(action, suffix, target)
|
||||
else
|
||||
FriendNudgedEvent.NudgedByHimself(action, suffix, target)
|
||||
}
|
||||
)
|
||||
}
|
||||
else -> {
|
||||
bot.logger.debug {
|
||||
|
@ -14,9 +14,9 @@
|
||||
package net.mamoe.mirai.event.events
|
||||
|
||||
import net.mamoe.mirai.Bot
|
||||
import net.mamoe.mirai.contact.User
|
||||
import net.mamoe.mirai.contact.*
|
||||
import net.mamoe.mirai.event.AbstractEvent
|
||||
import net.mamoe.mirai.message.action.Nudge
|
||||
import net.mamoe.mirai.message.MessageEvent
|
||||
import net.mamoe.mirai.qqandroid.network.Packet
|
||||
import net.mamoe.mirai.utils.MiraiExperimentalAPI
|
||||
import net.mamoe.mirai.utils.MiraiInternalAPI
|
||||
@ -126,6 +126,93 @@ public data class BotNickChangedEvent(
|
||||
public val to: String
|
||||
) : BotEvent, Packet, AbstractEvent()
|
||||
|
||||
|
||||
@MiraiExperimentalAPI
|
||||
@SinceMirai("1.3.0")
|
||||
public sealed class BotNudgedEvent : AbstractEvent(), BotEvent, Packet {
|
||||
/**
|
||||
* 戳一戳的发起人,为 [Bot] 的某一好友, 或某一群员, 或 [Bot.selfQQ]
|
||||
*/
|
||||
public abstract val from: User
|
||||
|
||||
/** 戳一戳的动作名称 */
|
||||
public abstract val action: String
|
||||
|
||||
/** 戳一戳中设置的自定义后缀 */
|
||||
public abstract val suffix: String
|
||||
|
||||
@MiraiExperimentalAPI
|
||||
@SinceMirai("2.0.0")
|
||||
/** [Bot] 在群聊中被戳 */
|
||||
public sealed class InGroup : BotNudgedEvent(), GroupMemberEvent {
|
||||
abstract override val from: Member
|
||||
override val bot: Bot get() = from.bot
|
||||
|
||||
/** [Bot] 在 [Group] 中被 [Member] 戳了 */
|
||||
public data class ByMember internal constructor(
|
||||
override val action: String,
|
||||
override val suffix: String,
|
||||
override val member: Member
|
||||
) : InGroup() {
|
||||
override val from: Member
|
||||
get() = member
|
||||
|
||||
override fun toString(): String {
|
||||
return "BotNudgedEvent.InGroup.ByMember(member=$member, action=$action, suffix=$suffix)"
|
||||
}
|
||||
}
|
||||
|
||||
/** [Bot] 在 [Group] 中自己戳了自己 */
|
||||
public data class ByBot internal constructor(
|
||||
override val action: String,
|
||||
override val suffix: String,
|
||||
override val group: Group
|
||||
) : InGroup() {
|
||||
override val member: Member get() = group.botAsMember
|
||||
override val from: Member get() = member
|
||||
|
||||
override fun toString(): String {
|
||||
return "BotNudgedEvent.InGroup.ByBot(group=$group, action=$action, suffix=$suffix)"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@MiraiExperimentalAPI
|
||||
@SinceMirai("2.0.0")
|
||||
/** [Bot] 在私聊中被戳 */
|
||||
public sealed class InPrivateSession : BotNudgedEvent(), FriendEvent {
|
||||
abstract override val from: Friend
|
||||
override val bot: Bot get() = from.bot
|
||||
override val friend: Friend get() = from
|
||||
|
||||
/** 在私聊中 [Friend] 戳了 [Bot] */
|
||||
public data class ByFriend internal constructor(
|
||||
override val friend: Friend,
|
||||
override val action: String,
|
||||
override val suffix: String
|
||||
) : InPrivateSession() {
|
||||
override val from: Friend get() = friend
|
||||
override fun toString(): String {
|
||||
return "BotNudgedEvent.InPrivateSession.ByFriend(friend=$friend, action=$action, suffix=$suffix)"
|
||||
}
|
||||
}
|
||||
|
||||
/** [Bot] 在私聊中自己戳了自己 */
|
||||
public data class ByBot internal constructor(
|
||||
/** [Bot] 的对话对象 */
|
||||
override val friend: Friend,
|
||||
override val action: String,
|
||||
override val suffix: String
|
||||
) : InPrivateSession() {
|
||||
override val from: Friend get() = bot.selfQQ
|
||||
override fun toString(): String {
|
||||
return "BotNudgedEvent.InPrivateSession.ByBot(friend=$friend, action=$action, suffix=$suffix)"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* [Bot] 被 [戳][Nudge] 的事件.
|
||||
*/
|
||||
@ -133,7 +220,7 @@ public data class BotNickChangedEvent(
|
||||
@SinceMirai("1.3.0")
|
||||
public data class BotNudgedEvent internal constructor(
|
||||
/**
|
||||
* 戳一戳的发起人,为 [Bot] 的某一好友, 或某一群员
|
||||
* 戳一戳的发起人,为 [Bot] 的某一好友, 或某一群员, 或 [Bot.selfQQ]
|
||||
*/
|
||||
public val from: User,
|
||||
/**
|
||||
@ -149,7 +236,22 @@ public data class BotNudgedEvent internal constructor(
|
||||
* 戳一戳的目标
|
||||
*/
|
||||
public override val bot: Bot get() = from.bot
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* 戳一戳发起的会话环境, 可能是 [Friend] 或者 [Group]
|
||||
*
|
||||
* @see MessageEvent.subject
|
||||
*/
|
||||
@MiraiExperimentalAPI
|
||||
@SinceMirai("1.3.2")
|
||||
public val BotNudgedEvent.subject: Contact
|
||||
get() = when (val inlineFrom = from) {
|
||||
is Member -> inlineFrom.group
|
||||
else -> inlineFrom
|
||||
}
|
||||
|
||||
// region 图片
|
||||
|
||||
|
@ -20,7 +20,9 @@ import net.mamoe.mirai.contact.Group
|
||||
import net.mamoe.mirai.contact.User
|
||||
import net.mamoe.mirai.event.AbstractEvent
|
||||
import net.mamoe.mirai.event.internal.MiraiAtomicBoolean
|
||||
import net.mamoe.mirai.message.action.Nudge
|
||||
import net.mamoe.mirai.qqandroid.network.Packet
|
||||
import net.mamoe.mirai.utils.MiraiExperimentalAPI
|
||||
import net.mamoe.mirai.utils.SinceMirai
|
||||
import net.mamoe.mirai.utils.internal.runBlocking
|
||||
import kotlin.jvm.*
|
||||
@ -132,3 +134,57 @@ public data class FriendInputStatusChangedEvent internal constructor(
|
||||
public val inputting: Boolean
|
||||
|
||||
) : FriendEvent, Packet, AbstractEvent()
|
||||
|
||||
/**
|
||||
* 在 [Friend] 与 [Bot] 的对话中, [Friend] 被 [戳][Nudge] 事件
|
||||
*
|
||||
* 注: 此事件仅可能在私聊中发生
|
||||
*/
|
||||
@SinceMirai("2.0.0")
|
||||
@MiraiExperimentalAPI
|
||||
public sealed class FriendNudgedEvent : AbstractEvent(), FriendEvent, Packet {
|
||||
/**
|
||||
* 戳一戳的发起人, 为 [Bot] 的某一好友, 或是 [Bot.selfQQ]
|
||||
*/
|
||||
public abstract val from: Friend
|
||||
|
||||
/**
|
||||
* 戳一戳的动作名称
|
||||
*/
|
||||
public abstract val action: String
|
||||
|
||||
/**
|
||||
* 戳一戳中设置的自定义后缀
|
||||
*/
|
||||
public abstract val suffix: String
|
||||
|
||||
/** 在 [Bot] 与 [Friend] 的对话中 [Friend] 戳了自己事件 */
|
||||
@MiraiExperimentalAPI
|
||||
public data class NudgedByHimself internal constructor(
|
||||
override val action: String,
|
||||
override val suffix: String,
|
||||
override val friend: Friend
|
||||
) : FriendNudgedEvent() {
|
||||
override fun toString(): String {
|
||||
return "FriendNudgedEvent.NudgedByHimself(friend=$friend, action=$action, suffix=$suffix)"
|
||||
}
|
||||
|
||||
override val from: Friend
|
||||
get() = friend
|
||||
}
|
||||
|
||||
/** [Bot] 戳了 [Friend] */
|
||||
@MiraiExperimentalAPI
|
||||
public data class NudgedByBot internal constructor(
|
||||
override val action: String,
|
||||
override val suffix: String,
|
||||
override val friend: Friend
|
||||
) : FriendNudgedEvent() {
|
||||
override fun toString(): String {
|
||||
return "FriendNudgedEvent.NudgedByBot(friend=$friend, action=$action, suffix=$suffix)"
|
||||
}
|
||||
|
||||
override val from: Friend
|
||||
get() = bot.selfQQ
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user