From ccdca908cffd0f9e5cf148842f11c2320b7801ad Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Sun, 17 Apr 2022 15:55:25 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=91=98=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=EF=BC=9A=E6=94=AF=E6=8C=81this=E5=85=B3=E9=94=AE=E8=AF=8D?= =?UTF-8?q?=E6=A0=87=E8=AF=86=E6=9C=AC=E7=BE=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../qqbot/MessageEvent/AdminMessage.java | 102 +++++++++--------- 1 file changed, 52 insertions(+), 50 deletions(-) diff --git a/src/main/java/com/yutou/qqbot/MessageEvent/AdminMessage.java b/src/main/java/com/yutou/qqbot/MessageEvent/AdminMessage.java index 446bbb5..fe7885e 100644 --- a/src/main/java/com/yutou/qqbot/MessageEvent/AdminMessage.java +++ b/src/main/java/com/yutou/qqbot/MessageEvent/AdminMessage.java @@ -23,16 +23,16 @@ public class AdminMessage extends Message { private static final String MODEL_SHOW = "!查看模块"; private static final String MODEL_DEL = "!删除模块"; - public static final String SYSTEM_RESTART_QQ="!重启qq"; - public static final String SYSTEM_RESTART_TOOLS="!重启服务"; + public static final String SYSTEM_RESTART_QQ = "!重启qq"; + public static final String SYSTEM_RESTART_TOOLS = "!重启服务"; - public static final String SYSTEM_UPDATE_QQ="!更新qq"; - public static final String SYSTEM_UPDATE_NAS="!更新服务"; + public static final String SYSTEM_UPDATE_QQ = "!更新qq"; + public static final String SYSTEM_UPDATE_NAS = "!更新服务"; - private static final String SHOW="!列表"; - private static final String HELP="!help"; - private static final String SIGN="!签到"; + private static final String SHOW = "!列表"; + private static final String HELP = "!help"; + private static final String SIGN = "!签到"; } public AdminMessage(Long qq, String msg) { @@ -40,7 +40,7 @@ public class AdminMessage extends Message { String[] msgGroup = msg.replace("!", "!").split(" "); switch (msgGroup[0]) { - case QQCommands.HELP -> QQBotManager.getInstance().sendMessage(qq,Model.getCommands(QQCommands.class).toString()); + case QQCommands.HELP -> QQBotManager.getInstance().sendMessage(qq, Model.getCommands(QQCommands.class).toString()); case QQCommands.POWER_ADD -> { if (msgGroup.length == 1) { StringBuilder builder = Model.getCommands(Model.QQGroupCommands.class); @@ -84,7 +84,7 @@ public class AdminMessage extends Message { StringBuilder builder = new StringBuilder(); for (Class aClass : Model.classList) { try { - Model model= (Model) aClass.getDeclaredConstructor().newInstance(); + Model model = (Model) aClass.getDeclaredConstructor().newInstance(); builder.append("[").append(model.getModelName()).append("]"); } catch (Exception e) { e.printStackTrace(); @@ -97,9 +97,9 @@ public class AdminMessage extends Message { if (msgGroup.length <= 2) { addModel(msgGroup[1], null); } else { - if("this".equals(msgGroup[1])){ - addModel(sendQQ+"",msgGroup[2]); - }else { + if ("this".equals(msgGroup[1])) { + addModel(sendQQ + "", msgGroup[2]); + } else { addModel(msgGroup[1], msgGroup[2]); } } @@ -109,9 +109,9 @@ public class AdminMessage extends Message { if (msgGroup.length == 1) { QQBotManager.getInstance().sendMessage(qq, "使用方法:" + QQCommands.MODEL_SHOW + " [qqnumber]"); } else { - String qqGroup=msgGroup[1]; - if("this".equals(qqGroup)){ - qqGroup=sendQQ+""; + String qqGroup = msgGroup[1]; + if ("this".equals(qqGroup)) { + qqGroup = sendQQ + ""; } List list = QQNumberManager.getManager().getUseModel(Long.parseLong(qqGroup)); StringBuilder builder = new StringBuilder(); @@ -125,9 +125,9 @@ public class AdminMessage extends Message { if (msgGroup.length == 1) { QQBotManager.getInstance().sendMessage(qq, "使用方法:" + QQCommands.MODEL_DEL + " [qqnumber] 模块 用&分割"); } else { - String qqGroup=msgGroup[1]; - if("this".equals(qqGroup)){ - qqGroup=sendQQ+""; + String qqGroup = msgGroup[1]; + if ("this".equals(qqGroup)) { + qqGroup = sendQQ + ""; } if (msgGroup.length <= 2) { delModel(qqGroup, null); @@ -137,71 +137,71 @@ public class AdminMessage extends Message { } } case QQCommands.SHOW -> { - List users=QQNumberManager.getManager().getNumber(); - StringBuilder builder=new StringBuilder(); + List users = QQNumberManager.getManager().getNumber(); + StringBuilder builder = new StringBuilder(); for (Long user : users) { builder.append(user).append(":\n"); - List modelPower=QQNumberManager.getManager().getUseModel(user); + List modelPower = QQNumberManager.getManager().getUseModel(user); builder.append("模块(").append(modelPower.size()).append("):\n"); for (String model : modelPower) { builder.append(model).append("\n"); } - List list=QQNumberManager.getManager().getPower(user); + List list = QQNumberManager.getManager().getPower(user); builder.append("权限(").append(list.size()).append("):\n"); for (String power : list) { builder.append(power).append("\n"); } builder.append("\n"); } - QQBotManager.getInstance().sendMessage(qq,builder.toString()); + QQBotManager.getInstance().sendMessage(qq, builder.toString()); } case QQCommands.SYSTEM_RESTART_QQ -> { - QQBotManager.getInstance().sendMessage(qq,"正在重启机器人"); + QQBotManager.getInstance().sendMessage(qq, "正在重启机器人"); System.out.println("结束进程"); - AppTools.exec("cd /home/yutou/public/servier/qqbot && ./start.sh",null,true,false); + AppTools.exec("cd /home/yutou/public/servier/qqbot && ./start.sh", null, true, false); } - case QQCommands.SYSTEM_RESTART_TOOLS ->{ - QQBotManager.getInstance().sendMessage(qq,"正在重启服务"); + case QQCommands.SYSTEM_RESTART_TOOLS -> { + QQBotManager.getInstance().sendMessage(qq, "正在重启服务"); 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); } - case QQCommands.SYSTEM_UPDATE_QQ ->{ - QQBotManager.getInstance().sendMessage(qq,"正在更新qq"); + case QQCommands.SYSTEM_UPDATE_QQ -> { + QQBotManager.getInstance().sendMessage(qq, "正在更新qq"); System.out.println("结束进程"); - AppTools.exec("cd /root/git/QQBot && ./update.sh",null,true,false); + AppTools.exec("cd /root/git/QQBot && ./update.sh", null, true, false); } - case QQCommands.SYSTEM_UPDATE_NAS ->{ - QQBotManager.getInstance().sendMessage(qq,"正在更新NAS服务"); + case QQCommands.SYSTEM_UPDATE_NAS -> { + QQBotManager.getInstance().sendMessage(qq, "正在更新NAS服务"); System.out.println("结束进程"); - AppTools.exec("cd /root/git/nas-service && ./update.sh",null,true,false); + AppTools.exec("cd /root/git/nas-service && ./update.sh", null, true, false); } case QQCommands.SIGN -> { - boolean sign=true; + boolean sign = true; Log.i("开始签到"); - try{ + try { new Tsdm().tsdmSign(); - }catch (Exception e){ - sign=false; - QQBotManager.getInstance().sendMessage(qq,"tsdm签到失败:"+AppTools.getExceptionString(e)); + } catch (Exception e) { + sign = false; + QQBotManager.getInstance().sendMessage(qq, "tsdm签到失败:" + AppTools.getExceptionString(e)); e.printStackTrace(); } try { new BaiHeHui().sign(); - }catch (Exception e){ - sign=false; - QQBotManager.getInstance().sendMessage(qq,"百合会签到失败:"+AppTools.getExceptionString(e)); + } catch (Exception e) { + sign = false; + QQBotManager.getInstance().sendMessage(qq, "百合会签到失败:" + AppTools.getExceptionString(e)); e.printStackTrace(); } try { new NicePT().sign(); - }catch (Exception e){ - sign=false; - QQBotManager.getInstance().sendMessage(qq,"NicePT签到失败:"+AppTools.getExceptionString(e)); + } catch (Exception e) { + sign = false; + QQBotManager.getInstance().sendMessage(qq, "NicePT签到失败:" + AppTools.getExceptionString(e)); e.printStackTrace(); } - if(sign){ - QQBotManager.getInstance().sendMessage(qq,"签到任务完成"); + if (sign) { + QQBotManager.getInstance().sendMessage(qq, "签到任务完成"); } } } @@ -259,20 +259,22 @@ public class AdminMessage extends Message { } private void delModel(String qq, String model) { + boolean flag=false; try { if (model == null) { List list = QQNumberManager.getManager().getUseModel(Long.parseLong(qq)); for (String power : list) { - QQNumberManager.getManager().delUseModel(Long.parseLong(qq), Class.forName(power)); + flag=QQNumberManager.getManager().delUseModel(Long.parseLong(qq), Class.forName(power)); } } else { for (String power : model.split("&")) { - QQNumberManager.getManager().delUseModel(Long.parseLong(qq), Class.forName(power)); + flag=QQNumberManager.getManager().delUseModel(Long.parseLong(qq), Class.forName(power)); } } - }catch (Exception e){ + } catch (Exception e) { e.printStackTrace(); } + QQBotManager.getInstance().sendMessage(sendQQ, flag ? "删除成功" : "删除失败"); } }