This repository has been archived by the owner on Oct 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
18 changed files
with
559 additions
and
130 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.forte.qqrobot.anno; | ||
|
||
import com.forte.qqrobot.anno.depend.Beans; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* 在监听器中进行异常处理, 标注在实现了ExceptionHandle接口的类上 | ||
* | ||
* @author ForteScarlet <[email][email protected]> | ||
* @since JDK1.8 | ||
**/ | ||
@Retention(RetentionPolicy.RUNTIME) //注解会在class字节码文件中存在,在运行时可以通过反射获取到 | ||
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.ANNOTATION_TYPE}) //接口、类、枚举、注解、方法 | ||
@Beans | ||
public @interface ExceptionCatch { | ||
|
||
/** 捕获的异常类型,默认为{@link Exception}类型 */ | ||
Class<? extends Exception>[] value() default java.lang.Exception.class; | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,8 @@ | |
import java.util.stream.Stream; | ||
|
||
/** | ||
* CQCode参数 | ||
* <pre> CQCode封装类 | ||
* <pre> 从核心1.10.2开始,不再进行权限认证。 | ||
* @author ForteScarlet <[163邮箱地址][email protected]> | ||
* @date Created in 2019/3/9 11:42 | ||
* @since JDK1.8 | ||
|
@@ -223,29 +224,6 @@ public Stream<Entry<String, String>> stream(){ | |
protected CQCode(CQCodeTypes cqCodeTypes, Map<String, String> params){ | ||
this.CqCodeType = cqCodeTypes; | ||
this.params = params; | ||
|
||
//遍历参数,判断参数是否都是符合规范的 | ||
//需要的参数 | ||
String[] keys = cqCodeTypes.getKeys(); | ||
//获取可以忽略的参数 | ||
Set<String> ignoreAbleKeys = cqCodeTypes.getIgnoreAbleKeys(); | ||
for (String key : keys) { | ||
String getParams = params.get(key); | ||
if(getParams == null && (!ignoreAbleKeys.contains(key))){ | ||
throw new CQParamsException("paramCannotIgnore", cqCodeTypes, key); | ||
} | ||
|
||
if(getParams != null){ | ||
String keyRegex = cqCodeTypes.getKeyRegex(key); | ||
if(keyRegex != null && !getParams.matches(keyRegex)){ | ||
throw new CQParamsException("paramMismatch", cqCodeTypes, key, keyRegex, getParams); | ||
} | ||
|
||
} | ||
|
||
|
||
} | ||
|
||
updateToString(); | ||
} | ||
|
||
|
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 |
---|---|---|
|
@@ -9,14 +9,13 @@ | |
import java.util.stream.Collectors; | ||
|
||
/** | ||
* 此枚举保存全部的CQCode类型。<br> | ||
* 且提供了一个{@link com.forte.qqrobot.factory.CQCodeTypeFactory}来支持动态扩展此枚举。<br> | ||
* 请不要使用任何非工厂创建的形式(例如自己通过反射或者其他工具)创建此类的实例对象。此类中维护一个function映射, | ||
* 用于通过function值快速定位CQCodeType,并且提供了一个注册接口{@link #register(CQCodeTypes)} 来支持额外注册的实例对象,并对其进行验证。 | ||
* 包括{@link com.forte.qqrobot.factory.CQCodeTypeFactory}中也提供了直接创建新枚举实例的相关接口,并提供参数验证。 | ||
* 假如您使用了其他手段自己创建了一个额外的实例,可能会导致valueOf所取值与内部的function映射值不相符、参数冲突等一系列问题。 | ||
* <br> | ||
* <br> | ||
* <pre> 此枚举保存全部的CQCode类型。 | ||
* <pre> 且提供了一个{@link com.forte.qqrobot.factory.CQCodeTypeFactory}来支持动态扩展此枚举。 | ||
* <pre> 请不要使用任何非工厂创建的形式(例如自己通过反射或者其他工具)创建此类的实例对象。此类中维护一个function映射, | ||
* <pre> 用于通过function值快速定位CQCodeType,并且提供了一个注册接口{@link #register(CQCodeTypes)} 来支持额外注册的实例对象,并对其进行验证。 | ||
* <pre> 包括{@link com.forte.qqrobot.factory.CQCodeTypeFactory}中也提供了直接创建新枚举实例的相关接口,并提供参数验证。 | ||
* <pre> 假如您使用了其他手段自己创建了一个额外的实例,可能会导致valueOf所取值与内部的function映射值不相符、参数冲突等一系列问题。 | ||
* <pre> 从核心1.10.2开始,不再进行权限认证。 | ||
* | ||
* @author ForteScarlet <[163邮箱地址][email protected]> | ||
* @date Created in 2019/3/8 14:55 | ||
|
@@ -27,7 +26,7 @@ public enum CQCodeTypes { | |
/** | ||
* 默认的未知类型,当无法获取或解析的时候将会使用此类型 | ||
*/ | ||
defaultType("", new String[0], new String[0], new String[0], -99), | ||
defaultType("?", new String[0], new String[0], new String[0], -99), | ||
|
||
/** | ||
* [CQ:face,id={1}] - QQ表情 | ||
|
@@ -301,7 +300,7 @@ public static CQCodeTypes getTypeByFunction(String function) { | |
|
||
/** | ||
* 根据类型和参数名称列表来获取一个具体的枚举类型对象实例 | ||
* | ||
* 1.10.2: 如果function只存在一个,直接返回,否则再通过参数判断 | ||
* @param function function 值, 即类型,例如"image"或者"share"之类的 | ||
* @param paramNames 参数列表值,需要保证顺序 | ||
* @return CQCodeTypes实例对象, 如果没有则会返回defaultType | ||
|
@@ -311,9 +310,10 @@ public static CQCodeTypes getTypeByFunctionAndParams(String function, String... | |
CQCodeTypes[] cqCodeTypes = AllCQCodeTypeMap.get(function); | ||
if (cqCodeTypes == null || cqCodeTypes.length == 0) { | ||
return defaultType; | ||
} else { | ||
} else if(cqCodeTypes.length == 1) { | ||
return cqCodeTypes[0]; | ||
} else{ | ||
// 筛选paramNames | ||
|
||
// 如果不为null,则遍历并匹配参数match | ||
for (CQCodeTypes type : cqCodeTypes) { | ||
// 根据type筛选params并匹配 | ||
|
@@ -527,7 +527,6 @@ public boolean match(String text) { | |
* 查看某个字符串中是否存在此类型的CQ码 | ||
*/ | ||
public boolean contains(String text) { | ||
// return text.matches(".*" + this.matchRegex + ".*"); | ||
return matchRegexPattern.matcher(text).find(); | ||
} | ||
|
||
|
@@ -581,6 +580,7 @@ public static CQCodeTypes[] getCQCodeTypesByFunction(String function) { | |
return Arrays.copyOf(cqCodeTypes, cqCodeTypes.length); | ||
} | ||
|
||
|
||
/** | ||
* 判断是否为两个等值的CQ码 | ||
*/ | ||
|
75 changes: 75 additions & 0 deletions
75
src/main/java/com/forte/qqrobot/exception/ExceptionProcessException.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,75 @@ | ||
package com.forte.qqrobot.exception; | ||
|
||
/** | ||
* 异常处理中心的异常 | ||
* exception.exceptionProcess | ||
* @author <a href="https://github.com/ForteScarlet"> ForteScarlet </a> | ||
*/ | ||
public class ExceptionProcessException extends RobotRuntimeException { | ||
|
||
public ExceptionProcessException() { | ||
} | ||
|
||
public ExceptionProcessException(String message, Object... format) { | ||
super(message, format); | ||
} | ||
|
||
public ExceptionProcessException(String message) { | ||
super(message); | ||
} | ||
|
||
public ExceptionProcessException(String message, Throwable cause, Object... format) { | ||
super(message, cause, format); | ||
} | ||
|
||
public ExceptionProcessException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public ExceptionProcessException(Throwable cause) { | ||
super(cause); | ||
} | ||
|
||
public ExceptionProcessException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { | ||
super(message, cause, enableSuppression, writableStackTrace); | ||
} | ||
|
||
public ExceptionProcessException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace, Object... format) { | ||
super(message, cause, enableSuppression, writableStackTrace, format); | ||
} | ||
|
||
/** | ||
* 不进行语言国际化转化的构造方法 | ||
* | ||
* @param pointless 无意义参数,填任意值 pointless param | ||
* @param message 信息正文 | ||
*/ | ||
public ExceptionProcessException(int pointless, String message) { | ||
super(pointless, message); | ||
} | ||
|
||
/** | ||
* 不进行语言国际化转化的构造方法 | ||
* | ||
* @param pointless 无意义参数,填任意值 pointless param | ||
* @param message 信息正文 | ||
* @param cause 异常 | ||
*/ | ||
public ExceptionProcessException(int pointless, String message, Throwable cause) { | ||
super(pointless, message, cause); | ||
} | ||
|
||
/** | ||
* 不进行语言国际化转化的构造方法 | ||
* | ||
* @param pointless 无意义参数,填任意值 pointless param | ||
* @param message 信息正文 | ||
* @param cause 异常 | ||
* @param enableSuppression whether or not suppression is enabled | ||
* or disabled | ||
* @param writableStackTrace whether or not the stack trace should | ||
*/ | ||
public ExceptionProcessException(int pointless, String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { | ||
super(pointless, message, cause, enableSuppression, writableStackTrace); | ||
} | ||
} |
Oops, something went wrong.