forked from askedrelic/todayIs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
postbot.php
165 lines (136 loc) · 4.84 KB
/
postbot.php
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?php
//electroly's thread parsing
require_once 'include/Global.php';
require_once 'shackapi.php';
require_once 'post.php';
require_once 'birthdayPost.php';
require_once 'infPost.php';
require_once 'lolPost.php';
require_once 'tagPost.php';
require_once 'unfPost.php';
require_once 'awardPost.php';
require_once 'shackmeetsPost.php';
require_once 'shackbattlesPost.php';
//set timezone to work with DateTime objects
date_default_timezone_set('America/New_York');
function date_diff2($date1, $date2) {
$current = $date1;
$datetime2 = date_create($date2);
$count = 0;
while(date_create($current) < $datetime2){
$current = gmdate("Y-m-d", strtotime("+1 day", strtotime($current)));
$count++;
}
return $count;
}
function differenceInDays($firstDate, $secondDate){
$firstDateTimeStamp = $firstDate->format("U");
$secondDateTimeStamp = $secondDate->format("U");
$rv = round ((($firstDateTimeStamp - $secondDateTimeStamp))/86400);
return $rv;
}
class PostBot {
public $username;
public $password;
public $parentId;
private $posts = array();
private $sleeptime;
private $debugMode;
public function __construct($username, $password, $sleeptime=120, $parentId = null) {
$this->username = $username;
$this->password = $password;
//default sleeptime between posts
$this->sleeptime = $sleeptime;
//override parentId if testing
$this->parentId = $parentId;
$this->setRootPost();
}
public function setRootPost() {
$p = new Post('');
$dayth = $p->ord_suf(date('z')+1);
$body = "*[y{Today is ".date('l\, \t\h\e jS \o\f F').", the {$dayth} day of ".date('Y').".}y]*\n";
//$body .= system("curl -Is slashdot.org | egrep '^X-(F|B|L)' | sed s/^X-//");
//TODO create quote database to use here
//$body .= "\n\n";
// $body .= "This is the Best Of shacknews:";
//$body .= "\n";
//$body .= $this->insertShackconRelease();
//$snacks = $this->insertBrownies();
//if (!empty($snacks)) {
// $body .= $snacks;
//}
$p->body = $body;
//make first post and override parentId
$this->parentId = $this->post($p);
}
public function makePosts() {
$this->addAwardPost();
//post all posts in the pool
foreach($this->posts as $p) {
print "--> on post {$p}\n";
print "--> sleeping for {$this->sleeptime} seconds\n";
sleep($this->sleeptime);
print "http://www.shacknews.com/chatty?id=" . $this->post($p);
print "\n";
}
}
public function addAwardPost() {
$awardPost = new AwardPost($this->posts);
if($awardPost->checkAwardWinner()) {
print "THERE ARE AWARDS!\n";
$this->addPost($awardPost);
}
}
public function addPost($post) {
//add a post to the pool
array_push($this->posts, $post);
}
private function post($post) {
try {
print "\n---------\n";
print $post->body;
print "\n---------\n";
return ShackApi::post($this->username, $this->password, $post->body, $this->parentId);
} catch (Exception $e) {
print "--> exception while posting {$e}\n";
while (true) {
print "--> exception caused sleep 120 secs\n";
sleep(120);
return ShackApi::post($this->username, $this->password, $post->body, $this->parentId);
}
}
}
private function insertBrownies() {
//sigh unix > php
//$snacks = system('curl -s http://www.defconyum.com/askedrelic.php');
//if (empty($snacks) || strripos($snacks, "closed") !== false) {
// return "";
//}
$ret = "\n";
/* $ret .= "HEY p[MULTISYNC]p buy some delicious "; */
$ret .= "Rest In Crumbles Defcon YUM :(\n";
$ret .+ "http://www.defconyum.com/goodbye.php\n";
/* $ret .= ", today only at http://www.defconyum.com/\n"; */
//if ($day == "2012-10-17") {
// $ret .= "Today only, r{Chocolate Overload Espresso Brownies}r";
//} elseif ($day == "2012-10-25") {
// $ret .= "r{Apple Cider Caramel Cookies}r";
//} else {
// return "";
//}
return $ret;
}
private function insertShackconRelease() {
$launch_date = new DateTime('2013-07-04');
$today = new DateTime("now");
$interval = differenceInDays($launch_date, $today);
if ($interval > 1) {
return "There are ". $interval ." days until Shackcon 2013!\n";
} elseif ($interval == 1) {
return "There is ". $interval ." day until Shackcon 2013!\n";
} elseif ($interval == 0) {
return "ZOMG VEGAS SHACKCON!!!\n";
}
}
}
?>