async getfile

This commit is contained in:
mrbesen 2021-01-20 23:42:30 +01:00
parent 97b72385a3
commit 279dca0286
Signed by: MrBesen
GPG Key ID: 596B2350DCD67504
2 changed files with 13 additions and 10 deletions

View File

@ -30,10 +30,8 @@ import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.concurrent.Callable;
import java.util.function.*;
import java.util.stream.Collector;
import static java.util.stream.Collector.Characteristics.IDENTITY_FINISH;
@ -307,6 +305,17 @@ public class TelegramAPI implements Runnable {
return new TFile(jfile.getJSONObject("result"));
}
public void getFile(final String fileid, Consumer<TFile> callback) {
async.enque(new Task("getFile", "file_id=" + fileid, 0, new Callback<JSONObject, Void>() {
@Override
public Void call(JSONObject j) throws Throwable {
TFile file = new TFile(j.getJSONObject("result"));
callback.accept(file);
return null;
}
}));
}
public void sendTypedMessage(final String msg, final TUser user, final int seconds) {
new Thread(new Runnable() {
@Override

View File

@ -29,12 +29,6 @@ public class TMessage extends JSONBased {
} else {
return TUser.sendMessage(api, chatid != 0 ? chatid : from.getID(), msg, rm, message_id, false, null);
}
// try {
// return api.request("sendMessage", "chat_id=" + from.getID() + "&text=" + msg + "&reply_to_message_id=" + message_id ).getBoolean("ok") ;
// } catch (IOException | NullPointerException e) {
// e.printStackTrace();
// return false;
// }
}
public boolean reply(String msg) {
return reply(msg, null);