ReportNotifier Slack notification support
This commit is contained in:
parent
df4c402f1a
commit
d09953da07
@ -1669,3 +1669,9 @@
|
||||
'<a href="https://youtu.be/$2" target="_blank" class="file">'.
|
||||
'<img style="width:360px;height:270px;" src="//img.youtube.com/vi/$2/0.jpg" class="post-image"/>'.
|
||||
'</a></div>';
|
||||
|
||||
// Slack Report Notification
|
||||
$config['slack'] = true;
|
||||
$config['slack_channel'] = "reports";
|
||||
$config['slack_incoming_webhook_endpoint'] = "https://hooks.slack.com/services/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";
|
||||
|
||||
|
38
post.php
38
post.php
@ -141,15 +141,15 @@ if (isset($_POST['delete'])) {
|
||||
markup($reason);
|
||||
|
||||
foreach ($report as &$id) {
|
||||
$query = prepare(sprintf("SELECT `thread` FROM ``posts_%s`` WHERE `id` = :id", $board['uri']));
|
||||
$query = prepare(sprintf("SELECT `thread` , `body_nomarkup` FROM ``posts_%s`` WHERE `id` = :id", $board['uri']));
|
||||
$query->bindValue(':id', $id, PDO::PARAM_INT);
|
||||
$query->execute() or error(db_error($query));
|
||||
|
||||
$thread = $query->fetchColumn();
|
||||
$thread = $query->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($config['syslog'])
|
||||
_syslog(LOG_INFO, 'Reported post: ' .
|
||||
'/' . $board['dir'] . $config['dir']['res'] . link_for($post) . ($thread ? '#' . $id : '') .
|
||||
'/' . $board['dir'] . $config['dir']['res'] . link_for($post) . ($thread['thread'] ? '#' . $id : '') .
|
||||
' for "' . $reason . '"'
|
||||
);
|
||||
$query = prepare("INSERT INTO ``reports`` VALUES (NULL, :time, :ip, :board, :post, :reason)");
|
||||
@ -159,6 +159,38 @@ if (isset($_POST['delete'])) {
|
||||
$query->bindValue(':post', $id, PDO::PARAM_INT);
|
||||
$query->bindValue(':reason', $reason, PDO::PARAM_STR);
|
||||
$query->execute() or error(db_error($query));
|
||||
if ($config['slack'])
|
||||
{
|
||||
function slack($message, $room = "reports", $icon = ":no_entry_sign:")
|
||||
{
|
||||
$room = ($room) ? $room : "reports";
|
||||
$data = "payload=" . json_encode(array(
|
||||
"channel" => "#{$room}",
|
||||
"text" => urlencode($message),
|
||||
"icon_emoji" => $icon
|
||||
));
|
||||
|
||||
// You can get your webhook endpoint from your Slack settings
|
||||
// For some reason using the configuration key doesn't work
|
||||
//$ch = curl_init($config['slack_incoming_webhook_endpoint']);
|
||||
$ch = curl_init("https://hooks.slack.com/services/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");
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$result = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
$postcontent = mb_substr($thread['body_nomarkup'], 0, 120) . '... _*(POST TRIMMED)*_';
|
||||
$slackmessage = 'Post: <' .$config['domain'] . "/mod.php?/" . $board['dir'] . $config['dir']['res'] . ( $thread['thread'] ? $thread['thread'] : $id ) . ".html" . ($thread['thread'] ? '#' . $id : '') . '> \n Post Content: ' . $postcontent . '\n Reason: ' . $reason . '\n';
|
||||
|
||||
$slackresult = slack($slackmessage, $config['slack_channel']);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
$is_mod = isset($_POST['mod']) && $_POST['mod'];
|
||||
|
Loading…
Reference in New Issue
Block a user