From 13b43f96111d4100ac0c21e81d91c2f0ad2a7577 Mon Sep 17 00:00:00 2001 From: sijanec Date: Tue, 3 Nov 2020 23:27:34 +0100 Subject: dodal worddetect za pozigalca ampak ni narejen do konca --- bot/banned_subs.txt | 0 bot/banned_users.txt | 0 bot/index.php | 27 ---------------------- bot/mentions.php | 55 --------------------------------------------- bot/processed.txt | 0 main.php | 19 +++++++++++++++- mentions/banned_subs.txt | 0 mentions/banned_users.txt | 0 mentions/index.php | 27 ++++++++++++++++++++++ mentions/mentions.php | 55 +++++++++++++++++++++++++++++++++++++++++++++ mentions/processed.txt | 0 mentions/worddetect.php | 38 +++++++++++++++++++++++++++++++ worddetect/banned_subs.txt | 0 worddetect/banned_users.txt | 0 worddetect/processed.txt | 0 worddetect/worddetect.php | 38 +++++++++++++++++++++++++++++++ 16 files changed, 176 insertions(+), 83 deletions(-) delete mode 100644 bot/banned_subs.txt delete mode 100644 bot/banned_users.txt delete mode 100644 bot/index.php delete mode 100755 bot/mentions.php delete mode 100644 bot/processed.txt create mode 100644 mentions/banned_subs.txt create mode 100644 mentions/banned_users.txt create mode 100644 mentions/index.php create mode 100755 mentions/mentions.php create mode 100644 mentions/processed.txt create mode 100755 mentions/worddetect.php create mode 100644 worddetect/banned_subs.txt create mode 100644 worddetect/banned_users.txt create mode 100644 worddetect/processed.txt create mode 100755 worddetect/worddetect.php diff --git a/bot/banned_subs.txt b/bot/banned_subs.txt deleted file mode 100644 index e69de29..0000000 diff --git a/bot/banned_users.txt b/bot/banned_users.txt deleted file mode 100644 index e69de29..0000000 diff --git a/bot/index.php b/bot/index.php deleted file mode 100644 index 005efb0..0000000 --- a/bot/index.php +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - ImgLinkBot - - - - - '; - } - ?> - - diff --git a/bot/mentions.php b/bot/mentions.php deleted file mode 100755 index 3b87abf..0000000 --- a/bot/mentions.php +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env php -setusername(getenv("orC_user")); - $o->setpassword(getenv("orC_pass")); - $botsignature = "\n\n-- [/u/ImgLinkBot](/u/ImgLinkBot) | [ImgLinkBot.ž.ga](https://imglinkbot.xn--jha.ga/)"; - while (true) { - $mentions = $o->fetch("mentions"); - if ($mentions < 0) { - file_put_contents("log.txt", '[mentions.php] ERROR in $mentions'."\n", FILE_APPEND); - continue; - } - foreach($mentions["data"]["children"] as $mention) { - $processed = file_get_contents("processed.txt"); - if ($processed === false) { - file_put_contents("log.txt", "[mentions.php] ERROR: can't read processed.txt\n", FILE_APPEND); - continue; - } - if (in_array($mention["data"]["id"], explode("\n", $processed))) { - continue; - } - if (in_array($mention["data"]["subreddit"], explode("\n", file_get_contents("banned_subs.txt")))) { - continue; - } - if (in_array($mention["data"]["author"], explode("\n", file_get_contents("banned_users.txt")))) { - continue; - } - $post = explode("/", $mention["data"]["context"])[4]; - $post = $o->fetch("post", $post); - var_dump($post); - if ($post < 0) { - file_put_contents("log.txt", '[mentions.php] ERROR in $post'."\n", FILE_APPEND); - continue; - } - $post = $post[0]["data"]["children"][0]; - $parent = "t1_".$mention["data"]["id"]; - if (!file_put_contents("processed.txt", $mention["data"]["id"]."\n", FILE_APPEND)) { - file_put_contents("log.txt", "[mentions.php] ERROR mentions_processed.txt PUT\n", FILE_APPEND); - continue; - } - if (!in_array("media_metadata", array_keys($post["data"]))) { - $o->comment("Error: This post does not appear to be a gallery.$botsignature", $parent); - } else { - $imgs = ""; - foreach ($post["data"]["media_metadata"] as $metadata) { - $imgs .= get_string_between($metadata["s"]["u"], "dd.it/", "?width=").","; - } - $imgs = substr($imgs, 0, -1); // da odstranimo zadnjo vejico - $o->comment("[https://imglinkbot.ž.ga/?i=$imgs](https://imglinkbot.xn--jha.ga/?i=$imgs)$botsignature", $parent); - } - } - sleep(10); - } -?> diff --git a/bot/processed.txt b/bot/processed.txt deleted file mode 100644 index e69de29..0000000 diff --git a/main.php b/main.php index 31dee80..e453cae 100644 --- a/main.php +++ b/main.php @@ -209,6 +209,7 @@ Errors: } if ($limit>100) { echo "\n[oldredditclient] WARN get(): multipage not implemented (limit>100)!\n"; + return -4; } $ch = $this->ch; switch($what) { @@ -225,7 +226,7 @@ Errors: } $arr = json_decode($response, true, 512); return $arr; - break; + break; case "post": curl_setopt($ch, CURLOPT_URL, $this->redditurl.$value.".json"); curl_setopt($ch, CURLOPT_POST, 0); @@ -239,8 +240,24 @@ Errors: } $arr = json_decode($response, true, 512); return $arr; + break; // unreachable code amirite + case "comments": // value=r/Slovenia || value=u/first + curl_setopt($ch, CURLOPT_URL, $this->redditurl.$value."/comments/.json"); + curl_setopt($ch, CURLOPT_POST, 0); + curl_setopt($ch, CURLOPT_HTTPHEADER, array( + "X-Modhash: ".$this->modhash, + "X-ContactBotDeveloper: ".$this->adminemail + )); + $response = curl_exec($ch); + if (curl_getinfo($ch, CURLINFO_RESPONSE_CODE) != 200) { + return false; + } + $arr = json_decode($response, true, 512); + return $arr; + break; // te breake delam nagonsko default: return -5; + break; } } public function comment($text = "oldredditClient", $in_reply_to = "jd2fm5") { diff --git a/mentions/banned_subs.txt b/mentions/banned_subs.txt new file mode 100644 index 0000000..e69de29 diff --git a/mentions/banned_users.txt b/mentions/banned_users.txt new file mode 100644 index 0000000..e69de29 diff --git a/mentions/index.php b/mentions/index.php new file mode 100644 index 0000000..005efb0 --- /dev/null +++ b/mentions/index.php @@ -0,0 +1,27 @@ + + + + + + + ImgLinkBot + + + + + '; + } + ?> + + diff --git a/mentions/mentions.php b/mentions/mentions.php new file mode 100755 index 0000000..c3d095b --- /dev/null +++ b/mentions/mentions.php @@ -0,0 +1,55 @@ +#!/usr/bin/env php +setusername(getenv("orC_user")); + $o->setpassword(getenv("orC_pass")); + $botsignature = "\n\n-- [/u/ImgLinkBot](/u/ImgLinkBot)"; + while (true) { + $mentions = $o->fetch("mentions"); + if ($mentions < 0) { + file_put_contents("log.txt", '[mentions.php] ERROR in $mentions'."\n", FILE_APPEND); + continue; + } + foreach($mentions["data"]["children"] as $mention) { + $processed = file_get_contents("processed.txt"); + if ($processed === false) { + file_put_contents("log.txt", "[mentions.php] ERROR: can't read processed.txt\n", FILE_APPEND); + continue; + } + if (in_array($mention["data"]["id"], explode("\n", $processed))) { + continue; + } + if (in_array($mention["data"]["subreddit"], explode("\n", file_get_contents("banned_subs.txt")))) { + continue; + } + if (in_array($mention["data"]["author"], explode("\n", file_get_contents("banned_users.txt")))) { + continue; + } + $post = explode("/", $mention["data"]["context"])[4]; + $post = $o->fetch("post", $post); + var_dump($post); + if ($post < 0) { + file_put_contents("log.txt", '[mentions.php] ERROR in $post'."\n", FILE_APPEND); + continue; + } + $post = $post[0]["data"]["children"][0]; + $parent = "t1_".$mention["data"]["id"]; + if (!file_put_contents("processed.txt", $mention["data"]["id"]."\n", FILE_APPEND)) { + file_put_contents("log.txt", "[mentions.php] ERROR mentions_processed.txt PUT\n", FILE_APPEND); + continue; + } + if (!in_array("media_metadata", array_keys($post["data"]))) { + $o->comment("Error: This post does not appear to be a gallery.$botsignature", $parent); + } else { + $imgs = ""; + foreach ($post["data"]["media_metadata"] as $metadata) { + $imgs .= get_string_between($metadata["s"]["u"], "dd.it/", "?width=").","; + } + $imgs = substr($imgs, 0, -1); // da odstranimo zadnjo vejico + $o->comment("[https://imglinkbot.ž.ga/?i=$imgs](https://imglinkbot.xn--jha.ga/?i=$imgs)$botsignature", $parent); + } + } + sleep(10); + } +?> diff --git a/mentions/processed.txt b/mentions/processed.txt new file mode 100644 index 0000000..e69de29 diff --git a/mentions/worddetect.php b/mentions/worddetect.php new file mode 100755 index 0000000..9e63526 --- /dev/null +++ b/mentions/worddetect.php @@ -0,0 +1,38 @@ +#!/usr/bin/env php +setusername(getenv("orC_user")); + $o->setpassword(getenv("orC_pass")); + $botsignature = "\n\n-- [/u/PozigalecBot](/u/PozigalecBot)"; + while (true) { + $comments = $o->fetch("comments"); + if ($comments < 0) { + file_put_contents("log.txt", '[worddetect.php] ERROR in $comments'."\n", FILE_APPEND); + continue; + } + foreach($comment["data"]["children"] as $comment) { + $processed = file_get_contents("processed.txt"); + if ($processed === false) { + file_put_contents("log.txt", "[worddetect.php] ERROR: can't read processed.txt\n", FILE_APPEND); + continue; + } + if (in_array($comment["data"]["id"], explode("\n", $processed))) { + continue; + } + if (in_array($comment["data"]["subreddit"], explode("\n", file_get_contents("banned_subs.txt")))) { + continue; + } + if (in_array($comment"data"]["author"], explode("\n", file_get_contents("banned_users.txt")))) { + continue; + } + $parent = "t1_".$comment["data"]["id"]; + if (!file_put_contents("processed.txt", $comment["data"]["id"]."\n", FILE_APPEND)) { + file_put_contents("log.txt", "[worddetect.php] ERROR mentions_processed.txt PUT\n", FILE_APPEND); + continue; + } + $o->comment("Pa je zašvicu ful! $botsignature", $parent); // TODO! + } + sleep(10); + } +?> diff --git a/worddetect/banned_subs.txt b/worddetect/banned_subs.txt new file mode 100644 index 0000000..e69de29 diff --git a/worddetect/banned_users.txt b/worddetect/banned_users.txt new file mode 100644 index 0000000..e69de29 diff --git a/worddetect/processed.txt b/worddetect/processed.txt new file mode 100644 index 0000000..e69de29 diff --git a/worddetect/worddetect.php b/worddetect/worddetect.php new file mode 100755 index 0000000..9e63526 --- /dev/null +++ b/worddetect/worddetect.php @@ -0,0 +1,38 @@ +#!/usr/bin/env php +setusername(getenv("orC_user")); + $o->setpassword(getenv("orC_pass")); + $botsignature = "\n\n-- [/u/PozigalecBot](/u/PozigalecBot)"; + while (true) { + $comments = $o->fetch("comments"); + if ($comments < 0) { + file_put_contents("log.txt", '[worddetect.php] ERROR in $comments'."\n", FILE_APPEND); + continue; + } + foreach($comment["data"]["children"] as $comment) { + $processed = file_get_contents("processed.txt"); + if ($processed === false) { + file_put_contents("log.txt", "[worddetect.php] ERROR: can't read processed.txt\n", FILE_APPEND); + continue; + } + if (in_array($comment["data"]["id"], explode("\n", $processed))) { + continue; + } + if (in_array($comment["data"]["subreddit"], explode("\n", file_get_contents("banned_subs.txt")))) { + continue; + } + if (in_array($comment"data"]["author"], explode("\n", file_get_contents("banned_users.txt")))) { + continue; + } + $parent = "t1_".$comment["data"]["id"]; + if (!file_put_contents("processed.txt", $comment["data"]["id"]."\n", FILE_APPEND)) { + file_put_contents("log.txt", "[worddetect.php] ERROR mentions_processed.txt PUT\n", FILE_APPEND); + continue; + } + $o->comment("Pa je zašvicu ful! $botsignature", $parent); // TODO! + } + sleep(10); + } +?> -- cgit v1.2.3