diff --git a/plumbot-bukkit/src/main/java/me/regadpole/plumbot/event/kook/KookEvent.java b/plumbot-bukkit/src/main/java/me/regadpole/plumbot/event/kook/KookEvent.java index 758bafc..58f9807 100644 --- a/plumbot-bukkit/src/main/java/me/regadpole/plumbot/event/kook/KookEvent.java +++ b/plumbot-bukkit/src/main/java/me/regadpole/plumbot/event/kook/KookEvent.java @@ -8,6 +8,7 @@ import me.regadpole.plumbot.event.server.ServerManager; import me.regadpole.plumbot.event.server.ServerTps; import me.regadpole.plumbot.internal.FoliaSupport; +import me.regadpole.plumbot.internal.WhitelistHelper; import me.regadpole.plumbot.internal.database.DatabaseManager; import me.regadpole.plumbot.tool.StringTool; import org.bukkit.Bukkit; @@ -97,44 +98,57 @@ public void onChannelMessageReceive(ChannelMessageEvent e) { if (!Config.WhiteList()) { return; } - String name = matcher.group().replace(Prefix + "删除白名单 ", ""); - if (name.isEmpty()) { - e.getMessage().reply("id不能为空"); + String para = matcher.group().replace(Prefix + "删除白名单 ", ""); + if (para.isEmpty()) { + e.getMessage().reply("参数不能为空"); return; } - PlumBot.getScheduler().runTaskAsynchronously(() -> { - long nameForId = DatabaseManager.getBindId(name, DataBase.type().toLowerCase(), PlumBot.getDatabase()); - if (nameForId == 0L) { - e.getMessage().reply("尚未申请白名单"); + if (para.startsWith("id:")) { + String name = para.substring(3); + if (name.isEmpty()) { + e.getMessage().reply("id不能为空"); return; } - DatabaseManager.removeBindid(name, DataBase.type().toLowerCase(), PlumBot.getDatabase()); - e.getMessage().reply("成功移出白名单"); - }); - return; - } - - pattern = Pattern.compile(Prefix + "删除User白名单 .*"); - matcher = pattern.matcher(msg); - if (matcher.find()) { - if (!Config.WhiteList()) { - return; - } - String qq = matcher.group().replace(Prefix + "删除User白名单 ", ""); - if (qq.isEmpty()) { - e.getMessage().reply("QQ不能为空"); + PlumBot.getScheduler().runTaskAsynchronously(() -> { + if (WhitelistHelper.checkIDNotExist(name)) { + e.getMessage().reply("ID尚未申请白名单"); + return; + } + DatabaseManager.removeBindid(name, DataBase.type().toLowerCase(), PlumBot.getDatabase()); + e.getMessage().reply("成功移出白名单"); + }); return; - } - PlumBot.getScheduler().runTaskAsynchronously(() -> { - List idForName = DatabaseManager.getBind(qq, DataBase.type().toLowerCase(), PlumBot.getDatabase()); - if (idForName.isEmpty()) { - e.getMessage().reply("尚未申请白名单"); + } else if (para.startsWith("qq:")) { + String qq = para.substring(3); + if (qq.isEmpty()) { + e.getMessage().reply("QQ不能为空"); return; } - DatabaseManager.removeBind(qq, DataBase.type().toLowerCase(), PlumBot.getDatabase()); - e.getMessage().reply("成功移出白名单"); - }); - return; + String[] p = qq.split(" "); + PlumBot.getScheduler().runTaskAsynchronously(() -> { + List idForName = DatabaseManager.getBind(p[0], DataBase.type().toLowerCase(), PlumBot.getDatabase()); + if (idForName.isEmpty()) { + e.getMessage().reply(p[0]+"尚未申请白名单"); + return; + } + int num = Integer.parseInt(p[1]); + List id = WhitelistHelper.removeAndGet(p[0], num, DataBase.type().toLowerCase(), PlumBot.getDatabase()); + e.getMessage().reply("成功移出白名单,"+p[0]+"目前拥有的白名单为"+id); + }); + return; + } else { + int num = Integer.parseInt(matcher.group().replace(Prefix + "删除白名单 ", "")); + PlumBot.getScheduler().runTaskAsynchronously(() -> { + List idForName = DatabaseManager.getBind(String.valueOf(senderID), DataBase.type().toLowerCase(), PlumBot.getDatabase()); + if (idForName.isEmpty()) { + e.getMessage().reply("您尚未申请白名单"); + return; + } + List id = WhitelistHelper.removeAndGet(String.valueOf(senderID), num, DataBase.type().toLowerCase(), PlumBot.getDatabase()); + e.getMessage().reply("成功移出白名单,您目前拥有的白名单为"+id); + }); + return; + } } pattern = Pattern.compile(Prefix+".*"); @@ -154,6 +168,52 @@ public void onChannelMessageReceive(ChannelMessageEvent e) { } } + pattern = Pattern.compile(Prefix + "查询白名单 .*"); + matcher = pattern.matcher(msg); + if (matcher.find()) { + if (!Config.WhiteList()) { + return; + } + String para = matcher.group().replace(Prefix + "查询白名单 ", ""); + if (para.isEmpty()) { + e.getMessage().reply("参数不能为空"); + return; + } + if (para.startsWith("id:")) { + String name = para.substring(3); + if (name.isEmpty()) { + e.getMessage().reply("id不能为空"); + return; + } + PlumBot.getScheduler().runTaskAsynchronously(() -> { + long qq = DatabaseManager.getBindId(name, DataBase.type().toLowerCase(), PlumBot.getDatabase()); + if (qq==0L) { + e.getMessage().reply("ID尚未申请白名单"); + return; + } + e.getMessage().reply(name+"的申请用户为"+qq); + }); + return; + } else if (para.startsWith("qq:")) { + String qq = para.substring(3); + if (qq.isEmpty()) { + e.getMessage().reply("QQ不能为空"); + return; + } + PlumBot.getScheduler().runTaskAsynchronously(() -> { + List id = DatabaseManager.getBind(qq, DataBase.type().toLowerCase(), PlumBot.getDatabase()); + if (id.isEmpty()) { + e.getMessage().reply(qq+"尚未申请白名单"); + return; + } + e.getMessage().reply(qq+"拥有白名单ID:"+id); + }); + return; + } + return; + } + + } if(msg.equals(Prefix+"帮助")) { @@ -163,11 +223,14 @@ public void onChannelMessageReceive(ChannelMessageEvent e) { messages.add(Prefix+"在线人数 查看服务器当前在线人数"); messages.add(Prefix+"tps 查看服务器当前tps"); messages.add(Prefix+"申请白名单 为自己申请白名单"); - messages.add(Prefix+"删除白名单 删除自己的白名单"); + messages.add(Prefix+"删除白名单 <序号> 删除自己的白名单"); + messages.add(Prefix+"查询白名单 查询自己的白名单"); messages.add("管理命令:"); messages.add(Prefix+"cmd 向服务器发送命令"); - messages.add(Prefix+"删除白名单 删除指定游戏id的白名单"); - messages.add(Prefix+"删除User白名单 删除指定群成员的白名单"); + messages.add(Prefix+"申请白名单 为指定用户申请白名单"); + messages.add(Prefix+"删除白名单 删除指定游戏id或kook用户的白名单"); + messages.add(Prefix+"查询白名单 查询指定游戏id或kook用户的白名单"); + messages.add("ps:请通过查询白名单获得序号"); for (String message : messages) { if (messages.get(messages.size() - 1).equalsIgnoreCase(message)) { stringBuilder.append(message.replaceAll("§\\S", "")); @@ -196,6 +259,23 @@ public void onChannelMessageReceive(ChannelMessageEvent e) { return; } + pattern = Pattern.compile(Prefix + "查询白名单"); + matcher = pattern.matcher(msg); + if (matcher.find()) { + if (!Config.WhiteList()) { + return; + } + PlumBot.getScheduler().runTaskAsynchronously(() -> { + List idForName = DatabaseManager.getBind(String.valueOf(senderID), DataBase.type().toLowerCase(), PlumBot.getDatabase()); + if (idForName.isEmpty()) { + e.getMessage().reply("您尚未申请白名单"); + return; + } + e.getMessage().reply(senderID +"拥有白名单ID:"+idForName); + }); + return; + } + pattern = Pattern.compile(Prefix + "申请白名单 .*"); matcher = pattern.matcher(msg); if (matcher.find()) { @@ -203,35 +283,63 @@ public void onChannelMessageReceive(ChannelMessageEvent e) { return; } String PlayerName = matcher.group().replace(Prefix + "申请白名单 ", ""); - if (PlayerName.isEmpty()) { - e.getMessage().reply("id不能为空"); + String[] para = PlayerName.split(" "); + if (para.length==1){ + if (PlayerName.isEmpty()) { + e.getMessage().reply("id不能为空"); + return; + } + if(Config.getAdmins().contains(senderID)) { + if (!WhitelistHelper.checkIDNotExist(PlayerName)) { + e.getMessage().reply("绑定失败,此ID已绑定用户"+DatabaseManager.getBindId(PlayerName, DataBase.type().toLowerCase(), PlumBot.getDatabase())); + return; + } + List id = WhitelistHelper.addAndGet(PlayerName, String.valueOf(senderID), DataBase.type().toLowerCase(), PlumBot.getDatabase()); + e.getMessage().reply("成功申请白名单,您目前的白名单为"+id); + return; + } + PlumBot.getScheduler().runTaskAsynchronously(() -> { + if (!WhitelistHelper.checkCount(String.valueOf(senderID))) { + e.getMessage().reply("绑定失败,该用户已绑定:"+DatabaseManager.getBind(String.valueOf(senderID), DataBase.type().toLowerCase(), PlumBot.getDatabase())); + return; + } + if (!WhitelistHelper.checkIDNotExist(PlayerName)){ + e.getMessage().reply("绑定失败,此ID已绑定用户"+DatabaseManager.getBindId(PlayerName, DataBase.type().toLowerCase(), PlumBot.getDatabase())); + return; + } + List id = WhitelistHelper.addAndGet(PlayerName, String.valueOf(senderID), DataBase.type().toLowerCase(), PlumBot.getDatabase()); + e.getMessage().reply("成功申请白名单,您目前的白名单为"+id); + }); return; - } - PlumBot.getScheduler().runTaskAsynchronously(() -> { - if ((DatabaseManager.getBind(senderID, DataBase.type().toLowerCase(), PlumBot.getDatabase())!=null) || (DatabaseManager.getBindId(PlayerName, DataBase.type().toLowerCase(), PlumBot.getDatabase()) != 0L)) { - e.getMessage().reply("绑定失败"); + } else if (para.length==2) { + if(Config.getAdmins().contains(senderID)) { + if (!WhitelistHelper.checkIDNotExist(para[1])) { + e.getMessage().reply("绑定失败,此ID已绑定用户"+DatabaseManager.getBindId(para[1], DataBase.type().toLowerCase(), PlumBot.getDatabase())); + return; + } + List id = WhitelistHelper.addAndGet(para[1], para[0], DataBase.type().toLowerCase(), PlumBot.getDatabase()); + e.getMessage().reply("成功申请白名单,"+para[0]+"目前的白名单为"+id); return; } - DatabaseManager.addBind(PlayerName, senderID, DataBase.type().toLowerCase(), PlumBot.getDatabase()); - e.getMessage().reply("成功申请白名单"); - }); + } return; } - pattern = Pattern.compile(Prefix + "删除白名单"); + pattern = Pattern.compile(Prefix + "删除白名单 .*"); matcher = pattern.matcher(msg); if (matcher.find()) { if (!Config.WhiteList()) { return; } + int num = Integer.parseInt(matcher.group().replace(Prefix + "删除白名单 ", "")); PlumBot.getScheduler().runTaskAsynchronously(() -> { List idForName = DatabaseManager.getBind(String.valueOf(senderID), DataBase.type().toLowerCase(), PlumBot.getDatabase()); if (idForName.isEmpty()) { e.getMessage().reply("您尚未申请白名单"); return; } - DatabaseManager.removeBind(String.valueOf(senderID), DataBase.type().toLowerCase(), PlumBot.getDatabase()); - e.getMessage().reply("成功移出白名单"); + List result = WhitelistHelper.removeAndGet(String.valueOf(senderID), num, DataBase.type().toLowerCase(), PlumBot.getDatabase()); + e.getMessage().reply("成功移出白名单,您目前的白名单为"+result); }); return; } diff --git a/plumbot-bukkit/src/main/java/me/regadpole/plumbot/event/qq/QQEvent.java b/plumbot-bukkit/src/main/java/me/regadpole/plumbot/event/qq/QQEvent.java index 7a2e242..f6309bf 100644 --- a/plumbot-bukkit/src/main/java/me/regadpole/plumbot/event/qq/QQEvent.java +++ b/plumbot-bukkit/src/main/java/me/regadpole/plumbot/event/qq/QQEvent.java @@ -256,6 +256,7 @@ public void onGroupMessageReceive(GroupMessage e){ messages.add(Prefix+"申请白名单 为指定用户申请白名单"); messages.add(Prefix+"删除白名单 删除指定游戏id或qq的白名单"); messages.add(Prefix+"查询白名单 查询指定游戏id或qq的白名单"); + messages.add("ps:请通过查询白名单获得序号"); for (String message : messages) { if (messages.get(messages.size() - 1).equalsIgnoreCase(message)) { stringBuilder.append(message.replaceAll("§\\S", ""));