update captions

This commit is contained in:
MrBesen 2019-02-11 17:24:21 +01:00
parent d52e8f22a4
commit 077017f590
Signed by: MrBesen
GPG Key ID: 596B2350DCD67504
1 changed files with 21 additions and 7 deletions

View File

@ -4,6 +4,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.net.URL; import java.net.URL;
import java.net.URLEncoder;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Scanner; import java.util.Scanner;
@ -47,7 +48,7 @@ public class TelegramAPI implements Runnable {
//stats //stats
protected int fetchedUpdates = 0; protected int fetchedUpdates = 0;
protected long start = 0; protected long start = 0;
private LinkedList<TUser> users = new LinkedList<>(); private LinkedList<TUser> users = new LinkedList<>();
private CommandManager cmdmgr = new CommandManager(); private CommandManager cmdmgr = new CommandManager();
private EventManager evntmgr = new EventManager(); private EventManager evntmgr = new EventManager();
@ -125,7 +126,7 @@ public class TelegramAPI implements Runnable {
//throw new IOException("API request returned HTTP " + con.getResponseCode() + " (" + con.getResponseMessage() + ") for action " + request + "\nurl: " + url.toString() + "\nparams: " + parameter + "\nerror description: " + errdesc); //throw new IOException("API request returned HTTP " + con.getResponseCode() + " (" + con.getResponseMessage() + ") for action " + request + "\nurl: " + url.toString() + "\nparams: " + parameter + "\nerror description: " + errdesc);
} }
} }
protected String readfromIS(InputStream is) { protected String readfromIS(InputStream is) {
Scanner s = new Scanner(is); Scanner s = new Scanner(is);
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
@ -161,7 +162,7 @@ public class TelegramAPI implements Runnable {
} }
return null; return null;
} }
public void sendTypedMessage(final String msg, final TUser user, final int seconds) { public void sendTypedMessage(final String msg, final TUser user, final int seconds) {
new Thread(new Runnable() { new Thread(new Runnable() {
@Override @Override
@ -177,6 +178,19 @@ public class TelegramAPI implements Runnable {
}).start(); }).start();
} }
public void updateCaption(final String newCaption, int chatid, int msg_id, boolean async, Callback<JSONObject, ?> clb) {
try {
String q = "chat_id=" + chatid + "&message_id=" + msg_id + "&caption=" + URLEncoder.encode(newCaption, "UTF-8");
if(async) {
this.async.enque("editMessageCaption", q);
} else {
request("editMessageCaption", q);
}
} catch(IOException e) {
log.log("", e);
}
}
public void stop() { public void stop() {
run = false; run = false;
thread.interrupt(); thread.interrupt();
@ -201,8 +215,8 @@ public class TelegramAPI implements Runnable {
fetchedUpdates++; fetchedUpdates++;
try { try {
int wait = (int) (updateInterval - (System.currentTimeMillis() - runstart)); int wait = (int) (updateInterval - (System.currentTimeMillis() - runstart));
if(wait > 0) if(wait > 0)
Thread.sleep(wait); Thread.sleep(wait);
} catch (InterruptedException e) { } catch (InterruptedException e) {
break; break;
} }
@ -304,7 +318,7 @@ public class TelegramAPI implements Runnable {
public int getupdateInterval() { public int getupdateInterval() {
return updateInterval; return updateInterval;
} }
public float getUpdatesperSecond() { public float getUpdatesperSecond() {
if(start == 0) if(start == 0)
return -1; return -1;
@ -410,7 +424,7 @@ public class TelegramAPI implements Runnable {
isArray = b; isArray = b;
} }
} }
public class APIError extends IOException { public class APIError extends IOException {
/** /**
* *