From 4fabd514a73af32c88f3b317b69b6fc1f6d899fc Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Fri, 5 Aug 2022 11:50:56 +0800 Subject: [PATCH 1/2] =?UTF-8?q?update:=E8=B0=83=E6=95=B4QQBot=E7=9A=84?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../qqbot/Controllers/AppController.java | 5 ++-- .../java/com/yutou/qqbot/QQBotManager.java | 29 ++++++++++--------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/yutou/qqbot/Controllers/AppController.java b/src/main/java/com/yutou/qqbot/Controllers/AppController.java index d544d04..c733677 100644 --- a/src/main/java/com/yutou/qqbot/Controllers/AppController.java +++ b/src/main/java/com/yutou/qqbot/Controllers/AppController.java @@ -6,6 +6,7 @@ import com.yutou.qqbot.utlis.AppTools; import com.yutou.qqbot.utlis.HttpTools; import com.yutou.qqbot.utlis.RedisTools; import com.yutou.qqbot.utlis.StringUtils; +import net.mamoe.mirai.message.MessageReceipt; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -63,7 +64,7 @@ public class AppController { @RequestMapping("/qq/send.do") public String sendQQ(@RequestBody JSONObject json) { File image = null; - String ret; + MessageReceipt ret; if(json.getString("message").isEmpty()){ return "not message"; } @@ -76,7 +77,7 @@ public class AppController { } else { ret = QQBotManager.getInstance().sendMessage(json.getLong("qq"), json.getString("message")); } - return ret; + return ret==null?"message send fail":"message send success"; } @ResponseBody diff --git a/src/main/java/com/yutou/qqbot/QQBotManager.java b/src/main/java/com/yutou/qqbot/QQBotManager.java index 2d06898..33f49ab 100644 --- a/src/main/java/com/yutou/qqbot/QQBotManager.java +++ b/src/main/java/com/yutou/qqbot/QQBotManager.java @@ -6,7 +6,9 @@ import com.yutou.qqbot.Listeners.QQMessageListener; import com.yutou.qqbot.utlis.*; import net.mamoe.mirai.Bot; import net.mamoe.mirai.BotFactory; +import net.mamoe.mirai.contact.Group; import net.mamoe.mirai.event.GlobalEventChannel; +import net.mamoe.mirai.message.MessageReceipt; import net.mamoe.mirai.message.data.Image; import net.mamoe.mirai.message.data.MessageChain; import net.mamoe.mirai.message.data.MessageChainBuilder; @@ -127,36 +129,37 @@ public class QQBotManager { return getNotLoginQQ(); } - public String sendMessage(Long group, String text) { + public MessageReceipt sendMessage(Long group, String text) { if (bot != null) { try { if (QQNumberManager.getManager().isGroup(group)) { - return Objects.requireNonNull(bot.getGroup(group)).sendMessage(text).toString(); + return Objects.requireNonNull(bot.getGroup(group)).sendMessage(text); } else { - return Objects.requireNonNull(bot.getFriend(group)).sendMessage(text).toString(); + return Objects.requireNonNull(bot.getFriend(group)).sendMessage(text); } } catch (Exception e) { e.printStackTrace(); } } - return getNotLoginQQ(); + return null; } - public void sendMessage(Long group, MessageChainBuilder builder) { + public MessageReceipt sendMessage(Long group, MessageChainBuilder builder) { if (bot != null) { if (QQNumberManager.getManager().isGroup(group)) { - Objects.requireNonNull(bot.getGroup(group)).sendMessage(builder.asMessageChain()); + return Objects.requireNonNull(bot.getGroup(group)).sendMessage(builder.asMessageChain()); } else { - Objects.requireNonNull(bot.getFriend(group)).sendMessage(builder.asMessageChain()); + return Objects.requireNonNull(bot.getFriend(group)).sendMessage(builder.asMessageChain()); } } + return null; } - public String sendMessage(File imageFile, Long qq, String text) { + public MessageReceipt sendMessage(File imageFile, Long qq, String text) { return sendMessage(imageFile, qq, null, text); } - public String sendMessage(File imageFile, Long qq, MessageChain replyMessage, String text) { + public MessageReceipt sendMessage(File imageFile, Long qq, MessageChain replyMessage, String text) { try { if (bot != null) { Image image = getImage(imageFile, qq); @@ -169,19 +172,19 @@ public class QQBotManager { } builder.append(text); if (QQNumberManager.getManager().isGroup(qq)) { - return Objects.requireNonNull(bot.getGroup(qq)).sendMessage(builder.asMessageChain()).toString(); + return Objects.requireNonNull(bot.getGroup(qq)).sendMessage(builder.asMessageChain()); } else { - return Objects.requireNonNull(bot.getFriend(qq)).sendMessage(builder.asMessageChain()).toString(); + return Objects.requireNonNull(bot.getFriend(qq)).sendMessage(builder.asMessageChain()); } } } catch (Exception e) { e.printStackTrace(); } - return getNotLoginQQ(); + return null; } - public String sendMessage(File imageFile, String text) { + public MessageReceipt sendMessage(File imageFile, String text) { return sendMessage(imageFile, qqGroup, text); } From 8160d64867aca8c1d27b81593b8cde05f57bcee8 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Fri, 5 Aug 2022 11:52:45 +0800 Subject: [PATCH 2/2] =?UTF-8?q?add:=E4=BC=98=E5=8C=96=20#4=20=E6=B6=A9?= =?UTF-8?q?=E5=9B=BE=E6=A8=A1=E5=9D=97=E5=9B=BE=E6=96=87=E5=88=86=E7=A6=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/yutou/qqbot/QQBotApplication.java | 2 +- src/main/java/com/yutou/qqbot/models/setu/GetSeTu.java | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/yutou/qqbot/QQBotApplication.java b/src/main/java/com/yutou/qqbot/QQBotApplication.java index 1058dc6..7b87786 100644 --- a/src/main/java/com/yutou/qqbot/QQBotApplication.java +++ b/src/main/java/com/yutou/qqbot/QQBotApplication.java @@ -6,7 +6,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class QQBotApplication { - public static final String version="QQBot v.1.3.3"; + public static final String version="QQBot v.1.3.4"; public static void main(String[] args) { System.out.println("version = " + version); SpringApplication.run(QQBotApplication.class, args); diff --git a/src/main/java/com/yutou/qqbot/models/setu/GetSeTu.java b/src/main/java/com/yutou/qqbot/models/setu/GetSeTu.java index 3de3d28..08ef889 100644 --- a/src/main/java/com/yutou/qqbot/models/setu/GetSeTu.java +++ b/src/main/java/com/yutou/qqbot/models/setu/GetSeTu.java @@ -12,8 +12,10 @@ import com.yutou.qqbot.utlis.Log; import com.yutou.qqbot.utlis.RedisTools; import com.yutou.qqbot.utlis.StringUtils; import net.mamoe.mirai.event.events.MessageEvent; +import net.mamoe.mirai.message.MessageReceipt; import net.mamoe.mirai.message.data.At; import net.mamoe.mirai.message.data.MessageChainBuilder; +import net.mamoe.mirai.message.data.QuoteReply; import redis.clients.jedis.Jedis; import java.io.File; @@ -213,8 +215,13 @@ public class GetSeTu extends Model { @Override public void onDownload(File file) { super.onDownload(file); - String message = QQBotManager.getInstance().sendMessage(file, qq, event.getMessage(), builder.toString()); + QQBotManager.getInstance().sendMessage(file, qq, event.getMessage(), ""); + MessageChainBuilder chain = new MessageChainBuilder(); + chain.append(new QuoteReply(event.getMessage())); + chain.append(builder.toString()); + MessageReceipt message=QQBotManager.getInstance().sendMessage(qq,chain); Log.i(getModelName(),message); + } @Override