Fix handling of poll updates without user information

This commit is contained in:
Abbas Abou Daya 2020-04-25 17:32:38 -07:00
parent 52d69853e3
commit 05566742c0
3 changed files with 18 additions and 0 deletions

View File

@ -465,6 +465,10 @@ public abstract class BaseAbilityBot extends DefaultAbsSender implements Ability
Update addUser(Update update) {
User endUser = AbilityUtils.getUser(update);
if (endUser.equals(EMPTY_USER)) {
// Can't add an empty user, return the update as is
return update;
}
users().compute(endUser.getId(), (id, user) -> {
if (user == null) {

View File

@ -25,6 +25,10 @@ public enum Flag implements Predicate<Update> {
EDITED_MESSAGE(Update::hasEditedMessage),
INLINE_QUERY(Update::hasInlineQuery),
CHOSEN_INLINE_QUERY(Update::hasChosenInlineQuery),
SHIPPING_QUERY(Update::hasShippingQuery),
PRECHECKOUT_QUERY(Update::hasPreCheckoutQuery),
POLL(Update::hasPoll),
POLL_ANSWER(Update::hasPollAnswer),
// Message Flags
REPLY(upd -> MESSAGE.test(upd) && upd.getMessage().isReply()),

View File

@ -24,6 +24,8 @@ import static org.telegram.abilitybots.api.objects.Flag.*;
* Helper and utility methods
*/
public final class AbilityUtils {
public static User EMPTY_USER = new User();
private AbilityUtils() {
}
@ -69,6 +71,14 @@ public final class AbilityUtils {
return update.getEditedMessage().getFrom();
} else if (CHOSEN_INLINE_QUERY.test(update)) {
return update.getChosenInlineQuery().getFrom();
} else if (SHIPPING_QUERY.test(update)) {
return update.getShippingQuery().getFrom();
} else if (PRECHECKOUT_QUERY.test(update)) {
return update.getPreCheckoutQuery().getFrom();
} else if (POLL_ANSWER.test(update)) {
return update.getPollAnswer().getUser();
} else if (POLL.test(update)) {
return EMPTY_USER;
} else {
throw new IllegalStateException("Could not retrieve originating user from update");
}