diff --git a/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/message/AbstractMessageEvent.java b/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/message/AbstractMessageEvent.java new file mode 100644 index 0000000..ba42f71 --- /dev/null +++ b/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/message/AbstractMessageEvent.java @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2020 LamGC + * + * ContentGrabbingJi is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * ContentGrabbingJi is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package net.lamgc.cgj.bot.framework.message; + +import net.lamgc.cgj.bot.event.AbstractEventObject; +import net.lamgc.cgj.bot.framework.Platform; + +import java.util.Objects; +import java.util.ResourceBundle; + +/** + * 消息事件. + * @author LamGC + */ +public abstract class AbstractMessageEvent extends AbstractEventObject { + + private final Platform fromPlatform; + private final MessageSource messageSource; + /** + * 消息来源 Id. + *

fromId 必须要与 {@link #getSender()} 中的 {@link MessageSender#getId() getId()} 一致. + */ + private final long fromId; + /** + * 消息发送者 Id. + *

当 Sender 为 Group 等非个人的时候, 将无法获取具体消息发送者, 故添加 SenderId 参数以指向具体发送者. + *

当 Sender 为消息来源时, SenderId 与 {@link MessageSender#getId()} 一致. + */ + private final long senderId; + private final Message content; + private final MessageSender sender; + + /** + * 语言包. + *

如果激活 i18n 的话就会使用到该属性, Bot 将使用对应的消息模板构建回复消息内容. + *

当 Framework 不提供时将使用内置默认语言包. + */ + private ResourceBundle resourceBundle = null; + + protected AbstractMessageEvent( + Platform fromPlatform, + MessageSource messageSource, + long fromId, + long senderId, + Message messageContent, + MessageSender sender) { + this.fromPlatform = Objects.requireNonNull(fromPlatform); + this.messageSource = Objects.requireNonNull(messageSource); + this.fromId = fromId; + this.senderId = senderId; + this.content = messageContent; + this.sender = sender; + } + + public Platform getFromPlatform() { + return fromPlatform; + } + + public MessageSource getMessageSource() { + return messageSource; + } + + public long getFromId() { + return fromId; + } + + public long getSenderId() { + return senderId; + } + + public Message getContent() { + return content; + } + + public ResourceBundle getResourceBundle() { + return resourceBundle; + } + + public void setResourceBundle(ResourceBundle resourceBundle) { + this.resourceBundle = resourceBundle; + } + + public MessageSender getSender() { + return sender; + } + +}