完成基本功能转移
This commit is contained in:
@@ -1,17 +1,19 @@
|
||||
package com.yutou.qqbot.utlis;
|
||||
|
||||
import com.yutou.napcat.QQDatabase;
|
||||
import com.yutou.napcat.model.GroupBean;
|
||||
import com.yutou.qqbot.Annotations.UseModel;
|
||||
import com.yutou.qqbot.QQBotManager;
|
||||
import com.yutou.qqbot.QQNumberManager;
|
||||
import com.yutou.qqbot.models.Model;
|
||||
import net.mamoe.mirai.Bot;
|
||||
import net.mamoe.mirai.contact.Group;
|
||||
import lombok.val;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
@@ -35,7 +37,15 @@ public class ApplicationInit implements ApplicationRunner {
|
||||
for (Class<?> model : Model.classList) {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
Bot bot = QQBotManager.getInstance().getBot();
|
||||
List<GroupBean> groups = QQDatabase.getGroups();
|
||||
Model useModel = (Model) model.getDeclaredConstructor().newInstance();
|
||||
for (GroupBean group : groups) {
|
||||
if (QQNumberManager.getManager().isUseModel(group.getGroupId(), model)) {
|
||||
useModel.onTime(group.getGroupId(), time);
|
||||
}
|
||||
}
|
||||
|
||||
/* Bot bot = QQBotManager.getInstance().getBot();
|
||||
if (bot == null) {
|
||||
return;
|
||||
}
|
||||
@@ -44,7 +54,7 @@ public class ApplicationInit implements ApplicationRunner {
|
||||
if (QQNumberManager.getManager().isUseModel(group.getId(), model)) {
|
||||
useModel.onTime(group.getId(), time);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -13,9 +13,10 @@ import java.util.Map;
|
||||
public class BaiduGPTManager {
|
||||
private static int MAX_MESSAGE = 5;
|
||||
private static BaiduGPTManager manager;
|
||||
private static final String url = "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions";
|
||||
private static final String url_3_5 = "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions";
|
||||
//4.0
|
||||
//private static final String url = "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions_pro";
|
||||
private static final String url_4_0 = "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions_pro";
|
||||
private static String url = url_3_5;
|
||||
private static final String AppID = "36668599";
|
||||
private static final String ApiKey = "eyHo6K2ILBm7i378701Az1eT";
|
||||
private static final String SecretKey = "U4vXt8AOTM9FgB0Omft5IOh6vwhzoDgZ";
|
||||
@@ -37,6 +38,14 @@ public class BaiduGPTManager {
|
||||
return MAX_MESSAGE;
|
||||
}
|
||||
|
||||
public void setModelFor40() {
|
||||
url = url_4_0;
|
||||
}
|
||||
|
||||
public void setModelFor35() {
|
||||
url = url_3_5;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
msgMap.clear();
|
||||
}
|
||||
@@ -67,7 +76,7 @@ public class BaiduGPTManager {
|
||||
map.put("Content-Type", "application/json");
|
||||
map.put("Content-Length", String.valueOf(json.toJSONString().getBytes(StandardCharsets.UTF_8).length));
|
||||
String post = HttpTools.http_post(url + "?access_token=" + getToken()
|
||||
, json.toJSONString().getBytes(StandardCharsets.UTF_8),0,map);
|
||||
, json.toJSONString().getBytes(StandardCharsets.UTF_8), 0, map);
|
||||
System.out.println("post = " + post);
|
||||
if (StringUtils.isEmpty(post)) {
|
||||
clear();
|
||||
@@ -80,9 +89,12 @@ public class BaiduGPTManager {
|
||||
return response;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
ResponseMessage message = BaiduGPTManager.getManager().sendMessage("test", "2023年创业什么赚钱?");
|
||||
System.out.println(message.getResult());
|
||||
public String getGPTVersion() {
|
||||
return (url.equals(url_3_5) ? "3.5" : "4.0");
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
ResponseMessage message = BaiduGPTManager.getManager().sendMessage("test", "你是那个版本的大模型?");
|
||||
System.out.println(message.getResult());
|
||||
}
|
||||
}
|
||||
|
||||
38
src/main/java/com/yutou/qqbot/utlis/Base64Tools.java
Normal file
38
src/main/java/com/yutou/qqbot/utlis/Base64Tools.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package com.yutou.qqbot.utlis;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Base64;
|
||||
|
||||
public class Base64Tools {
|
||||
public static String encode(String str) {
|
||||
return java.util.Base64.getEncoder().encodeToString(str.getBytes());
|
||||
}
|
||||
|
||||
public static String decode(String str) {
|
||||
return new String(java.util.Base64.getDecoder().decode(str));
|
||||
}
|
||||
|
||||
public static String encode(byte[] bytes) {
|
||||
return java.util.Base64.getEncoder().encodeToString(bytes);
|
||||
}
|
||||
|
||||
public static String encode(File file) {
|
||||
try {
|
||||
byte[] fileContent = Files.readAllBytes(Paths.get(file.getAbsolutePath()));
|
||||
return encode(fileContent);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
File file=new File("遥遥领先.mp3");
|
||||
|
||||
String base64 = encode(file);
|
||||
System.out.println(base64);
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,8 @@ public class ConfigTools {
|
||||
public static final String SQLITE = "sqlite.json";
|
||||
public static final String BiliBili = "bilibili.cookie";
|
||||
|
||||
private static final String SERVER_URL = load(CONFIG, "server.url", String.class);
|
||||
|
||||
static {
|
||||
try {
|
||||
File file = new File(CONFIG);
|
||||
@@ -45,7 +47,7 @@ public class ConfigTools {
|
||||
String src = readFile(file);
|
||||
if (src != null) {
|
||||
try {
|
||||
JSONObject json = JSONObject.parseObject(src,JSONObject.class);
|
||||
JSONObject json = JSONObject.parseObject(src, JSONObject.class);
|
||||
return json.getObject(key, t);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@@ -60,10 +62,10 @@ public class ConfigTools {
|
||||
BufferedReader reader = new BufferedReader(new FileReader(file));
|
||||
String tmp, str = null;
|
||||
while ((tmp = reader.readLine()) != null) {
|
||||
if(tmp.startsWith(key+"=")){
|
||||
str=tmp.split("=")[1];
|
||||
if(StringUtils.isEmpty(str)){
|
||||
str=null;
|
||||
if (tmp.startsWith(key + "=")) {
|
||||
str = tmp.split("=")[1];
|
||||
if (StringUtils.isEmpty(str)) {
|
||||
str = null;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -116,4 +118,8 @@ public class ConfigTools {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getServerUrl() {
|
||||
return SERVER_URL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
package com.yutou.qqbot.utlis;
|
||||
|
||||
import net.mamoe.mirai.utils.BotConfiguration;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class FixProtocolVersion {
|
||||
public static void fix(){
|
||||
try {
|
||||
|
||||
Class<?> MiraiProtocolInternal = Class.forName("net.mamoe.mirai.internal.utils.MiraiProtocolInternal");
|
||||
Field field = MiraiProtocolInternal.getFields()[0];
|
||||
Object companion = field.get(Object.class);
|
||||
|
||||
EnumMap<BotConfiguration.MiraiProtocol, Object> protocols = (EnumMap<BotConfiguration.MiraiProtocol, Object>)companion.getClass().getMethod("getProtocols$mirai_core").invoke(companion);
|
||||
Object pad = protocols.get(BotConfiguration.MiraiProtocol.ANDROID_PAD);
|
||||
/*
|
||||
* apkId: String,
|
||||
id: Long,
|
||||
ver: String,
|
||||
sdkVer: String,
|
||||
miscBitMap: Int,
|
||||
subSigMap: Int,
|
||||
mainSigMap: Int,
|
||||
sign: String,
|
||||
buildTime: Long,
|
||||
ssoVersion: Int,
|
||||
canDoQRCodeLogin: Boolean = false,
|
||||
* */
|
||||
Class<?> padClass = pad.getClass();
|
||||
Map<String, Object> padData = new HashMap<String, Object>(){{
|
||||
put("id", 537152242);
|
||||
put("ver", "8.9.35.10440");
|
||||
put("sdkVer", "6.0.0.2535");
|
||||
put("buildTime", 1676531414L);
|
||||
}};
|
||||
for (Field f : padClass.getFields()) {
|
||||
f.setAccessible(true);
|
||||
if(padData.containsKey(f.getName())){
|
||||
f.set(pad, padData.get(f.getName()));
|
||||
}
|
||||
f.setAccessible(false);
|
||||
}
|
||||
|
||||
Object phone = protocols.get(BotConfiguration.MiraiProtocol.ANDROID_PHONE);
|
||||
Map<String, Object> phoneData = new HashMap<String, Object>(){{
|
||||
put("id", 537153294);
|
||||
put("ver", "8.9.35.10440");
|
||||
put("sdkVer", "6.0.0.2535");
|
||||
put("buildTime", 1676531414L);
|
||||
}};
|
||||
for (Field f : padClass.getFields()) {
|
||||
f.setAccessible(true);
|
||||
if(padData.containsKey(f.getName())){
|
||||
f.set(phone, phoneData.get(f.getName()));
|
||||
}
|
||||
f.setAccessible(false);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public class RedisTools {
|
||||
//Properties properties = PropertyUtil.loadProperties("jedis.properties");
|
||||
//host = properties.getProperty("redis.host");
|
||||
//port = Integer.valueOf(properties.getProperty("redis.port"));
|
||||
host = "127.0.0.1";
|
||||
host = "localhost";
|
||||
port = 6379;
|
||||
}
|
||||
|
||||
@@ -411,6 +411,7 @@ public class RedisTools {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
RedisTools.pullMsg("msg", "abc");
|
||||
// RedisTools.pullMsg("msg", "abc");
|
||||
RedisTools.set("test","abc");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user