Skip to content

Commit 3d5eb1e

Browse files
committed
Prevent bot answers when the message would be undeliverable
1 parent a2aae5c commit 3d5eb1e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/main/java/com/github/stickerifier/stickerify/bot/Stickerify.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,10 @@ private File retrieveFile(String fileId) throws TelegramApiException, FileOperat
171171

172172
private void processFailure(TelegramRequest request, Exception e, String fileId) {
173173
if (e instanceof TelegramApiException telegramException) {
174-
processTelegramFailure(telegramException, false);
174+
boolean replyToUser = processTelegramFailure(telegramException, false);
175+
if (!replyToUser) {
176+
return;
177+
}
175178
}
176179

177180
if (e instanceof CorruptedFileException) {
@@ -183,16 +186,21 @@ private void processFailure(TelegramRequest request, Exception e, String fileId)
183186
}
184187
}
185188

186-
private void processTelegramFailure(TelegramApiException e, boolean logUnmatchedFailure) {
189+
private boolean processTelegramFailure(TelegramApiException e, boolean logUnmatchedFailure) {
190+
boolean replyToUser = false;
191+
187192
switch (e.getDescription()) {
188193
case "Bad Request: message to be replied not found" -> LOGGER.at(Level.INFO).log("Unable to reply to the request: the message sent has been deleted");
189194
case "Forbidden: bot was blocked by the user" -> LOGGER.at(Level.INFO).log("Unable to reply to the request: the user blocked the bot");
190195
default -> {
191196
if (logUnmatchedFailure) {
192197
LOGGER.at(Level.ERROR).setCause(e).log("Unable to reply to the request");
193198
}
199+
replyToUser = true;
194200
}
195201
}
202+
203+
return replyToUser;
196204
}
197205

198206
private void answerText(TelegramRequest request) {

0 commit comments

Comments
 (0)