From 07361fb616cd0d2f0fca3a030164915bf223fdc6 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Fri, 14 Oct 2022 21:11:31 +0800 Subject: [PATCH] =?UTF-8?q?fix=20B=E7=AB=99=E6=B7=BB=E5=8A=A0=E7=9B=B4?= =?UTF-8?q?=E6=92=AD=E9=97=B4=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../qqbot/models/BiliBili/BiliBiliLive.java | 34 +++++++++++++------ .../java/com/yutou/qqbot/models/Model.java | 1 + 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java b/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java index bf64b9a..2545d59 100644 --- a/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java +++ b/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java @@ -20,7 +20,8 @@ public class BiliBiliLive extends Model { @Override public String[] getUsePowers() { return new String[]{ - Model.QQGroupCommands.BILI_LIVE_DANMU_SEND + Model.QQGroupCommands.BILI_LIVE_DANMU_SEND, + QQGroupCommands.BILI_LIVE_DANMU_DEL }; } @@ -47,26 +48,39 @@ public class BiliBiliLive extends Model { @Override public void onMessage(Long qq, MessageEvent event, boolean isGroup) { super.onMessage(qq, event, isGroup); - if (!msg.startsWith(QQGroupCommands.BILI_LIVE_DANMU_SEND)) { + if (!msg.startsWith(QQGroupCommands.BILI_LIVE_DANMU_SEND) && !msg.startsWith(QQGroupCommands.BILI_LIVE_DANMU_DEL)) { return; } StringBuilder message; + message = new StringBuilder(); try { - Integer roomId = Integer.getInteger(msg); - if (BiliBiliUtils.checkLiveRoom(roomId) && !RedisTools.list_isExist("bili_live", roomId + "")) { - RedisTools.list_add("bili_live", roomId + ""); - message = new StringBuilder("live sign Add Success"); + boolean isDel = false; + if (msg.startsWith(QQGroupCommands.BILI_LIVE_DANMU_DEL)) { + isDel = true; + msg = msg.replace(QQGroupCommands.BILI_LIVE_DANMU_DEL, "").trim(); } else { - message = new StringBuilder("live sign Add Error\n"); - message.append("-----live sign roomId-----\n"); + msg = msg.replace(QQGroupCommands.BILI_LIVE_DANMU_SEND, "").trim(); + } + Integer roomId = Integer.getInteger(msg); + if (BiliBiliUtils.checkLiveRoom(roomId)) { + if (isDel && RedisTools.list_isExist("bili_live", roomId + "")) { + RedisTools.list_remove("bili_live", roomId + ""); + message.append("直播签到删除成功").append("\n"); + } else if (!RedisTools.list_isExist("bili_live", roomId + "")) { + RedisTools.list_add("bili_live", roomId + ""); + message.append("直播签到添加成功").append("\n"); + } + } else { + message.append("直播签到操作失败\n"); + message.append("-----直播签到房间号----\n"); Set biliLive = RedisTools.list_get("bili_live"); for (String id : biliLive) { message.append(id).append("\n"); } } } catch (Exception e) { - message = new StringBuilder("live sign Add Error\n"); - message.append("-----live sign roomId-----\n"); + message = new StringBuilder("直播签到添加失败\n"); + message.append("-----直播签到房间号-----\n"); Set biliLive = RedisTools.list_get("bili_live"); for (String id : biliLive) { message.append(id).append("\n"); diff --git a/src/main/java/com/yutou/qqbot/models/Model.java b/src/main/java/com/yutou/qqbot/models/Model.java index c6e2e5d..6a90381 100644 --- a/src/main/java/com/yutou/qqbot/models/Model.java +++ b/src/main/java/com/yutou/qqbot/models/Model.java @@ -36,6 +36,7 @@ public abstract class Model implements ModelInterface { public final static String QQ_MOYU = "!摸鱼"; public final static String BILI_LIVE_DANMU_SEND="!b站签到"; + public final static String BILI_LIVE_DANMU_DEL="!b站签到删除"; }