Compare commits

...

6 Commits

Author SHA1 Message Date
10cad32efa [Version] 更新版本(2.2.1 -> 2.3.0); 2020-04-28 23:16:10 +08:00
22a113ef38 [Change] 调整CGJ包结构, 将机器人平台相关类单独存放在framework包内; 2020-04-28 23:15:55 +08:00
6824b12e8f [Add] MiraiMessageSender 增加对闪照的支持; 2020-04-28 10:57:17 +08:00
1c556c5b94 [Update] MiraiMessageSender 对已上传的图片所属ImageId设置10天有效期; 2020-04-28 00:32:40 +08:00
dbc9f4c90b [Fix] BotCommandProcess 修复了通过缓存获取排行榜时排行榜从第2名开始读取的bug;
[Update] MiraiMain, MiraiMessageSender, MiraiMessageEvent 更新Mirai框架(0.32.0 -> 0.39.4)并适配框架新版本的变动;
2020-04-28 00:19:24 +08:00
d3c1975722 [Fix] PixivURL 修复由于智障修复导致的bug; 2020-04-27 23:26:22 +08:00
13 changed files with 49 additions and 33 deletions

View File

@ -6,7 +6,7 @@
<groupId>net.lamgc</groupId>
<artifactId>ContentGrabbingJi</artifactId>
<version>2.2.1</version>
<version>2.3.0</version>
<repositories>
<repository>
@ -19,7 +19,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
<mirai.CoreVersion>0.32.0</mirai.CoreVersion>
<mirai.CoreVersion>0.39.4</mirai.CoreVersion>
<mirai.JaptVersion>1.1.1</mirai.JaptVersion>
<kotlin.version>1.3.71</kotlin.version>
<ktor.version>1.3.2</ktor.version>
@ -151,12 +151,12 @@
</dependency>
<dependency>
<groupId>net.mamoe</groupId>
<artifactId>mirai-core-jvm</artifactId>
<artifactId>mirai-core</artifactId>
<version>${mirai.CoreVersion}</version>
</dependency>
<dependency>
<groupId>net.mamoe</groupId>
<artifactId>mirai-core-qqandroid-jvm</artifactId>
<artifactId>mirai-core-qqandroid</artifactId>
<version>${mirai.CoreVersion}</version>
</dependency>
<dependency>

View File

@ -7,8 +7,8 @@ import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import net.lamgc.cgj.bot.CQConfig;
import net.lamgc.cgj.bot.MiraiMain;
import net.lamgc.cgj.bot.framework.coolq.CQConfig;
import net.lamgc.cgj.bot.framework.mirai.MiraiMain;
import net.lamgc.cgj.pixiv.*;
import net.lamgc.cgj.proxy.PixivAccessProxyServer;
import net.lamgc.plps.PixivLoginProxyServer;

View File

@ -786,7 +786,7 @@ public class BotCommandProcess {
}
if (Objects.isNull(result)) {
result = rankingCache.getCache(requestSign, start, range);
result = rankingCache.getCache(requestSign, start - 1, range);
log.debug("RequestSign [{}] 缓存命中.", requestSign);
}
log.debug("Result-Length: {}", result.size());

View File

@ -1,4 +1,4 @@
package net.lamgc.cgj.bot;
package net.lamgc.cgj.bot.framework.coolq;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import net.lz1998.cq.CQGlobal;

View File

@ -1,7 +1,7 @@
package net.lamgc.cgj.bot;
package net.lamgc.cgj.bot.framework.coolq;
import net.lamgc.cgj.bot.event.BotEventHandler;
import net.lamgc.cgj.bot.event.SpringCQMessageEvent;
import net.lamgc.cgj.bot.framework.coolq.message.SpringCQMessageEvent;
import net.lamgc.utils.event.EventHandler;
import net.lz1998.cq.event.message.CQDiscussMessageEvent;
import net.lz1998.cq.event.message.CQGroupMessageEvent;

View File

