在自定义包中为 If 条件添加条件
- Updated: 2022/05/19
在自定义包中添加条件。
在 操作 中创建条件值
- 要创建条件,请将机器人命令注释的命令类型属性的值设置为条件。
- 要定义条件的输入方法,请使用注释条件测试。
@BotCommand(commandType = Condition) @CommandPkg(label = "File exists", name = "fileExists", description = "Checks if the file exists.", node_label = "file exists at {{sourceFilePath}}", icon = "") public class Exist extends AbstractCondition { @ConditionTest public boolean test(@Idx(index = "1", type = FILE) @LocalFile @Pkg(label = "File path") @NotEmpty String sourceFilePath, @Idx(index = "2", type = NUMBER) @Pkg(label = "How long you would like to wait for this condition to be true?(Seconds)", default_value = "0", default_value_type = DataType.NUMBER) @GreaterThanEqualTo("0") @LessThanEqualTo("99999") @NotEmpty @NumberInteger Double waitTimeout) { // Add the logic to check for the condition } }
以下示例验证提供的布尔值是否为假。
将命令类型设置为条件。
@BotCommand(commandType = Condition) @CommandPkg(label = "False condition example", name = "conditionalTypeExample", description = "Checks if the boolean value is false.") public class ConditionalTypeExample { @ConditionTest public Boolean validate( @Idx(index = "1", type = AttributeType.BOOLEAN) @VariableType(BOOLEAN) @Pkg(label = "Boolean variable", default_value_type = BOOLEAN) @NotEmpty Boolean variable ) { return variable == null ? false : !variable ; }