Merge branch 'master' of ssh://git.mrbesen.de:2222/GamingServerGeraet/TelegramAPI

This commit is contained in:
MrBesen 2019-04-13 01:58:47 +02:00
commit 80ab409e64
2 changed files with 30 additions and 10 deletions

View File

@ -249,14 +249,21 @@ public class MessageBuilder {
public static Attachment getForFileExt(String extention) { public static Attachment getForFileExt(String extention) {
if(extention.startsWith(".")) if(extention.startsWith("."))
extention = extention.substring(1); extention = extention.substring(1);
if(extention.equalsIgnoreCase("mp4")) { extention = extention.toLowerCase();
if(extention.equals("mp4")) {
return Attachment.Video; return Attachment.Video;
} else if(extention.equalsIgnoreCase("mp3")) { } else if(extention.equals("mp3")) {
return Attachment.Audio; return Attachment.Audio;
} else if(extention.equalsIgnoreCase("ogg")) { } else if(extention.equals("ogg")) {
return Attachment.Voice; return Attachment.Voice;
} 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; return Attachment.Document;
} }
@ -273,6 +280,4 @@ public class MessageBuilder {
super("The Object " + missing_obj + " is missing or invalid."); super("The Object " + missing_obj + " is missing or invalid.");
} }
} }
} }

View File

@ -10,6 +10,7 @@ import java.util.Scanner;
import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.HttpsURLConnection;
import de.mrbesen.telegram.commands.JSONCommandHandler;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
@ -126,8 +127,8 @@ public class TelegramAPI implements Runnable {
} else { } else {
String errdesc = "[No description available]"; String errdesc = "[No description available]";
try { try {
//try to read anyway to get error message //try to read error message
JSONObject returned = new JSONObject(readfromIS(con.getInputStream())); JSONObject returned = new JSONObject(readfromIS(con.getErrorStream()));
errdesc = returned.getString("description"); errdesc = returned.getString("description");
} catch(Throwable ignore) { } } catch(Throwable ignore) { }
throw new APIError(parameter, request, con.getResponseCode(), null, errdesc); throw new APIError(parameter, request, con.getResponseCode(), null, errdesc);
@ -187,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 newCaption
* @param chatid * @param chatid
* @param msg_id * @param msg_id
@ -202,7 +203,21 @@ public class TelegramAPI implements Runnable {
rply = "&reply_markup=" + URLEncoder.encode(rm.toJSONString(), "UTF-8"); 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; String q = "chat_id=" + chatid + "&message_id=" + msg_id + "&caption=" + URLEncoder.encode(newCaption, "UTF-8") + rply;
if(async) { 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 { } else {
request("editMessageCaption", q); request("editMessageCaption", q);
} }