-
Notifications
You must be signed in to change notification settings - Fork 3
/
bukkitbot.php
98 lines (61 loc) · 2.67 KB
/
bukkitbot.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
<?php
$foundone = 'null';
$bukkitBaseURL = 'http://bukk.it/';
$channelToken = 'zgZtHd0u3l5KIbaHmpbIfIZH';
$channel = $_GET["channel_name"];
$username = $_GET["user_name"];
$request = $_GET["text"];
$header404 = 'HTTP/1.1 404 Not Found';
if ($request == "-help") {
echo "_BukkitBot -help:_ use either a whole file name (e.g. `clap.gif`) or you can leave the extension off (e.g. `clurb`) and BukkitBot will try to find a match. In the case of multiple matches (e.g. `catbus`) it will prioritize a gif over other file types. Use `-popular` to see some examples.";
} else if ($request == "-popular") {
echo "_BukkitBot -popular:_ `allthefucks`, `ameliewait`, `bale-kermit`, `beaker-freak`, `caruso`, `clap`, `facepalm`, `golfclap`, `gotime`, `gunn-cant`, `i-cant`, `imout`, `irl.jpg`, `jakedance`, `joy`, `lineup`, `maaaaaaaagic`, `mandybrown`, `mindblown`, `needhugs`, `no`, `nopenope`, `notallfish`, `omg`, `omgjake`, `oooooooo`, `party`, `pizzaaa`, `sad`, `shutup`, `skeletor`, `slayer`, `success`, `thinkin`, `umad`, `umguys`, `wat2`, `welp`, `whar.jpg`, `what.jpg`, `why`, `wilto`, `wonkagtfo`, `yay`, `yayyy`, `yes`, `zen`, `zeroregrets`";
} else if ($channel != 'general') {
echo "Sorry, BukkitBot only works in the #general channel for the moment.";
} else {
$file = $bukkitBaseURL . $request;
$file_headers = @get_headers($file);
if($file_headers[0] != $header404) {
$foundone = $file;
};
$file = $bukkitBaseURL . $request . '.jpg';
$file_headers = @get_headers($file);
if($file_headers[0] != $header404) {
$foundone = $file;
};
$file = $bukkitBaseURL . $request . '.jpeg';
$file_headers = @get_headers($file);
if($file_headers[0] != $header404) {
$foundone = $file;
};
$file = $bukkitBaseURL . $request . '.png';
$file_headers = @get_headers($file);
if($file_headers[0] != $header404) {
$foundone = $file;
};
$file = $bukkitBaseURL . $request . '.gif';
$file_headers = @get_headers($file);
if($file_headers[0] != $header404) {
$foundone = $file;
};
if ($foundone == "null") {
echo "BukkitBot looked for `" . $request . "` on `" . $bukkitBaseURL . "` but couldn't find an image :sob:";
} else {
$ch = curl_init();
$curlConfig = array(
CURLOPT_URL => "https://alistapart.slack.com/services/hooks/incoming-webhook?token=" . $channelToken,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => json_encode(array(
'text' => $foundone,
'username' => 'bukkit',
'channel_name' => $channel,
'username' => $username,
))
);
curl_setopt_array($ch, $curlConfig);
$result = curl_exec($ch);
curl_close($ch);
}
}
?>