mirror of
				https://github.com/LamGC/ContentGrabbingJi.git
				synced 2025-10-31 00:26:56 +00:00 
			
		
		
		
	[Change] SpringCQMessageSenderFactory 尝试通过ThreadLocal获取当前处理的CoolQ对象, 目前EventExecutor暂不支持, 仅预留;
[Change] CQPluginMain 调整'processMessage'方法修饰符, 补充Javadoc;
This commit is contained in:
		| @ -17,6 +17,7 @@ public class CQPluginMain extends CQPlugin implements EventHandler { | |||||||
|  |  | ||||||
|     public CQPluginMain() { |     public CQPluginMain() { | ||||||
|         // TODO(LamGC, 2020.04.21): SpringCQ无法适配MessageSenderBuilder |         // TODO(LamGC, 2020.04.21): SpringCQ无法适配MessageSenderBuilder | ||||||
|  |         // MessageSenderBuilder.setCurrentMessageSenderFactory(new SpringCQMessageSenderFactory()); | ||||||
|         BotEventHandler.preLoad(); |         BotEventHandler.preLoad(); | ||||||
|         LoggerFactory.getLogger(CQPluginMain.class.getName()) |         LoggerFactory.getLogger(CQPluginMain.class.getName()) | ||||||
|                 .info("BotEventHandler.COMMAND_PREFIX = {}", BotEventHandler.COMMAND_PREFIX); |                 .info("BotEventHandler.COMMAND_PREFIX = {}", BotEventHandler.COMMAND_PREFIX); | ||||||
| @ -37,7 +38,13 @@ public class CQPluginMain extends CQPlugin implements EventHandler { | |||||||
|         return processMessage(cq, event); |         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())) { |         if(!BotEventHandler.match(event.getMessage())) { | ||||||
|             return MESSAGE_IGNORE; |             return MESSAGE_IGNORE; | ||||||
|         } |         } | ||||||
|  | |||||||
| @ -5,16 +5,14 @@ import net.lamgc.cgj.bot.message.MessageSenderFactory; | |||||||
| import net.lamgc.cgj.bot.message.MessageSource; | import net.lamgc.cgj.bot.message.MessageSource; | ||||||
| import net.lz1998.cq.robot.CoolQ; | import net.lz1998.cq.robot.CoolQ; | ||||||
|  |  | ||||||
|  | import java.util.Objects; | ||||||
|  |  | ||||||
| public class SpringCQMessageSenderFactory implements MessageSenderFactory { | public class SpringCQMessageSenderFactory implements MessageSenderFactory { | ||||||
|  |  | ||||||
|     private final CoolQ coolQ; |     private final static ThreadLocal<CoolQ> threadCoolQ = new ThreadLocal<>(); | ||||||
|  |  | ||||||
|     public SpringCQMessageSenderFactory(CoolQ coolQ) { |  | ||||||
|         this.coolQ = coolQ; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public MessageSender createMessageSender(MessageSource source, long id) { |     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); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user