summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bot/banned_subs.txt0
-rw-r--r--bot/banned_users.txt0
-rwxr-xr-xbot/mentions.php54
-rw-r--r--bot/processed.txt1
-rw-r--r--main.php65
-rw-r--r--mentions.php21
6 files changed, 140 insertions, 1 deletions
diff --git a/bot/banned_subs.txt b/bot/banned_subs.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/bot/banned_subs.txt
diff --git a/bot/banned_users.txt b/bot/banned_users.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/bot/banned_users.txt
diff --git a/bot/mentions.php b/bot/mentions.php
new file mode 100755
index 0000000..0b4345e
--- /dev/null
+++ b/bot/mentions.php
@@ -0,0 +1,54 @@
+#!/usr/bin/env php
+<?php
+ require_once("../main.php");
+ $o = new oldredditClient();
+ $o->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=");
+ }
+ $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
new file mode 100644
index 0000000..4fde78b
--- /dev/null
+++ b/bot/processed.txt
@@ -0,0 +1 @@
+g95m3jm
diff --git a/main.php b/main.php
index 0b869e6..31dee80 100644
--- a/main.php
+++ b/main.php
@@ -59,7 +59,7 @@ Errors:
-2 you are not logged in (aj blin trms of srvis bi neseseri)
-3 bad username and/or password (diplomatski odgovor ;-)
-4 not written yet (suka bljet)
- -5
+ -5 value from argument not supported
-6 error in fetched data
0 bad
1 good
@@ -69,8 +69,10 @@ Errors:
private $password;
public $version = array(0, 0, 1);
private $programname = "oldredditclient";
+ private $adminemail = "a"."n"."t"."o"."n"."@"."s"."i"."j"."a"."n"."ec.eu";
private $programdomain = 'oldredditclient.sijanec.eu';
private $cookiedir; // set at runtime, ker je get_curerent_user, v login()
+ private $redditurl = "https://old.reddit.com/";
private $loginurl = "https://old.reddit.com/api/login/";
private $setflairurl = "https://old.reddit.com/api/selectflair";
private $modflairurl = "https://old.reddit.com/api/flair";
@@ -199,5 +201,66 @@ Errors:
}
return true;
}
+ public function fetch($what = "mentions", $value = "jd2fm5", $limit = 100) {
+ if(!curl_getinfo($this->ch)) {
+ if (!$this->login()) {
+ return -2;
+ }
+ }
+ if ($limit>100) {
+ echo "\n[oldredditclient] WARN get(): multipage not implemented (limit>100)!\n";
+ }
+ $ch = $this->ch;
+ switch($what) {
+ case "mentions":
+ curl_setopt($ch, CURLOPT_URL, $this->redditurl."message/mentions.json?limit=".$limit);
+ 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;
+ case "post":
+ curl_setopt($ch, CURLOPT_URL, $this->redditurl.$value.".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;
+ default:
+ return -5;
+ }
+ }
+ public function comment($text = "oldredditClient", $in_reply_to = "jd2fm5") {
+ if (!curl_getinfo($this->ch)) {
+ if (!$this->login()) {
+ return -2;
+ }
+ }
+ $ch = $this->ch;
+ curl_setopt($ch, CURLOPT_URL, $this->redditurl."api/comment");
+ curl_setopt($ch, CURLOPT_POST, 1);
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array(
+ 'X-Modhash: '.$this->modhash,
+ 'X-ContactBotDeveloper: '.$this->adminemail
+ ));
+ curl_setopt($ch, CURLOPT_POSTFIELDS, "thing_id=$in_reply_to&text=".urlencode($text));
+ $response = curl_exec($ch);
+ if (curl_getinfo($ch, CURLINFO_RESPONSE_CODE) != 200)
+ return false;
+ return true;
+ }
}
?>
diff --git a/mentions.php b/mentions.php
new file mode 100644
index 0000000..66d35e1
--- /dev/null
+++ b/mentions.php
@@ -0,0 +1,21 @@
+<?php
+ require_once("../main.php");
+ $o = new oldredditclient();
+ $o->setusername($_ENV["orc_user"]);
+ $o->setpasword($_ENV["orc_pass"]);
+ while (true) {
+ $mentions = $o->get("mentions");
+ if ($mentions < 0) {
+ echo "\n".'[mentions.php] ERROR in $mentions';
+ continue;
+ }
+ foreach($mentions["data"]["children"] as $mention) {
+ if (in_array(explode("\n", file_get_contents("banned_subs.txt")), $mention["subreddit"])) {
+ continue;
+ }
+ if (in_array(explode("\n", file_get_contents("banned_authors.txt")), $mention["author"])) {
+ continue;
+ }
+ }
+ }
+?>