更新机器人版本1.3.1 → 1.3.3

更新音乐收藏夹接口
工具类新增个打印异常的方法
This commit is contained in:
yutou 2020-12-02 11:53:13 +08:00
parent acb1e90acb
commit f575d0f287
6 changed files with 89 additions and 28 deletions

View File

@ -109,7 +109,7 @@
<dependency>
<groupId>net.mamoe</groupId>
<artifactId>mirai-core-qqandroid</artifactId>
<version>1.3.1</version> <!-- 替换版本为最新版本 -->
<version>1.3.3</version> <!-- 替换版本为最新版本 -->
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>

View File

@ -9,7 +9,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
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) {
System.out.println("当前版本号:"+version);

View File

@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.Date;
/**
* 收藏夹相关
@ -51,6 +52,8 @@ public class MusicFavoritesController{
json.put("data", JSONArray.toJSON(favoritesDirDao.selectByExample(new MusicFavoritesDirExample())));
return json.toJSONString();
}
@RequestMapping("dir/rename.do")
@ResponseBody
public String renameFavoriteDir(String id,String title){
JSONObject json=new JSONObject();
MusicFavoritesDir favoritesDir=favoritesDirDao.selectByPrimaryKey(Integer.parseInt(id));
@ -65,4 +68,35 @@ public class MusicFavoritesController{
}
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();
}
}

View File

@ -68,6 +68,9 @@ public class MusicTools implements MusicToolsService {
if (isScan) {
return;
}
if(ConfigTools.load(ConfigTools.CONFIG,"musicScan").equals("false")){
return;
}
musicPath = (String) ConfigTools.load(ConfigTools.CONFIG, "musicDir");
musicDataDao.truncate();
System.out.println("执行扫描:" + musicPath);
@ -129,10 +132,8 @@ public class MusicTools implements MusicToolsService {
} else {
main = musicDataDao.selectByRegexp(path.replace(File.separator, replacement) + replacement + "([^" + replacement + "]+)$");
}
System.out.println(path + " " + isDir);
if (!path.equals(MusicController.defaultMusicPath) && !path.equals("root") && main.size() > 0) {
if (!path.equals(MusicController.defaultMusicPath) && !path.equals("root")) {
MusicData tmp = main.get(0);
System.out.println(tmp);
MusicData t2 = new MusicData();
t2.setTitle("返回");
t2.setFile(new File(tmp.getLastdir()).getAbsolutePath());
@ -141,7 +142,6 @@ public class MusicTools implements MusicToolsService {
}
getDirList(path, list);
list.addAll(main);
System.out.println(list.size());
return list;
}
@ -404,6 +404,7 @@ public class MusicTools implements MusicToolsService {
data.setIsdir(file.isDirectory() ? 1 : 0);
data.setLastdir(file.getParentFile().getParent());
data.setMd5(Tools.getFileMD5(file));
QQBotManager.getInstance().sendMessage("添加音乐文件失败:\n"+data.toString()+"\n"+Tools.getExceptionString(e));
}
return data;
}

View File

@ -9,12 +9,12 @@ import net.mamoe.mirai.event.Events;
import net.mamoe.mirai.event.ListeningStatus;
import net.mamoe.mirai.event.SimpleListenerHost;
import net.mamoe.mirai.message.GroupMessageEvent;
import net.mamoe.mirai.message.MessageEvent;
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.MessageUtils;
import net.mamoe.mirai.utils.BotConfiguration;
import net.mamoe.mirai.utils.MiraiLogger;
import org.jetbrains.annotations.NotNull;
import java.io.File;
@ -23,13 +23,13 @@ public class QQBotManager {
private static QQBotManager botManager = null;
private Bot bot;
private static final long qqGroup = 891655174L;
private boolean isLogin=false;
private boolean isLogin = false;
private QQBotManager() {
Object isRun = ConfigTools.load(ConfigTools.CONFIG, "qq_bot");
if (isRun != null && (boolean) isRun) {
init();
isLogin=true;
isLogin = true;
}
}
@ -37,9 +37,9 @@ public class QQBotManager {
new Thread(new Runnable() {
@Override
public void run() {
long qq=2476945931L;
String password="zhang34864394";
if(ConfigTools.load(ConfigTools.CONFIG, "model").equals("dev")) {
long qq = 2476945931L;
String password = "zhang34864394";
if (ConfigTools.load(ConfigTools.CONFIG, "model").equals("dev")) {
qq = 3620756944L;
password = "UAs6YBYMyxJU";
}
@ -47,7 +47,7 @@ public class QQBotManager {
bot = BotFactoryJvm.newBot(qq, password, new BotConfiguration() {
{
fileBasedDeviceInfo("qq_bot_devices_info.json");
if(ConfigTools.load(ConfigTools.CONFIG, "model").equals("nas")) {
if (ConfigTools.load(ConfigTools.CONFIG, "model").equals("nas")) {
noBotLog();
noNetworkLog();
}
@ -70,16 +70,23 @@ public class QQBotManager {
}
return botManager;
}
public boolean isLogin(){
public boolean isLogin() {
return isLogin;
}
private String getNotLoginQQ(){
private String getNotLoginQQ() {
return "没有登录QQ";
}
public String sendMessage(String text) {
if (bot != null) {
MessageReceipt<Contact> receipt= bot.getGroup(qqGroup).sendMessage(text);
try {
MessageReceipt<Contact> receipt = bot.getGroup(qqGroup).sendMessage(text);
return receipt.toString();
} catch (Exception e) {
e.printStackTrace();
}
}
return getNotLoginQQ();
}
@ -88,7 +95,7 @@ public class QQBotManager {
if (bot != null) {
Image image = bot.getGroup(qqGroup).uploadImage(imageFile);
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 getNotLoginQQ();
@ -102,31 +109,38 @@ public class QQBotManager {
@Override
public void handleException(@NotNull CoroutineContext context, @NotNull Throwable exception) {
super.handleException(context, exception);
System.out.println("error: "+exception.getLocalizedMessage());
System.out.println("error: " + exception.getLocalizedMessage());
}
@EventHandler
public ListeningStatus onGroupMessage(GroupMessageEvent event) {
if(event.getGroup().getId()==qqGroup){
String msg=event.getMessage().contentToString();
msg=msg.replace("","!");
switch (msg){
if (event.getGroup().getId() == qqGroup) {
String msg = event.getMessage().contentToString();
msg = msg.replace("", "!");
switch (msg) {
case "!开机":
RedisTools.Consumer.system("openPC",null);
RedisTools.Consumer.system("openPC", null);
break;
case "!更新IP":
RedisTools.Consumer.system("updateIP",null);
RedisTools.Consumer.system("updateIP", null);
break;
case "!ip":
RedisTools.Consumer.bot("getip");
break;
default:
if(msg.startsWith("!cmd")){
RedisTools.Consumer.system("cmd",msg.replace("!cmd",""));
}
if (msg.startsWith("!cmd")) {
RedisTools.Consumer.system("cmd", msg.replace("!cmd", ""));
}
}
}/*else{
sendMessage("群:"+event.getGroup().getId()+" 发来消息:\n"+event.getMessage().contentToString());
}*/
return ListeningStatus.LISTENING;
}
@EventHandler
public void onMessage(@NotNull MessageEvent event) throws Exception {
// sendMessage("个人:"+event.getSender().getNick()+" 发来消息:"+event.getMessage().contentToString());
}
}
}

View File

@ -376,4 +376,16 @@ public class Tools {
base=base.replace(" ","+");
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();
}
}