Package 

Annotation Filter

  • All Implemented Interfaces:
    java.lang.annotation.Annotation

    @Retention(value = RetentionPolicy.RUNTIME)@Target(value = {ElementType.METHOD, ElementType.ANNOTATION_TYPE})@Documented()@Repeatable(value = Filters.class.class) 
    public @interface Filter
    
                        

    注解过滤器,通过一些简单的消息匹配规则以实现对监听消息进行过滤。

    这种可复数的注解暂时不支持注解继承。如要继承,请尝试直接继承其对应上级注解 Filters

    • Method Summary

      Modifier and Type Method Description
      abstract String value() 匹配关键词内容。比如一个正则,或者一个equals字符串。如果为空字符串则忽略此参数。
      abstract String target() 过滤目标。默认情况下,一个过滤器是通过 getText 进行过滤的。但是可能在某些情况下,你需要通过其他目标进行过滤匹配,例如 getMsg 或者 love.forte.simbot.listener.ListenerContext 中的某个值。此参数提供一些可选值,以允许你重新指定一个目标过滤源。目前可选值如下:
      • {@code text} - 为空或者为{@code 'text'}都指的是使用getText 进行过滤。
      • {@code msg} - {@code 'msg'}使用getMsg 进行过滤。
      • {@code context.global.[nonnull,nullable].xxx} - {@code 'context.global.xxx'} 使用 getContext 中的 GLOBAL(即全局变量) 进行过滤。其中的 {@code 'nonnull' 或 'nullable' } 代表其是否可以为null。如果是 {@code nonnull}, 那么当获取到的元素为null的时候,不会通过过滤匹配,反之,如果为 {@code nullable}, 那么如果获取到的元素为null,则会通过匹配 。{@code 'xxx'} 为 GLOBAL 中的一个任意的元素值。

        例如:{@code @Filter(value = "hello", target = "context.global.nullable.myTarget")}

      • {@code context.instant.[nonnull,nullable].xxx} - 含义与上述的 {@code context.global.[nonnull,nullable].xxx} 基本一致,唯一不同的就是此处是通过 EVENT_INSTANT 进行匹配的。

        例如:{@code @Filter(value = "hi", target = "context.instant.nullable.myTarget")}

      上述中,只有通过 {@code context.xxx} 进行匹配的参数才有 {@code nonnull 或 nullable}的选择,{@code text 和 msg}的null选择为核心的默认情况,即如果为null则认为当前消息 不支持进行文本过滤。提供一个常量类 FilterTargets 以降低手写的出错概率.
      abstract boolean targetByParent() 如果 target 未指定,是否尝试使用 target .
      abstract MatchType matchType() 匹配模式,默认为相等匹配。
      abstract Array<String> codes() 匹配这段消息的账号列表。如果为空, 且codesByParent 为true,则尝试使用 codes。如果仍为空,则对任何账号都匹配生效。如果对应消息无法获取账号信息,则此参数失效。
      abstract boolean codesByParent() 是否尝试使用父注解的codes。如果为true,则当 codes 为空,则尝试优先使用 codes
      abstract Array<String> groups() 匹配当前消息的群列表。如果为空, 且groupsByParent 为true,则尝试使用 groups。如果仍为空,则对任何群都匹配生效。如果对应消息无法获取群账号信息,则此参数失效。
      abstract boolean groupsByParent() 是否尝试使用父注解的groups。如果为true,则当 groups 为空,则尝试优先使用 groups
      abstract Array<String> bots() 匹配当前消息的bot列表。如果为空, 且botsByParent 为true,则尝试使用 bots。如果仍为空,则对任何bot都匹配生效。
      abstract boolean botsByParent() 是否尝试使用父注解的bots。如果为true,则当 bots 为空,则尝试优先使用 bots
      abstract boolean atBot() 当bot被at的时候才会触发。
      abstract boolean atBotByParent() 如果 atBot 为 false 且此参数为true,则使用atBot 的值。
      abstract boolean anyAt() 有人被at了才会触发。其中可能不包括bot自身。如果此为true,则at 失效。
      abstract boolean anyAtByParent() 如果 anyAt 为 false 且此参数为true,则使用anyAt 的值。
      abstract Array<String> at() 当下列账号中的人被at了才会触发。如果 anyAt 为true则失效。
      abstract boolean atByParent() 如果 at 为 空 且此参数为true,则使用at 的值。
      abstract boolean trim() 匹配前是否去除前后空格。
      abstract Class<out AnnotatedListenerFilterProcessor> processor() 为当前 Filter 指定一个专属的处理器过滤器。当此参数不为空的时候,其他参数全部失效,通过此参数指定的处理器不会被 love.forte.simbot.filter.FilterManager 所管理,必须提供一个无参构造。processor()processorName 同时存在时,在 严格模式 下将会抛出异常,否则优先使用 processor() 所指定的处理器。
      abstract String processorName() 通过名称在 love.forte.simbot.filter.FilterManager 中寻找 注解处理器 类型的 过滤器.
      • Methods inherited from class java.lang.annotation.Annotation

        annotationType, equals, hashCode, toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • value

         abstract String value()

        匹配关键词内容。比如一个正则,或者一个equals字符串。如果为空字符串则忽略此参数。

      • target

         abstract String target()

        过滤目标。默认情况下,一个过滤器是通过 getText 进行过滤的。但是可能在某些情况下,你需要通过其他目标进行过滤匹配,例如 getMsg 或者 love.forte.simbot.listener.ListenerContext 中的某个值。

        此参数提供一些可选值,以允许你重新指定一个目标过滤源。目前可选值如下:

        • {@code text} - 为空或者为{@code 'text'}都指的是使用getText 进行过滤。
        • {@code msg} - {@code 'msg'}使用getMsg 进行过滤。
        • {@code context.global.[nonnull,nullable].xxx} - {@code 'context.global.xxx'} 使用 getContext 中的 GLOBAL(即全局变量) 进行过滤。其中的 {@code 'nonnull' 或 'nullable' } 代表其是否可以为null。如果是 {@code nonnull}, 那么当获取到的元素为null的时候,不会通过过滤匹配,反之,如果为 {@code nullable}, 那么如果获取到的元素为null,则会通过匹配 。{@code 'xxx'} 为 GLOBAL 中的一个任意的元素值。

          例如:{@code @Filter(value = "hello", target = "context.global.nullable.myTarget")}

        • {@code context.instant.[nonnull,nullable].xxx} - 含义与上述的 {@code context.global.[nonnull,nullable].xxx} 基本一致,唯一不同的就是此处是通过 EVENT_INSTANT 进行匹配的。

          例如:{@code @Filter(value = "hi", target = "context.instant.nullable.myTarget")}

        上述中,只有通过 {@code context.xxx} 进行匹配的参数才有 {@code nonnull 或 nullable}的选择,{@code text 和 msg}的null选择为核心的默认情况,即如果为null则认为当前消息 不支持进行文本过滤。

        提供一个常量类 FilterTargets 以降低手写的出错概率.

        例如:

        {@code @Filter(target = FilterTargets.MSG) // 使用 .getMsg() 进行过滤。 }

        {@code @Filter(target = FilterTargets.CONTEXT_GLOBAL_NONNULL + "myTarget") // 使用 getContextMap().getGlobal().get("myTarget") 中的值进行过滤。} 当然,除了上述的可选值以外,你也可以通过 love.forte.common.ioc.annotation.PrePass 操作 getCheckers 中的返回值来添加你的自定义解析器。

      • codes

         abstract Array<String> codes()

        匹配这段消息的账号列表。如果为空, 且codesByParent 为true,则尝试使用 codes。如果仍为空,则对任何账号都匹配生效。如果对应消息无法获取账号信息,则此参数失效。

      • codesByParent

         abstract boolean codesByParent()

        是否尝试使用父注解的codes。如果为true,则当 codes 为空,则尝试优先使用 codes

      • groups

         abstract Array<String> groups()

        匹配当前消息的群列表。如果为空, 且groupsByParent 为true,则尝试使用 groups。如果仍为空,则对任何群都匹配生效。如果对应消息无法获取群账号信息,则此参数失效。

      • groupsByParent

         abstract boolean groupsByParent()

        是否尝试使用父注解的groups。如果为true,则当 groups 为空,则尝试优先使用 groups

      • bots

         abstract Array<String> bots()

        匹配当前消息的bot列表。如果为空, 且botsByParent 为true,则尝试使用 bots。如果仍为空,则对任何bot都匹配生效。

      • botsByParent

         abstract boolean botsByParent()

        是否尝试使用父注解的bots。如果为true,则当 bots 为空,则尝试优先使用 bots

      • atBot

         abstract boolean atBot()

        当bot被at的时候才会触发。

      • atBotByParent

         abstract boolean atBotByParent()

        如果 atBot 为 false 且此参数为true,则使用atBot 的值。

      • anyAt

         abstract boolean anyAt()

        有人被at了才会触发。其中可能不包括bot自身。如果此为true,则at 失效。

      • anyAtByParent

         abstract boolean anyAtByParent()

        如果 anyAt 为 false 且此参数为true,则使用anyAt 的值。

      • at

         abstract Array<String> at()

        当下列账号中的人被at了才会触发。如果 anyAt 为true则失效。

      • atByParent

         abstract boolean atByParent()

        如果 at 为 空 且此参数为true,则使用at 的值。

      • trim

         abstract boolean trim()

        匹配前是否去除前后空格。

      • processor

         abstract Class<out AnnotatedListenerFilterProcessor> processor()

        为当前 Filter 指定一个专属的处理器过滤器。当此参数不为空的时候,其他参数全部失效,通过此参数指定的处理器不会被 love.forte.simbot.filter.FilterManager 所管理,必须提供一个无参构造。processor()processorName 同时存在时,在 严格模式 下将会抛出异常,否则优先使用 processor() 所指定的处理器。