Fix broken entities

This commit is contained in:
Andrea Cavalli 2022-01-22 12:46:10 +01:00
parent 1daa69cbea
commit 82bc60d510
4 changed files with 17 additions and 1 deletions

View File

@ -76,7 +76,7 @@ public class MessageEntity implements BotApiObject {
@JsonIgnore
private String text; ///< Text present in the entity. Computed from offset and length
protected void computeText(String message) {
public void computeText(String message) {
if (message != null) {
byte[] bytes = message.getBytes(StandardCharsets.UTF_16LE);
text = new String(Arrays.copyOfRange(bytes, offset, offset + length),

View File

@ -82,4 +82,11 @@ public class Game implements BotApiObject {
public boolean hasEntities() {
return entities != null && !entities.isEmpty();
}
public List<MessageEntity> getEntities() {
if (entities != null) {
entities.forEach(x -> x.computeText(text));
}
return entities;
}
}

View File

@ -71,4 +71,11 @@ public class Poll implements BotApiObject {
private String explanation; ///< Optional. Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll, 0-200 characters
@JsonProperty(EXPLANATIONENTITIES_FIELD)
private List<MessageEntity> explanationEntities; ///< Optional. Special entities like usernames, URLs, bot commands, etc. that appear in the explanation
public List<MessageEntity> getExplanationEntities() {
if (explanationEntities != null) {
explanationEntities.forEach(x -> x.computeText(explanation));
}
return explanationEntities;
}
}

View File

@ -318,6 +318,8 @@ public class DefaultBotSession implements BotSession {
} catch (InterruptedException e) {
log.debug(e.getLocalizedMessage(), e);
interrupt();
} catch (MalformedUpdateException e) {
log.error("Malformed update", e.getCause());
} catch (Exception e) {
log.error(e.getLocalizedMessage(), e);
}