-
Notifications
You must be signed in to change notification settings - Fork 2
/
insulter.php
38 lines (31 loc) · 1.04 KB
/
insulter.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
<?php
/**
* @author Mathias Larsen <[email protected]>
* @link https://github.com/tripox/slack-insulter
* @todo Add more insults
*/
require 'vendor/autoload.php';
// Array with insults
$insults = file('insults.txt');
// Pick a random insult
$insult = array_rand($insults);
// Find a 🖕 fuck you GIF on Giphy
$url = 'http://api.giphy.com/v1/gifs/translate?s=fuck+you&api_key=dc6zaTOxFJmzC&limit=1';
$image = json_decode(file_get_contents($url));
$imageurl = $image->data->images->original->url;
// Our JSON payload to Slack
$data = array(
'response_type' => 'in_channel',
'mrkdwn' => true,
'text' => !empty($_POST['text']) ? '*Hey ' . '<' . $_POST['text'] . '>!*' : '*Hey!*',
'attachments' => array(
array(
'image_url' => $imageurl,
'pretext' => 'You\'ve been insulted with :hearts: by <@' . $_POST['user_name'] . '>',
'text' => $insults[$insult] . ' :trollface:',
),
),
);
$client = new \GuzzleHttp\Client();
$request = $client->request('POST', $_POST['response_url'], ['body' => json_encode($data)]);
$request->send();