Skip to content
This repository has been archived by the owner on Oct 13, 2022. It is now read-only.

Commit

Permalink
准备1.10.2更新
Browse files Browse the repository at this point in the history
降低CQ码的参数匹配等级
增加at判断函数的注册
增加一些未来代码
  • Loading branch information
ForteScarlet committed Mar 16, 2020
1 parent 62f0498 commit d8c7446
Show file tree
Hide file tree
Showing 18 changed files with 559 additions and 130 deletions.
15 changes: 9 additions & 6 deletions src/main/java/com/forte/qqrobot/BaseApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
* @date Created in 2019/3/29 10:18
* @since JDK1.8
**/
public abstract class BaseApplication<CONFIG extends BaseConfiguration,
public abstract class BaseApplication<
CONFIG extends BaseConfiguration,
SEND extends SenderSendList,
SET extends SenderSetList,
GET extends SenderGetList,
Expand Down Expand Up @@ -418,12 +419,14 @@ protected void beforeDepend(CONFIG config, Application<CONFIG> app, Register reg
protected void afterDepend(CONFIG config, Application<CONFIG> app, Register register, DependCenter dependCenter) {
// 初始化http模板
initHttpTemplate(dependCenter);

// 初始化bot验证函数与路径拼接函数
//**************** 注册PathAssembler和VerifyFunction ****************//
VerifyFunction verifyFunction = verifyBot();
dependCenter.load(verifyFunction);
PathAssembler pathAssembler = config.getPathAssembler();
dependCenter.load(pathAssembler);

// 初始化bot管理中心
BotManager botManager = initBotManager(dependCenter);

Expand Down Expand Up @@ -812,14 +815,14 @@ private DependCenter scanAndInject(CONFIG config, Application<CONFIG> app) {
/**
* 有些事情需要连接之后才能做,例如加载定时任务,需要空函数送信器
*/
private void after(CONFIG config) {
private void after(CONFIG config, MsgSender defaultMsgSender) {
// 注册定时任务
registerTimeTask();
registerTimeTask(defaultMsgSender);
}

private void registerTimeTask(){
private void registerTimeTask(MsgSender defaultMsgSender){
//注册定时任务
this.register.registerTimeTask(this.defaultMsgSender);
this.register.registerTimeTask(defaultMsgSender);
}

/**
Expand Down Expand Up @@ -991,7 +994,7 @@ public CONTEXT run(Application<CONFIG> app, String... args) {
//获取CQCodeUtil实例
CQCodeUtil cqCodeUtil = ResourceDispatchCenter.getCQCodeUtil();

after(configuration);
after(configuration, startResult.getDefaultMsgSender());

long e = System.currentTimeMillis();
// 展示连接成功的信息
Expand Down
20 changes: 0 additions & 20 deletions src/main/java/com/forte/qqrobot/anno/Catch.java

This file was deleted.

24 changes: 24 additions & 0 deletions src/main/java/com/forte/qqrobot/anno/ExceptionCatch.java
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;

}
52 changes: 0 additions & 52 deletions src/main/java/com/forte/qqrobot/anno/data/Catch.java

This file was deleted.

26 changes: 2 additions & 24 deletions src/main/java/com/forte/qqrobot/beans/cqcode/CQCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}

Expand Down
26 changes: 13 additions & 13 deletions src/main/java/com/forte/qqrobot/beans/types/CQCodeTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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表情
Expand Down Expand Up @@ -301,7 +300,7 @@ public static CQCodeTypes getTypeByFunction(String function) {

/**
* 根据类型和参数名称列表来获取一个具体的枚举类型对象实例
*
* 1.10.2: 如果function只存在一个,直接返回,否则再通过参数判断
* @param function function 值, 即类型,例如"image"或者"share"之类的
* @param paramNames 参数列表值,需要保证顺序
* @return CQCodeTypes实例对象, 如果没有则会返回defaultType
Expand All @@ -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并匹配
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -581,6 +580,7 @@ public static CQCodeTypes[] getCQCodeTypesByFunction(String function) {
return Arrays.copyOf(cqCodeTypes, cqCodeTypes.length);
}


/**
* 判断是否为两个等值的CQ码
*/
Expand Down
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);
}
}
Loading

0 comments on commit d8c7446

Please sign in to comment.