Fix #444: FriendMessageEvent is not a subclass of FriendEvent

This commit is contained in:
Him188 2020-07-30 00:15:57 +08:00
parent c1d54f2fdf
commit dd35cc62d5

View File

@ -14,11 +14,13 @@ package net.mamoe.mirai.message
import net.mamoe.mirai.Bot import net.mamoe.mirai.Bot
import net.mamoe.mirai.contact.Friend import net.mamoe.mirai.contact.Friend
import net.mamoe.mirai.event.BroadcastControllable import net.mamoe.mirai.event.BroadcastControllable
import net.mamoe.mirai.event.events.FriendEvent
import net.mamoe.mirai.message.data.MessageChain import net.mamoe.mirai.message.data.MessageChain
import net.mamoe.mirai.message.data.MessageSource import net.mamoe.mirai.message.data.MessageSource
import net.mamoe.mirai.message.data.OnlineMessageSource import net.mamoe.mirai.message.data.OnlineMessageSource
import net.mamoe.mirai.message.data.source import net.mamoe.mirai.message.data.source
import net.mamoe.mirai.utils.PlannedRemoval import net.mamoe.mirai.utils.PlannedRemoval
import net.mamoe.mirai.utils.SinceMirai
/** /**
* 机器人收到的好友消息的事件 * 机器人收到的好友消息的事件
@ -29,14 +31,17 @@ public class FriendMessageEvent constructor(
public override val sender: Friend, public override val sender: Friend,
public override val message: MessageChain, public override val message: MessageChain,
public override val time: Int public override val time: Int
) : @PlannedRemoval("1.2.0") FriendMessage(), BroadcastControllable { ) : @PlannedRemoval("1.2.0") FriendMessage(), BroadcastControllable, @SinceMirai("1.2.0") FriendEvent {
init { init {
val source = val source =
message[MessageSource] ?: throw IllegalArgumentException("Cannot find MessageSource from message") message[MessageSource] ?: throw IllegalArgumentException("Cannot find MessageSource from message")
check(source is OnlineMessageSource.Incoming.FromFriend) { "source provided to a FriendMessage must be an instance of OnlineMessageSource.Incoming.FromFriend" } check(source is OnlineMessageSource.Incoming.FromFriend) { "source provided to a FriendMessage must be an instance of OnlineMessageSource.Incoming.FromFriend" }
} }
public override val bot: Bot get() = sender.bot @SinceMirai("1.2.0")
public override val friend: Friend
get() = sender
public override val bot: Bot get() = super.bot
public override val subject: Friend get() = sender public override val subject: Friend get() = sender
public override val senderName: String get() = sender.nick public override val senderName: String get() = sender.nick
public override val source: OnlineMessageSource.Incoming.FromFriend get() = message.source as OnlineMessageSource.Incoming.FromFriend public override val source: OnlineMessageSource.Incoming.FromFriend get() = message.source as OnlineMessageSource.Incoming.FromFriend