Fix keyboard builder
This commit is contained in:
@@ -32,7 +32,7 @@ public class BotResponseImpl implements BotResponse {
|
||||
public void send(Screen screen) {
|
||||
log.trace("Send trace: \n============\n{}\n============", screen.getText().trim());
|
||||
|
||||
AbstractSendRequest<? extends AbstractSendRequest> sendMessage = SendMethodUtils.createFromScreen(chatId(), screen);
|
||||
AbstractSendRequest<? extends AbstractSendRequest<?>> sendMessage = SendMethodUtils.createFromScreen(chatId(), screen);
|
||||
|
||||
if (screen.getKeyboard() instanceof KeyboardImpl) {
|
||||
KeyboardImpl kk = (KeyboardImpl) screen.getKeyboard();
|
||||
@@ -110,14 +110,14 @@ public class BotResponseImpl implements BotResponse {
|
||||
|
||||
private Long chatId() {
|
||||
if (update.callbackQuery() != null) {
|
||||
return update.callbackQuery().message().chat().id();
|
||||
return update.callbackQuery().maybeInaccessibleMessage().chat().id();
|
||||
}
|
||||
return update.message().chat().id();
|
||||
}
|
||||
|
||||
private Integer messageId() {
|
||||
if (update.callbackQuery() != null) {
|
||||
return update.callbackQuery().message().messageId();
|
||||
return update.callbackQuery().maybeInaccessibleMessage().messageId();
|
||||
}
|
||||
return update.message().messageId();
|
||||
}
|
||||
|
||||
@@ -15,11 +15,11 @@ import java.util.stream.Stream;
|
||||
@Value
|
||||
class KeyboardImpl implements Keyboard {
|
||||
|
||||
private KeyboardButton[][] keyboard;
|
||||
KeyboardButton[][] keyboard;
|
||||
|
||||
private InlineKeyboardButton[][] inlineKeyboard;
|
||||
InlineKeyboardButton[][] inlineKeyboard;
|
||||
|
||||
private Map<Object, String> text = new HashMap<>();
|
||||
Map<Object, String> text = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
@@ -118,9 +118,14 @@ public class PengradKeyboardBuilder implements KeyboardBuilder {
|
||||
|
||||
private void put(Action action) {
|
||||
if (action.isInline()) {
|
||||
put(new InlineKeyboardButton(action.getText())
|
||||
.callbackData(action.getCallbackData())
|
||||
.url(action.getUrl()));
|
||||
InlineKeyboardButton inlineKeyboardButton = new InlineKeyboardButton(action.getText());
|
||||
if (action.getCallbackData() != null) {
|
||||
inlineKeyboardButton.setCallbackData(action.getCallbackData());
|
||||
}
|
||||
if (action.getUrl() != null) {
|
||||
inlineKeyboardButton.url(action.getUrl());
|
||||
}
|
||||
put(inlineKeyboardButton);
|
||||
} else {
|
||||
put(new KeyboardButton(action.getText())
|
||||
.requestContact(action.isRequestContact())
|
||||
|
||||
@@ -24,7 +24,7 @@ import java.util.function.Consumer;
|
||||
@UtilityClass
|
||||
class SendMethodUtils {
|
||||
|
||||
public AbstractSendRequest<? extends AbstractSendRequest> createFromScreen(@NonNull Object chatIdObj, @NonNull Screen screen) {
|
||||
public AbstractSendRequest<? extends AbstractSendRequest<?>> createFromScreen(@NonNull Object chatIdObj, @NonNull Screen screen) {
|
||||
long chatId = chatIdObj instanceof Long ? (Long) chatIdObj : 0;
|
||||
if (isMedia(screen)) {
|
||||
final Media media = screen.getMedia();
|
||||
@@ -80,7 +80,6 @@ class SendMethodUtils {
|
||||
return new SendMessage(chatId, screen.getText().trim())
|
||||
.parseMode(screen.getScreenProperties().isParseModeHtml() ? ParseMode.HTML : ParseMode.MarkdownV2)
|
||||
.linkPreviewOptions(new LinkPreviewOptions().isDisabled(screen.getScreenProperties().isDisableWebPagePreview()))
|
||||
// .disableWebPagePreview(screen.getScreenProperties().isDisableWebPagePreview())
|
||||
.disableNotification(screen.getScreenProperties().isDisableNotification());
|
||||
}
|
||||
|
||||
@@ -105,8 +104,7 @@ class SendMethodUtils {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private SendVoice createSendVoice(@NotNull Object chatIdObj, Media media) {
|
||||
long chatId = chatIdObj instanceof Long ? (Long) chatIdObj : 0;
|
||||
private SendVoice createSendVoice(long chatId, Media media) {
|
||||
if (media.getData() != null) {
|
||||
return new SendVoice(chatId, media.getData().get());
|
||||
}
|
||||
@@ -117,8 +115,7 @@ class SendMethodUtils {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private SendVideo createSendVideo(@NotNull Object chatIdObj, Media media) {
|
||||
long chatId = chatIdObj instanceof Long ? (Long) chatIdObj : 0;
|
||||
private SendVideo createSendVideo(long chatId, Media media) {
|
||||
if (media.getData() != null) {
|
||||
return new SendVideo(chatId, media.getData().get());
|
||||
}
|
||||
@@ -129,8 +126,7 @@ class SendMethodUtils {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private SendAudio createSendAudio(@NotNull Object chatIdObj, Media media) {
|
||||
long chatId = chatIdObj instanceof Long ? (Long) chatIdObj : 0;
|
||||
private SendAudio createSendAudio(long chatId, Media media) {
|
||||
if (media.getData() != null) {
|
||||
return new SendAudio(chatId, media.getData().get());
|
||||
}
|
||||
@@ -141,8 +137,7 @@ class SendMethodUtils {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private SendAnimation createSendAnimation(@NotNull Object chatIdObj, Media media) {
|
||||
long chatId = chatIdObj instanceof Long ? (Long) chatIdObj : 0;
|
||||
private SendAnimation createSendAnimation(long chatId, Media media) {
|
||||
if (media.getData() != null) {
|
||||
return new SendAnimation(chatId, media.getData().get());
|
||||
}
|
||||
@@ -153,8 +148,7 @@ class SendMethodUtils {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private SendPhoto createSendPhoto(@NotNull Object chatIdObj, Media media) {
|
||||
long chatId = chatIdObj instanceof Long ? (Long) chatIdObj : 0;
|
||||
private SendPhoto createSendPhoto(long chatId, Media media) {
|
||||
if (media.getData() != null) {
|
||||
return new SendPhoto(chatId, media.getData().get());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user