在 If 條件的自訂套件中加入條件
在自訂套件中加入條件。
在中建立條件值 Action
- 要創建條件,請設置 BotCommand 註釋的命令類型屬性,並將值設置 爲條件。
- 要定義條件的輸入方法,請使用註釋 ConditionTest。
@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
}
}
以下示例驗證提供的布爾值是否爲 false 。
將 命令類型設置 爲條件。
@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 ;
}