Fix broken entities
This commit is contained in:
parent
1daa69cbea
commit
82bc60d510
@ -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),
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user