Skip to content

Commit

Permalink
fix kook whitelist
Browse files Browse the repository at this point in the history
  • Loading branch information
RegadPoleCN committed Jun 26, 2024
1 parent 86141b7 commit 384e6a5
Show file tree
Hide file tree
Showing 2 changed files with 155 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> 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<String> 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<String> 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<String> idForName = DatabaseManager.getBind(String.valueOf(senderID), DataBase.type().toLowerCase(), PlumBot.getDatabase());
if (idForName.isEmpty()) {
e.getMessage().reply("您尚未申请白名单");
return;
}
List<String> id = WhitelistHelper.removeAndGet(String.valueOf(senderID), num, DataBase.type().toLowerCase(), PlumBot.getDatabase());
e.getMessage().reply("成功移出白名单,您目前拥有的白名单为"+id);
});
return;
}
}

pattern = Pattern.compile(Prefix+".*");
Expand All @@ -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<String> 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+"帮助")) {
Expand All @@ -163,11 +223,14 @@ public void onChannelMessageReceive(ChannelMessageEvent e) {
messages.add(Prefix+"在线人数 查看服务器当前在线人数");
messages.add(Prefix+"tps 查看服务器当前tps");
messages.add(Prefix+"申请白名单 <ID> 为自己申请白名单");
messages.add(Prefix+"删除白名单 删除自己的白名单");
messages.add(Prefix+"删除白名单 <序号> 删除自己的白名单");
messages.add(Prefix+"查询白名单 查询自己的白名单");
messages.add("管理命令:");
messages.add(Prefix+"cmd 向服务器发送命令");
messages.add(Prefix+"删除白名单 <ID> 删除指定游戏id的白名单");
messages.add(Prefix+"删除User白名单 <QQ号/kookID> 删除指定群成员的白名单");
messages.add(Prefix+"申请白名单 <qq> <id> 为指定用户申请白名单");
messages.add(Prefix+"删除白名单 <id:ID 或 qq:QQ 序号> 删除指定游戏id或kook用户的白名单");
messages.add(Prefix+"查询白名单 <id:ID 或 qq:QQ> 查询指定游戏id或kook用户的白名单");
messages.add("ps:请通过查询白名单获得序号");
for (String message : messages) {
if (messages.get(messages.size() - 1).equalsIgnoreCase(message)) {
stringBuilder.append(message.replaceAll(\\S", ""));
Expand Down Expand Up @@ -196,42 +259,87 @@ 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<String> 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()) {
if (!Config.WhiteList()) {
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<String> 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<String> 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<String> 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<String> 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<String> result = WhitelistHelper.removeAndGet(String.valueOf(senderID), num, DataBase.type().toLowerCase(), PlumBot.getDatabase());
e.getMessage().reply("成功移出白名单,您目前的白名单为"+result);
});
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ public void onGroupMessageReceive(GroupMessage e){
messages.add(Prefix+"申请白名单 <qq> <id> 为指定用户申请白名单");
messages.add(Prefix+"删除白名单 <id:ID 或 qq:QQ 序号> 删除指定游戏id或qq的白名单");
messages.add(Prefix+"查询白名单 <id:ID 或 qq:QQ> 查询指定游戏id或qq的白名单");
messages.add("ps:请通过查询白名单获得序号");
for (String message : messages) {
if (messages.get(messages.size() - 1).equalsIgnoreCase(message)) {
stringBuilder.append(message.replaceAll(\\S", ""));
Expand Down

0 comments on commit 384e6a5

Please sign in to comment.