-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrelay_functions.php
More file actions
69 lines (64 loc) · 2.35 KB
/
Copy pathrelay_functions.php
File metadata and controls
69 lines (64 loc) · 2.35 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
<?php
namespace CluebotNG;
/*
* Copyright (C) 2015 Jacobi Carter and Chris Breneman
*
* This file is part of ClueBot NG.
*
* ClueBot NG is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* ClueBot NG is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ClueBot NG. If not, see <http://www.gnu.org/licenses/>.
*/
class Relay
{
public static function publishEdit($change, $score = null, $reverted = false, $comment = null)
{
if ($score !== null || $reverted === true) {
self::send(json_encode([
'change' => [
'namespace' => $change['namespace'],
'title' => $change['namespaced_title'],
'revision_id' => $change['revid'],
'flags' => $change['flags'],
'user' => $change['user'],
'length' => $change['length'],
'comment' => $change['comment'],
'url' => $change['url'],
],
'score' => $score,
'reverted' => $reverted,
'comment' => $comment,
]));
}
}
public static function publishWarnedUser($username, $level)
{
self::send(json_encode(['username' => $username, 'level' => $level]));
}
private static function send($payload)
{
global $logger;
$url = 'http://' . Config::$relay_host . ':' . Config::$relay_port;
$logger->debug('Sending to ' . $url . ': ' . $payload);
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_TIMEOUT => 1,
CURLOPT_CONNECTTIMEOUT => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_POSTFIELDS => $payload,
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
]);
curl_exec($ch);
}
}