diff --git a/src/main/java/com/yutou/qqbot/Controllers/AppController.java b/src/main/java/com/yutou/qqbot/Controllers/AppController.java index 7ce89b4..b487ffd 100644 --- a/src/main/java/com/yutou/qqbot/Controllers/AppController.java +++ b/src/main/java/com/yutou/qqbot/Controllers/AppController.java @@ -71,12 +71,7 @@ public class AppController { if (json.containsKey("image")) { image = HttpTools.syncDownload(json.getString("image"), System.currentTimeMillis() + ".png",true); } - if (image != null) { - ret = QQBotManager.getInstance().sendMessage(image, json.getLong("qq"), json.getString("message")); - - } else { - ret = QQBotManager.getInstance().sendMessage(json.getLong("qq"), json.getString("message")); - } + ret = QQBotManager.getInstance().sendMessage(image, json.getLong("qq"), json.getString("message")); return ret==null?"message send fail":"message send success"; } diff --git a/src/main/java/com/yutou/qqbot/QQBotManager.java b/src/main/java/com/yutou/qqbot/QQBotManager.java index 33f49ab..468d2e3 100644 --- a/src/main/java/com/yutou/qqbot/QQBotManager.java +++ b/src/main/java/com/yutou/qqbot/QQBotManager.java @@ -9,10 +9,7 @@ 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; -import net.mamoe.mirai.message.data.QuoteReply; +import net.mamoe.mirai.message.data.*; import net.mamoe.mirai.utils.BotConfiguration; import net.mamoe.mirai.utils.ExternalResource; @@ -95,6 +92,9 @@ public class QQBotManager { } private Image getImage(File file, Long qq) { + if(file==null){ + return null; + } if (bot != null) { ExternalResource resource = ExternalResource.create(file); Image image; @@ -170,6 +170,15 @@ public class QQBotManager { if (image != null) { builder.append(image); } + List list=PatternTools.getQQ(text); + if (!list.isEmpty()) { + for (String _qq : list) { + String[] tmp = text.split(_qq); + builder.append(tmp[0]); + builder.append(new At(Long.parseLong(_qq.replace("@", "")))); + text = text.replace(tmp[0] + _qq, ""); + } + } builder.append(text); if (QQNumberManager.getManager().isGroup(qq)) { return Objects.requireNonNull(bot.getGroup(qq)).sendMessage(builder.asMessageChain()); diff --git a/src/main/java/com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java b/src/main/java/com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java new file mode 100644 index 0000000..1e221ec --- /dev/null +++ b/src/main/java/com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java @@ -0,0 +1,40 @@ +package com.yutou.qqbot.models.Commands; + +import com.yutou.qqbot.Annotations.UseModel; +import com.yutou.qqbot.QQBotManager; +import com.yutou.qqbot.models.Model; +import com.yutou.qqbot.utlis.AppTools; +import net.mamoe.mirai.event.events.MessageEvent; +import net.mamoe.mirai.message.data.MessageChainBuilder; +import net.mamoe.mirai.message.data.QuoteReply; + +import static com.yutou.qqbot.models.Model.QQGroupCommands.QQ_TIMEOUT; + +@UseModel +public class PaoPaoSleepWaring extends Model { + @Override + public boolean isUserPublic() { + return false; + } + + @Override + public String[] getUsePowers() { + return new String[]{QQ_TIMEOUT}; + } + + @Override + public String getModelName() { + return "paopao"; + } + + @Override + public void onMessage(Long qq, MessageEvent event, boolean isGroup) { + super.onMessage(qq, event, isGroup); + if(Integer.parseInt(AppTools.getHours())>22 && event.getSource().getFromId() == 914520754){ + MessageChainBuilder builder=new MessageChainBuilder(); + builder.append(new QuoteReply(event.getMessage())); + builder.append("别水了,该睡了~"); + QQBotManager.getInstance().sendMessage(qq,builder); + } + } +} diff --git a/src/main/java/com/yutou/qqbot/models/Model.java b/src/main/java/com/yutou/qqbot/models/Model.java index 07c24bf..c7023ad 100644 --- a/src/main/java/com/yutou/qqbot/models/Model.java +++ b/src/main/java/com/yutou/qqbot/models/Model.java @@ -39,6 +39,7 @@ public abstract class Model implements ModelInterface { public final static String BILI_LIVE_DANMU_DEL="!b站签到删除"; public final static String QQ_WOODEN="!电子木鱼"; + public final static String QQ_TIMEOUT="!timer"; } diff --git a/src/main/java/com/yutou/qqbot/utlis/PatternTools.java b/src/main/java/com/yutou/qqbot/utlis/PatternTools.java new file mode 100644 index 0000000..6db6326 --- /dev/null +++ b/src/main/java/com/yutou/qqbot/utlis/PatternTools.java @@ -0,0 +1,25 @@ +package com.yutou.qqbot.utlis; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class PatternTools { + private static List exec(String regex, String input){ + List list=new ArrayList<>(); + Pattern pattern=Pattern.compile(regex); + Matcher matcher = pattern.matcher(input); + while(matcher.find()){ + list.add(matcher.group()); + } + return list; + } + public static List pattern(String text,String start,String end){ + return exec(String.format(".(?<=%s).*(?=%s)", start,end), text); + } + public static List getQQ(String text){ + return exec("(@[0-9]\\d*)",text); + } +}