改成onebot-11通用接口 #9

Merged
yutou merged 10 commits from dev_HTTP服务化 into master 2024-05-10 13:09:42 +08:00
11 changed files with 55 additions and 24 deletions
Showing only changes of commit 604d186cc2 - Show all commits

View File

@ -7,7 +7,7 @@ import com.yutou.qqbot.utlis.ConfigTools;
public class NapCatApi extends BaseApi { public class NapCatApi extends BaseApi {
private static final String URL; private static final String URL;
static { static {
URL= ConfigTools.load(ConfigTools.CONFIG,"napcat.url",String.class); URL= ConfigTools.load(ConfigTools.CONFIG,ConfigTools.NAPCAT_URL,String.class);
} }
public static void setLog(boolean log){ public static void setLog(boolean log){

View File

@ -10,7 +10,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication @SpringBootApplication
public class QQBotApplication { public class QQBotApplication {
public static final String version = "QQBot v.1.7.2"; public static final String version = "QQBot v.1.7.3";
public static void main(String[] args) { public static void main(String[] args) {
System.out.println("version = " + version); System.out.println("version = " + version);
@ -18,7 +18,7 @@ public class QQBotApplication {
NapCatApi.setLog(true); NapCatApi.setLog(true);
RedisTools.initRedisPoolSub(); RedisTools.initRedisPoolSub();
QQBotManager.getInstance(); QQBotManager.getInstance();
val log = ConfigTools.load(ConfigTools.CONFIG, "qq.log", Boolean.class); val log = ConfigTools.load(ConfigTools.CONFIG, ConfigTools.QQ_LOG, Boolean.class);
NapCatApi.setLog(log); NapCatApi.setLog(log);
//1 //1
} }

View File

@ -120,6 +120,9 @@ public class QQBotManager {
public SendMessageResponse sendMessage(boolean isUser, Long qq, List<BaseHandle<?>> items) { public SendMessageResponse sendMessage(boolean isUser, Long qq, List<BaseHandle<?>> items) {
try { try {
if(!ConfigTools.load(ConfigTools.CONFIG,ConfigTools.QQ, Boolean.class)){
return null;
}
MessageHandleBuild handleBuild = MessageHandleBuild MessageHandleBuild handleBuild = MessageHandleBuild
.create() .create()
.setGroup(!isUser) .setGroup(!isUser)

View File

@ -333,7 +333,7 @@ public class BiliBiliUtils {
public void download_ffmpeg(final List<String> url, final String saveName) { public void download_ffmpeg(final List<String> url, final String saveName) {
new Thread(() -> { new Thread(() -> {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append(ConfigTools.load(ConfigTools.CONFIG, "ffmpeg", String.class)).append(" "); builder.append(ConfigTools.load(ConfigTools.CONFIG, ConfigTools.FFMPEG, String.class)).append(" ");
/* builder.append("-user_agent").append(" "); /* builder.append("-user_agent").append(" ");
builder.append("\"").append("User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36 Referer:https://live.bilibili.com").append("\"").append(" "); builder.append("\"").append("User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36 Referer:https://live.bilibili.com").append("\"").append(" ");
builder.append("-cookies").append(" "); builder.append("-cookies").append(" ");

View File

@ -10,12 +10,14 @@ import com.yutou.qqbot.utlis.BaiduGPTManager;
import com.yutou.napcat.event.MessageEvent; import com.yutou.napcat.event.MessageEvent;
import com.yutou.qqbot.utlis.ConfigTools; import com.yutou.qqbot.utlis.ConfigTools;
import com.yutou.qqbot.utlis.StringUtils; import com.yutou.qqbot.utlis.StringUtils;
import lombok.val;
import org.apache.catalina.valves.JsonErrorReportValve;
import java.util.ArrayList;
@UseModel @UseModel
public class BaiduGPT extends Model { public class BaiduGPT extends Model {
private static String version = null;
@Override @Override
public boolean isUserPublic() { public boolean isUserPublic() {
return true; return true;
@ -37,18 +39,17 @@ public class BaiduGPT extends Model {
@Override @Override
public void onMessage(Long qq, MessageEvent event, boolean isGroup) { public void onMessage(Long qq, MessageEvent event, boolean isGroup) {
super.onMessage(qq, event, isGroup); super.onMessage(qq, event, isGroup);
if (version == null) { String version = ConfigTools.load(ConfigTools.CONFIG, ConfigTools.BAIDU_GPT_VERSION, String.class);
version = ConfigTools.load(ConfigTools.CONFIG, "baidu.gpt.version", String.class);
if (StringUtils.isEmpty(version)) { if (StringUtils.isEmpty(version)) {
version = "3.5"; version = "3.5";
BaiduGPTManager.getManager().setModelFor35(); BaiduGPTManager.getManager().setModelFor35();
} }
}
if ("3.5".equals(version)) { if ("3.5".equals(version)) {
BaiduGPTManager.getManager().setModelFor35(); BaiduGPTManager.getManager().setModelFor35();
} else if ("4.0".equals(version)) { } else if ("4.0".equals(version)) {
BaiduGPTManager.getManager().setModelFor40(); BaiduGPTManager.getManager().setModelFor40();
} }
System.out.println("version = " + version);
if (event.getTextMessage().equals(QQGroupCommands.GPT_CLEAR)) { if (event.getTextMessage().equals(QQGroupCommands.GPT_CLEAR)) {
BaiduGPTManager.getManager().clear(); BaiduGPTManager.getManager().clear();
QQBotManager.getInstance().sendMessage(event.isUser(), qq, new Text("已经失忆捏")); QQBotManager.getInstance().sendMessage(event.isUser(), qq, new Text("已经失忆捏"));
@ -79,6 +80,16 @@ public class BaiduGPT extends Model {
} }
public static void main(String[] args) { public static void main(String[] args) {
System.out.println(ConfigTools.load(ConfigTools.CONFIG,"baidu.gpt.version")); System.out.println(ConfigTools.load(ConfigTools.CONFIG, ConfigTools.BAIDU_GPT_VERSION));
val messageEvent = new MessageEvent();
messageEvent.setMessage(new ArrayList<>());
messageEvent.setRawMessage("");
new BaiduGPT().onMessage(123456789L, messageEvent, false);
BaiduGPTManager.getManager().clear();
BaiduGPTManager.getManager().setModelFor40();
new BaiduGPT().onMessage(123456789L, messageEvent, false);
/* BaiduGPTManager.getManager().clear();
BaiduGPTManager.getManager().setModelFor35();
new BaiduGPT().onMessage(123456789L, messageEvent, false);*/
} }
} }

View File

@ -122,6 +122,6 @@ public abstract class Model implements ModelInterface {
} }
public boolean isAt() { public boolean isAt() {
return msg.contains("@" + ConfigTools.load(ConfigTools.CONFIG, "qq_number", String.class)); return msg.contains("@" + ConfigTools.load(ConfigTools.CONFIG, ConfigTools.QQ_NUMBER, String.class));
} }
} }

View File

@ -153,7 +153,7 @@ public class AppTools {
Log.i("title=" + title + " msg=" + msg); Log.i("title=" + title + " msg=" + msg);
HttpTools.post("https://sctapi.ftqq.com/SCT2619Tpqu93OYtQCrK4LOZYEfr2irm.send", HttpTools.post("https://sctapi.ftqq.com/SCT2619Tpqu93OYtQCrK4LOZYEfr2irm.send",
("title="+ URLEncoder.encode(title, "UTF-8") + "&desp=" + URLEncoder.encode(msg, "UTF-8")).getBytes(StandardCharsets.UTF_8)); ("title="+ URLEncoder.encode(title, "UTF-8") + "&desp=" + URLEncoder.encode(msg, "UTF-8")).getBytes(StandardCharsets.UTF_8));
if (ConfigTools.load(ConfigTools.CONFIG, "model").equals("nas")) { if (ConfigTools.load(ConfigTools.CONFIG, ConfigTools.MODEL).equals("nas")) {
String img = null; String img = null;
msg = msg.replace("<br/>", "\n"); msg = msg.replace("<br/>", "\n");
if (msg.contains("![logo]")) { if (msg.contains("![logo]")) {

View File

@ -17,9 +17,9 @@ public class BaiduGPTManager {
//4.0 //4.0
private static final String url_4_0 = "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 String url = url_3_5;
private static final String AppID = ConfigTools.load(ConfigTools.CONFIG,"baidu.gpt.appid", String.class); private static final String AppID = ConfigTools.load(ConfigTools.CONFIG,ConfigTools.BAIDU_GPT_APPID, String.class);
private static final String ApiKey =ConfigTools.load(ConfigTools.CONFIG,"baidu.gpt.apikey", String.class); private static final String ApiKey =ConfigTools.load(ConfigTools.CONFIG,ConfigTools.BAIDU_GPT_API_KEY, String.class);
private static final String SecretKey =ConfigTools.load(ConfigTools.CONFIG,"baidu.gpt.SecretKey", String.class); private static final String SecretKey =ConfigTools.load(ConfigTools.CONFIG,ConfigTools.BAIDU_GPT_SECRET_KEY, String.class);
private final Map<String, List<Message>> msgMap; private final Map<String, List<Message>> msgMap;
private BaiduGPTManager() { private BaiduGPTManager() {
@ -40,12 +40,12 @@ public class BaiduGPTManager {
public void setModelFor40() { public void setModelFor40() {
url = url_4_0; url = url_4_0;
ConfigTools.save(ConfigTools.CONFIG,"baidu.gpt.version","4.0"); ConfigTools.save(ConfigTools.CONFIG,ConfigTools.BAIDU_GPT_VERSION,"4.0");
} }
public void setModelFor35() { public void setModelFor35() {
url = url_3_5; url = url_3_5;
ConfigTools.save(ConfigTools.CONFIG,"baidu.gpt.version","3.5"); ConfigTools.save(ConfigTools.CONFIG,ConfigTools.BAIDU_GPT_VERSION,"3.5");
} }
public void clear() { public void clear() {

View File

@ -13,8 +13,25 @@ public class ConfigTools {
public static final String DATA = "data.json"; public static final String DATA = "data.json";
public static final String SQLITE = "sqlite.json"; public static final String SQLITE = "sqlite.json";
public static final String BiliBili = "bilibili.cookie"; public static final String BiliBili = "bilibili.cookie";
public static final String QQ = "qq_bot";
public static final String QQ_NUMBER = "qq_number";
public static final String QQ_PASSWORD = "qq_password";
public static final String MODEL = "model";
public static final String OS = "os";
public static final String MUSIC_SCAN = "musicScan";
public static final String SERVICE_LOG = "service.log";
public static final String QQ_LOG = "qq.log";
public static final String CHROME = "chrome";
public static final String FIREFOX = "firefox";
public static final String FFMPEG = "ffmpeg";
public static final String SIGN_URL = "sign_url";
public static final String NAPCAT_URL = "napcat.url";
public static final String SERVER_URL = "server.url";
public static final String BAIDU_GPT_VERSION = "baidu.gpt.version";
public static final String BAIDU_GPT_APPID = "baidu.gpt.appid";
public static final String BAIDU_GPT_API_KEY = "baidu.gpt.apikey";
public static final String BAIDU_GPT_SECRET_KEY = "baidu.gpt.SecretKey";
private static final String SERVER_URL = load(CONFIG, "server.url", String.class);
static { static {
try { try {
@ -120,6 +137,6 @@ public class ConfigTools {
} }
public static String getServerUrl() { public static String getServerUrl() {
return SERVER_URL; return ConfigTools.load(CONFIG, SERVER_URL, String.class);
} }
} }

View File

@ -6,7 +6,7 @@ public class Log {
} }
public static void i(Object log) { public static void i(Object log) {
if (ConfigTools.load(ConfigTools.CONFIG, "service.log", boolean.class, false)) { if (ConfigTools.load(ConfigTools.CONFIG, ConfigTools.SERVICE_LOG, boolean.class, false)) {
System.out.printf("[%s]%s%n", System.out.printf("[%s]%s%n",
AppTools.getToDayNowTimeToString(), AppTools.getToDayNowTimeToString(),
log log

View File

@ -39,7 +39,7 @@ public class WebClient {
private WebClient() { private WebClient() {
//System.setProperty("webdriver.http.factory", "jdk-http-client"); //System.setProperty("webdriver.http.factory", "jdk-http-client");
System.setProperty("webdriver.chrome.driver", System.setProperty("webdriver.chrome.driver",
ConfigTools.load(ConfigTools.CONFIG, "chrome", String.class)); ConfigTools.load(ConfigTools.CONFIG, ConfigTools.CHROME, String.class));
// System.setProperty("webdriver.chrome.whitelistedIps", ""); // System.setProperty("webdriver.chrome.whitelistedIps", "");
// java.util.logging.Logger.getLogger("org.openqa.selenium").setLevel(Level.OFF); // java.util.logging.Logger.getLogger("org.openqa.selenium").setLevel(Level.OFF);
} }