diff --git a/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/NoFoundSenderException.java b/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/NoFoundSenderException.java new file mode 100644 index 0000000..e05a262 --- /dev/null +++ b/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/NoFoundSenderException.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2021 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. + * + * 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; + +import net.lamgc.cgj.bot.framework.message.MessageSource; + +/** + * 无对应消息源异常. + *

当 {@link SenderFactory} 无法通过传入的 {@link MessageSource} 和 Id 找到对应消息源时, 将抛出本异常. + * @see SenderFactory + */ +public class NoFoundSenderException extends RuntimeException { + + private final MessageSource source; + private final long id; + + /** + * 构造异常. + * @param source 传入的消息源类型. + * @param id 传入的消息源 Id. + */ + public NoFoundSenderException(MessageSource source, long id) { + super("Source Type: " + source + ", id: " + id); + this.source = source; + this.id = id; + } + + /** + * 获取引发该异常时传入的 {@link MessageSource} 类型. + * @return 返回引发该异常时提供的 MessageSource. + */ + public MessageSource getSource() { + return source; + } + + /** + * 获取引发该异常时传入的消息源 Id. + * @return 返回引发该异常时提供的消息源 Id. + */ + public long getId() { + return id; + } +} diff --git a/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/SenderFactory.java b/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/SenderFactory.java new file mode 100644 index 0000000..52445a8 --- /dev/null +++ b/ContentGrabbingJi-framework-api/src/main/java/net/lamgc/cgj/bot/framework/SenderFactory.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2021 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. + * + * 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; + +import net.lamgc.cgj.bot.framework.message.MessageSender; +import net.lamgc.cgj.bot.framework.message.MessageSource; +import org.pf4j.ExtensionPoint; + +/** + * 消息源发送器构造工厂. + *

该接口实现将由对应框架实现, 每个框架仅允许实现一个. + * @author LamGC + */ +public interface SenderFactory extends ExtensionPoint { + + /** + * 获取所属平台. + * @return 返回平台信息对象. + */ + Platform getPlatform(); + + /** + * 获取发送器. + * @param source 消息源类型. + * @param id 消息源 Id. + * @return 返回消息发送器, 本方法不允许返回 null. + * @throws NoFoundSenderException 当无法获取对应的消息源发送器时, 将抛出该异常. + */ + MessageSender getSender(MessageSource source, long id) throws NoFoundSenderException; + +}