-
Notifications
You must be signed in to change notification settings - Fork 0
/
elonshow.php
63 lines (54 loc) · 1.53 KB
/
elonshow.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
<?php
$commandText = TEXT;
$ids = array();
if(preg_match('/<@(\w+)\|(\w+)>/', $commandText, $user_matches) ) {
$user_name = $user_matches[2];
$user_id = trim($user_matches[1], "@");
array_push($ids, array(
"id" => $user_id,
"name" => $user_id,
));
} else if (preg_match('/<!(\w+)>/', $commandText, $user_matches)) {
$group = $user_matches[1];
if( $group === "everyone" ) {
$allUsers = json_decode(execCurl("https://slack.com/api/users.list", array("presence" => true)), true);
foreach ($allUsers["members"] as $key => $user) {
if( !$user["deleted"] && !$user["is_bot"] && $user["id"] !== "USLACKBOT" ) {
array_push($ids, array(
"id" => $user["id"],
"name" => $user["name"],
));
}
}
} else {
returnToSlackChannel("Nie podałeś użytkownika!");
exit();
}
} else {
returnToSlackChannel("Nie podałeś użytkownika!");
exit();
}
$query = "SELECT * FROM `users`";
for($x=0; $x<count($ids); $x++){
if( $x === 0 ) {
$query .= " WHERE ";
} else {
$query .= " OR ";
}
$query .= "`id` = ";
$query .= "'". $ids[$x]["id"] ."'";
}
$all_reps = execQuery($query);
$outputText = "";
foreach ($all_reps as $key => $value) {
$reps[$value["id"]] = $value["reputation"];
}
for($x=0; $x<count($ids); $x++){
$user_id = $ids[$x]["id"];
$user_name = $ids[$x]["name"];
$rep = isset($reps[$user_id]) ? $reps[$user_id] : 0;
$outputText .= "Reputacja użytkownika <@$user_id|$user_name> to *$rep*.\n";
}
returnToSlackChannel($outputText);
// /elon show @channel
?>