修改部分QQ发送消息的代码

This commit is contained in:
2022-01-16 12:51:26 +08:00
parent 11534b04f7
commit 6d9ba12cf1
7 changed files with 48 additions and 312 deletions

View File

@@ -1,7 +1,6 @@
package com.yutou.nas.utils;
import com.yutou.nas.Services.impl.MusicToolsServiceImpl;
import com.yutou.nas.other.QQSetu;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
@@ -68,7 +67,6 @@ public class ApplicationInit implements ApplicationRunner {
QQBotManager.getInstance().reportToDayBangumi();
break;
case "23:59":
QQSetu.printTodaySetu();
break;
}

View File

@@ -15,7 +15,10 @@ import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
public class BTDownloadManager implements ApplicationContextAware {
@@ -97,8 +100,7 @@ public class BTDownloadManager implements ApplicationContextAware {
array.add(item.getString("title"));
RedisTools.set(bangumiItem.getTitle(), array.toJSONString());
if (item.containsKey("thumbnail")) {
File file = HttpTools.syncDownload(item.getString("thumbnail"), bangumiItem.getTitle() + ".jpg");
onSend(file, item);
onSend(item.getString("thumbnail"), item);
} else {
onSend(null, item);
}
@@ -114,13 +116,13 @@ public class BTDownloadManager implements ApplicationContextAware {
}
}
private void onSend(File file, JSONObject item) {
private void onSend(String fileUrl, JSONObject item) {
String text = "启动下载器\n已提交到下载:" + item.getString("title");
Log.i(text);
if (file == null) {
if (fileUrl == null) {
QQBotManager.getInstance().sendMessage(text);
} else {
QQBotManager.getInstance().sendMessage(file, text);
QQBotManager.getInstance().sendMessage(fileUrl, text);
}
}
@@ -163,15 +165,7 @@ public class BTDownloadManager implements ApplicationContextAware {
}
public static void main(String[] args) {
AnimationData data = new AnimationData();
BangumiItem item = new BangumiItem();
item.setAuthor(data.nameToValue("lleeopen", true) + "");
item.setCategories(data.nameToValue("動畫", false) + "");
item.setTitle("無職轉生~到了異世界就拿出真本事~");
item.setTitlekey("无职转生");
String url = new BTDownloadManager().getRSSUrl(item);
com.yutou.nas.utils.Log.i(url);
}
@Override

View File

@@ -1,10 +1,10 @@
package com.yutou.nas.utils;
import com.alibaba.fastjson.JSONObject;
import com.yutou.nas.NasApplication;
import com.yutou.nas.bangumi.BangumiTools;
import com.yutou.nas.interfaces.DownloadInterface;
import com.yutou.nas.other.QQAudio;
import com.yutou.nas.other.QQSetu;
import net.mamoe.mirai.Bot;
import net.mamoe.mirai.BotFactory;
import net.mamoe.mirai.event.GlobalEventChannel;
@@ -13,15 +13,12 @@ import net.mamoe.mirai.message.data.Image;
import net.mamoe.mirai.message.data.MessageChainBuilder;
import net.mamoe.mirai.utils.BotConfiguration;
import net.mamoe.mirai.utils.ExternalResource;
import com.yutou.nas.utils.StringUtils;
import java.io.File;
import java.lang.reflect.Field;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.*;
import java.util.function.Consumer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -48,7 +45,7 @@ public class QQBotManager {
private final static String QQ_TOOLS_IDEA_FILE = "!idea>";
private final static String QQ_TOOLS_IDEA_URL = "!idea_url";
public final static String QQ_BANGUMI_INFO="!保存动画信息>";
public final static String QQ_BANGUMI_INFO = "!保存动画信息>";
}
private static QQBotManager botManager = null;
@@ -99,7 +96,7 @@ public class QQBotManager {
} catch (InterruptedException e) {
e.printStackTrace();
}
String str = sendMessage("姬妻酱上线拉~☆Daze~ 当前版本:"+NasApplication.version);
String str = sendMessage("姬妻酱上线拉~☆Daze~ 当前版本:" + NasApplication.version);
com.yutou.nas.utils.Log.i(str);
}
@@ -138,25 +135,21 @@ public class QQBotManager {
}
public String sendMessage(String text) {
if (bot != null&&!StringUtils.isEmpty(text)) {
try {
return Objects.requireNonNull(bot.getGroup(qqGroup)).sendMessage(text).toString();
} catch (Exception e) {
e.printStackTrace();
}
}
return getNotLoginQQ();
JSONObject json = new JSONObject();
json.put("qq", 891655174);
json.put("message",text);
Map<String, String> header = new HashMap<>();
header.put("content-type", "application/json");
return HttpTools.http_post("http://192.168.31.88:802/qq/send.do", json.toString().getBytes(StandardCharsets.UTF_8), 1, header);
}
public String sendMessage(Long group, String text) {
if (bot != null) {
try {
return Objects.requireNonNull(bot.getGroup(group)).sendMessage(text).toString();
} catch (Exception e) {
e.printStackTrace();
}
}
return getNotLoginQQ();
JSONObject json = new JSONObject();
json.put("qq", group);
json.put("message",text);
Map<String, String> header = new HashMap<>();
header.put("content-type", "application/json");
return HttpTools.http_post("http://192.168.31.88:802/qq/send.do", json.toString().getBytes(StandardCharsets.UTF_8), 1, header);
}
public void sendMessage(Long group, MessageChainBuilder builder) {
@@ -166,22 +159,14 @@ public class QQBotManager {
}
public String sendMessage(File imageFile, String text) {
try {
if (bot != null) {
Image image = getImage(imageFile);
MessageChainBuilder builder = new MessageChainBuilder();
if (image != null) {
builder.append(image);
}
builder.append(text);
return Objects.requireNonNull(bot.getGroup(qqGroup)).sendMessage(builder.asMessageChain()).toString();
}
} catch (Exception e) {
e.printStackTrace();
}
return getNotLoginQQ();
public String sendMessage(String imageUrl, String message) {
JSONObject json = new JSONObject();
json.put("qq", 891655174);
json.put("message",message);
json.put("image", imageUrl);
Map<String, String> header = new HashMap<>();
header.put("content-type", "application/json");
return HttpTools.http_post("http://192.168.31.88:802/qq/send.do", json.toString().getBytes(StandardCharsets.UTF_8), 1, header);
}
public String sendMessage(List<File> imgs, String text) {
@@ -219,20 +204,13 @@ public class QQBotManager {
@Override
public void accept(GroupMessageEvent event) {
String msg = event.getMessage().contentToString();
switch (event.getGroup().getId() + "") {
case qqGroup + "":
myGroup(msg);
case "570197155":
new QQSetu().setu(msg, event);
}
}
private void myGroup(String msg) {
StringBuilder builder;
String msgSrc=msg;
String msgSrc = msg;
msg = msg.replace("", "!").toLowerCase();
Log.i("QQBot","command = "+msg);
Log.i("QQBot", "command = " + msg);
switch (msg) {
case QQCommands.QQ_OPEN_PC:
RedisTools.Consumer.system("openPC", null);
@@ -269,7 +247,7 @@ public class QQBotManager {
case QQCommands.QQ_SYSTEM_RESTART:
getInstance().sendMessage("正在重启服务");
System.out.println("结束进程");
AppTools.exec("cd /home/yutou/public/servier/tools && ./start.sh",null,true,false);
AppTools.exec("cd /home/yutou/public/servier/tools && ./start.sh", null, true, false);
break;
case QQCommands.QQ_HELP:
builder = new StringBuilder();
@@ -285,13 +263,13 @@ public class QQBotManager {
break;
case QQCommands.QQ_TOOLS_IDEA:
builder = new StringBuilder();
if(StringUtils.isEmpty(RedisTools.get("ideaUrl"))){
if (StringUtils.isEmpty(RedisTools.get("ideaUrl"))) {
builder.append("暂未设置IDEA激活码下载地址");
}else {
} else {
for (String name : IdeaTools.getIdeaList(RedisTools.get("ideaUrl"))) {
builder.append(QQCommands.QQ_TOOLS_IDEA_FILE).append(name).append("\n");
}
if(builder.toString().trim().length()==0){
if (builder.toString().trim().length() == 0) {
builder.append("激活码文件中未包含txt文件");
}
}
@@ -322,11 +300,11 @@ public class QQBotManager {
} else if (msg.startsWith(QQCommands.QQ_AUDIO)) {
QQAudio.playText(msg.replace(QQCommands.QQ_AUDIO, ""));
}else if(msg.startsWith(QQCommands.QQ_TOOLS_IDEA_FILE)){
getInstance().sendMessage(IdeaTools.getIdea(msgSrc.replace(QQCommands.QQ_TOOLS_IDEA_FILE,"")));
}else if(msg.startsWith(QQCommands.QQ_TOOLS_IDEA_URL)){
RedisTools.set("ideaUrl",msg.replace(QQCommands.QQ_TOOLS_IDEA_URL,"").trim());
getInstance().sendMessage("已设定下载地址:"+RedisTools.get("ideaUrl"));
} else if (msg.startsWith(QQCommands.QQ_TOOLS_IDEA_FILE)) {
getInstance().sendMessage(IdeaTools.getIdea(msgSrc.replace(QQCommands.QQ_TOOLS_IDEA_FILE, "")));
} else if (msg.startsWith(QQCommands.QQ_TOOLS_IDEA_URL)) {
RedisTools.set("ideaUrl", msg.replace(QQCommands.QQ_TOOLS_IDEA_URL, "").trim());
getInstance().sendMessage("已设定下载地址:" + RedisTools.get("ideaUrl"));
}
}
}

View File

@@ -111,23 +111,8 @@ public class Tools {
if (img == null) {
QQBotManager.getInstance().sendMessage(title + "\n" + msg);
} else {
String finalMsg = msg;
String finalImg = img;
if (QQBotManager.getInstance().isLogin()) {
download(img, new DownloadInterface() {
@Override
public void onDownload(File file) {
super.onDownload(file);
QQBotManager.getInstance().sendMessage(file, title + "\n" + finalMsg);
}
QQBotManager.getInstance().sendMessage(img, title + "\n" + msg);
@Override
public void onError(Exception e) {
super.onError(e);
QQBotManager.getInstance().sendMessage(title + "\n" + finalMsg + "\n" + finalImg);
}
});
}
}
} else if (!StringUtils.isEmpty(UpdateIp.nas_ip)) {
String img = null;