-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.php
73 lines (58 loc) · 2.19 KB
/
bot.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
<?php
/**
* YourHusbandoBot
*
* @author @vampire__
* @author @alvaroveliz
* @version 1.0
*/
require_once 'libs/twitteroauth.php';
require_once 'config.php';
include 'husbando.php';
// configuring twitter
$twitter = new twitteroauth(CONSUMER_KEY, CONSUMER_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET);
// getting user mentions
$mentions_url = 'https://api.twitter.com/1.1/statuses/mentions_timeline.json';
$statuses_url = 'https://api.twitter.com/1.1/statuses/update.json';
$upload_url = 'https://upload.twitter.com/1.1/media/upload.json';
$mentions_params = array();
$mentions = $twitter->get($mentions_url, $mentions_params);
// using while because foreach and for uses more memory :3
$m = 0;
if (array_key_exists('errors', $mentions)) {
print_r($mentions);
} else {
while ($m < (count($mentions)-1)) {
$user_to_reply = $mentions[$m]->user->screen_name;
$tweet_id = $mentions[$m]->id;
$husbando = what_is_my_husbando($user_to_reply, $tweet_id);
if ($husbando !== false) {
// first we upload the photo
$image_path = 'husbandos/'.$husbando['picture'];
$uploaded_image = '';
if (file_exists($image_path)) {
echo "Uploading husbando picture : ".$image_path."\r\n";
$media_base64 = base64_encode(file_get_contents($image_path));
$image_params = array(
'media' => $media_base64
);
$uploaded_image = $twitter->post($upload_url, $image_params);
}
$status = '@'.$user_to_reply.' Your husbando is '.$husbando['name'];
echo date('Y-m-d H:i:s') . ' -- '. $status."\r\n";
$tweet_params = array(
'status' => $status,
'in_reply_to_status_id' => $mentions[$m]->id,
);
if (is_object($uploaded_image)) {
$tweet_params['media_ids'] = "$uploaded_image->media_id_string";
}
$twitter->post($statuses_url, $tweet_params);
} else {
echo "Husbando already sent to ".$user_to_reply."\r\n";
}
$m++;
}
}
echo '========== Process end at '.date('d-m-Y H:i:s').'==========';
exit;