-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ 与chatImage联动
- Loading branch information
Showing
12 changed files
with
105 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package cn.evolvefield.mods.botapi; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
/** | ||
* Description: | ||
* Author: cnlimiter | ||
* Date: 2022/10/1 16:58 | ||
* Version: 1.0 | ||
*/ | ||
public class Const { | ||
public static final String MODID = "botapi"; | ||
public static final Logger LOGGER = LogManager.getLogger(MODID); | ||
public static boolean ChatImageOn; | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/main/java/cn/evolvefield/mods/botapi/util/onebot/CQUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package cn.evolvefield.mods.botapi.util.onebot; | ||
|
||
import cn.evolvefield.mods.botapi.Const; | ||
import cn.evolvefield.onebot.sdk.util.BotUtils; | ||
import cn.evolvefield.onebot.sdk.util.RegexUtils; | ||
|
||
import java.util.Arrays; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* Project: Bot-Connect-fabric-1.18 | ||
* Author: cnlimiter | ||
* Date: 2023/2/10 1:11 | ||
* Description: | ||
*/ | ||
public class CQUtils { | ||
|
||
private final static String CQ_CODE_SPLIT = "(?<=\\[CQ:[^]]{1,99999}])|(?=\\[CQ:[^]]{1,99999}])"; | ||
|
||
private final static String CQ_CODE_REGEX = "\\[CQ:([^,\\[\\]]+)((?:,[^,=\\[\\]]+=[^,\\[\\]]*)*)]"; | ||
|
||
|
||
public static boolean hasImg(String msg) { | ||
String regex = "\\[CQ:image,[(\\s\\S)]*\\]"; | ||
var p = Pattern.compile(regex); | ||
var m = p.matcher(msg); | ||
return m.find(); | ||
} | ||
|
||
public static String replace(String msg) { | ||
if (Const.ChatImageOn) { | ||
var matcher = RegexUtils.regexMatcher(CQ_CODE_REGEX, msg);//匹配cq码格式 | ||
AtomicReference<String> returnMsg = new AtomicReference<>("");//返回字符串 | ||
if (matcher == null) { | ||
returnMsg.set(msg);//不包含任何cq码则返回原msg | ||
} else { | ||
//while (matcher.find()){//找到所有符合的matcher | ||
if (matcher.group(1).equals("image")) {//如果是图片格式 | ||
Arrays.stream(matcher.group(2).split(","))//具体数据分割 | ||
.filter(args -> !args.isEmpty())//非空判断 | ||
.forEach(args -> { | ||
if (args.substring(0, args.indexOf("=")).equals("url")) {//url | ||
var v = BotUtils.unescape(args.substring(args.indexOf("=") + 1));//去除空格 | ||
|
||
returnMsg.set(matcher.replaceAll(String.format("[[CICode,url=%s,name=来自QQ的图片]]", v)));//转换ci码 | ||
} | ||
}); | ||
} | ||
//} | ||
} | ||
|
||
return returnMsg.get(); | ||
|
||
} else return msg; | ||
} | ||
} |