1
0
mirror of https://github.com/fabianonline/telegram_backup.git synced 2024-11-23 01:06:17 +00:00

Moved FLOOD_WAIT exception handling to Utils class.

This commit is contained in:
Fabian Schlenz 2016-07-06 08:30:23 +02:00
parent b3913ac123
commit 0d431beba6
2 changed files with 24 additions and 29 deletions

View File

@ -63,17 +63,7 @@ class DownloadManager {
} catch (RpcErrorException e) { } catch (RpcErrorException e) {
if (e.getTag().startsWith("420: FLOOD_WAIT_")) { if (e.getTag().startsWith("420: FLOOD_WAIT_")) {
completed = false; completed = false;
Config.DELAY_AFTER_GET_MESSAGES = 1500; Utils.obeyFloodWaitException(e);
int delay = Integer.parseInt(e.getTag().substring(16));
System.out.println("");
System.out.println("Telegram complained about us (okay, me) making too many requests in too short time.");
System.out.println("So we now have to wait a bit. Telegram asked us to wait for " + delay + " seconds, which");
System.out.println("is about " + ((delay / 60) + 1) + " minutes.");
System.out.println("So I'm going to do that now. If you don't want to wait, you can quit by pressing");
System.out.println("Ctrl+C. You can restart me at any time and I will just continue to download your");
System.out.println("messages and media. But be advised that just restarting me is not going to change");
System.out.println("the fact that Telegram won't talk to me until then.");
try { Thread.sleep((delay + 60) * 1000); } catch(InterruptedException e2) {}
} else { } else {
throw e; throw e;
} }
@ -170,23 +160,7 @@ class DownloadManager {
} catch (RpcErrorException e) { } catch (RpcErrorException e) {
if (e.getTag().startsWith("420: FLOOD_WAIT_")) { if (e.getTag().startsWith("420: FLOOD_WAIT_")) {
completed = false; completed = false;
Config.DELAY_AFTER_GET_FILE = 1500; Utils.obeyFloodWaitException(e);
int delay = Integer.parseInt(e.getTag().substring(16));
int minutes = (delay/60)+1;
int wait = (minutes / 5) * 5 + 5;
System.out.println("");
System.out.println(
"Telegram complained about us (okay, me) making too many requests in too short time by\n" +
"sending us \"" + e.getTag() + "\" as an error. So we now have to wait a bit. Telegram\n" +
"asked us to wait for " + delay + " seconds, which is about " + minutes + " minutes.\n" +
"I'm adding a few minutes to let the API recover, so we are going to wait for " + wait + " mins.\n" +
"\n" +
"So I'm going to do just that for now. If you don't want to wait, you can quit by pressing\n" +
"Ctrl+C. You can restart me at any time and I will just continue to download your\n" +
"messages and media. But be advised that just restarting me is not going to change\n" +
"the fact that Telegram won't talk to me until then.");
try { Thread.sleep(wait * 60 * 1000); } catch(InterruptedException e2) {}
System.out.println("");
} else { } else {
throw e; throw e;
} }

View File

@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. */ * along with this program. If not, see <http://www.gnu.org/licenses/>. */
package de.fabianonline.telegram_backup; package de.fabianonline.telegram_backup;
import com.github.badoualy.telegram.tl.exception.RpcErrorException;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;
import java.util.Vector; import java.util.Vector;
@ -32,4 +32,25 @@ public class Utils {
} }
return accounts; return accounts;
} }
static void obeyFloodWaitException(RpcErrorException e) throws RpcErrorException {
if (e==null || ! e.getTag().startsWith("420: FLOOD_WAIT_")) return;
int delay = Integer.parseInt(e.getTag().substring(16));
int minutes = (delay/60)+1;
int wait = (minutes / 5) * 5 + 5;
System.out.println("");
System.out.println(
"Telegram complained about us (okay, me) making too many requests in too short time by\n" +
"sending us \"" + e.getTag() + "\" as an error. So we now have to wait a bit. Telegram\n" +
"asked us to wait for " + delay + " seconds, which is about " + minutes + " minutes.\n" +
"I'm adding a few minutes to let the API recover, so we are going to wait for " + wait + " mins.\n" +
"\n" +
"So I'm going to do just that for now. If you don't want to wait, you can quit by pressing\n" +
"Ctrl+C. You can restart me at any time and I will just continue to download your\n" +
"messages and media. But be advised that just restarting me is not going to change\n" +
"the fact that Telegram won't talk to me until then.");
try { Thread.sleep(wait * 60 * 1000); } catch(InterruptedException e2) {}
System.out.println("");
}
} }