Merge branch 'master' of ssh://git.mrbesen.de:2222/GamingServerGeraet/TelegramAPI
This commit is contained in:
commit
80ab409e64
|
@ -249,14 +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.equals("jpg") || extention.equals("jpeg") || extention.equals("png")) {
|
||||
return Attachment.Photo;
|
||||
} else if(extention.equals("gif")) {
|
||||
return Attachment.Animation;
|
||||
}
|
||||
|
||||
return Attachment.Document;
|
||||
}
|
||||
|
||||
|
@ -273,6 +280,4 @@ public class MessageBuilder {
|
|||
super("The Object " + missing_obj + " is missing or invalid.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import java.util.Scanner;
|
|||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
|
||||
import de.mrbesen.telegram.commands.JSONCommandHandler;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
|
@ -126,8 +127,8 @@ public class TelegramAPI implements Runnable {
|
|||
} else {
|
||||
String errdesc = "[No description available]";
|
||||
try {
|
||||
//try to read anyway to get error message
|
||||
JSONObject returned = new JSONObject(readfromIS(con.getInputStream()));
|
||||
//try to read error message
|
||||
JSONObject returned = new JSONObject(readfromIS(con.getErrorStream()));
|
||||
errdesc = returned.getString("description");
|
||||
} catch(Throwable ignore) { }
|
||||
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 chatid
|
||||
* @param msg_id
|
||||
|
@ -202,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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue