fix: address code review — log curl_exec errors, update discordmsg docblock
Agent-Logs-Url: https://github.com/GameServerPanel/GSP/sessions/e4d38343-77ed-4c7a-afac-a2a815a059fd Co-authored-by: iaretechnician <2749183+iaretechnician@users.noreply.github.com>
This commit is contained in:
parent
4babef08eb
commit
57400aba81
1 changed files with 7 additions and 37 deletions
|
|
@ -24,43 +24,10 @@
|
|||
|
||||
#functions go here
|
||||
|
||||
//discordmsg() posts a message to webhook
|
||||
//can post form data. Minium is username and content
|
||||
/*
|
||||
$msg = json_decode('
|
||||
{
|
||||
"username":"BOTNAME",
|
||||
"content":"The message the BOTNAME posts.",
|
||||
"embeds": [{
|
||||
"title":"The Link Title",
|
||||
"description":"The Link Description",
|
||||
"url":"https://www.thelinkurl.com/",
|
||||
"color":DECIMALCOLORCODE,
|
||||
"author":{
|
||||
"name":"Site Name",
|
||||
"url":"https://www.sitelink.com/",
|
||||
"icon_url":"URLTOIMG"
|
||||
},
|
||||
"fields":[
|
||||
{
|
||||
"name":"LISTITEM1",
|
||||
"value":"LISTVALUE1",
|
||||
"inline":true
|
||||
},
|
||||
{
|
||||
"name":"LISTITEM2",
|
||||
"value":"LISTVALUE2",
|
||||
"inline":true
|
||||
},
|
||||
{
|
||||
"name":"LISTITEM3",
|
||||
"value":"LISTVALUE3",
|
||||
"inline":true
|
||||
}]
|
||||
}]
|
||||
}
|
||||
', true);
|
||||
*/
|
||||
//discordmsg() posts a message to a Discord webhook.
|
||||
// $msg - associative array (e.g. ['content' => '...']) to send as payload_json.
|
||||
// $webhook - Discord webhook URL; no-op (returns false) when empty.
|
||||
// Returns the response string on success, or false on failure / skipped.
|
||||
function discordmsg($msg, $webhook) {
|
||||
if (empty($webhook)) {
|
||||
return false;
|
||||
|
|
@ -80,6 +47,9 @@ function discordmsg($msg, $webhook) {
|
|||
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
|
||||
$result = curl_exec($ch);
|
||||
if ($result === false) {
|
||||
error_log("GSP Discord webhook error: " . curl_error($ch));
|
||||
}
|
||||
curl_close($ch);
|
||||
return $result;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue