feat(bot): 添加张vv表情包生成功能
- 新增 ZVVImageUtils 类实现表情包生成逻辑 - 在 BaiduGPT 类中集成该功能,支持回复如何评论/评价相关问题 - 更新 QQBotApplication 版本号至 1.7.20 - 优化 QQBean 类中的随机数逻辑 - 移除 MessageChainBuilder 类中冗余的 toString 方法 - 删除 QQSetu 类中未使用的 MessageChainBuilder 导包
This commit is contained in:
parent
f770fcc8fb
commit
e53760f280
@ -10,7 +10,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class QQBotApplication {
|
||||
public static final String version = "QQBot v.1.7.19";
|
||||
public static final String version = "QQBot v.1.7.20";
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("version = " + version);
|
||||
|
@ -13,4 +13,9 @@ public class MessageChainBuilder {
|
||||
sb.append(o.toString());
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
@ -11,10 +11,7 @@ import com.yutou.qqbot.interfaces.DownloadInterface;
|
||||
import com.yutou.qqbot.models.Model;
|
||||
import com.yutou.qqbot.gpt.BaiduGPTManager;
|
||||
import com.yutou.napcat.event.MessageEvent;
|
||||
import com.yutou.qqbot.utlis.ConfigTools;
|
||||
import com.yutou.qqbot.utlis.HttpTools;
|
||||
import com.yutou.qqbot.utlis.Log;
|
||||
import com.yutou.qqbot.utlis.StringUtils;
|
||||
import com.yutou.qqbot.utlis.*;
|
||||
import lombok.val;
|
||||
|
||||
import java.io.File;
|
||||
@ -139,6 +136,21 @@ public class BaiduGPT extends Model {
|
||||
AbsGPTManager.getManager(gptManager).clear();
|
||||
QQBotManager.getInstance().sendMessage(event.isUser(), qq, list);
|
||||
return;
|
||||
}else if(event.getTextMessage().startsWith("如何评论")||event.getTextMessage().startsWith("如何评价")){
|
||||
ZVVImageUtils.getInstance().zvv(event.getTextMessage(), new DownloadInterface() {
|
||||
@Override
|
||||
public void onDownload(File file) {
|
||||
super.onDownload(file);
|
||||
QQBotManager.getInstance().sendMessage(qq,new Image(file));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception e) {
|
||||
super.onError(e);
|
||||
QQBotManager.getInstance().sendMessage(qq,new Text("vv啥也不想说"));
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (checkImage()) {
|
||||
parseImage(event, qq);
|
||||
|
@ -52,9 +52,7 @@ public class QQBean extends Model {
|
||||
int day = 1440;
|
||||
int max = 30 * day;
|
||||
int time = 1;
|
||||
if (random.nextInt(100) == 23) {
|
||||
releaseAll(qq, true);
|
||||
} else if (random.nextInt(10) > 2) {
|
||||
if (random.nextInt(10) > 2) {
|
||||
time = random.nextInt(hour);
|
||||
} else if (random.nextInt(10) > 4) {
|
||||
time = random.nextInt(day);
|
||||
|
@ -13,7 +13,6 @@ import com.yutou.napcat.model.MessageBean;
|
||||
import com.yutou.okhttp.HttpBody;
|
||||
import com.yutou.qqbot.Annotations.UseModel;
|
||||
import com.yutou.qqbot.QQBotManager;
|
||||
import com.yutou.qqbot.data.MessageChainBuilder;
|
||||
import com.yutou.qqbot.models.Model;
|
||||
import com.yutou.qqbot.utlis.AppTools;
|
||||
import com.yutou.qqbot.utlis.Log;
|
||||
|
101
src/main/java/com/yutou/qqbot/utlis/ZVVImageUtils.java
Normal file
101
src/main/java/com/yutou/qqbot/utlis/ZVVImageUtils.java
Normal file
@ -0,0 +1,101 @@
|
||||
package com.yutou.qqbot.utlis;
|
||||
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.okhttp.HttpDownloadUtils;
|
||||
import com.yutou.okhttp.api.BaseApi;
|
||||
import com.yutou.qqbot.interfaces.DownloadInterface;
|
||||
import lombok.val;
|
||||
import okhttp3.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 张vv表情包生成器
|
||||
*/
|
||||
public class ZVVImageUtils {
|
||||
// 单例实例
|
||||
private static volatile ZVVImageUtils instance;
|
||||
private boolean isLocalModel=false;
|
||||
private String queryUrl="https://api.xy0v0.top/search?q=";
|
||||
private String downloadUrl="https://cn-sy1.rains3.com/clouddisk/clouddisk/images/";
|
||||
OkHttpClient okHttpClient = new OkHttpClient.Builder()
|
||||
.connectTimeout(2, TimeUnit.MINUTES)
|
||||
.readTimeout(2, TimeUnit.MINUTES)
|
||||
.build();
|
||||
// 私有构造函数,防止外部实例化
|
||||
private ZVVImageUtils() {
|
||||
}
|
||||
|
||||
// 获取单例实例的方法
|
||||
public static ZVVImageUtils getInstance() {
|
||||
if (instance == null) {
|
||||
synchronized (ZVVImageUtils.class) {
|
||||
if (instance == null) {
|
||||
instance = new ZVVImageUtils();
|
||||
}
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
private void checkModel(){
|
||||
isLocalModel=ConfigTools.load(ConfigTools.CONFIG,"zvv.model.local", Boolean.class,false);
|
||||
if(isLocalModel){
|
||||
queryUrl="http://192.168.31.88:8501/search?q=";
|
||||
downloadUrl="http://192.168.31.88:8501/clouddisk/clouddisk/images/";
|
||||
}else{
|
||||
String queryUrl="https://api.xy0v0.top/search?q=";
|
||||
String downloadUrl="https://cn-sy1.rains3.com/clouddisk/clouddisk/images/";
|
||||
}
|
||||
}
|
||||
public void zvv(String text, DownloadInterface downloadInterface) {
|
||||
// checkModel();
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("query", text);
|
||||
json.put("amount", 1);
|
||||
RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=UTF-8"), json.toString().getBytes(StandardCharsets.UTF_8));
|
||||
Request.Builder rb = new Request.Builder()
|
||||
.post(body)
|
||||
.addHeader("User-Agent", ConfigTools.getUserAgent())
|
||||
.url(queryUrl + text + "&n=1");
|
||||
Request request = rb.build();
|
||||
okHttpClient.newCall(request).enqueue(new Callback() {
|
||||
@Override
|
||||
public void onFailure(@NotNull Call call, @NotNull IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
|
||||
if (response.isSuccessful()) {
|
||||
val string = response.body().string();
|
||||
if (!StringUtils.isEmpty(string)) {
|
||||
String imageUrl = JSONArray.parse(string).getString(0);
|
||||
HttpDownloadUtils.download(new HttpDownloadUtils.Builder()
|
||||
.setUrl(downloadUrl + imageUrl)
|
||||
.setFileName(imageUrl)
|
||||
.setPath(new File("tmp").getAbsolutePath())
|
||||
.setDownloadInterface(downloadInterface)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
ZVVImageUtils.getInstance().zvv("如何评论马督工", new DownloadInterface() {
|
||||
@Override
|
||||
public void onDownload(File file) {
|
||||
super.onDownload(file);
|
||||
System.out.println("file.getAbsolutePath() = " + file.getAbsolutePath());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user