mirror of
https://github.com/LamGC/ContentGrabbingJi.git
synced 2025-04-29 22:27:33 +00:00
[Change] SpringCQMessageSenderFactory 尝试通过ThreadLocal获取当前处理的CoolQ对象, 目前EventExecutor暂不支持, 仅预留;
[Change] CQPluginMain 调整'processMessage'方法修饰符, 补充Javadoc;
This commit is contained in:
parent
0fafddc715
commit
f5140a7a1e
@ -17,6 +17,7 @@ public class CQPluginMain extends CQPlugin implements EventHandler {
|
||||
|
||||
public CQPluginMain() {
|
||||
// TODO(LamGC, 2020.04.21): SpringCQ无法适配MessageSenderBuilder
|
||||
// MessageSenderBuilder.setCurrentMessageSenderFactory(new SpringCQMessageSenderFactory());
|
||||
BotEventHandler.preLoad();
|
||||
LoggerFactory.getLogger(CQPluginMain.class.getName())
|
||||
.info("BotEventHandler.COMMAND_PREFIX = {}", BotEventHandler.COMMAND_PREFIX);
|
||||
@ -37,7 +38,13 @@ public class CQPluginMain extends CQPlugin implements EventHandler {
|
||||
return processMessage(cq, event);
|
||||
}
|
||||
|
||||
public int processMessage(CoolQ cq, CQMessageEvent event) {
|
||||
/**
|
||||
* 处理消息
|
||||
* @param cq CoolQ机器人对象
|
||||
* @param event 消息事件
|
||||
* @return 是否拦截消息
|
||||
*/
|
||||
private static int processMessage(CoolQ cq, CQMessageEvent event) {
|
||||
if(!BotEventHandler.match(event.getMessage())) {
|
||||
return MESSAGE_IGNORE;
|
||||
}
|
||||
|
@ -5,16 +5,14 @@ import net.lamgc.cgj.bot.message.MessageSenderFactory;
|
||||
import net.lamgc.cgj.bot.message.MessageSource;
|
||||
import net.lz1998.cq.robot.CoolQ;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class SpringCQMessageSenderFactory implements MessageSenderFactory {
|
||||
|
||||
private final CoolQ coolQ;
|
||||
|
||||
public SpringCQMessageSenderFactory(CoolQ coolQ) {
|
||||
this.coolQ = coolQ;
|
||||
}
|
||||
|
||||
private final static ThreadLocal<CoolQ> threadCoolQ = new ThreadLocal<>();
|
||||
@Override
|
||||
public MessageSender createMessageSender(MessageSource source, long id) {
|
||||
return new SpringCQMessageSender(coolQ, source, id);
|
||||
return new SpringCQMessageSender(
|
||||
Objects.requireNonNull(threadCoolQ.get(), "CoolQ object is not included in ThreadLocal"), source, id);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user