新版改版:
模块化各个功能 改为okhttp网络请求 改为sqlite作为存储 预设QQ机器人API
This commit is contained in:
29
qqbot/pom.xml
Normal file
29
qqbot/pom.xml
Normal file
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.yutou</groupId>
|
||||
<artifactId>bilibili</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>qqbot</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>21</maven.compiler.source>
|
||||
<maven.compiler.target>21</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<dependencies>
|
||||
|
||||
|
||||
<!-- <dependency>
|
||||
<groupId>com.yutou</groupId>
|
||||
<artifactId>common</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>-->
|
||||
</dependencies>
|
||||
</project>
|
||||
57
qqbot/src/main/java/com/yutou/napcat/NapCatQQ.java
Normal file
57
qqbot/src/main/java/com/yutou/napcat/NapCatQQ.java
Normal file
@@ -0,0 +1,57 @@
|
||||
package com.yutou.napcat;
|
||||
|
||||
import com.yutou.napcat.handle.MessageHandleBuild;
|
||||
import com.yutou.napcat.handle.Text;
|
||||
import com.yutou.napcat.http.NapCatApi;
|
||||
import com.yutou.napcat.model.SendMessageResponse;
|
||||
import com.yutou.okhttp.HttpCallback;
|
||||
import okhttp3.Headers;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class NapCatQQ {
|
||||
|
||||
|
||||
private NapCatQQ() {
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
/* List<BaseHandle<?>> list = new ArrayList<>();
|
||||
list.add(new Text("1", false));
|
||||
list.add(new Text("2", false));
|
||||
list.add(new Text("3"));
|
||||
list.add(new Text("4", false));
|
||||
list.add(new At(583819556L));
|
||||
list.add(new Text("5"));
|
||||
QQBotManager.getInstance().sendMessage(false, 891655174L, list);*/
|
||||
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(Headers headers, 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();
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 私聊
|
||||
{"self_id":240828363,"user_id":583819556,"time":1714472684,"message_id":376,"real_id":376,"message_type":"private","sender":{"user_id":583819556,"nickname":"魔芋","card":""},"raw_message":"123","font":14,"sub_type":"friend","message":[{"data":{"text":"123"},"type":"text"}],"message_format":"array","post_type":"message"}
|
||||
*/
|
||||
|
||||
/**
|
||||
* 群聊
|
||||
* {"self_id":240828363,"user_id":583819556,"time":1714472695,"message_id":377,"real_id":377,"message_type":"group","sender":{"user_id":583819556,"nickname":"魔芋","card":"","role":"owner"},"raw_message":"222","font":14,"sub_type":"normal","message":[{"data":{"text":"222"},"type":"text"}],"message_format":"array","post_type":"message","group_id":891655174}
|
||||
*/
|
||||
}
|
||||
54
qqbot/src/main/java/com/yutou/napcat/QQDatabase.java
Normal file
54
qqbot/src/main/java/com/yutou/napcat/QQDatabase.java
Normal file
@@ -0,0 +1,54 @@
|
||||
package com.yutou.napcat;
|
||||
|
||||
import com.yutou.napcat.model.FriendBean;
|
||||
import com.yutou.napcat.model.GroupBean;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class QQDatabase {
|
||||
private static Map<Long, Object> data = new HashMap<>();
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private static FriendBean me;
|
||||
|
||||
public static void addUser(Long qq, FriendBean bean) {
|
||||
data.put(qq, bean);
|
||||
}
|
||||
|
||||
public static void addGroup(Long qq, GroupBean bean) {
|
||||
data.put(qq, bean);
|
||||
}
|
||||
|
||||
public static boolean checkFriend(Long qq) {
|
||||
if (data.containsKey(qq)) {
|
||||
return data.get(qq) instanceof FriendBean;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean checkGroup(Long qq) {
|
||||
if (data.containsKey(qq)) {
|
||||
return data.get(qq) instanceof GroupBean;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static List<GroupBean> getGroups() {
|
||||
List<GroupBean> numbers = new ArrayList<>();
|
||||
for (Long qq : data.keySet()) {
|
||||
if (data.get(qq) instanceof GroupBean) {
|
||||
{
|
||||
numbers.add((GroupBean) data.get(qq));
|
||||
}
|
||||
}
|
||||
}
|
||||
return numbers;
|
||||
}
|
||||
|
||||
}
|
||||
145
qqbot/src/main/java/com/yutou/napcat/QQNumberManager.java
Normal file
145
qqbot/src/main/java/com/yutou/napcat/QQNumberManager.java
Normal file
@@ -0,0 +1,145 @@
|
||||
package com.yutou.napcat;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.utils.RedisTools;
|
||||
import redis.clients.jedis.Jedis;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class QQNumberManager {
|
||||
private static QQNumberManager manager;
|
||||
private QQNumberManager(){
|
||||
|
||||
}
|
||||
|
||||
public static QQNumberManager getManager() {
|
||||
if(manager==null) {
|
||||
manager=new QQNumberManager();
|
||||
}
|
||||
return manager;
|
||||
}
|
||||
public void addNumber(Long qq,boolean isGroup){
|
||||
if(RedisTools.exists(qq,null)){
|
||||
return;
|
||||
}
|
||||
JSONObject json=new JSONObject();
|
||||
json.put("group",isGroup);
|
||||
json.put("power",new JSONArray());
|
||||
json.put("model",new JSONArray());
|
||||
RedisTools.set(qq,json.toJSONString());
|
||||
}
|
||||
public List<Long> getNumber(){
|
||||
List<Long> list =new ArrayList<>();
|
||||
Jedis jedis=RedisTools.getRedis();
|
||||
jedis.select(RedisTools.QQBOT_USER);
|
||||
Set<String> set=jedis.keys("*");
|
||||
for (String s : set) {
|
||||
try {
|
||||
list.add(Long.parseLong(s));
|
||||
}catch (Exception ignored){
|
||||
|
||||
}
|
||||
}
|
||||
jedis.close();
|
||||
return list;
|
||||
}
|
||||
public boolean addPower(Long qq, String power){
|
||||
if(RedisTools.exists(qq,null)){
|
||||
JSONObject json=JSON.parseObject(RedisTools.get(qq));
|
||||
JSONArray array=json.getJSONArray("power");
|
||||
array.add(power);
|
||||
json.put("power",array);
|
||||
return RedisTools.set(qq,json.toJSONString());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public List<String> getPower(Long qq){
|
||||
List<String> list=new ArrayList<>();
|
||||
if(RedisTools.exists(qq,null)){
|
||||
JSONObject json=JSON.parseObject(RedisTools.get(qq));
|
||||
JSONArray array=json.getJSONArray("power");
|
||||
for (Object power : array) {
|
||||
list.add((String) power);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
public List<String> getUseModel(long qq) {
|
||||
List<String> list=new ArrayList<>();
|
||||
if(RedisTools.exists(qq,null)){
|
||||
JSONObject json=JSON.parseObject(RedisTools.get(qq));
|
||||
JSONArray array=json.getJSONArray("model");
|
||||
for (Object power : array) {
|
||||
list.add((String) power);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
public boolean delPower(Long qq, String power){
|
||||
if(RedisTools.exists(qq,null)){
|
||||
JSONObject json=JSON.parseObject(RedisTools.get(qq));
|
||||
JSONArray array=json.getJSONArray("power");
|
||||
array.remove(power);
|
||||
json.put("power",array);
|
||||
return RedisTools.set(qq,json.toJSONString());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public boolean addUseModel(Long qq,Class<?> modelClass){
|
||||
if(RedisTools.exists(qq,null)){
|
||||
JSONObject json=JSON.parseObject(RedisTools.get(qq));
|
||||
JSONArray array=json.getJSONArray("model");
|
||||
array.add(modelClass.getName());
|
||||
json.put("model",array);
|
||||
return RedisTools.set(qq,json.toJSONString());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public boolean delUseModel(Long qq,Class<?> modelClass){
|
||||
if(RedisTools.exists(qq,null)){
|
||||
JSONObject json=JSON.parseObject(RedisTools.get(qq));
|
||||
JSONArray array=json.getJSONArray("model");
|
||||
array.remove(modelClass.getName());
|
||||
json.put("model",array);
|
||||
return RedisTools.set(qq,json.toJSONString());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public boolean isExistsPower(Long qq, String... power){
|
||||
//1
|
||||
if(RedisTools.exists(qq,null)){
|
||||
JSONObject json=JSON.parseObject(RedisTools.get(qq));
|
||||
JSONArray array=json.getJSONArray("power");
|
||||
for (String key : power) {
|
||||
if(!array.contains(key)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public boolean isGroup(Long qq){
|
||||
if(RedisTools.exists(qq,null)){
|
||||
JSONObject json= JSON.parseObject(RedisTools.get(qq));
|
||||
return json.getBooleanValue("group");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public boolean isUseModel(Long qq,Class<?> modelClass){
|
||||
if(RedisTools.exists(qq,null)){
|
||||
JSONObject json=JSON.parseObject(RedisTools.get(qq));
|
||||
JSONArray array=json.getJSONArray("model");
|
||||
return array.contains(modelClass.getName());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
29
qqbot/src/main/java/com/yutou/napcat/enums/MessageEnum.java
Normal file
29
qqbot/src/main/java/com/yutou/napcat/enums/MessageEnum.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package com.yutou.napcat.enums;
|
||||
|
||||
public enum MessageEnum {
|
||||
TEXT("text"),
|
||||
IMAGE("image"),
|
||||
AT("at"),
|
||||
REPLY("reply"),
|
||||
JSON("json");
|
||||
|
||||
String type;
|
||||
|
||||
MessageEnum(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public static MessageEnum of(String type) {
|
||||
for (MessageEnum messageEnum : MessageEnum.values()) {
|
||||
if (messageEnum.getType().equals(type)) {
|
||||
return messageEnum;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.yutou.napcat.enums;
|
||||
|
||||
public enum RecordFormatEnum {
|
||||
MP3("mp3"),
|
||||
AMR("amr"),
|
||||
WMA("wma"),
|
||||
M4A("m4a"),
|
||||
SPX("spx"),
|
||||
OGG("ogg"),
|
||||
WAV("wav"),
|
||||
FLAC("flac");
|
||||
|
||||
|
||||
private final String format;
|
||||
|
||||
RecordFormatEnum(String format) {
|
||||
this.format = format;
|
||||
}
|
||||
|
||||
public String getFormat() {
|
||||
return format;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return format;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.yutou.napcat.event;
|
||||
|
||||
import com.yutou.napcat.model.GroupFrom;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
public class GroupMessageEvent extends MessageEvent {
|
||||
private GroupFrom group;
|
||||
|
||||
}
|
||||
183
qqbot/src/main/java/com/yutou/napcat/event/MessageEvent.java
Normal file
183
qqbot/src/main/java/com/yutou/napcat/event/MessageEvent.java
Normal file
@@ -0,0 +1,183 @@
|
||||
package com.yutou.napcat.event;
|
||||
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import com.yutou.napcat.QQDatabase;
|
||||
import com.yutou.napcat.enums.MessageEnum;
|
||||
import com.yutou.napcat.handle.*;
|
||||
import com.yutou.napcat.model.SourceFrom;
|
||||
import lombok.Data;
|
||||
import lombok.val;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class MessageEvent {
|
||||
|
||||
@JSONField(name = "self_id")
|
||||
private Long selfId;
|
||||
|
||||
@JSONField(name = "user_id")
|
||||
private Long userId;
|
||||
|
||||
@JSONField(name = "time")
|
||||
private Long time;
|
||||
|
||||
@JSONField(name = "message_id")
|
||||
private Integer messageId;
|
||||
|
||||
@JSONField(name = "real_id")
|
||||
private Integer realId;
|
||||
|
||||
@JSONField(name = "message_type")
|
||||
private String messageType;
|
||||
|
||||
@JSONField(name = "sender")
|
||||
private SourceFrom source;
|
||||
|
||||
@JSONField(name = "raw_message")
|
||||
private String rawMessage;
|
||||
|
||||
@JSONField(name = "font")
|
||||
private Integer font;
|
||||
|
||||
@JSONField(name = "sub_type")
|
||||
private String subType;
|
||||
|
||||
@JSONField(name = "message")
|
||||
private List<BaseHandle<?>> message;
|
||||
|
||||
@JSONField(name = "message_format")
|
||||
private String messageFormat;
|
||||
|
||||
@JSONField(name = "post_type")
|
||||
private String postType;
|
||||
|
||||
@JSONField(name = "group_id")
|
||||
private Long groupId;
|
||||
|
||||
|
||||
public static MessageEvent parseHandleHttp(String jsonString) {
|
||||
|
||||
return parseHandle(JSONObject.parseObject(jsonString).getJSONObject("data").toString());
|
||||
}
|
||||
|
||||
public static MessageEvent parseHandle(String jsonString) {
|
||||
JSONObject json = JSONObject.parseObject(jsonString);
|
||||
|
||||
JSONArray array = json.getJSONArray("message");
|
||||
List<BaseHandle<?>> messageList = new ArrayList<>();
|
||||
for (Object o : array) {
|
||||
JSONObject _json = (JSONObject) o;
|
||||
Type classType = null;
|
||||
MessageEnum _type = MessageEnum.of(_json.getString("type"));
|
||||
classType = switch (_type) {
|
||||
case TEXT -> Text.TextInfo.class;
|
||||
case IMAGE -> Image.ImageInfo.class;
|
||||
case AT -> At.AtData.class;
|
||||
case JSON -> OtherHandle.OtherInfo.class;
|
||||
case REPLY -> Reply.ReplyInfo.class;
|
||||
default -> classType;
|
||||
};
|
||||
BaseHandle<?> handle = new BaseHandle<>(_type.getType());
|
||||
if (_type == MessageEnum.JSON) {
|
||||
handle.setData(JSONObject.parseObject(((JSONObject) o).getJSONObject("data").getString("data"), classType));
|
||||
} else {
|
||||
handle.setData(JSONObject.parseObject(((JSONObject) o).getJSONObject("data").toString(), classType));
|
||||
}
|
||||
messageList.add(handle);
|
||||
}
|
||||
|
||||
|
||||
SourceFrom sender = new SourceFrom();
|
||||
sender.setUserId(json.getJSONObject("sender").getLong("user_id"));
|
||||
sender.setNickname(json.getJSONObject("sender").getString("nickname"));
|
||||
sender.setCard(json.getJSONObject("sender").getString("card"));
|
||||
|
||||
MessageEvent event = new MessageEvent();
|
||||
event.setSelfId(json.getLong("self_id"));
|
||||
event.setUserId(json.getLong("user_id"));
|
||||
event.setTime(json.getLong("time"));
|
||||
event.setMessageId(json.getInteger("message_id"));
|
||||
event.setRealId(json.getInteger("real_id"));
|
||||
event.setMessageType(json.getString("message_type"));
|
||||
event.setSource(sender);
|
||||
event.setRawMessage(json.getString("raw_message"));
|
||||
event.setFont(json.getInteger("font"));
|
||||
event.setSubType(json.getString("sub_type"));
|
||||
event.setMessageFormat(json.getString("message_format"));
|
||||
event.setPostType(json.getString("post_type"));
|
||||
event.setGroupId(json.getLong("group_id"));
|
||||
event.setMessage(messageList);
|
||||
return event;
|
||||
}
|
||||
|
||||
public boolean hasType(MessageEnum messageEnum) {
|
||||
for (BaseHandle<?> handle : message) {
|
||||
if (MessageEnum.of(handle.getType()) == messageEnum) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public <T extends BaseHandle> List<T> findAllType(Class<T> t) {
|
||||
List<T> tmp = new ArrayList<>();
|
||||
try {
|
||||
T newed = t.getDeclaredConstructor().newInstance();
|
||||
for (BaseHandle<?> baseHandle : message) {
|
||||
if (baseHandle.getType().equals(newed.getType())) {
|
||||
newed.setData(baseHandle.getData());
|
||||
tmp.add(newed);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
public <T extends BaseHandle> T findType(Class<T> tClass) {
|
||||
List<T> list = findAllType(tClass);
|
||||
if (list == null || list.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return list.get(0);
|
||||
}
|
||||
|
||||
|
||||
public boolean isAtMe() {
|
||||
if (!hasType(MessageEnum.AT)) {
|
||||
return false;
|
||||
}
|
||||
List<At> list = findAllType(At.class);
|
||||
for (At handle : list) {
|
||||
if (handle.getData().getQq() == QQDatabase.getMe().getUserId()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getTextMessage() {
|
||||
val texts = findAllType(Text.class);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Text text : texts) {
|
||||
sb.append(text);
|
||||
}
|
||||
return sb.toString().trim();
|
||||
}
|
||||
|
||||
public boolean isUser() {
|
||||
return "private".equals(messageType);
|
||||
}
|
||||
|
||||
public boolean isGroup() {
|
||||
return "group".equals(messageType);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
32
qqbot/src/main/java/com/yutou/napcat/handle/At.java
Normal file
32
qqbot/src/main/java/com/yutou/napcat/handle/At.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package com.yutou.napcat.handle;
|
||||
|
||||
import com.yutou.okhttp.BaseBean;
|
||||
import lombok.Data;
|
||||
|
||||
public class At extends BaseHandle<At.AtData> {
|
||||
public At() {
|
||||
super("at");
|
||||
}
|
||||
|
||||
public At(Long userId) {
|
||||
super("at");
|
||||
data = new AtData(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
return String.format("[CQ:at,qq=%d]", data.qq);
|
||||
}
|
||||
|
||||
@Data
|
||||
public class AtData extends BaseBean {
|
||||
private Long qq;
|
||||
|
||||
public AtData(Long qq) {
|
||||
this.qq = qq;
|
||||
}
|
||||
}
|
||||
}
|
||||
22
qqbot/src/main/java/com/yutou/napcat/handle/BaseHandle.java
Normal file
22
qqbot/src/main/java/com/yutou/napcat/handle/BaseHandle.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package com.yutou.napcat.handle;
|
||||
|
||||
import com.yutou.okhttp.BaseBean;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class BaseHandle<T> extends BaseBean {
|
||||
protected String type;
|
||||
protected T data;
|
||||
protected String src;
|
||||
|
||||
public BaseHandle(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
public BaseHandle(String type, Object obj) {
|
||||
super();
|
||||
this.type = type;
|
||||
this.data= (T) obj;
|
||||
}
|
||||
}
|
||||
35
qqbot/src/main/java/com/yutou/napcat/handle/Image.java
Normal file
35
qqbot/src/main/java/com/yutou/napcat/handle/Image.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package com.yutou.napcat.handle;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import com.yutou.utils.Base64Tools;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class Image extends BaseHandle<Image.ImageInfo> {
|
||||
|
||||
public Image() {
|
||||
super("image");
|
||||
}
|
||||
|
||||
public Image(String imageUrl) {
|
||||
super("image");
|
||||
data = new ImageInfo(imageUrl);
|
||||
}
|
||||
public Image(File imageFile){
|
||||
super("image");
|
||||
data=new ImageInfo("base64://"+ Base64Tools.encode(imageFile));
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class ImageInfo {
|
||||
String file;
|
||||
String url;
|
||||
@JSONField(name = "file_size")
|
||||
String fileSize;
|
||||
|
||||
public ImageInfo(String file) {
|
||||
this.file = file;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.yutou.napcat.handle;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MessageHandleBuild {
|
||||
private List<BaseHandle<?>> msgList = new ArrayList<>();
|
||||
private long qq;
|
||||
private boolean autoEscape;
|
||||
private boolean isGroup;
|
||||
|
||||
public static MessageHandleBuild create() {
|
||||
return new MessageHandleBuild();
|
||||
}
|
||||
|
||||
private MessageHandleBuild() {
|
||||
msgList = new ArrayList<>();
|
||||
}
|
||||
|
||||
public MessageHandleBuild setQQNumber(long qq) {
|
||||
this.qq = qq;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MessageHandleBuild setAutoEscape(boolean autoEscape) {
|
||||
this.autoEscape = autoEscape;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MessageHandleBuild add(BaseHandle<?> msg) {
|
||||
msgList.add(msg);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MessageHandleBuild setGroup(boolean group) {
|
||||
isGroup = group;
|
||||
return this;
|
||||
}
|
||||
|
||||
public JSONObject build() {
|
||||
JSONObject json=new JSONObject();
|
||||
if(isGroup){
|
||||
json.put("group_id", qq);
|
||||
}else {
|
||||
json.put("user_id", qq);
|
||||
}
|
||||
json.put("auto_escape", autoEscape);
|
||||
json.put("message", msgList);
|
||||
return json;
|
||||
}
|
||||
}
|
||||
19
qqbot/src/main/java/com/yutou/napcat/handle/OtherHandle.java
Normal file
19
qqbot/src/main/java/com/yutou/napcat/handle/OtherHandle.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package com.yutou.napcat.handle;
|
||||
|
||||
import com.yutou.napcat.model.AppShareBean;
|
||||
import lombok.Data;
|
||||
|
||||
public class OtherHandle extends BaseHandle<OtherHandle.OtherInfo>{
|
||||
|
||||
public OtherHandle() {
|
||||
super("json");
|
||||
data= new OtherInfo();
|
||||
}
|
||||
|
||||
|
||||
@Data
|
||||
public static class OtherInfo extends AppShareBean{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
14
qqbot/src/main/java/com/yutou/napcat/handle/QuoteReply.java
Normal file
14
qqbot/src/main/java/com/yutou/napcat/handle/QuoteReply.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package com.yutou.napcat.handle;
|
||||
|
||||
public class QuoteReply {
|
||||
private final String messageId;
|
||||
|
||||
public QuoteReply(String messageId) {
|
||||
this.messageId = messageId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("[CQ:reply,id=%s]",messageId);
|
||||
}
|
||||
}
|
||||
38
qqbot/src/main/java/com/yutou/napcat/handle/Record.java
Normal file
38
qqbot/src/main/java/com/yutou/napcat/handle/Record.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package com.yutou.napcat.handle;
|
||||
|
||||
import com.yutou.utils.ConfigTools;
|
||||
import lombok.Data;
|
||||
|
||||
public class Record extends BaseHandle<Record.RecordInfo> {
|
||||
|
||||
public Record() {
|
||||
super("record");
|
||||
}
|
||||
|
||||
public Record(String file) {
|
||||
super("record");
|
||||
data = new RecordInfo(file);
|
||||
}
|
||||
|
||||
public Record(String file, boolean proxy) {
|
||||
super("record");
|
||||
data = new RecordInfo(file);
|
||||
data.proxy = proxy ? "1" : "0";
|
||||
}
|
||||
|
||||
|
||||
@Data
|
||||
public static class RecordInfo {
|
||||
String file;
|
||||
int magic;
|
||||
String url;
|
||||
String cache;
|
||||
String proxy;
|
||||
String timeout;
|
||||
|
||||
public RecordInfo(String file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
24
qqbot/src/main/java/com/yutou/napcat/handle/Reply.java
Normal file
24
qqbot/src/main/java/com/yutou/napcat/handle/Reply.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package com.yutou.napcat.handle;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
public class Reply extends BaseHandle<Reply.ReplyInfo> {
|
||||
|
||||
public Reply() {
|
||||
super("reply");
|
||||
}
|
||||
|
||||
public Reply(long id) {
|
||||
super("reply");
|
||||
data = new ReplyInfo(id);
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class ReplyInfo {
|
||||
private long id;
|
||||
|
||||
public ReplyInfo(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
}
|
||||
51
qqbot/src/main/java/com/yutou/napcat/handle/Text.java
Normal file
51
qqbot/src/main/java/com/yutou/napcat/handle/Text.java
Normal file
@@ -0,0 +1,51 @@
|
||||
package com.yutou.napcat.handle;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
public class Text extends BaseHandle<Text.TextInfo> {
|
||||
|
||||
public Text() {
|
||||
super("text");
|
||||
}
|
||||
|
||||
public Text(String text) {
|
||||
super("text");
|
||||
data = new TextInfo(text + "\n");
|
||||
}
|
||||
|
||||
public Text(String text, boolean isNewLine) {
|
||||
super("text");
|
||||
if (isNewLine) {
|
||||
data = new TextInfo(text + "\n");
|
||||
} else {
|
||||
data = new TextInfo(text);
|
||||
}
|
||||
}
|
||||
|
||||
public Text(boolean isNewLine, String... text) {
|
||||
super("text");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String s : text) {
|
||||
sb.append(s);
|
||||
}
|
||||
if (isNewLine) {
|
||||
data = new TextInfo(sb + "\n");
|
||||
} else {
|
||||
data = new TextInfo(sb.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return data.text.trim();
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class TextInfo {
|
||||
String text;
|
||||
|
||||
public TextInfo(String text) {
|
||||
this.text = text.trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
14
qqbot/src/main/java/com/yutou/napcat/http/FriendApi.java
Normal file
14
qqbot/src/main/java/com/yutou/napcat/http/FriendApi.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package com.yutou.napcat.http;
|
||||
|
||||
import com.yutou.napcat.model.FriendBean;
|
||||
import com.yutou.okhttp.HttpBody;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.POST;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface FriendApi {
|
||||
@POST("/get_friend_list")
|
||||
Call<HttpBody<List<FriendBean>>> getFriendList(
|
||||
);
|
||||
}
|
||||
70
qqbot/src/main/java/com/yutou/napcat/http/GroupApi.java
Normal file
70
qqbot/src/main/java/com/yutou/napcat/http/GroupApi.java
Normal file
@@ -0,0 +1,70 @@
|
||||
package com.yutou.napcat.http;
|
||||
|
||||
import com.yutou.napcat.model.GroupBean;
|
||||
import com.yutou.napcat.model.GroupUserBean;
|
||||
import com.yutou.okhttp.BaseBean;
|
||||
import com.yutou.okhttp.HttpBody;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.Field;
|
||||
import retrofit2.http.FormUrlEncoded;
|
||||
import retrofit2.http.POST;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface GroupApi {
|
||||
/**
|
||||
* 禁言
|
||||
* @param group 群号
|
||||
* @param user 用户
|
||||
* @param duration 禁言时长,单位秒
|
||||
*
|
||||
*/
|
||||
@FormUrlEncoded
|
||||
@POST("/set_group_ban")
|
||||
Call<HttpBody<BaseBean>> groupBan(
|
||||
@Field("group_id") long group,
|
||||
@Field("user_id") long user,
|
||||
@Field("duration") long duration
|
||||
);
|
||||
|
||||
/**
|
||||
* 禁言群组全体成员
|
||||
* @param group 群号
|
||||
*/
|
||||
@FormUrlEncoded
|
||||
@POST("/set_group_whole_ban")
|
||||
Call<HttpBody<BaseBean>> groupBanAll(
|
||||
@Field("group_id") long group
|
||||
);
|
||||
|
||||
/**
|
||||
* 获取群组列表
|
||||
*/
|
||||
@POST("/get_group_list")
|
||||
Call<HttpBody<List<GroupBean>>> getGroupList(
|
||||
);
|
||||
|
||||
/**
|
||||
* 获取群组信息
|
||||
*/
|
||||
@POST("/get_group_info")
|
||||
Call<HttpBody<GroupBean>> getGroupInfo(
|
||||
);
|
||||
|
||||
/**
|
||||
* 获取群组成员信息
|
||||
*/
|
||||
@POST("/get_group_member_info")
|
||||
Call<HttpBody<GroupUserBean>> getGroupUserInfo(
|
||||
);
|
||||
|
||||
/**
|
||||
* 获取群组成员列表
|
||||
* @param group 群号
|
||||
*/
|
||||
@FormUrlEncoded
|
||||
@POST("/get_group_member_list")
|
||||
Call<HttpBody<GroupUserBean>> getGroupUserList(
|
||||
@Field("group_id") long group
|
||||
);
|
||||
}
|
||||
50
qqbot/src/main/java/com/yutou/napcat/http/MessageAPI.java
Normal file
50
qqbot/src/main/java/com/yutou/napcat/http/MessageAPI.java
Normal file
@@ -0,0 +1,50 @@
|
||||
package com.yutou.napcat.http;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.napcat.model.MessageBean;
|
||||
import com.yutou.napcat.model.SendMessageResponse;
|
||||
import com.yutou.okhttp.BaseBean;
|
||||
import com.yutou.okhttp.HttpBody;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.Field;
|
||||
import retrofit2.http.FormUrlEncoded;
|
||||
import retrofit2.http.POST;
|
||||
|
||||
public interface MessageAPI {
|
||||
/**
|
||||
* 发送私聊消息
|
||||
* @param message {@link com.yutou.napcat.handle.MessageHandleBuild}
|
||||
* @return 消息id
|
||||
*/
|
||||
@POST("/send_private_msg")
|
||||
Call<HttpBody<SendMessageResponse>> sendPrivateMsg(
|
||||
@Body
|
||||
JSONObject message);
|
||||
/**
|
||||
* 发送群聊消息
|
||||
* @param message 消息内容
|
||||
* @return 消息id
|
||||
*/
|
||||
@POST("/send_group_msg")
|
||||
Call<HttpBody<SendMessageResponse>> sendGroupMsg(
|
||||
@Body
|
||||
JSONObject message
|
||||
);
|
||||
|
||||
/**
|
||||
* 撤回消息
|
||||
* @param messageId 消息id
|
||||
*/
|
||||
@FormUrlEncoded
|
||||
@POST("/delete_msg")
|
||||
Call<HttpBody<BaseBean>> delMsg(
|
||||
@Field("message_id") long messageId
|
||||
);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST("/get_msg")
|
||||
Call<HttpBody<MessageBean>> getMessage(
|
||||
@Field("message_id") long messageId
|
||||
);
|
||||
}
|
||||
33
qqbot/src/main/java/com/yutou/napcat/http/NapCatApi.java
Normal file
33
qqbot/src/main/java/com/yutou/napcat/http/NapCatApi.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package com.yutou.napcat.http;
|
||||
|
||||
import com.yutou.okhttp.HttpLoggingInterceptor;
|
||||
import com.yutou.okhttp.api.BaseApi;
|
||||
import com.yutou.utils.ConfigTools;
|
||||
|
||||
public class NapCatApi extends BaseApi {
|
||||
private static final String URL;
|
||||
static {
|
||||
URL= ConfigTools.load(ConfigTools.CONFIG,ConfigTools.NAPCAT_URL,String.class);
|
||||
}
|
||||
|
||||
public NapCatApi() {
|
||||
super(URL);
|
||||
}
|
||||
|
||||
public static void setLog(boolean log){
|
||||
HttpLoggingInterceptor.setLog(log);
|
||||
}
|
||||
|
||||
public static MessageAPI getMessageApi(){
|
||||
return new NapCatApi().setURL(URL).createApi(MessageAPI.class);
|
||||
}
|
||||
public static UtilsApi getUtilsApi(){
|
||||
return new NapCatApi().setURL(URL).createApi(UtilsApi.class);
|
||||
}
|
||||
public static GroupApi getGroupApi(){
|
||||
return new NapCatApi().setURL(URL).createApi(GroupApi.class);
|
||||
}
|
||||
public static FriendApi getFriendApi(){
|
||||
return new NapCatApi().setURL(URL).createApi(FriendApi.class);
|
||||
}
|
||||
}
|
||||
80
qqbot/src/main/java/com/yutou/napcat/http/UtilsApi.java
Normal file
80
qqbot/src/main/java/com/yutou/napcat/http/UtilsApi.java
Normal file
@@ -0,0 +1,80 @@
|
||||
package com.yutou.napcat.http;
|
||||
|
||||
import com.yutou.napcat.model.*;
|
||||
import com.yutou.okhttp.BaseBean;
|
||||
import com.yutou.okhttp.HttpBody;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.Field;
|
||||
import retrofit2.http.FormUrlEncoded;
|
||||
import retrofit2.http.POST;
|
||||
|
||||
public interface UtilsApi {
|
||||
/**
|
||||
* 获取语音
|
||||
*
|
||||
* @param fileId 收到的语音文件名(消息段的 file 参数),如 0B38145AA44505000B38145AA4450500.silk
|
||||
* @param format 要转换到的格式,目前支持 mp3、amr、wma、m4a、spx、ogg、wav、flac {@link com.yutou.napcat.enums.RecordFormatEnum}
|
||||
* @return 转换后的语音文件路径
|
||||
*/
|
||||
@FormUrlEncoded
|
||||
@POST("/get_record")
|
||||
Call<HttpBody<String>> getMessageRecord(
|
||||
@Field("file") String fileId,
|
||||
@Field("out_format") String format
|
||||
);
|
||||
|
||||
/**
|
||||
* 获取图片
|
||||
*
|
||||
* @param fileId 收到的图片文件名(消息段的 file 参数)
|
||||
* @return 下载后的图片文件路径
|
||||
*/
|
||||
@FormUrlEncoded
|
||||
@POST("/get_image")
|
||||
Call<HttpBody<String>> getMessageImage(
|
||||
@Field("file") String fileId
|
||||
);
|
||||
|
||||
/**
|
||||
* 检查是否可以发送图片
|
||||
*/
|
||||
@POST("/can_send_image")
|
||||
Call<HttpBody<CheckSendImageBean>> checkSendImage(
|
||||
);
|
||||
|
||||
/**
|
||||
* 检查是否可以发送语音
|
||||
*/
|
||||
@POST("/can_send_record")
|
||||
Call<HttpBody<CheckSendRecordBean>> checkSendRecord(
|
||||
);
|
||||
|
||||
/**
|
||||
* 获取机器人状态
|
||||
*/
|
||||
@POST("/get_status")
|
||||
Call<HttpBody<QQBotStatusBean>> checkQQBotStatus(
|
||||
);
|
||||
|
||||
/**
|
||||
* 获取机器人版本信息
|
||||
*/
|
||||
@POST("/get_version_info")
|
||||
Call<HttpBody<QQBotVersionBean>> checkQQBotVersion(
|
||||
);
|
||||
|
||||
/**
|
||||
* 清理缓存
|
||||
*/
|
||||
@POST("/clean_cache")
|
||||
Call<HttpBody<BaseBean>> cleanCache(
|
||||
);
|
||||
|
||||
/**
|
||||
* 获取登录信息
|
||||
*/
|
||||
@POST("/get_login_info")
|
||||
Call<HttpBody<FriendBean>> getLoginInfo(
|
||||
);
|
||||
|
||||
}
|
||||
139
qqbot/src/main/java/com/yutou/napcat/model/AppShareBean.java
Normal file
139
qqbot/src/main/java/com/yutou/napcat/model/AppShareBean.java
Normal file
@@ -0,0 +1,139 @@
|
||||
package com.yutou.napcat.model;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import com.yutou.okhttp.BaseBean;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
|
||||
public class AppShareBean extends BaseBean {
|
||||
|
||||
@JSONField(name = "ver")
|
||||
private String version;
|
||||
|
||||
@JSONField(name = "prompt")
|
||||
private String prompt;
|
||||
|
||||
@JSONField(name = "config")
|
||||
private Config config;
|
||||
|
||||
@JSONField(name = "needShareCallBack")
|
||||
private boolean needShareCallBack;
|
||||
|
||||
@JSONField(name = "app")
|
||||
private String app;
|
||||
|
||||
@JSONField(name = "view")
|
||||
private String view;
|
||||
|
||||
@JSONField(name = "meta")
|
||||
private Meta meta;
|
||||
|
||||
// getters and setters...
|
||||
|
||||
// Inner classes
|
||||
|
||||
@Data
|
||||
public static class Config {
|
||||
@JSONField(name = "type")
|
||||
private String type;
|
||||
|
||||
@JSONField(name = "width")
|
||||
private int width;
|
||||
|
||||
@JSONField(name = "height")
|
||||
private int height;
|
||||
|
||||
@JSONField(name = "forward")
|
||||
private int forward;
|
||||
|
||||
@JSONField(name = "autoSize")
|
||||
private int autoSize;
|
||||
|
||||
@JSONField(name = "ctime")
|
||||
private long ctime;
|
||||
|
||||
@JSONField(name = "token")
|
||||
private String token;
|
||||
|
||||
// getters and setters...
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Meta {
|
||||
@JSONField(name = "detail_1")
|
||||
private Detail detail1;
|
||||
|
||||
// If there can be multiple "detail_X" entries, you might need a Map
|
||||
// @JSONField(name = "detail_X")
|
||||
// private Map<String, Detail> details;
|
||||
|
||||
// getters and setters...
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Detail {
|
||||
@JSONField(name = "appid")
|
||||
private String appid;
|
||||
|
||||
@JSONField(name = "appType")
|
||||
private int appType;
|
||||
|
||||
@JSONField(name = "title")
|
||||
private String title;
|
||||
|
||||
@JSONField(name = "desc")
|
||||
private String desc;
|
||||
|
||||
@JSONField(name = "icon")
|
||||
private String icon;
|
||||
|
||||
@JSONField(name = "preview")
|
||||
private String preview;
|
||||
|
||||
@JSONField(name = "url")
|
||||
private String url;
|
||||
|
||||
@JSONField(name = "scene")
|
||||
private int scene;
|
||||
|
||||
@JSONField(name = "host")
|
||||
private Host host;
|
||||
|
||||
@JSONField(name = "shareTemplateId")
|
||||
private String shareTemplateId;
|
||||
|
||||
// Since "shareTemplateData" is an empty object, it can be left as a Map or a specific class
|
||||
// if you know the structure of the data that might be there
|
||||
@JSONField(name = "shareTemplateData")
|
||||
private Map<String, Object> shareTemplateData;
|
||||
|
||||
@JSONField(name = "qqdocurl")
|
||||
private String qqdocurl;
|
||||
|
||||
@JSONField(name = "showLittleTail")
|
||||
private String showLittleTail;
|
||||
|
||||
@JSONField(name = "gamePoints")
|
||||
private String gamePoints;
|
||||
|
||||
@JSONField(name = "gamePointsUrl")
|
||||
private String gamePointsUrl;
|
||||
|
||||
// getters and setters...
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Host {
|
||||
@JSONField(name = "uin")
|
||||
private long uin;
|
||||
|
||||
@JSONField(name = "nick")
|
||||
private String nick;
|
||||
|
||||
// getters and setters...
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.yutou.napcat.model;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import com.yutou.okhttp.BaseBean;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CheckSendImageBean extends BaseBean {
|
||||
@JSONField(name = "yes")
|
||||
private boolean yes;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.yutou.napcat.model;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import com.yutou.okhttp.BaseBean;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CheckSendRecordBean extends BaseBean {
|
||||
@JSONField(name = "yes")
|
||||
private boolean yes;
|
||||
|
||||
}
|
||||
15
qqbot/src/main/java/com/yutou/napcat/model/FriendBean.java
Normal file
15
qqbot/src/main/java/com/yutou/napcat/model/FriendBean.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package com.yutou.napcat.model;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import com.yutou.okhttp.BaseBean;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class FriendBean extends BaseBean {
|
||||
@JSONField(name = "user_id")
|
||||
private long userId;//qq号
|
||||
@JSONField(name = "nickname")
|
||||
private String nickName;//昵称
|
||||
@JSONField(name = "remark")
|
||||
private String remark;//备注
|
||||
}
|
||||
18
qqbot/src/main/java/com/yutou/napcat/model/GroupBean.java
Normal file
18
qqbot/src/main/java/com/yutou/napcat/model/GroupBean.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package com.yutou.napcat.model;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import com.yutou.okhttp.BaseBean;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class GroupBean extends BaseBean {
|
||||
@JSONField(name = "group_id")
|
||||
private long groupId;
|
||||
@JSONField(name = "group_name")
|
||||
private String groupName;
|
||||
@JSONField(name = "member_count")
|
||||
private int userCount;
|
||||
@JSONField(name = "max_member_count")
|
||||
private int userMaxCount;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.yutou.napcat.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class GroupFrom {
|
||||
private long id;
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.yutou.napcat.model;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import com.yutou.okhttp.BaseBean;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class GroupUserBean extends BaseBean {
|
||||
// 群号
|
||||
@JSONField(name = "group_id")
|
||||
private long groupId;
|
||||
|
||||
// QQ号
|
||||
@JSONField(name = "user_id")
|
||||
private long userId;
|
||||
|
||||
// 昵称
|
||||
@JSONField(name = "nickname")
|
||||
private String nickname;
|
||||
|
||||
// 群名片/备注
|
||||
@JSONField(name = "card")
|
||||
private String card;
|
||||
|
||||
// 性别,male 或 female 或 unknown
|
||||
@JSONField(name = "sex")
|
||||
private String sex;
|
||||
|
||||
// 年龄
|
||||
@JSONField(name = "age")
|
||||
private int age;
|
||||
|
||||
// 地区
|
||||
@JSONField(name = "area")
|
||||
private String area;
|
||||
|
||||
// 加群时间戳
|
||||
@JSONField(name = "join_time")
|
||||
private int joinTime;
|
||||
|
||||
// 最后发言时间戳
|
||||
@JSONField(name = "last_sent_time")
|
||||
private int lastSentTime;
|
||||
|
||||
// 成员等级
|
||||
@JSONField(name = "level")
|
||||
private String level;
|
||||
|
||||
// 角色,owner 或 admin 或 member
|
||||
@JSONField(name = "role")
|
||||
private String role;
|
||||
|
||||
// 是否不良记录成员
|
||||
@JSONField(name = "unfriendly")
|
||||
private boolean unfriendly;
|
||||
|
||||
// 专属头衔
|
||||
@JSONField(name = "title")
|
||||
private String title;
|
||||
|
||||
// 专属头衔过期时间戳
|
||||
@JSONField(name = "title_expire_time")
|
||||
private int titleExpireTime;
|
||||
|
||||
// 是否允许修改群名片
|
||||
@JSONField(name = "card_changeable")
|
||||
private boolean cardChangeable;
|
||||
|
||||
}
|
||||
23
qqbot/src/main/java/com/yutou/napcat/model/Message.java
Normal file
23
qqbot/src/main/java/com/yutou/napcat/model/Message.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package com.yutou.napcat.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class Message {
|
||||
private String message;
|
||||
private String srcMessage;
|
||||
private String id;
|
||||
public Message(String message, String srcMessage) {
|
||||
this.message = message;
|
||||
this.srcMessage = srcMessage;
|
||||
}
|
||||
|
||||
public String serializeToMiraiCode(){
|
||||
return srcMessage;
|
||||
}
|
||||
|
||||
public String contentToString(){
|
||||
return message;
|
||||
}
|
||||
|
||||
}
|
||||
45
qqbot/src/main/java/com/yutou/napcat/model/MessageBean.java
Normal file
45
qqbot/src/main/java/com/yutou/napcat/model/MessageBean.java
Normal file
@@ -0,0 +1,45 @@
|
||||
package com.yutou.napcat.model;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import com.yutou.okhttp.BaseBean;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 消息
|
||||
* @see <a href="https://github.com/botuniverse/onebot-11/blob/master/api/public.md#get_msg-%E8%8E%B7%E5%8F%96%E6%B6%88%E6%81%AF">文档</a>
|
||||
*/
|
||||
@Data
|
||||
public class MessageBean extends BaseBean {
|
||||
/**
|
||||
*发送时间
|
||||
*/
|
||||
@JSONField(name = "time")
|
||||
private long time;
|
||||
/**
|
||||
* 消息类型,同 <a href="https://github.com/botuniverse/onebot-11/blob/master/event/message.md">消息事件</a>
|
||||
*/
|
||||
@JSONField(name = "message_type")
|
||||
private String type;
|
||||
/**
|
||||
* 消息 ID
|
||||
*/
|
||||
@JSONField(name = "message_id")
|
||||
private int messageId;
|
||||
/**
|
||||
* 消息真实 ID
|
||||
*/
|
||||
@JSONField(name = "real_id")
|
||||
private int realId;
|
||||
/**
|
||||
* 发送人信息,同 <a href="https://github.com/botuniverse/onebot-11/blob/master/event/message.md">消息事件</a>
|
||||
*/
|
||||
@JSONField(name = "sender")
|
||||
private SenderBean sender;
|
||||
/**
|
||||
* 消息内容
|
||||
*/
|
||||
@JSONField(name = "message")
|
||||
private String message;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.yutou.napcat.model;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import com.yutou.okhttp.BaseBean;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class QQBotStatusBean extends BaseBean {
|
||||
@JSONField(name = "online")
|
||||
private String online;//当前 QQ 在线,null 表示无法查询到在线状态
|
||||
@JSONField(name = "good")
|
||||
private String good;//状态符合预期,意味着各模块正常运行、功能正常,且 QQ 在线
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.yutou.napcat.model;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class QQBotVersionBean {
|
||||
@JSONField(name = "app_name")
|
||||
private String appName;//应用标识,如 mirai-native
|
||||
|
||||
@JSONField(name = "app_version")
|
||||
private String appVersion;//应用版本,如 1.2.3
|
||||
|
||||
@JSONField(name = "protocol_version")
|
||||
private String protocolVersion;//OneBot 标准版本,如 v11
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.yutou.napcat.model;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import com.yutou.napcat.handle.BaseHandle;
|
||||
import com.yutou.okhttp.BaseBean;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.List;
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class SendMessageRequest extends BaseBean {
|
||||
@JSONField(name = "user_id")
|
||||
private long userId;
|
||||
@JSONField
|
||||
List<BaseHandle<?>> message;
|
||||
@SerializedName("auto_escape")
|
||||
private boolean notCQCode;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.yutou.napcat.model;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import com.yutou.okhttp.BaseBean;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class SendMessageResponse extends BaseBean {
|
||||
@JSONField( name = "message_id")
|
||||
private int id;
|
||||
|
||||
private String e;
|
||||
|
||||
}
|
||||
24
qqbot/src/main/java/com/yutou/napcat/model/SenderBean.java
Normal file
24
qqbot/src/main/java/com/yutou/napcat/model/SenderBean.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package com.yutou.napcat.model;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import com.yutou.okhttp.BaseBean;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 发送人结构体
|
||||
*
|
||||
*/
|
||||
@Data
|
||||
public class SenderBean extends BaseBean {
|
||||
@JSONField(name = "user_id")
|
||||
private long userId;
|
||||
@JSONField(name = "nickname")
|
||||
private String nickName;
|
||||
/**
|
||||
* male 或 female 或 unknown
|
||||
*/
|
||||
@JSONField(name = "sex")
|
||||
private String sex;
|
||||
@JSONField(name = "age")
|
||||
private int age;
|
||||
}
|
||||
17
qqbot/src/main/java/com/yutou/napcat/model/SourceFrom.java
Normal file
17
qqbot/src/main/java/com/yutou/napcat/model/SourceFrom.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package com.yutou.napcat.model;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class SourceFrom {
|
||||
@JSONField(name = "user_id")
|
||||
private long userId;
|
||||
private String nickname;
|
||||
private String card;
|
||||
private String role;
|
||||
|
||||
public Long getFromId() {
|
||||
return userId;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user