mirror of
https://github.com/LamGC/ContentGrabbingJi.git
synced 2025-04-29 22:27:33 +00:00
[Add] Framework-API 添加提供给应用内部(或命令扩展)用于主动获取对应平台 Sender 的扩展接口;
[Add] SenderFactory 添加用于主动获取 Sender 的扩展接口; [Add] NoFoundSenderException 添加相关异常;
This commit is contained in:
parent
711c80175e
commit
68f13a38c1
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.lamgc.cgj.bot.framework;
|
||||||
|
|
||||||
|
import net.lamgc.cgj.bot.framework.message.MessageSource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 无对应消息源异常.
|
||||||
|
* <p> 当 {@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;
|
||||||
|
}
|
||||||
|
}
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息源发送器构造工厂.
|
||||||
|
* <p> 该接口实现将由对应框架实现, 每个框架仅允许实现一个.
|
||||||
|
* @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;
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user