改成onebot-11通用接口 #9

Merged
yutou merged 10 commits from dev_HTTP服务化 into master 2024-05-10 13:09:42 +08:00
7 changed files with 67 additions and 15 deletions
Showing only changes of commit 7e9fa60f6a - Show all commits

View File

@ -8,8 +8,10 @@ import com.yutou.napcat.model.*;
import com.yutou.okhttp.HttpCallback;
import com.yutou.napcat.http.NapCatApi;
import com.yutou.qqbot.QQBotManager;
import com.yutou.qqbot.utlis.Base64Tools;
import lombok.val;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@ -30,8 +32,25 @@ public class NapCatQQ {
list.add(new At(583819556L));
list.add(new Text("5"));
QQBotManager.getInstance().sendMessage(false, 891655174L, list);*/
val at = new At();
System.out.println("at = " + at);
NapCatApi.setLog(false);
File file = new File("C:\\Users\\58381\\Downloads\\0074TT8Yly1hp5mqidwqeg30g20f27wh.gif");
NapCatApi.getMessageApi().sendPrivateMsg(
MessageHandleBuild.create()
.setQQNumber(583819556L)
//.add(new Image(file))
.add(new Text("abc"))
.build()
).enqueue(new HttpCallback<SendMessageResponse>() {
@Override
public void onResponse(int code, String status, SendMessageResponse response, String rawResponse) {
System.out.println("code = " + code + ", status = " + status + ", response = " + response + ", rawResponse = " + rawResponse);
}
@Override
public void onFailure(Throwable throwable) {
throwable.printStackTrace();
}
});
}
/**
* 私聊

View File

@ -1,8 +1,11 @@
package com.yutou.napcat.handle;
import com.alibaba.fastjson2.annotation.JSONField;
import com.yutou.qqbot.utlis.Base64Tools;
import lombok.Data;
import java.io.File;
public class Image extends BaseHandle<Image.ImageInfo> {
public Image() {
@ -13,6 +16,10 @@ public class Image extends BaseHandle<Image.ImageInfo> {
super("image");
data = new ImageInfo(imageUrl);
}
public Image(File imageFile){
super("image");
data=new ImageInfo("base64://"+ Base64Tools.encode(imageFile));
}
@Data
public static class ImageInfo {

View File

@ -51,7 +51,6 @@ public class MessageHandleBuild {
}
json.put("auto_escape", autoEscape);
json.put("message", msgList);
System.out.println(json);
return json;
}
}

View File

@ -39,7 +39,7 @@ public class Text extends BaseHandle<Text.TextInfo> {
@Override
public String toString() {
return data.text;
return data.text.trim();
}
@Data
@ -47,7 +47,7 @@ public class Text extends BaseHandle<Text.TextInfo> {
String text;
public TextInfo(String text) {
this.text = text;
this.text = text.trim();
}
}
}

View File

@ -5,6 +5,7 @@ import com.alibaba.fastjson2.JSONObject;
import com.yutou.napcat.QQDatabase;
import com.yutou.napcat.handle.BaseHandle;
import com.yutou.napcat.handle.MessageHandleBuild;
import com.yutou.napcat.handle.Reply;
import com.yutou.napcat.handle.Text;
import com.yutou.napcat.http.NapCatApi;
import com.yutou.napcat.model.FriendBean;
@ -127,6 +128,11 @@ public class QQBotManager {
if (item.getData() == null) {
continue;
}
if (item instanceof Reply) {
if (((Reply) item).getData().getId() == -1) {
continue;
}
}
handleBuild.add(item);
}
Response<HttpBody<SendMessageResponse>> response;

View File

@ -219,14 +219,36 @@ public class GetSeTu extends Model {
builder.append(tags).append("");
}
builder.append("\n看不到图?点这里:").append(item.getJSONObject("urls").getString("regular"));
QQBotManager.getInstance().sendMessage(false, qq,
new Image(item.getJSONObject("urls").getString("regular")),
new Reply(event.getMessageId())
);
QQBotManager.getInstance().sendMessage(false, qq,
new Reply(event.getMessageId()),
new Text(builder.toString())
);
HttpTools.download(item.getJSONObject("urls").getString("regular"),
System.currentTimeMillis() + ".png",
true,
new DownloadInterface() {
@Override
public void onDownload(File file) {
super.onDownload(file);
Log.i("下载完成");
QQBotManager.getInstance().sendMessage(false, qq,
new Image(file),
new Reply(event.getMessageId())
);
}
@Override
public void onError(Exception e) {
super.onError(e);
QQBotManager.getInstance().sendMessage(false, qq,
new Image(item.getJSONObject("urls").getString("regular")),
new Reply(event.getMessageId())
);
}
}
);
return true;
}
@ -236,9 +258,12 @@ public class GetSeTu extends Model {
Matcher matcher = pattern.matcher(msg);
MessageEvent event = new MessageEvent();
SourceFrom sourceFrom = new SourceFrom();
sourceFrom.setUserId(583819556L);
sourceFrom.setUserId(891655174L);
event.setMessageType("private");
event.setSource(sourceFrom);
event.setGroupId(891655174L);
event.setMessageId(-1);
event.setRawMessage(msg);
new GetSeTu().onMessage(583819556L, event, false);
new GetSeTu().onMessage(891655174L, event, true);
}
}

View File

@ -30,9 +30,5 @@ public class Base64Tools {
}
public static void main(String[] args) {
File file=new File("遥遥领先.mp3");
String base64 = encode(file);
System.out.println(base64);
}
}