Implement Discord reporting (requires get_discord_webhook() in config)

This commit is contained in:
Sanqui 2021-06-28 12:41:42 -07:00
parent 0b023e761a
commit 57185f6cda

View File

@ -1335,7 +1335,7 @@ function addslashes_array($data) {
} }
} }
// general purpose report function, now with discord!
function xk_ircout($type, $user, $in) { function xk_ircout($type, $user, $in) {
// gone // gone
@ -1357,18 +1357,33 @@ function addslashes_array($data) {
if ($in['pmatch'] >= 3) $color = array(7, 4); if ($in['pmatch'] >= 3) $color = array(7, 4);
elseif ($in['pmatch'] >= 5) $color = array(4, 5); elseif ($in['pmatch'] >= 5) $color = array(4, 5);
$extra = " (". xk($color[1]) ."Password matches: ". xk($color[0]) . $in['pmatch'] . xk() .")"; $extra = " (". xk($color[1]) ."Password matches: ". xk($color[0]) . $in['pmatch'] . xk() .")";
$extradiscord = " (**Password matches**: " . $in['pmatch'] . ")";
} }
$out = "1|New user: #". xk(12) . $in['id'] . xk(11) ." $user ". xk() ."(IP: ". xk(12) . $in['ip'] . xk() .")$extra: https://jul.rustedlogic.net/?u=". $in['id']; $out = "1|New user: #". xk(12) . $in['id'] . xk(11) ." $user ". xk() ."(IP: ". xk(12) . $in['ip'] . xk() .")$extra: https://jul.rustedlogic.net/?u=". $in['id'];
$outdiscord = "New user: **#" . $in['id'] . "** (IP: " . $in['ip'] . ")$extra: <https://jul.rustedlogic.net/?u=" . $in['id'] . ">";
} else { } else {
// global $sql; // global $sql;
// $res = $sql -> resultq("SELECT COUNT(`id`) FROM `posts`"); // $res = $sql -> resultq("SELECT COUNT(`id`) FROM `posts`");
$out = "$dest|New $type by ". xk(11) . $user . xk() ." (". xk(12) . $in['forum'] .": ". xk(11) . $in['thread'] . xk() ."): https://jul.rustedlogic.net/?p=". $in['pid']; $out = "$dest|New $type by ". xk(11) . $user . xk() ." (". xk(12) . $in['forum'] .": ". xk(11) . $in['thread'] . xk() ."): https://jul.rustedlogic.net/?p=". $in['pid'];
$outdiscord = "New $type by **" . $user . "** (" . $in['forum'] . ": **" . $in['thread'] . "**): <https://jul.rustedlogic.net/?p=". $in['pid'] . ">";
} }
xk_ircsend($out); xk_ircsend($out);
// discord part
// logic to decide where the message goes based on info provided
if (!function_exists('get_discord_webhook')) return;
$wh_url = get_discord_webhook($type, $user, $in);
if (!$wh_url) return;
discord_send($wh_url, $outdiscord);
} }
function xk_ircsend($str) { function xk_ircsend($str) {
@ -1387,6 +1402,28 @@ function addslashes_array($data) {
return true; return true;
} }
function discord_send($url, $msg) {
// stripped down from https://gist.github.com/Mo45/cb0813cb8a6ebcd6524f6a36d4f8862c
$json_data = json_encode([
"content" => $msg
], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
// echo $response;
curl_close($ch);
return true;
}
function xk($n = -1) { function xk($n = -1) {
if ($n == -1) $k = ""; if ($n == -1) $k = "";
else $k = str_pad($n, 2, 0, STR_PAD_LEFT); else $k = str_pad($n, 2, 0, STR_PAD_LEFT);