mirror of
https://github.com/LamGC/ContentGrabbingJi.git
synced 2025-04-30 06:37:36 +00:00
[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:
parent
62e3affef1
commit
d3d6f151d4
2
pom.xml
2
pom.xml
@ -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>
|
||||
|
@ -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<>();
|
||||
|
@ -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()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -1,2 +0,0 @@
|
||||
server.port=8081
|
||||
server.tomcat.max-threads=1
|
12
src/main/resources/application.yml
Normal file
12
src/main/resources/application.yml
Normal 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
|
Loading…
Reference in New Issue
Block a user