Repository navigation
Expand file tree
/
Copy pathindex.php
More file actions
40 lines (38 loc) · 2.67 KB
/
Copy pathindex.php
File metadata and controls
40 lines (38 loc) · 2.67 KB
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
39
40
<?php
/*
TODO for next archiving of /r/trumptracker: Change t3 to t4 on line 23 and add new mode which deletes all 'please use the comments' comments from /u/TrumpTracker.
Made by /u/Luit03 for /r/TrumpTracker
*/
require('trumptrackerbot.class.php');
$clientId = ""; //App credentials from https://www.reddit.com/prefs/apps/
$clientSecret = "";
$mode = "";
$debug = true;
set_time_limit(0);
$bot = new TrumpTrackerBot($clientId,$clientSecret);
if(!isset($_GET['code'])) { //TrumpTracker is not logged in, lets ask to log in
$bot->oAuthLogin();
}
else {
$bot->connectToReddit($_GET['code']); //We have permission, lets log in
$json = $bot->getData(); //Get the data.json
foreach($json['promises'] as $index => $promise) { //For every policy or quote from Donald Trump
if($mode == "archiving") {
$comment = $bot->submitComment("**This is an archived post. You won't be able to vote or comment.**\n\nReddit automatically archives posts after 6 months. Therefore, [a new post has been created to discuss this promise or policy](" . $promise['url'] . "?reddit).\n\n------\n\n*This comment was automatically generated by the official TrumpTracker-bot.*","t3_" . str_replace("https://redd.it/","",$promise['comments'][0]));
$bot->distinguishItem($comment['result']['json']['data']['things'][0]['data']['name'],"yes",true);
}
elseif($mode == "new") {
$format = $bot->format($promise['title'],$promise['url']); //Make a template for the post
$post = $bot->submitPost($format['title'],$format['url'],"trumptracker"); //Submit the template to the subreddit
$comment = $bot->submitComment("Please use the comments to discuss this promise/policy. Please keep comments civil and respect everyone's opinion.\n\n------\n\n*This post was automatically generated by the official TrumpTracker-bot.*\n\n[Official website](https://trumptracker.github.io) | [Submit new policy](https://viren8.typeform.com/to/CA1RiV?) | [About TrumpTracker](https://trumptracker.github.io/about/) | [Contribute](https://github.com/TrumpTracker/trumptracker.github.io)",$post['result']['json']['data']['name']);
$bot->distinguishItem($comment['result']['json']['data']['things'][0]['data']['name'],"yes",true); //Sticky and distinguish the comment
$bot->distinguishItem($post['result']['json']['data']['name'],"yes"); //Distinguish the post
$bot->approvePost($post['result']['json']['data']['name']); //Auto approve the post
array_unshift($json['promises'][$index]['comments'], "https://redd.it/" . $post['result']['json']['data']['link_id']); //Add the new url to data.json
}
if($debug || file_exists('kill.txt')) { //If killswitch is activated
die();
}
}
$bot->exportJSON($json,"data.json"); //Export the new data.json
}