add PaoPaoSleepWaring

This commit is contained in:
Yutousama 2022-11-10 14:18:12 +08:00
parent 5ac0b45540
commit ab1facc747
5 changed files with 80 additions and 10 deletions

View File

@ -71,12 +71,7 @@ public class AppController {
if (json.containsKey("image")) { if (json.containsKey("image")) {
image = HttpTools.syncDownload(json.getString("image"), System.currentTimeMillis() + ".png",true); image = HttpTools.syncDownload(json.getString("image"), System.currentTimeMillis() + ".png",true);
} }
if (image != null) {
ret = QQBotManager.getInstance().sendMessage(image, json.getLong("qq"), json.getString("message")); ret = QQBotManager.getInstance().sendMessage(image, json.getLong("qq"), json.getString("message"));
} else {
ret = QQBotManager.getInstance().sendMessage(json.getLong("qq"), json.getString("message"));
}
return ret==null?"message send fail":"message send success"; return ret==null?"message send fail":"message send success";
} }

View File

@ -9,10 +9,7 @@ import net.mamoe.mirai.BotFactory;
import net.mamoe.mirai.contact.Group; import net.mamoe.mirai.contact.Group;
import net.mamoe.mirai.event.GlobalEventChannel; import net.mamoe.mirai.event.GlobalEventChannel;
import net.mamoe.mirai.message.MessageReceipt; import net.mamoe.mirai.message.MessageReceipt;
import net.mamoe.mirai.message.data.Image; import net.mamoe.mirai.message.data.*;
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.utils.BotConfiguration; import net.mamoe.mirai.utils.BotConfiguration;
import net.mamoe.mirai.utils.ExternalResource; import net.mamoe.mirai.utils.ExternalResource;
@ -95,6 +92,9 @@ public class QQBotManager {
} }
private Image getImage(File file, Long qq) { private Image getImage(File file, Long qq) {
if(file==null){
return null;
}
if (bot != null) { if (bot != null) {
ExternalResource resource = ExternalResource.create(file); ExternalResource resource = ExternalResource.create(file);
Image image; Image image;
@ -170,6 +170,15 @@ public class QQBotManager {
if (image != null) { if (image != null) {
builder.append(image); builder.append(image);
} }
List<String> 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); builder.append(text);
if (QQNumberManager.getManager().isGroup(qq)) { if (QQNumberManager.getManager().isGroup(qq)) {
return Objects.requireNonNull(bot.getGroup(qq)).sendMessage(builder.asMessageChain()); return Objects.requireNonNull(bot.getGroup(qq)).sendMessage(builder.asMessageChain());

View File

@ -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);
}
}
}

View File

@ -39,6 +39,7 @@ public abstract class Model implements ModelInterface {
public final static String BILI_LIVE_DANMU_DEL="!b站签到删除"; public final static String BILI_LIVE_DANMU_DEL="!b站签到删除";
public final static String QQ_WOODEN="!电子木鱼"; public final static String QQ_WOODEN="!电子木鱼";
public final static String QQ_TIMEOUT="!timer";
} }

View File

@ -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<String> exec(String regex, String input){
List<String> 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<String> pattern(String text,String start,String end){
return exec(String.format(".(?<=%s).*(?=%s)", start,end), text);
}
public static List<String> getQQ(String text){
return exec("(@[0-9]\\d*)",text);
}
}