更新机器人版本1.3.1 → 1.3.3
更新音乐收藏夹接口 工具类新增个打印异常的方法
This commit is contained in:
parent
acb1e90acb
commit
f575d0f287
2
pom.xml
2
pom.xml
@ -109,7 +109,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.mamoe</groupId>
|
<groupId>net.mamoe</groupId>
|
||||||
<artifactId>mirai-core-qqandroid</artifactId>
|
<artifactId>mirai-core-qqandroid</artifactId>
|
||||||
<version>1.3.1</version> <!-- 替换版本为最新版本 -->
|
<version>1.3.3</version> <!-- 替换版本为最新版本 -->
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jetbrains.kotlin</groupId>
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
@ -9,7 +9,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class ToolsApplication {
|
public class ToolsApplication {
|
||||||
public static final String version="1.0.11";
|
public static final String version="1.0.12";
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
System.out.println("当前版本号:"+version);
|
System.out.println("当前版本号:"+version);
|
||||||
|
@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 收藏夹相关
|
* 收藏夹相关
|
||||||
@ -51,6 +52,8 @@ public class MusicFavoritesController{
|
|||||||
json.put("data", JSONArray.toJSON(favoritesDirDao.selectByExample(new MusicFavoritesDirExample())));
|
json.put("data", JSONArray.toJSON(favoritesDirDao.selectByExample(new MusicFavoritesDirExample())));
|
||||||
return json.toJSONString();
|
return json.toJSONString();
|
||||||
}
|
}
|
||||||
|
@RequestMapping("dir/rename.do")
|
||||||
|
@ResponseBody
|
||||||
public String renameFavoriteDir(String id,String title){
|
public String renameFavoriteDir(String id,String title){
|
||||||
JSONObject json=new JSONObject();
|
JSONObject json=new JSONObject();
|
||||||
MusicFavoritesDir favoritesDir=favoritesDirDao.selectByPrimaryKey(Integer.parseInt(id));
|
MusicFavoritesDir favoritesDir=favoritesDirDao.selectByPrimaryKey(Integer.parseInt(id));
|
||||||
@ -65,4 +68,35 @@ public class MusicFavoritesController{
|
|||||||
}
|
}
|
||||||
return json.toJSONString();
|
return json.toJSONString();
|
||||||
}
|
}
|
||||||
|
@RequestMapping("add.do")
|
||||||
|
@ResponseBody
|
||||||
|
public String addFavorite(int fid,String md5s){
|
||||||
|
JSONObject json=new JSONObject();
|
||||||
|
JSONArray array=JSONArray.parseArray(md5s);
|
||||||
|
if(array==null){
|
||||||
|
json.put("code",-1);
|
||||||
|
json.put("msg","参数异常");
|
||||||
|
return json.toJSONString();
|
||||||
|
}
|
||||||
|
for (Object o : array) {
|
||||||
|
String md5= (String) o;
|
||||||
|
MusicFavorites favorites=new MusicFavorites();
|
||||||
|
favorites.setMusisMd5(md5);
|
||||||
|
favorites.setFavoriteid(fid);
|
||||||
|
favorites.setSubTime(new Date());
|
||||||
|
favoritesDao.insert(favorites);
|
||||||
|
}
|
||||||
|
json.put("code",0);
|
||||||
|
json.put("msg","添加成功");
|
||||||
|
return json.toJSONString();
|
||||||
|
}
|
||||||
|
@RequestMapping("remove.do")
|
||||||
|
@ResponseBody
|
||||||
|
public String removeFavorite(int fid){
|
||||||
|
JSONObject json=new JSONObject();
|
||||||
|
int ret=favoritesDao.deleteByPrimaryKey(fid);
|
||||||
|
json.put("code",ret==0?-1:0);
|
||||||
|
json.put("msg",ret==0?"移除失败":"已从收藏夹中移除");
|
||||||
|
return json.toJSONString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,6 +68,9 @@ public class MusicTools implements MusicToolsService {
|
|||||||
if (isScan) {
|
if (isScan) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if(ConfigTools.load(ConfigTools.CONFIG,"musicScan").equals("false")){
|
||||||
|
return;
|
||||||
|
}
|
||||||
musicPath = (String) ConfigTools.load(ConfigTools.CONFIG, "musicDir");
|
musicPath = (String) ConfigTools.load(ConfigTools.CONFIG, "musicDir");
|
||||||
musicDataDao.truncate();
|
musicDataDao.truncate();
|
||||||
System.out.println("执行扫描:" + musicPath);
|
System.out.println("执行扫描:" + musicPath);
|
||||||
@ -129,10 +132,8 @@ public class MusicTools implements MusicToolsService {
|
|||||||
} else {
|
} else {
|
||||||
main = musicDataDao.selectByRegexp(path.replace(File.separator, replacement) + replacement + "([^" + replacement + "]+)$");
|
main = musicDataDao.selectByRegexp(path.replace(File.separator, replacement) + replacement + "([^" + replacement + "]+)$");
|
||||||
}
|
}
|
||||||
System.out.println(path + " " + isDir);
|
if (!path.equals(MusicController.defaultMusicPath) && !path.equals("root")) {
|
||||||
if (!path.equals(MusicController.defaultMusicPath) && !path.equals("root") && main.size() > 0) {
|
|
||||||
MusicData tmp = main.get(0);
|
MusicData tmp = main.get(0);
|
||||||
System.out.println(tmp);
|
|
||||||
MusicData t2 = new MusicData();
|
MusicData t2 = new MusicData();
|
||||||
t2.setTitle("返回");
|
t2.setTitle("返回");
|
||||||
t2.setFile(new File(tmp.getLastdir()).getAbsolutePath());
|
t2.setFile(new File(tmp.getLastdir()).getAbsolutePath());
|
||||||
@ -141,7 +142,6 @@ public class MusicTools implements MusicToolsService {
|
|||||||
}
|
}
|
||||||
getDirList(path, list);
|
getDirList(path, list);
|
||||||
list.addAll(main);
|
list.addAll(main);
|
||||||
System.out.println(list.size());
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -404,6 +404,7 @@ public class MusicTools implements MusicToolsService {
|
|||||||
data.setIsdir(file.isDirectory() ? 1 : 0);
|
data.setIsdir(file.isDirectory() ? 1 : 0);
|
||||||
data.setLastdir(file.getParentFile().getParent());
|
data.setLastdir(file.getParentFile().getParent());
|
||||||
data.setMd5(Tools.getFileMD5(file));
|
data.setMd5(Tools.getFileMD5(file));
|
||||||
|
QQBotManager.getInstance().sendMessage("添加音乐文件失败:\n"+data.toString()+"\n"+Tools.getExceptionString(e));
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
@ -9,12 +9,12 @@ import net.mamoe.mirai.event.Events;
|
|||||||
import net.mamoe.mirai.event.ListeningStatus;
|
import net.mamoe.mirai.event.ListeningStatus;
|
||||||
import net.mamoe.mirai.event.SimpleListenerHost;
|
import net.mamoe.mirai.event.SimpleListenerHost;
|
||||||
import net.mamoe.mirai.message.GroupMessageEvent;
|
import net.mamoe.mirai.message.GroupMessageEvent;
|
||||||
|
import net.mamoe.mirai.message.MessageEvent;
|
||||||
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.Image;
|
||||||
import net.mamoe.mirai.message.data.MessageChain;
|
import net.mamoe.mirai.message.data.MessageChain;
|
||||||
import net.mamoe.mirai.message.data.MessageUtils;
|
import net.mamoe.mirai.message.data.MessageUtils;
|
||||||
import net.mamoe.mirai.utils.BotConfiguration;
|
import net.mamoe.mirai.utils.BotConfiguration;
|
||||||
import net.mamoe.mirai.utils.MiraiLogger;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -23,13 +23,13 @@ public class QQBotManager {
|
|||||||
private static QQBotManager botManager = null;
|
private static QQBotManager botManager = null;
|
||||||
private Bot bot;
|
private Bot bot;
|
||||||
private static final long qqGroup = 891655174L;
|
private static final long qqGroup = 891655174L;
|
||||||
private boolean isLogin=false;
|
private boolean isLogin = false;
|
||||||
|
|
||||||
private QQBotManager() {
|
private QQBotManager() {
|
||||||
Object isRun = ConfigTools.load(ConfigTools.CONFIG, "qq_bot");
|
Object isRun = ConfigTools.load(ConfigTools.CONFIG, "qq_bot");
|
||||||
if (isRun != null && (boolean) isRun) {
|
if (isRun != null && (boolean) isRun) {
|
||||||
init();
|
init();
|
||||||
isLogin=true;
|
isLogin = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,9 +37,9 @@ public class QQBotManager {
|
|||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
long qq=2476945931L;
|
long qq = 2476945931L;
|
||||||
String password="zhang34864394";
|
String password = "zhang34864394";
|
||||||
if(ConfigTools.load(ConfigTools.CONFIG, "model").equals("dev")) {
|
if (ConfigTools.load(ConfigTools.CONFIG, "model").equals("dev")) {
|
||||||
qq = 3620756944L;
|
qq = 3620756944L;
|
||||||
password = "UAs6YBYMyxJU";
|
password = "UAs6YBYMyxJU";
|
||||||
}
|
}
|
||||||
@ -47,7 +47,7 @@ public class QQBotManager {
|
|||||||
bot = BotFactoryJvm.newBot(qq, password, new BotConfiguration() {
|
bot = BotFactoryJvm.newBot(qq, password, new BotConfiguration() {
|
||||||
{
|
{
|
||||||
fileBasedDeviceInfo("qq_bot_devices_info.json");
|
fileBasedDeviceInfo("qq_bot_devices_info.json");
|
||||||
if(ConfigTools.load(ConfigTools.CONFIG, "model").equals("nas")) {
|
if (ConfigTools.load(ConfigTools.CONFIG, "model").equals("nas")) {
|
||||||
noBotLog();
|
noBotLog();
|
||||||
noNetworkLog();
|
noNetworkLog();
|
||||||
}
|
}
|
||||||
@ -70,16 +70,23 @@ public class QQBotManager {
|
|||||||
}
|
}
|
||||||
return botManager;
|
return botManager;
|
||||||
}
|
}
|
||||||
public boolean isLogin(){
|
|
||||||
|
public boolean isLogin() {
|
||||||
return isLogin;
|
return isLogin;
|
||||||
}
|
}
|
||||||
private String getNotLoginQQ(){
|
|
||||||
|
private String getNotLoginQQ() {
|
||||||
return "没有登录QQ";
|
return "没有登录QQ";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String sendMessage(String text) {
|
public String sendMessage(String text) {
|
||||||
if (bot != null) {
|
if (bot != null) {
|
||||||
MessageReceipt<Contact> receipt= bot.getGroup(qqGroup).sendMessage(text);
|
try {
|
||||||
|
MessageReceipt<Contact> receipt = bot.getGroup(qqGroup).sendMessage(text);
|
||||||
return receipt.toString();
|
return receipt.toString();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return getNotLoginQQ();
|
return getNotLoginQQ();
|
||||||
}
|
}
|
||||||
@ -88,7 +95,7 @@ public class QQBotManager {
|
|||||||
if (bot != null) {
|
if (bot != null) {
|
||||||
Image image = bot.getGroup(qqGroup).uploadImage(imageFile);
|
Image image = bot.getGroup(qqGroup).uploadImage(imageFile);
|
||||||
MessageChain chain = MessageUtils.newImage(image.getImageId()).plus(text);
|
MessageChain chain = MessageUtils.newImage(image.getImageId()).plus(text);
|
||||||
MessageReceipt<Contact> receipt=bot.getGroup(qqGroup).sendMessage(chain);
|
MessageReceipt<Contact> receipt = bot.getGroup(qqGroup).sendMessage(chain);
|
||||||
return receipt.toString();
|
return receipt.toString();
|
||||||
}
|
}
|
||||||
return getNotLoginQQ();
|
return getNotLoginQQ();
|
||||||
@ -102,31 +109,38 @@ public class QQBotManager {
|
|||||||
@Override
|
@Override
|
||||||
public void handleException(@NotNull CoroutineContext context, @NotNull Throwable exception) {
|
public void handleException(@NotNull CoroutineContext context, @NotNull Throwable exception) {
|
||||||
super.handleException(context, exception);
|
super.handleException(context, exception);
|
||||||
System.out.println("error: "+exception.getLocalizedMessage());
|
System.out.println("error: " + exception.getLocalizedMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public ListeningStatus onGroupMessage(GroupMessageEvent event) {
|
public ListeningStatus onGroupMessage(GroupMessageEvent event) {
|
||||||
if(event.getGroup().getId()==qqGroup){
|
if (event.getGroup().getId() == qqGroup) {
|
||||||
String msg=event.getMessage().contentToString();
|
String msg = event.getMessage().contentToString();
|
||||||
msg=msg.replace("!","!");
|
msg = msg.replace("!", "!");
|
||||||
switch (msg){
|
switch (msg) {
|
||||||
case "!开机":
|
case "!开机":
|
||||||
RedisTools.Consumer.system("openPC",null);
|
RedisTools.Consumer.system("openPC", null);
|
||||||
break;
|
break;
|
||||||
case "!更新IP":
|
case "!更新IP":
|
||||||
RedisTools.Consumer.system("updateIP",null);
|
RedisTools.Consumer.system("updateIP", null);
|
||||||
break;
|
break;
|
||||||
case "!ip":
|
case "!ip":
|
||||||
RedisTools.Consumer.bot("getip");
|
RedisTools.Consumer.bot("getip");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if(msg.startsWith("!cmd")){
|
if (msg.startsWith("!cmd")) {
|
||||||
RedisTools.Consumer.system("cmd",msg.replace("!cmd",""));
|
RedisTools.Consumer.system("cmd", msg.replace("!cmd", ""));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}/*else{
|
||||||
|
sendMessage("群:"+event.getGroup().getId()+" 发来消息:\n"+event.getMessage().contentToString());
|
||||||
|
}*/
|
||||||
return ListeningStatus.LISTENING;
|
return ListeningStatus.LISTENING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onMessage(@NotNull MessageEvent event) throws Exception {
|
||||||
|
// sendMessage("个人:"+event.getSender().getNick()+" 发来消息:"+event.getMessage().contentToString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -376,4 +376,16 @@ public class Tools {
|
|||||||
base=base.replace(" ","+");
|
base=base.replace(" ","+");
|
||||||
return new String(Base64.getDecoder().decode(base.replace("\r\n","").getBytes()));
|
return new String(Base64.getDecoder().decode(base.replace("\r\n","").getBytes()));
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 异常输出
|
||||||
|
* @param e 异常
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getExceptionString(Exception e) {
|
||||||
|
StringWriter writer=new StringWriter();
|
||||||
|
PrintWriter printWriter=new PrintWriter(writer);
|
||||||
|
e.printStackTrace(printWriter);
|
||||||
|
printWriter.close();
|
||||||
|
return writer.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user