@ -1,9 +1,9 @@
package net.lamgc.cgj.bot.event;
package net.lamgc.cgj.bot.framework.coolq.message;
import net.lamgc.cgj.bot.BotCode;
import net.lamgc.cgj.bot.event.MessageEvent;
import net.lamgc.cgj.bot.message.MessageSender;
import net.lamgc.cgj.bot.message.MessageSource;
import net.lamgc.cgj.bot.message.SpringCQMessageSender;
import net.lz1998.cq.event.message.CQDiscussMessageEvent;
import net.lz1998.cq.event.message.CQGroupMessageEvent;
import net.lz1998.cq.event.message.CQMessageEvent;

View File

@ -1,5 +1,7 @@
package net.lamgc.cgj.bot.message;
package net.lamgc.cgj.bot.framework.coolq.message;
import net.lamgc.cgj.bot.message.MessageSender;
import net.lamgc.cgj.bot.message.MessageSource;
import net.lz1998.cq.robot.CoolQ;
public class SpringCQMessageSender implements MessageSender {

View File

@ -1,5 +1,8 @@
package net.lamgc.cgj.bot.message;
package net.lamgc.cgj.bot.framework.coolq.message;
import net.lamgc.cgj.bot.message.MessageSender;
import net.lamgc.cgj.bot.message.MessageSenderFactory;
import net.lamgc.cgj.bot.message.MessageSource;
import net.lz1998.cq.robot.CoolQ;
public class SpringCQMessageSenderFactory implements MessageSenderFactory {

View File

@ -1,14 +1,14 @@
package net.lamgc.cgj.bot;
package net.lamgc.cgj.bot.framework.mirai;
import net.lamgc.cgj.bot.event.BotEventHandler;
import net.lamgc.cgj.bot.event.MiraiMessageEvent;
import net.lamgc.cgj.bot.framework.mirai.message.MiraiMessageEvent;
import net.lamgc.cgj.bot.message.MessageSenderBuilder;
import net.lamgc.cgj.bot.message.MiraiMessageSenderFactory;
import net.lamgc.cgj.bot.framework.mirai.message.MiraiMessageSenderFactory;
import net.mamoe.mirai.Bot;
import net.mamoe.mirai.BotFactoryJvm;
import net.mamoe.mirai.japt.Events;
import net.mamoe.mirai.message.FriendMessage;
import net.mamoe.mirai.message.GroupMessage;
import net.mamoe.mirai.qqandroid.QQAndroid;
import net.mamoe.mirai.utils.BotConfiguration;
import org.apache.commons.net.util.Base64;
import org.slf4j.Logger;
@ -42,7 +42,7 @@ public class MiraiMain implements Closeable {
return;
}
bot = QQAndroid.INSTANCE.newBot(Long.parseLong(botProperties.getProperty("bot.qq", "0")), Base64.decodeBase64(botProperties.getProperty("bot.password", "")), new BotConfiguration());
bot = BotFactoryJvm.newBot(Long.parseLong(botProperties.getProperty("bot.qq", "0")), Base64.decodeBase64(botProperties.getProperty("bot.password", "")), new BotConfiguration());
Events.subscribeAlways(GroupMessage.class, (msg) -> BotEventHandler.executor.executor(new MiraiMessageEvent(msg)));
Events.subscribeAlways(FriendMessage.class, (msg) -> BotEventHandler.executor.executor(new MiraiMessageEvent(msg)));
bot.login();

View File

@ -1,8 +1,8 @@
package net.lamgc.cgj.bot.event;
package net.lamgc.cgj.bot.framework.mirai.message;
import net.lamgc.cgj.bot.event.MessageEvent;
import net.lamgc.cgj.bot.message.MessageSender;
import net.lamgc.cgj.bot.message.MessageSource;
import net.lamgc.cgj.bot.message.MiraiMessageSender;
import net.mamoe.mirai.message.ContactMessage;
import net.mamoe.mirai.message.GroupMessage;
import net.mamoe.mirai.message.data.MessageUtils;
@ -16,7 +16,7 @@ public class MiraiMessageEvent extends MessageEvent {
public MiraiMessageEvent(ContactMessage message) {
super(message instanceof GroupMessage ? ((GroupMessage) message).getGroup().getId() : 0,
message.getSender().getId(), message.getMessage().toString());
message.getSender().getId(), message.getMessage().contentToString());
this.messageObject = Objects.requireNonNull(message);
if(message instanceof GroupMessage) {
messageSender = new MiraiMessageSender(((GroupMessage) message).getGroup(), MessageSource.Group);

View File

@ -1,4 +1,4 @@
package net.lamgc.cgj.bot.message;
package net.lamgc.cgj.bot.framework.mirai.message;
import com.google.common.base.Strings;
import net.lamgc.cgj.bot.BotCode;
@ -7,11 +7,13 @@ import net.lamgc.cgj.bot.cache.HotDataCacheStore;
import net.lamgc.cgj.bot.cache.LocalHashCacheStore;
import net.lamgc.cgj.bot.cache.StringRedisCacheStore;
import net.lamgc.cgj.bot.event.BotEventHandler;
import net.lamgc.cgj.bot.message.MessageSender;
import net.lamgc.cgj.bot.message.MessageSource;
import net.mamoe.mirai.Bot;
import net.mamoe.mirai.contact.Contact;
import net.mamoe.mirai.message.data.CombinedMessage;
import net.mamoe.mirai.message.data.Image;
import net.mamoe.mirai.message.data.Message;
import net.mamoe.mirai.message.data.MessageChain;
import net.mamoe.mirai.message.data.MessageUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -78,7 +80,7 @@ public class MiraiMessageSender implements MessageSender {
.replaceAll("&38", "&")
.split("\\|");
CombinedMessage chain = MessageUtils.newChain().plus("");
MessageChain messages = MessageUtils.newChain().plus("");
int codeIndex = 0;
for(String text : texts) {
if(text.equals("{BotCode}")) {
@ -89,25 +91,31 @@ public class MiraiMessageSender implements MessageSender {
log.warn("解析待发送消息内的BotCode时发生异常, 请检查错误格式BotCode的来源并尽快排错!", e);
continue;
}
chain = chain.plus(processBotCode(code));
messages = messages.plus(processBotCode(code));
} else {
chain = chain.plus(text);
messages = messages.plus(text);
}
}
return chain;
return messages;
}
private Message processBotCode(BotCode code) {
switch(code.getFunctionName().toLowerCase()) {
case "image":
Image img;
if(code.containsParameter("id")) {
return MessageUtils.newImage(code.getParameter("id"));
img = MessageUtils.newImage(code.getParameter("id"));
} else if(code.containsParameter("absolutePath")) {
return uploadImage(code);
img = uploadImage(code);
} else {
return MessageUtils.newChain("(参数不存在)");
}
if(code.getParameter("flashImage").equalsIgnoreCase("true")) {
return MessageUtils.flash(img);
} else {
return img;
}
default:
log.warn("解析到不支持的BotCode: {}", code);
return MessageUtils.newChain("(不支持的BotCode)");
@ -138,7 +146,7 @@ public class MiraiMessageSender implements MessageSender {
log.debug("imageName [{}] 缓存失效或强制更新, 正在更新缓存...", imageName);
image = uploadImage0(new File(absolutePath));
String cacheExpireAt;
long expireTime = 0;
long expireTime = 864000000; // 10d
if(!Strings.isNullOrEmpty(cacheExpireAt = code.getParameter("cacheExpireAt"))) {
try {
expireTime = Integer.parseInt(cacheExpireAt);

View File

@ -1,5 +1,8 @@
package net.lamgc.cgj.bot.message;
package net.lamgc.cgj.bot.framework.mirai.message;
import net.lamgc.cgj.bot.message.MessageSender;
import net.lamgc.cgj.bot.message.MessageSenderFactory;
import net.lamgc.cgj.bot.message.MessageSource;
import net.mamoe.mirai.Bot;
public class MiraiMessageSenderFactory implements MessageSenderFactory {

View File

@ -336,7 +336,7 @@ public class PixivURL {
* @return 如果支持返回true
*/
public boolean isSupportedMode(RankingMode mode) {
return Arrays.binarySearch(supportedMode, mode) < 0;
return Arrays.binarySearch(supportedMode, mode) >= 0;
}
}