-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgroupme.php
144 lines (111 loc) · 3.8 KB
/
groupme.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
<?php
require_once 'vendor/autoload.php';
require_once 'config.php';
function getHasher(){
return new Jenssegers\ImageHash\ImageHash(new Jenssegers\ImageHash\Implementations\DifferenceHash(16));
}
function post_GroupMe($msg, $group=0){
if(!$group) $group = $GLOBALS['main_bot'];
$ch = curl_init();
$url = 'https://api.groupme.com/v3/bots/post';
$fields = array(
'bot_id' => $group,
'text' => $msg
);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
curl_close($ch);
}
function craft_message($repost, $post, $sureness){
$date = ' from ' . date('M d, Y h:i:s A', $post['created_at']);
$poster = $post['name'];
$reposter = $repost['name'];
$caption = ($repost['text']) ? ' with caption "' . $repost['text'] . '"' : '';
$recency = '';
{
$recent_msgs = curl_GroupMe('', 15);
$i = 1;
foreach($recent_msgs as $msg){
if($msg['id'] == $repost['id']) break;
$i += 1;
}
$recency = ($i < 10) ? ( ($i == 1) ? ' just now' : ' ' . $i . ' messages ago' ) : ' a while ago';
}
if($repost['sender_id'] == '22102250'){
return '@' . $repost['name'] . ' reposted' . $date . $recency . $caption . ' but it is an iconic meme';
}
if($repost['name'] != $post['name']){
return '@' . $repost['name'] . ' totally just reposted ' . $post['name'] . '\'s post' . $date . $recency . $caption;
}else{
return '@' . $repost['name'] . ' just reposted their post' . $date . $recency . $caption;
}
}
function callout_repost($repost, $post, $sureness){
$msg = craft_message($repost, $post, $sureness);
$tag = array(
'loci' => array(array(
strpos($msg, '@'),
strlen($repost['name']) + 1
)),
'type' => 'mentions',
'user_ids' => array($repost['sender_id'])
);
$ch = curl_init();
$url = 'https://api.groupme.com/v3/bots/post';
$fields = array(
'bot_id' => $GLOBALS['main_bot'],
'text' => $msg,
'attachments' => array($tag)
);
//post_GroupMe(json_encode($fields));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
curl_close($ch);
}
function curl_GroupMe($last = '', $limit = 100){
$msg = curl_init();
$id = $GLOBALS['main_group'];
$url = 'https://api.groupme.com/v3/groups/' . $id . '/messages';
$fields = array(
'token' => $GLOBALS['api'],
'limit' => $limit,
'before_id' => $last
);
curl_setopt($msg, CURLOPT_URL, $url . '?' . http_build_query($fields));
curl_setopt($msg, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($msg);
curl_close($msg);
return json_decode($server_output, true)['response']['messages'];
}
function callback_GroupMe(){
return json_decode(file_get_contents('php://input'), true);
}
function get_GroupMe($id){
$prev = curl_GroupMe($id, 1)[0]['id'];
$msg = curl_init();
$id = $GLOBALS['main_group'];
$url = 'https://api.groupme.com/v3/groups/' . $id . '/messages';
$fields = array(
'token' => $GLOBALS['api'],
'limit' => 1,
'after_id' => $prev
);
curl_setopt($msg, CURLOPT_URL, $url . '?' . http_build_query($fields));
curl_setopt($msg, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($msg);
curl_close($msg);
return json_decode($server_output, true)['response']['messages'][0];
}
function get_attachment($msg){
foreach($msg['attachments'] as $attach){
if($attach['type'] == 'image') return $attach;
}
}