Skip to content

Commit

Permalink
优化指令执行解析
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdoeswhat committed Mar 6, 2022
1 parent 8b42231 commit 8e8a981
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>me.albert</groupId>
<artifactId>AmazingBot</artifactId>
<packaging>jar</packaging>
<version>4.0.0</version>
<version>4.0.1</version>
<name>AmazingBot</name>

<properties>
Expand Down
2 changes: 1 addition & 1 deletion resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: AmazingBot
version: 4.0.0
version: 4.0.1
author: Albert
main: me.albert.amazingbot.AmazingBot
api-version: 1.13
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ public String getMsg() {
return message;
}


/**
* @return 消息中包含的所有纯文本信息
*/
public String getTextMessage() {
return message.replaceAll("(\\[)([\\s\\S]*?)(])", "");
return MsgUtil.deFormatCQCode(message.replaceAll("(\\[)([\\s\\S]*?)(])", "\n"));
}

public List<String> getImageIDList() {
Expand Down
8 changes: 3 additions & 5 deletions src/me/albert/amazingbot/listeners/OnCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,13 @@ public void onCommand(GroupMessageEvent e) {
return;
}
String label = getLabel(e.getGroupID());
if (label == null || !e.getMsg().startsWith(label)) {
String msg = e.getTextMessage();
if (label == null || !msg.startsWith(label)) {
return;
}
e.response("命令已提交");
Bukkit.getScheduler().runTaskAsynchronously(AmazingBot.getInstance(), () -> {
String cmd = e.getMsg().substring(label.length());
String cmd = msg.substring(label.length());
CommandSender sender = getSender(e.getGroupID(),true);
Bukkit.getScheduler().runTask(AmazingBot.getInstance(), () -> Bukkit.dispatchCommand(sender, cmd));
String log = AmazingBot.getInstance().getConfig().getString("messages.log_command")
Expand All @@ -90,9 +91,6 @@ public void onSwitch(GroupMessageEvent e) {
if (!isAdmin(e.getUserID())) {
return;
}
if (e.getMsg().equals("测试")) {
e.response("您的加群时间: " + e.getMember().getJoinTime());
}
FileConfiguration config = AmazingBot.getInstance().getConfig();
String serverName = config.getString("server_name");
String label = config.getString("commands.toggle_on").replace("%server%", serverName);
Expand Down
4 changes: 2 additions & 2 deletions src/me/albert/amazingbot/utils/MsgUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ public static String getXMLMsg(String xml) {
return "[CQ:xml,data=" + xml + "]";
}

public static String formatString(String str) {
public static String formatCQCode(String str) {
return str.replace("&", "&amp;")
.replace("[", "&#91;")
.replace("]", "&#93;")
.replace(",", "&#44;");
}

public static String deFormatString(String str) {
public static String deFormatCQCode(String str) {
return str.replace("&amp;", "&")
.replace("&#91;", "[")
.replace("&#93;", "]")
Expand Down

0 comments on commit 8e8a981

Please sign in to comment.