diff --git a/Reddit.own b/Reddit.own index 2a5aaee..7c4148d 100644 --- a/Reddit.own +++ b/Reddit.own @@ -1,4 +1,4 @@ -use ["okhttp", "types"] +use okhttp, types class Reddit { def Reddit(cookie) { diff --git a/modules.own b/modules.own index f6d2aa4..c6009ee 100644 --- a/modules.own +++ b/modules.own @@ -1,4 +1,4 @@ -use ["std"] +use std if (ARGS.length >= 2 && ARGS[0] == "owm") { use ["files", "json", "java"] diff --git a/redditimages.own b/redditimages.own index a4fcc28..e76e19d 100644 --- a/redditimages.own +++ b/redditimages.own @@ -1,4 +1,4 @@ -use ["std", "math", "http", "json", "functional", "files", "jdbc"] +use std, math, http, json, functional, files, jdbc conn = getConnection("jdbc:sqlite:redditimages.db") include "own-modules/telegram-bot/TelegramBot.own" include "Reddit.own" @@ -27,18 +27,30 @@ debug(media) while (length(media) > 0) { r = bot.sendMediaGroupSync(config.peer, media) if (r.ok) break - mediaIndex = try(def() = parseInt(r.description.replaceAll(".*failed.*?#(\\d+).*", "$1")), -1) + println r + retryAfter = try(def() = parseInt(r.description.replaceAll(".*retry after (\d+).*", "$1")), 0) + if (retryAfter > 0) { + sleep(retryAfter * 1000 + 2800) + continue + } + mediaIndex = try(def() = parseInt(r.description.replaceAll(".*failed.*?#(\d+).*", "$1")), -1) if (mediaIndex == -1) break media = arraySplice(media, mediaIndex - 1, 1) + sleep(3000) } +thread(def() { + sleep(15000) + exit(0) +}) + stIsPostExists.close() stAddPost.close() conn.close() // Helpers def debug(r) { -// echo(jsonencode(r)) + echo(jsonencode(r)) } def strToHashtag(str) = @@ -58,7 +70,7 @@ def getCaption(post) { } return sprintf( "%s\n" + - "🗨 Comments%s\n" + + "🗨 Comments%s\n" + "🔎 SauceNAO, " + "Alamy", safe(post.url), safe(post.title), @@ -68,7 +80,3 @@ def getCaption(post) { ) } -sleep(4000) -use "java" -System = newClass("java.lang.System") -System.exit(0)