catch message not modified exception

This commit is contained in:
mrbesen 2019-04-11 12:31:07 +02:00
parent 9a8de527a1
commit fbeae445ad
Signed by: MrBesen
GPG Key ID: 596B2350DCD67504
2 changed files with 26 additions and 9 deletions

View File

@ -249,16 +249,21 @@ public class MessageBuilder {
public static Attachment getForFileExt(String extention) {
if(extention.startsWith("."))
extention = extention.substring(1);
if(extention.equalsIgnoreCase("mp4")) {
extention = extention.toLowerCase();
if(extention.equals("mp4")) {
return Attachment.Video;
} else if(extention.equalsIgnoreCase("mp3")) {
} else if(extention.equals("mp3")) {
return Attachment.Audio;
} else if(extention.equalsIgnoreCase("ogg")) {
} else if(extention.equals("ogg")) {
return Attachment.Voice;
} else if(extention.equalsIgnoreCase("jpg") || extention.equalsIgnoreCase("jpeg") || extention.equalsIgnoreCase("png")) {
} else if(extention.equals("jpg") || extention.equals("jpeg") || extention.equals("png")) {
return Attachment.Photo;
} else if(extention.equals("gif")) {
return Attachment.Animation;
}
return Attachment.Document;
}
@ -275,6 +280,4 @@ public class MessageBuilder {
super("The Object " + missing_obj + " is missing or invalid.");
}
}
}

View File

@ -188,7 +188,7 @@ public class TelegramAPI implements Runnable {
}
/**
* creates internal APIEror, when message is not modyfied! TODO; run update Caption with MessageBuilder and catch that error
* creates internal APIEror, when message is not modyfied!
* @param newCaption
* @param chatid
* @param msg_id
@ -203,7 +203,21 @@ public class TelegramAPI implements Runnable {
rply = "&reply_markup=" + URLEncoder.encode(rm.toJSONString(), "UTF-8");
String q = "chat_id=" + chatid + "&message_id=" + msg_id + "&caption=" + URLEncoder.encode(newCaption, "UTF-8") + rply;
if(async) {
this.async.enque("editMessageCaption", q);
Task t = new Task("editMessageCaption", q);
t.setExceptionhandl(new Callback<Throwable, Void>() {
@Override
public Void call(Throwable j) throws Throwable {
if(j instanceof APIError) {
String errmsg = ((APIError) j).getMessage();
if(errmsg.equals("Bad Request: message is not modified") || errmsg.equals("Bad Request: message to edit not found")) {
//both have code 400
return null;
}
}
throw j;
}
});
this.async.enque(t);
} else {
request("editMessageCaption", q);
}