diff --git a/src/main/java/de/fabianonline/telegram_backup/DownloadManager.java b/src/main/java/de/fabianonline/telegram_backup/DownloadManager.java index 2ace054..71d75db 100644 --- a/src/main/java/de/fabianonline/telegram_backup/DownloadManager.java +++ b/src/main/java/de/fabianonline/telegram_backup/DownloadManager.java @@ -63,17 +63,7 @@ class DownloadManager { } catch (RpcErrorException e) { if (e.getTag().startsWith("420: FLOOD_WAIT_")) { completed = false; - Config.DELAY_AFTER_GET_MESSAGES = 1500; - 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) {} + Utils.obeyFloodWaitException(e); } else { throw e; } @@ -170,23 +160,7 @@ class DownloadManager { } catch (RpcErrorException e) { if (e.getTag().startsWith("420: FLOOD_WAIT_")) { completed = false; - Config.DELAY_AFTER_GET_FILE = 1500; - 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(""); + Utils.obeyFloodWaitException(e); } else { throw e; } diff --git a/src/main/java/de/fabianonline/telegram_backup/Utils.java b/src/main/java/de/fabianonline/telegram_backup/Utils.java index 1f07d83..3811537 100644 --- a/src/main/java/de/fabianonline/telegram_backup/Utils.java +++ b/src/main/java/de/fabianonline/telegram_backup/Utils.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ package de.fabianonline.telegram_backup; - +import com.github.badoualy.telegram.tl.exception.RpcErrorException; import java.io.File; import java.util.List; import java.util.Vector; @@ -32,4 +32,25 @@ public class Utils { } 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(""); + } }