Skip to content

Commit

Permalink
+ fix #75 #76
Browse files Browse the repository at this point in the history
  • Loading branch information
cnlimiter committed Apr 22, 2023
1 parent 45d9830 commit 645a577
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import cn.evolvefield.mods.botapi.init.callbacks.PlayerEvents;
import cn.evolvefield.mods.botapi.util.locale.I18n;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;


/**
Expand Down
32 changes: 18 additions & 14 deletions src/main/java/cn/evolvefield/mods/botapi/util/onebot/CQUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static boolean hasImg(String msg) {
public static String replace(String msg) {
if (msg.indexOf('[') == -1)
return BotUtils.unescape(msg);
String message = "";
StringBuilder message = new StringBuilder();
Pattern pattern = Pattern.compile(CQ_CODE_REGEX);
Matcher matcher = pattern.matcher(msg);
while (matcher.find()) {//全局匹配
Expand All @@ -45,12 +45,12 @@ public static String replace(String msg) {
.map(it -> it.substring(it.indexOf('=') + 1))
.findFirst();
if (url.isPresent()) {
message = matcher.replaceFirst(String.format("[[CICode,url=%s,name=来自QQ的图片]]", url.get()));
matcher.appendReplacement(message, String.format("[[CICode,url=%s,name=来自QQ的图片]]", url.get()));
} else {
message = matcher.replaceFirst("[图片]");
matcher.appendReplacement(message, "[图片]");
}
} else {
message = matcher.replaceFirst("[图片]");
matcher.appendReplacement(message, "[图片]");
}
break;
}
Expand All @@ -60,34 +60,38 @@ public static String replace(String msg) {
.map(it -> it.substring(it.indexOf('=') + 1))
.findFirst();
if (id.isPresent()) {
message = matcher.replaceFirst(String.format("@%s", id.get()));
matcher.appendReplacement(message, String.format("[@%s]", id.get()));
} else {
message = matcher.replaceFirst("[@]");
matcher.appendReplacement(message, "[@]");
}
break;
case "record":
message = matcher.replaceFirst("[语音]");
matcher.appendReplacement(message, "[语音]");
break;
case "forward":
message = matcher.replaceFirst("[合并转发]");
matcher.appendReplacement(message, "[合并转发]");
break;
case "video":
message = matcher.replaceFirst("[视频]");
matcher.appendReplacement(message, "[视频]");
break;
case "music":
message = matcher.replaceFirst("[音乐]");
matcher.appendReplacement(message, "[音乐]");
break;
case "redbag":
message = matcher.replaceFirst("[红包]");
matcher.appendReplacement(message, "[红包]");
break;
case "face":
message = matcher.replaceFirst("[表情]");
matcher.appendReplacement(message, "[表情]");
break;
case "reply":
matcher.appendReplacement(message, "[回复]");
break;
default:
message = matcher.replaceFirst("[?]");
matcher.appendReplacement(message, "[?]");
break;
}
}
return message;
matcher.appendTail(message);
return message.toString();
}
}

0 comments on commit 645a577

Please sign in to comment.