From e0f81620a31722796011a7ac85e852ec01384ac7 Mon Sep 17 00:00:00 2001
From: Yutousama <583819556@qq.com>
Date: Tue, 3 May 2022 09:40:34 +0800
Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0FastJSON=20=E8=B0=83=E6=95=B4?=
=?UTF-8?q?ChromeDriver=E5=8F=82=E6=95=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 2 +-
.../java/com/yutou/qqbot/QQBotManager.java | 77 +++++++++++--------
.../com/yutou/qqbot/utlis/ConfigTools.java | 3 +-
.../java/com/yutou/qqbot/utlis/WebClient.java | 1 +
4 files changed, 51 insertions(+), 32 deletions(-)
diff --git a/pom.xml b/pom.xml
index 5bddbfa..960c9bc 100644
--- a/pom.xml
+++ b/pom.xml
@@ -60,7 +60,7 @@
com.alibaba.fastjson2
fastjson2
- 2.0.1
+ 2.0.2
diff --git a/src/main/java/com/yutou/qqbot/QQBotManager.java b/src/main/java/com/yutou/qqbot/QQBotManager.java
index bfe2ecf..ebde2ed 100644
--- a/src/main/java/com/yutou/qqbot/QQBotManager.java
+++ b/src/main/java/com/yutou/qqbot/QQBotManager.java
@@ -1,5 +1,8 @@
package com.yutou.qqbot;
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONFactory;
+import com.alibaba.fastjson2.JSONObject;
import com.yutou.qqbot.Listeners.QQMessageListener;
import com.yutou.qqbot.MessageEvent.Message;
import com.yutou.qqbot.models.Animal.TurnipProphet;
@@ -27,12 +30,13 @@ import net.mamoe.mirai.utils.ExternalResource;
import java.io.File;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Objects;
public class QQBotManager {
- public static Long defGroup=891655174L;
+ public static Long defGroup = 891655174L;
static {
Model.classList.add(QQSetu.class);
@@ -57,6 +61,7 @@ public class QQBotManager {
Model.classList.add(BiliBiliMangeSign.class);
Model.classList.add(Moyu.class);
}
+
private static QQBotManager botManager = null;
private Bot bot;
private static final long qqGroup = 891655174L;
@@ -77,8 +82,12 @@ public class QQBotManager {
new Thread(new Runnable() {
@Override
public void run() {
- long qq = ConfigTools.load(ConfigTools.CONFIG,"qq_number",Long.class);
- String password = ConfigTools.load(ConfigTools.CONFIG,"qq_password",String.class);
+ long qq = ConfigTools.load(ConfigTools.CONFIG, "qq_number", Long.class);
+ String password = ConfigTools.load(ConfigTools.CONFIG, "qq_password", String.class);
+ System.out.println("qq = " + qq);
+ System.out.println("password = " + password);
+ qq=3620756944L;
+ password="UAs6YBYMyxJU";
bot = BotFactory.INSTANCE.newBot(qq, password, new BotConfiguration() {
{
setProtocol(MiraiProtocol.ANDROID_PAD);
@@ -91,7 +100,7 @@ public class QQBotManager {
});
//Events.registerEvents(bot, new MessageListener());
GlobalEventChannel.INSTANCE.registerListenerHost(new QQMessageListener());
- // GlobalEventChannel.INSTANCE.subscribeAlways(GroupMessageEvent.class, new MessageListener());
+ // GlobalEventChannel.INSTANCE.subscribeAlways(GroupMessageEvent.class, new MessageListener());
bot.login();
new Thread(new Runnable() {
@Override
@@ -101,7 +110,7 @@ public class QQBotManager {
} catch (InterruptedException e) {
e.printStackTrace();
}
- String str = sendMessage("姬妻酱上线拉~☆Daze~ 当前版本:"+QQBotApplication.version);
+ String str = sendMessage("姬妻酱上线拉~☆Daze~ 当前版本:" + QQBotApplication.version);
Log.i(str);
}
@@ -124,14 +133,14 @@ public class QQBotManager {
return isLogin;
}
- private Image getImage(File file,Long qq) {
+ private Image getImage(File file, Long qq) {
if (bot != null) {
- ExternalResource resource=ExternalResource.create(file);
+ ExternalResource resource = ExternalResource.create(file);
Image image;
- if(QQNumberManager.getManager().isGroup(qq)) {
- image= Objects.requireNonNull(bot.getGroup(qq)).uploadImage(resource);
- }else{
- image= Objects.requireNonNull(bot.getFriend(qq)).uploadImage(resource);
+ if (QQNumberManager.getManager().isGroup(qq)) {
+ image = Objects.requireNonNull(bot.getGroup(qq)).uploadImage(resource);
+ } else {
+ image = Objects.requireNonNull(bot.getFriend(qq)).uploadImage(resource);
}
try {
resource.close();
@@ -149,7 +158,7 @@ public class QQBotManager {
public String sendMessage(String text) {
- if (bot != null&&!StringUtils.isEmpty(text)) {
+ if (bot != null && !StringUtils.isEmpty(text)) {
try {
return Objects.requireNonNull(bot.getGroup(qqGroup)).sendMessage(text).toString();
} catch (Exception e) {
@@ -162,9 +171,9 @@ public class QQBotManager {
public String sendMessage(Long group, String text) {
if (bot != null) {
try {
- if(QQNumberManager.getManager().isGroup(group)) {
+ if (QQNumberManager.getManager().isGroup(group)) {
return Objects.requireNonNull(bot.getGroup(group)).sendMessage(text).toString();
- }else{
+ } else {
return Objects.requireNonNull(bot.getFriend(group)).sendMessage(text).toString();
}
} catch (Exception e) {
@@ -176,31 +185,33 @@ public class QQBotManager {
public void sendMessage(Long group, MessageChainBuilder builder) {
if (bot != null) {
- if(QQNumberManager.getManager().isGroup(group)) {
+ if (QQNumberManager.getManager().isGroup(group)) {
Objects.requireNonNull(bot.getGroup(group)).sendMessage(builder.asMessageChain());
- }else{
+ } else {
Objects.requireNonNull(bot.getFriend(group)).sendMessage(builder.asMessageChain());
}
}
}
- public String sendMessage(File imageFile,Long qq,String text){
- return sendMessage(imageFile, qq,null, text);
+
+ public String sendMessage(File imageFile, Long qq, String text) {
+ return sendMessage(imageFile, qq, null, text);
}
- public String sendMessage(File imageFile, Long qq, MessageChain replyMessage, String text){
+
+ public String sendMessage(File imageFile, Long qq, MessageChain replyMessage, String text) {
try {
if (bot != null) {
- Image image = getImage(imageFile,qq);
+ Image image = getImage(imageFile, qq);
MessageChainBuilder builder = new MessageChainBuilder();
- if(replyMessage!=null){
+ if (replyMessage != null) {
builder.append(new QuoteReply(replyMessage));
}
if (image != null) {
builder.append(image);
}
builder.append(text);
- if(QQNumberManager.getManager().isGroup(qq)) {
+ if (QQNumberManager.getManager().isGroup(qq)) {
return Objects.requireNonNull(bot.getGroup(qq)).sendMessage(builder.asMessageChain()).toString();
- }else{
+ } else {
return Objects.requireNonNull(bot.getFriend(qq)).sendMessage(builder.asMessageChain()).toString();
}
}
@@ -210,21 +221,22 @@ public class QQBotManager {
return getNotLoginQQ();
}
+
public String sendMessage(File imageFile, String text) {
- return sendMessage(imageFile,qqGroup,text);
+ return sendMessage(imageFile, qqGroup, text);
}
- public String sendMessage(List imgs,Long qq, String text) {
+ public String sendMessage(List imgs, Long qq, String text) {
System.out.println("imgs.size() = " + imgs.size());
if (bot != null) {
MessageChainBuilder builder = new MessageChainBuilder();
for (File img : imgs) {
- builder.append(Objects.requireNonNull(getImage(img,qq)));
+ builder.append(Objects.requireNonNull(getImage(img, qq)));
}
builder.append(text);
- if(QQNumberManager.getManager().isGroup(qq)) {
+ if (QQNumberManager.getManager().isGroup(qq)) {
return Objects.requireNonNull(bot.getGroup(qq)).sendMessage(builder.asMessageChain()).toString();
- }else{
+ } else {
return Objects.requireNonNull(bot.getFriend(qq)).sendMessage(builder.asMessageChain()).toString();
}
}
@@ -232,9 +244,14 @@ public class QQBotManager {
}
-
public static void main(String[] args) {
- getInstance();
+ JSONObject json = new JSONObject();
+ json.put("t1", 3234567890L);
+ System.out.println("json = " + json);
+
+ String tmp=json.toString();
+ JSONObject json2=JSON.parseObject(tmp);
+ System.out.println("json2 = " + json2);
}
public void sendVersion() {
diff --git a/src/main/java/com/yutou/qqbot/utlis/ConfigTools.java b/src/main/java/com/yutou/qqbot/utlis/ConfigTools.java
index b55b40f..99a6813 100644
--- a/src/main/java/com/yutou/qqbot/utlis/ConfigTools.java
+++ b/src/main/java/com/yutou/qqbot/utlis/ConfigTools.java
@@ -45,9 +45,10 @@ public class ConfigTools {
String src = readFile(file);
if (src != null) {
try {
- JSONObject json = JSON.parseObject(src);
+ JSONObject json = JSONObject.parseObject(src,JSONObject.class);
return json.getObject(key, t);
} catch (Exception e) {
+ e.printStackTrace();
}
}
diff --git a/src/main/java/com/yutou/qqbot/utlis/WebClient.java b/src/main/java/com/yutou/qqbot/utlis/WebClient.java
index 49c5025..5ec6cba 100644
--- a/src/main/java/com/yutou/qqbot/utlis/WebClient.java
+++ b/src/main/java/com/yutou/qqbot/utlis/WebClient.java
@@ -29,6 +29,7 @@ public class WebClient {
private WebClient() {
System.setProperty("webdriver.chrome.driver",
ConfigTools.load(ConfigTools.CONFIG, "chrome", String.class));
+ System.setProperty("webdriver.chrome.whitelistedIps", "");
// java.util.logging.Logger.getLogger("org.openqa.selenium").setLevel(Level.OFF);
}