commands with callbackData support
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -7,51 +7,51 @@ import lombok.ToString;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
@ToString(of = "text")
|
||||
@ToString(of = {"text", "inline"})
|
||||
public class Action {
|
||||
|
||||
public static Action simple(String text) {
|
||||
return builder().text(text).build();
|
||||
}
|
||||
public static Action simple(String text) {
|
||||
return builder().text(text).build();
|
||||
}
|
||||
|
||||
public static Action simple(String text, String cmd) {
|
||||
validateCmd(cmd);
|
||||
return builder().text(text).cmd(cmd).build();
|
||||
}
|
||||
public static Action simple(String text, String cmd) {
|
||||
validateCmd(cmd);
|
||||
return builder().text(text).cmd(cmd).build();
|
||||
}
|
||||
|
||||
public static Action callback(String text, String callbackData) {
|
||||
return builder().inline(true).text(text).callbackData(callbackData).build();
|
||||
}
|
||||
public static Action callback(String text, String callbackData) {
|
||||
return builder().inline(true).text(text).callbackData(callbackData).build();
|
||||
}
|
||||
|
||||
public static Action requestContact(String text) {
|
||||
return builder().text(text).requestContact(true).build();
|
||||
}
|
||||
public static Action requestContact(String text) {
|
||||
return builder().text(text).requestContact(true).build();
|
||||
}
|
||||
|
||||
private boolean inline;
|
||||
private boolean inline;
|
||||
|
||||
private String text;
|
||||
private String text;
|
||||
|
||||
private String cmd;
|
||||
private String cmd;
|
||||
|
||||
// in-line
|
||||
private String callbackData;
|
||||
private String url;
|
||||
// in-line
|
||||
private String callbackData;
|
||||
private String url;
|
||||
|
||||
// keyboard
|
||||
private boolean requestContact;
|
||||
private boolean requestLocation;
|
||||
// keyboard
|
||||
private boolean requestContact;
|
||||
private boolean requestLocation;
|
||||
|
||||
/**
|
||||
* Text of the command, 1-32 characters. Can contain only lowercase English
|
||||
* letters, digits and underscores.
|
||||
*/
|
||||
private static void validateCmd(@NonNull String cmd) {
|
||||
if (cmd.length() > 32) {
|
||||
throw new IllegalArgumentException("Max length - 32 characters");
|
||||
}
|
||||
if (!cmd.startsWith("/")) {
|
||||
throw new IllegalArgumentException("Command must start / character");
|
||||
}
|
||||
// TODO validate lowercase etc
|
||||
}
|
||||
/**
|
||||
* Text of the command, 1-32 characters. Can contain only lowercase English
|
||||
* letters, digits and underscores.
|
||||
*/
|
||||
private static void validateCmd(@NonNull String cmd) {
|
||||
if (cmd.length() > 32) {
|
||||
throw new IllegalArgumentException("Max length - 32 characters");
|
||||
}
|
||||
if (!cmd.startsWith("/")) {
|
||||
throw new IllegalArgumentException("Command must start / character");
|
||||
}
|
||||
// TODO validate lowercase etc
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ public class BotCommandChain implements CommandChain {
|
||||
if (!commands.isEmpty()) {
|
||||
try {
|
||||
Command command = commands.get(0);
|
||||
log.debug("Run command {}", command.getClass().getSimpleName());
|
||||
log.debug("Run command {} ({})", command.getClass().getSimpleName(), command);
|
||||
command.process(botRequest, botResponse,
|
||||
new BotCommandChain(commands.subList(1, commands.size())));
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -1,8 +1,20 @@
|
||||
package ru.penkrat.stbf.api;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface RequestMatcher {
|
||||
|
||||
boolean match(BotRequest botRequest);
|
||||
boolean match(BotRequest botRequest);
|
||||
|
||||
default RequestMatcher or(RequestMatcher other) {
|
||||
Objects.requireNonNull(other);
|
||||
return (botRequest) -> match(botRequest) || other.match(botRequest);
|
||||
}
|
||||
|
||||
default RequestMatcher and(RequestMatcher other) {
|
||||
Objects.requireNonNull(other);
|
||||
return (botRequest) -> match(botRequest) && other.match(botRequest);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user