summaryrefslogtreecommitdiffstats
path: root/worddetect/worddetect.php
blob: 9e635269a0f3c3da4315ea1e3c368fb9454ea989 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/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/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);
	}
?>