feat: adding auto group add and auto friend add
feat: adding new config fix: fix send command cannot send cq code bug fix: fix cannot at all bug
This commit is contained in:
parent
448167d021
commit
b5605c6a0f
2
.idea/fileTemplates/includes/Version.txt
generated
2
.idea/fileTemplates/includes/Version.txt
generated
@ -1 +1 @@
|
|||||||
1.0.2
|
1.0.3
|
@ -14,7 +14,7 @@ allprojects {
|
|||||||
apply(plugin = "java")
|
apply(plugin = "java")
|
||||||
val groupName by extra("cn.wzpmc")
|
val groupName by extra("cn.wzpmc")
|
||||||
val projectArtifactId by extra("my-bot")
|
val projectArtifactId by extra("my-bot")
|
||||||
val projectVersion by extra("1.0.2")
|
val projectVersion by extra("1.0.3")
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
maven("https://libraries.minecraft.net")
|
maven("https://libraries.minecraft.net")
|
||||||
|
@ -35,7 +35,7 @@ public class UserIdArguments implements ArgumentType<Long> {
|
|||||||
if (CqCodeUtils.isCQ(s)) {
|
if (CqCodeUtils.isCQ(s)) {
|
||||||
JsonMessagePart jsonMessagePart = CqCodeUtils.parseToPart(s);
|
JsonMessagePart jsonMessagePart = CqCodeUtils.parseToPart(s);
|
||||||
if (jsonMessagePart instanceof At) {
|
if (jsonMessagePart instanceof At) {
|
||||||
return ((At) jsonMessagePart).getQq();
|
return Long.parseLong(((At) jsonMessagePart).getQq());
|
||||||
}
|
}
|
||||||
throw new CqCodeException();
|
throw new CqCodeException();
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package cn.wzpmc.message.json.parts;
|
|||||||
|
|
||||||
import cn.wzpmc.message.json.JsonMessagePart;
|
import cn.wzpmc.message.json.JsonMessagePart;
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
|
import lombok.AccessLevel;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
@ -14,15 +15,38 @@ import lombok.NoArgsConstructor;
|
|||||||
* @since 2024/8/2 下午11:22
|
* @since 2024/8/2 下午11:22
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor(access = AccessLevel.PROTECTED)
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor(access = AccessLevel.PROTECTED)
|
||||||
public class At implements JsonMessagePart {
|
public class At implements JsonMessagePart {
|
||||||
/**
|
/**
|
||||||
* "@"的 QQ 号,all 表示全体成员
|
* "@"的 QQ 号,all 表示全体成员
|
||||||
*
|
*
|
||||||
* @since 2024/8/2 下午11:50 v0.0.3-dev
|
* @since 2024/8/2 下午11:50 v0.0.3-dev
|
||||||
*/
|
*/
|
||||||
private Long qq;
|
private String qq;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用于@全体成员的AT对象
|
||||||
|
*
|
||||||
|
* @return @全体成员的At对象
|
||||||
|
* @author wzp
|
||||||
|
* @since 2024/8/31 23:51 v1.0.3
|
||||||
|
*/
|
||||||
|
public static At all() {
|
||||||
|
return new At("all");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用于@用户的AT对象
|
||||||
|
*
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @return @指定用户的At对象
|
||||||
|
* @author wzp
|
||||||
|
* @since 2024/8/31 23:50 v1.0.3
|
||||||
|
*/
|
||||||
|
public static At user(Long userId) {
|
||||||
|
return new At(userId.toString());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PartType getPartType() {
|
public PartType getPartType() {
|
||||||
|
@ -28,4 +28,18 @@ public interface IConfiguration {
|
|||||||
* @since 2024/7/31 上午3:49 v0.0.1-dev
|
* @since 2024/7/31 上午3:49 v0.0.1-dev
|
||||||
*/
|
*/
|
||||||
IFallbackConfiguration getFallback();
|
IFallbackConfiguration getFallback();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return 获取好友配置
|
||||||
|
* @author wzp
|
||||||
|
* @since 2024/8/30 15:42 v1.0.3
|
||||||
|
*/
|
||||||
|
IFriendConfiguration getFriend();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return 获取群聊配置
|
||||||
|
* @author wzp
|
||||||
|
* @since 2024/8/31 23:56 v1.0.3
|
||||||
|
*/
|
||||||
|
IGroupConfiguration getGroup();
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,17 @@
|
|||||||
|
package cn.wzpmc.plugins.configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 好友配置
|
||||||
|
*
|
||||||
|
* @author wzp
|
||||||
|
* @version 1.0.3
|
||||||
|
* @since 2024/8/30 15:39
|
||||||
|
*/
|
||||||
|
public interface IFriendConfiguration {
|
||||||
|
/**
|
||||||
|
* @return 是否自动同意好友申请
|
||||||
|
* @author wzp
|
||||||
|
* @since 2024/8/30 15:41 v1.0.3
|
||||||
|
*/
|
||||||
|
boolean isAutoAccept();
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package cn.wzpmc.plugins.configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 群聊相关配置
|
||||||
|
*
|
||||||
|
* @author wzp
|
||||||
|
* @version 1.0.3
|
||||||
|
* @since 2024/8/31 23:55
|
||||||
|
*/
|
||||||
|
public interface IGroupConfiguration {
|
||||||
|
/**
|
||||||
|
* @return 是否自动同意加群邀请
|
||||||
|
* @author wzp
|
||||||
|
* @since 2024/8/30 15:41 v1.0.3
|
||||||
|
*/
|
||||||
|
boolean isAutoAccept();
|
||||||
|
}
|
@ -95,4 +95,49 @@ public interface CommandSender {
|
|||||||
default boolean isFullAdmin() {
|
default boolean isFullAdmin() {
|
||||||
return this instanceof IBot || IBot.getInstance().isBotOp(this.getId());
|
return this instanceof IBot || IBot.getInstance().isBotOp(this.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断指令发送者是否为好友/控制台
|
||||||
|
*
|
||||||
|
* @return 是否为好友/控制台
|
||||||
|
* @author wzp
|
||||||
|
* @since 2024/8/31 21:55 v1.0.3
|
||||||
|
*/
|
||||||
|
default boolean isPureUser() {
|
||||||
|
return isFriend() || isConsole();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断指令发送者是否为好友
|
||||||
|
*
|
||||||
|
* @return 是否为好友
|
||||||
|
* @author wzp
|
||||||
|
* @since 2024/8/31 21:58 v1.0.3
|
||||||
|
*/
|
||||||
|
default boolean isFriend() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断指令发送者是否为群用户
|
||||||
|
*
|
||||||
|
* @return 是否为群用户
|
||||||
|
* @author wzp
|
||||||
|
* @since 2024/8/31 21:55 v1.0.3
|
||||||
|
*/
|
||||||
|
default boolean isGroupUser() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断指令发送者是否为控制台
|
||||||
|
*
|
||||||
|
* @return 是否为控制台
|
||||||
|
* @author wzp
|
||||||
|
* @since 2024/8/31 21:55 v1.0.3
|
||||||
|
*/
|
||||||
|
default boolean isConsole() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -38,4 +38,9 @@ public class Friend extends IUser implements CommandSender {
|
|||||||
IMainApi mainApi = instance.getMainApi();
|
IMainApi mainApi = instance.getMainApi();
|
||||||
mainApi.doApiCall(new SendPrivateMessageAction(this.id, messageComponent));
|
mainApi.doApiCall(new SendPrivateMessageAction(this.id, messageComponent));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isFriend() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ public class GroupCommandSender extends GroupUser implements CommandSender {
|
|||||||
IMainApi mainApi = instance.getMainApi();
|
IMainApi mainApi = instance.getMainApi();
|
||||||
JsonMessage jsonMessage = new JsonMessage();
|
JsonMessage jsonMessage = new JsonMessage();
|
||||||
List<JsonMessagePart> messageParts = jsonMessage.getMessageParts();
|
List<JsonMessagePart> messageParts = jsonMessage.getMessageParts();
|
||||||
messageParts.add(new At(this.getId()));
|
messageParts.add(At.user(this.getId()));
|
||||||
messageParts.add(StringMessage.text(" "));
|
messageParts.add(StringMessage.text(" "));
|
||||||
if (messageComponent instanceof StringMessage) {
|
if (messageComponent instanceof StringMessage) {
|
||||||
messageParts.add((StringMessage) messageComponent);
|
messageParts.add((StringMessage) messageComponent);
|
||||||
@ -83,4 +83,9 @@ public class GroupCommandSender extends GroupUser implements CommandSender {
|
|||||||
SendGroupMessageAction sendGroupMessageAction = new SendGroupMessageAction(this.groupId, jsonMessage);
|
SendGroupMessageAction sendGroupMessageAction = new SendGroupMessageAction(this.groupId, jsonMessage);
|
||||||
mainApi.doApiCall(sendGroupMessageAction);
|
mainApi.doApiCall(sendGroupMessageAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isGroupUser() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package cn.wzpmc.utils;
|
package cn.wzpmc.utils;
|
||||||
|
|
||||||
import cn.wzpmc.message.json.JsonMessagePart;
|
import cn.wzpmc.message.json.JsonMessagePart;
|
||||||
|
import cn.wzpmc.message.json.parts.At;
|
||||||
import cn.wzpmc.message.json.parts.PartType;
|
import cn.wzpmc.message.json.parts.PartType;
|
||||||
import cn.wzpmc.message.json.parts.music.MusicType;
|
import cn.wzpmc.message.json.parts.music.MusicType;
|
||||||
import cn.wzpmc.message.json.parts.node.CustomNode;
|
import cn.wzpmc.message.json.parts.node.CustomNode;
|
||||||
@ -113,6 +114,13 @@ public class CqCodeUtils {
|
|||||||
PartType type = jsonObject.getObject("type", PartType.class);
|
PartType type = jsonObject.getObject("type", PartType.class);
|
||||||
Class<? extends JsonMessagePart> clazz = type.clazz;
|
Class<? extends JsonMessagePart> clazz = type.clazz;
|
||||||
JSONObject dataObject = jsonObject.getJSONObject("data");
|
JSONObject dataObject = jsonObject.getJSONObject("data");
|
||||||
|
if (type.equals(PartType.AT)) {
|
||||||
|
String string = dataObject.getString("qq");
|
||||||
|
if (string.equalsIgnoreCase("all")) {
|
||||||
|
return At.all();
|
||||||
|
}
|
||||||
|
return At.user(Long.parseLong(string));
|
||||||
|
}
|
||||||
if (type.equals(PartType.POKE)) {
|
if (type.equals(PartType.POKE)) {
|
||||||
Integer pokeType = dataObject.getInteger("type");
|
Integer pokeType = dataObject.getInteger("type");
|
||||||
Integer pokeId = dataObject.getInteger("id");
|
Integer pokeId = dataObject.getInteger("id");
|
||||||
|
@ -3,7 +3,9 @@ package cn.wzpmc;
|
|||||||
import cn.wzpmc.api.IMainApi;
|
import cn.wzpmc.api.IMainApi;
|
||||||
import cn.wzpmc.api.actions.message.get.GetLoginInfoAction;
|
import cn.wzpmc.api.actions.message.get.GetLoginInfoAction;
|
||||||
import cn.wzpmc.builtin.commands.*;
|
import cn.wzpmc.builtin.commands.*;
|
||||||
|
import cn.wzpmc.builtin.event.AddGroupEventHandler;
|
||||||
import cn.wzpmc.builtin.event.CommandEventHandler;
|
import cn.wzpmc.builtin.event.CommandEventHandler;
|
||||||
|
import cn.wzpmc.builtin.event.FriendAddEventHandler;
|
||||||
import cn.wzpmc.configuration.Configuration;
|
import cn.wzpmc.configuration.Configuration;
|
||||||
import cn.wzpmc.console.MyBotConsole;
|
import cn.wzpmc.console.MyBotConsole;
|
||||||
import cn.wzpmc.entities.user.bot.MyBot;
|
import cn.wzpmc.entities.user.bot.MyBot;
|
||||||
@ -128,6 +130,12 @@ public class Main {
|
|||||||
// 获取Bot消息
|
// 获取Bot消息
|
||||||
mainApi.doApiCall(new GetLoginInfoAction());
|
mainApi.doApiCall(new GetLoginInfoAction());
|
||||||
myBot.registerEventHandler(new CommandEventHandler());
|
myBot.registerEventHandler(new CommandEventHandler());
|
||||||
|
if (myBot.getConfiguration().getFriend().isAutoAccept()) {
|
||||||
|
myBot.registerEventHandler(new FriendAddEventHandler());
|
||||||
|
}
|
||||||
|
if (myBot.getConfiguration().getGroup().isAutoAccept()) {
|
||||||
|
myBot.registerEventHandler(new AddGroupEventHandler());
|
||||||
|
}
|
||||||
// 注册内置指令
|
// 注册内置指令
|
||||||
CommandManager commandManager = myBot.getCommandManager();
|
CommandManager commandManager = myBot.getCommandManager();
|
||||||
commandManager.registerCommand(new StopCommand(myBot));
|
commandManager.registerCommand(new StopCommand(myBot));
|
||||||
|
@ -0,0 +1,26 @@
|
|||||||
|
package cn.wzpmc.builtin.event;
|
||||||
|
|
||||||
|
import cn.wzpmc.api.IMainApi;
|
||||||
|
import cn.wzpmc.api.actions.message.set.SetGroupAddRequestAction;
|
||||||
|
import cn.wzpmc.events.request.group.GroupJoinRequestEvent;
|
||||||
|
import cn.wzpmc.plugins.event.EventHandler;
|
||||||
|
import cn.wzpmc.user.IBot;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理自动加群
|
||||||
|
*
|
||||||
|
* @author wzp
|
||||||
|
* @version 1.0.3
|
||||||
|
* @since 2024/8/31 23:53
|
||||||
|
*/
|
||||||
|
@Log4j2
|
||||||
|
public class AddGroupEventHandler {
|
||||||
|
@EventHandler
|
||||||
|
public void onUserInvite(GroupJoinRequestEvent event) {
|
||||||
|
IBot instance = IBot.getInstance();
|
||||||
|
IMainApi mainApi = instance.getMainApi();
|
||||||
|
mainApi.doApiCallSafe(new SetGroupAddRequestAction(event.getFlag(), event.getSubType()));
|
||||||
|
log.info("用户{}邀请你加入群{},已同意", event.getUserId(), event.getGroupId());
|
||||||
|
}
|
||||||
|
}
|
@ -9,6 +9,7 @@ import cn.wzpmc.plugins.event.EventHandler;
|
|||||||
import cn.wzpmc.user.Friend;
|
import cn.wzpmc.user.Friend;
|
||||||
import cn.wzpmc.user.IBot;
|
import cn.wzpmc.user.IBot;
|
||||||
import cn.wzpmc.user.group.GroupCommandSender;
|
import cn.wzpmc.user.group.GroupCommandSender;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@ -19,6 +20,7 @@ import java.util.regex.Pattern;
|
|||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
* @since 2024/8/25 13:40
|
* @since 2024/8/25 13:40
|
||||||
*/
|
*/
|
||||||
|
@Log4j2
|
||||||
public class CommandEventHandler {
|
public class CommandEventHandler {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onGroupMessage(GroupMessageEvent event) {
|
public void onGroupMessage(GroupMessageEvent event) {
|
||||||
@ -29,7 +31,9 @@ public class CommandEventHandler {
|
|||||||
Pattern compile = Pattern.compile("\\[CQ:at,qq=" + id + ".*?]\\s*?/.*");
|
Pattern compile = Pattern.compile("\\[CQ:at,qq=" + id + ".*?]\\s*?/.*");
|
||||||
if (compile.asMatchPredicate().test(message)) {
|
if (compile.asMatchPredicate().test(message)) {
|
||||||
CommandManager commandManager = (CommandManager) instance.getCommandManager();
|
CommandManager commandManager = (CommandManager) instance.getCommandManager();
|
||||||
commandManager.execute(groupCommandSender, message.replaceFirst("\\[CQ:at,qq=[0-9]{10}.*?]\\s*?/", ""));
|
String commandRaw = message.replaceFirst("\\[CQ:at,qq=[0-9]{10}.*?]\\s*?/", "");
|
||||||
|
log.info("群{}中的用户{}使用了指令{}", groupCommandSender.getGroupId(), groupCommandSender.getId(), commandRaw);
|
||||||
|
commandManager.execute(groupCommandSender, commandRaw);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,7 +45,9 @@ public class CommandEventHandler {
|
|||||||
String message = rawMessage.getMessage();
|
String message = rawMessage.getMessage();
|
||||||
if (message.startsWith("/")) {
|
if (message.startsWith("/")) {
|
||||||
CommandManager commandManager = (CommandManager) instance.getCommandManager();
|
CommandManager commandManager = (CommandManager) instance.getCommandManager();
|
||||||
commandManager.execute(sender, message.replaceFirst("/", ""));
|
String commandRaw = message.replaceFirst("/", "");
|
||||||
|
log.info("用户{}使用了指令{}", sender.getId(), commandRaw);
|
||||||
|
commandManager.execute(sender, commandRaw);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
package cn.wzpmc.builtin.event;
|
||||||
|
|
||||||
|
import cn.wzpmc.api.IMainApi;
|
||||||
|
import cn.wzpmc.api.actions.message.set.SetFriendAddRequestAction;
|
||||||
|
import cn.wzpmc.events.request.FriendAddRequestEvent;
|
||||||
|
import cn.wzpmc.plugins.event.EventHandler;
|
||||||
|
import cn.wzpmc.user.IBot;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自动通过好友申请相关事件
|
||||||
|
*
|
||||||
|
* @author wzp
|
||||||
|
* @version 1.0.3
|
||||||
|
* @since 2024/8/30 15:44
|
||||||
|
*/
|
||||||
|
@Log4j2
|
||||||
|
public class FriendAddEventHandler {
|
||||||
|
@EventHandler
|
||||||
|
public void onFriendAdd(FriendAddRequestEvent event) {
|
||||||
|
String flag = event.getFlag();
|
||||||
|
Long userId = event.getUserId();
|
||||||
|
IBot instance = IBot.getInstance();
|
||||||
|
IMainApi mainApi = instance.getMainApi();
|
||||||
|
mainApi.doApiCallSafe(new SetFriendAddRequestAction(flag));
|
||||||
|
log.info("已通过{}的好友申请", userId);
|
||||||
|
}
|
||||||
|
}
|
@ -30,4 +30,17 @@ public class Configuration implements IConfiguration {
|
|||||||
* @since 2024/7/30 下午11:49 v0.0.1-dev
|
* @since 2024/7/30 下午11:49 v0.0.1-dev
|
||||||
*/
|
*/
|
||||||
private FallbackConfiguration fallback;
|
private FallbackConfiguration fallback;
|
||||||
|
/**
|
||||||
|
* 好友配置
|
||||||
|
*
|
||||||
|
* @since 2024/8/30 15:43 v1.0.3
|
||||||
|
*/
|
||||||
|
private FriendConfiguration friend;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 群聊相关配置
|
||||||
|
*
|
||||||
|
* @since 2024/8/31 23:57 v1.0.3
|
||||||
|
*/
|
||||||
|
private GroupConfiguration group;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
package cn.wzpmc.configuration;
|
||||||
|
|
||||||
|
import cn.wzpmc.plugins.configuration.IFriendConfiguration;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author wzp
|
||||||
|
* @version 1.0.3
|
||||||
|
* @since 2024/8/30 15:39
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class FriendConfiguration implements IFriendConfiguration {
|
||||||
|
/**
|
||||||
|
* 是否自动同意好友
|
||||||
|
*
|
||||||
|
* @since 2024/8/30 15:43 v1.0.3
|
||||||
|
*/
|
||||||
|
private boolean autoAccept;
|
||||||
|
}
|
21
src/main/java/cn/wzpmc/configuration/GroupConfiguration.java
Normal file
21
src/main/java/cn/wzpmc/configuration/GroupConfiguration.java
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package cn.wzpmc.configuration;
|
||||||
|
|
||||||
|
import cn.wzpmc.plugins.configuration.IGroupConfiguration;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 群聊相关配置实现
|
||||||
|
*
|
||||||
|
* @author wzp
|
||||||
|
* @version 1.0.3
|
||||||
|
* @since 2024/8/31 23:56
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class GroupConfiguration implements IGroupConfiguration {
|
||||||
|
/**
|
||||||
|
* 是否自动同意好友
|
||||||
|
*
|
||||||
|
* @since 2024/8/30 15:43 v1.0.3
|
||||||
|
*/
|
||||||
|
private boolean autoAccept;
|
||||||
|
}
|
@ -104,6 +104,21 @@ public class MyBot extends IBot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isFriend() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isGroupUser() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isConsole() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop() {
|
public void stop() {
|
||||||
for (BasePlugin plugin : this.pluginManager.getPlugins()) {
|
for (BasePlugin plugin : this.pluginManager.getPlugins()) {
|
||||||
|
@ -22,6 +22,7 @@ import cn.wzpmc.utils.json.honor.HonorWriter;
|
|||||||
import cn.wzpmc.utils.json.message.JsonMessageReader;
|
import cn.wzpmc.utils.json.message.JsonMessageReader;
|
||||||
import cn.wzpmc.utils.json.message.JsonMessageWriter;
|
import cn.wzpmc.utils.json.message.JsonMessageWriter;
|
||||||
import cn.wzpmc.utils.json.message.StringMessageReader;
|
import cn.wzpmc.utils.json.message.StringMessageReader;
|
||||||
|
import cn.wzpmc.utils.json.message.StringMessageWriter;
|
||||||
import cn.wzpmc.utils.json.user.FriendUserReader;
|
import cn.wzpmc.utils.json.user.FriendUserReader;
|
||||||
import cn.wzpmc.utils.json.user.GroupUserReader;
|
import cn.wzpmc.utils.json.user.GroupUserReader;
|
||||||
import cn.wzpmc.utils.json.user.IBotReader;
|
import cn.wzpmc.utils.json.user.IBotReader;
|
||||||
@ -46,6 +47,7 @@ public class JsonUtils {
|
|||||||
JSON.register(JsonMessage.class, new JsonMessageWriter());
|
JSON.register(JsonMessage.class, new JsonMessageWriter());
|
||||||
JSON.register(Actions.class, new ActionWriter());
|
JSON.register(Actions.class, new ActionWriter());
|
||||||
JSON.register(HonorType.class, new HonorWriter());
|
JSON.register(HonorType.class, new HonorWriter());
|
||||||
|
JSON.register(StringMessage.class, new StringMessageWriter());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,10 +1,16 @@
|
|||||||
package cn.wzpmc.utils.json.message;
|
package cn.wzpmc.utils.json.message;
|
||||||
|
|
||||||
|
import cn.wzpmc.message.StringMessage;
|
||||||
import cn.wzpmc.message.json.JsonMessage;
|
import cn.wzpmc.message.json.JsonMessage;
|
||||||
|
import cn.wzpmc.message.json.JsonMessagePart;
|
||||||
|
import com.alibaba.fastjson2.JSONFactory;
|
||||||
import com.alibaba.fastjson2.JSONWriter;
|
import com.alibaba.fastjson2.JSONWriter;
|
||||||
import com.alibaba.fastjson2.writer.ObjectWriter;
|
import com.alibaba.fastjson2.writer.ObjectWriter;
|
||||||
|
import com.alibaba.fastjson2.writer.ObjectWriterCreator;
|
||||||
|
import com.alibaba.fastjson2.writer.ObjectWriterProvider;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JSON格式消息反序列化
|
* JSON格式消息反序列化
|
||||||
@ -17,7 +23,25 @@ public class JsonMessageWriter implements ObjectWriter<JsonMessage> {
|
|||||||
@Override
|
@Override
|
||||||
public void write(JSONWriter jsonWriter, Object object, Object fieldName, Type fieldType, long features) {
|
public void write(JSONWriter jsonWriter, Object object, Object fieldName, Type fieldType, long features) {
|
||||||
if (object instanceof JsonMessage) {
|
if (object instanceof JsonMessage) {
|
||||||
jsonWriter.write(((JsonMessage) object).getMessageParts());
|
List<JsonMessagePart> messageParts = ((JsonMessage) object).getMessageParts();
|
||||||
|
jsonWriter.startArray();
|
||||||
|
int size = messageParts.size();
|
||||||
|
int i = 0;
|
||||||
|
for (JsonMessagePart messagePart : messageParts) {
|
||||||
|
if (messagePart instanceof StringMessage) {
|
||||||
|
ObjectWriterProvider defaultObjectReaderProvider = JSONFactory.getDefaultObjectWriterProvider();
|
||||||
|
ObjectWriterCreator creator = defaultObjectReaderProvider.getCreator();
|
||||||
|
ObjectWriter<?> objectWriter = creator.createObjectWriter(StringMessage.class);
|
||||||
|
objectWriter.write(jsonWriter, messagePart);
|
||||||
|
} else {
|
||||||
|
jsonWriter.writeAny(messagePart);
|
||||||
|
}
|
||||||
|
if (i != size - 1) {
|
||||||
|
jsonWriter.writeComma();
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
jsonWriter.endArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
package cn.wzpmc.utils.json.message;
|
||||||
|
|
||||||
|
import cn.wzpmc.message.StringMessage;
|
||||||
|
import com.alibaba.fastjson2.JSONWriter;
|
||||||
|
import com.alibaba.fastjson2.writer.ObjectWriter;
|
||||||
|
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author wzp
|
||||||
|
* @version 1.0.3
|
||||||
|
* @since 2024/8/31 23:20
|
||||||
|
*/
|
||||||
|
public class StringMessageWriter implements ObjectWriter<StringMessage> {
|
||||||
|
@Override
|
||||||
|
public void write(JSONWriter jsonWriter, Object o, Object o1, Type type, long l) {
|
||||||
|
if (o instanceof StringMessage) {
|
||||||
|
jsonWriter.writeString(((StringMessage) o).getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -5,3 +5,7 @@ authorization:
|
|||||||
fallback:
|
fallback:
|
||||||
command: "Command Not Found!"
|
command: "Command Not Found!"
|
||||||
errorUncaught: "Had an error while run command!"
|
errorUncaught: "Had an error while run command!"
|
||||||
|
friend:
|
||||||
|
autoAccept: true
|
||||||
|
group:
|
||||||
|
autoAccept: true
|
Loading…
x
Reference in New Issue
Block a user