-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpolice.php
More file actions
71 lines (62 loc) · 1.94 KB
/
police.php
File metadata and controls
71 lines (62 loc) · 1.94 KB
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
<?php
$command = $_POST['command'];
$text = $_POST['text'];
$token = $_POST['token'];
$username = $_POST['user_name'];
//$url = 'https://hooks.slack.com/services/<url>';
$url = '<Incoming Slack Webhook URL>';
if($token != '<token>'){
$msg = "Invalid Token.";
die($msg);
echo $msg;
}
// *************************************
// Function to post to Slack Channel
// *************************************
function slackPost($dest,$user,$icon,$msg){
$ch = curl_init($GLOBALS['url']);
$payload = array(
'channel' => $dest,
'username' => $user,
'text' => $msg,
'icon_emoji' => $icon
);
$jsonDataEncoded = json_encode($payload);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$result = curl_exec($ch);
}
// *************************************
// Function to callPolice
// *************************************
function callPolice($textPart,$username){
if ($textPart[0] != ''){
$dest = $textPart[0];
slackPost($dest,'SlackPolice',':slackpolice:','Ok folks, Please move along... perhaps to #simple-social');
}else{
$reply = "Where do you want me to send the police? \n";
$reply .= ":interrobang: *Help* \n";
$reply .= "Usage: /police [channel] \n";
$reply .= "*/police #example* - Deploys police to the example channel \n";
echo $reply;
}
}
// *************************************
// Function to call action
// *************************************
function callAction($textPart,$username){
$action = $textPart[0];
if ($action == 'help'){
$reply = ":interrobang: *Help* \n";
$reply .= "Usage: /police [channel] \n";
$reply .= "*/police #example* - Deploys police to the example channel \n";
echo $reply;
}else{
callPolice($textPart,$username);
}
}
$debug = false;
$textPart = preg_split('/\s+/', $text);
callAction($textPart,$username);
?>