diff options
author | sijanec <sijanecantonluka@gmail.com> | 2020-10-18 02:25:07 +0200 |
---|---|---|
committer | sijanec <sijanecantonluka@gmail.com> | 2020-10-18 02:25:07 +0200 |
commit | 3ee87bc75472706f24a90c208b384deef1a89cea (patch) | |
tree | cbfe88e549a870602c0575c8d8de993c6a34788b /bot/mentions.php | |
parent | modflair dodan (diff) | |
download | oldredditclient-3ee87bc75472706f24a90c208b384deef1a89cea.tar oldredditclient-3ee87bc75472706f24a90c208b384deef1a89cea.tar.gz oldredditclient-3ee87bc75472706f24a90c208b384deef1a89cea.tar.bz2 oldredditclient-3ee87bc75472706f24a90c208b384deef1a89cea.tar.lz oldredditclient-3ee87bc75472706f24a90c208b384deef1a89cea.tar.xz oldredditclient-3ee87bc75472706f24a90c208b384deef1a89cea.tar.zst oldredditclient-3ee87bc75472706f24a90c208b384deef1a89cea.zip |
Diffstat (limited to 'bot/mentions.php')
-rwxr-xr-x | bot/mentions.php | 54 |
1 files changed, 54 insertions, 0 deletions
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); + } +?> |