[Delete] application.properties 移除Properties版Application配置文件;

[Delete] CQConfig 移除不兼容的类;
[Add] application.yml 添加yml格式的Application配置文件;
[Change] Main 移除CQConfig类引用;
[Update] net.lz1998:spring-cq 升级依赖项版本(4.14.0.6 -> 4.15.0.1);
[Change] SpringCQMessageSenderFactory, CQPluginMain 使用较为妥协的方法实现SenderFactory;
This commit is contained in:
LamGC 2020-07-02 14:02:01 +08:00
parent 62e3affef1
commit d3d6f151d4
Signed by: LamGC
GPG Key ID: 6C5AE2A913941E1D
7 changed files with 30 additions and 34 deletions

View File

@ -121,7 +121,7 @@
<dependency>
<groupId>net.lz1998</groupId>
<artifactId>spring-cq</artifactId>
<version>4.14.0.6</version>
<version>4.15.0.1</version>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>

View File

@ -8,7 +8,6 @@ import com.google.gson.JsonObject;
import net.lamgc.cgj.bot.boot.ApplicationBoot;
import net.lamgc.cgj.bot.boot.BotGlobal;
import net.lamgc.cgj.bot.framework.cli.ConsoleMain;
import net.lamgc.cgj.bot.framework.coolq.CQConfig;
import net.lamgc.cgj.bot.framework.mirai.MiraiMain;
import net.lamgc.cgj.pixiv.PixivDownload;
import net.lamgc.cgj.pixiv.PixivSearchLinkBuilder;
@ -106,7 +105,6 @@ public class Main {
@Command
public static void pluginMode(@Argument(name = "args", force = false) String argsStr) {
log.info("酷Q机器人根目录: {}", BotGlobal.getGlobal().getDataStoreDir().getPath());
CQConfig.init();
Pattern pattern = Pattern.compile("/\\s*(\".+?\"|[^:\\s])+((\\s*:\\s*(\".+?\"|[^\\s])+)|)|(\".+?\"|[^\"\\s])+");
Matcher matcher = pattern.matcher(Strings.nullToEmpty(argsStr));
ArrayList<String> argsList = new ArrayList<>();

View File

@ -1,27 +0,0 @@
package net.lamgc.cgj.bot.framework.coolq;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import net.lz1998.cq.CQGlobal;
import net.lz1998.cq.EnableCQ;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@EnableCQ
public class CQConfig {
public static void init() {
CQGlobal.pluginList.add(CQPluginMain.class);
CQGlobal.executor = new ThreadPoolExecutor(
(int) Math.ceil(Runtime.getRuntime().availableProcessors() / 2F),
Runtime.getRuntime().availableProcessors(),
25, TimeUnit.SECONDS,
new LinkedBlockingQueue<>(512),
new ThreadFactoryBuilder()
.setNameFormat("Plugin-ProcessThread-%d")
.build()
);
}
}

View File

@ -3,6 +3,7 @@ package net.lamgc.cgj.bot.framework.coolq;
import net.lamgc.cgj.bot.boot.ApplicationBoot;
import net.lamgc.cgj.bot.event.BotEventHandler;
import net.lamgc.cgj.bot.framework.coolq.message.SpringCQMessageEvent;
import net.lamgc.cgj.bot.framework.coolq.message.SpringCQMessageSenderFactory;
import net.lamgc.utils.event.EventHandler;
import net.lz1998.cq.event.message.CQDiscussMessageEvent;
import net.lz1998.cq.event.message.CQGroupMessageEvent;
@ -46,6 +47,7 @@ public class CQPluginMain extends CQPlugin implements EventHandler {
* @return 是否拦截消息
*/
private static int processMessage(CoolQ cq, CQMessageEvent event) {
SpringCQMessageSenderFactory.setCoolQ(cq);
if(BotEventHandler.mismatch(event.getMessage())) {
return MESSAGE_IGNORE;
}

View File

@ -6,13 +6,26 @@ import net.lamgc.cgj.bot.message.MessageSource;
import net.lz1998.cq.robot.CoolQ;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;
public class SpringCQMessageSenderFactory implements MessageSenderFactory {
private final static ThreadLocal<CoolQ> threadCoolQ = new ThreadLocal<>();
private final static AtomicReference<CoolQ> coolQ = new AtomicReference<>();
/**
* 设置CoolQ对象.
* <p>该方法仅接受第一次设置的CoolQ对象, 其他对象将会忽略.</p>
* @param coolQObj CoolQ对象
*/
public static void setCoolQ(CoolQ coolQObj) {
if(coolQ.get() == null) {
coolQ.set(coolQObj);
}
}
@Override
public MessageSender createMessageSender(MessageSource source, long id) {
return new SpringCQMessageSender(
Objects.requireNonNull(threadCoolQ.get(), "CoolQ object is not included in ThreadLocal"), source, id);
Objects.requireNonNull(coolQ.get(), "CoolQ object not ready"), source, id);
}
}

View File

@ -1,2 +0,0 @@
server.port=8081
server.tomcat.max-threads=1

View File

@ -0,0 +1,12 @@
server:
port: 8081
spring:
cq:
plugin-list:
- net.lamgc.cgj.bot.framework.coolq.CQPluginMain
event:
corePoolSize: 8
maxPoolSize: 16
keepAliveTime: 25000
workQueueSize: 1024