2021-01-20 23:29:57 +00:00
|
|
|
<?php
|
2023-09-04 23:09:01 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Mcp\Util;
|
|
|
|
|
|
|
|
class DiscordUtil
|
|
|
|
{
|
|
|
|
public static function sendMessageToWebhook($webhook, $title, $message): void
|
2021-01-20 23:29:57 +00:00
|
|
|
{
|
2023-09-05 20:00:18 +00:00
|
|
|
$rawMessage = file_get_contents("data/discordMessage.json");
|
2023-08-27 03:31:32 +00:00
|
|
|
$rawMessage = str_replace("%%message%%", $message, $rawMessage);
|
|
|
|
$rawMessage = str_replace("%%title%%", $title, $rawMessage);
|
2021-01-20 23:29:57 +00:00
|
|
|
|
|
|
|
$options = [
|
|
|
|
'http' => [
|
|
|
|
'method' => 'POST',
|
|
|
|
'header' => 'Content-Type: application/json',
|
|
|
|
'timeout' => 3,
|
2023-08-27 03:31:32 +00:00
|
|
|
'content' => $rawMessage
|
2021-01-20 23:29:57 +00:00
|
|
|
]
|
|
|
|
];
|
|
|
|
|
2023-08-27 03:31:32 +00:00
|
|
|
file_get_contents($webhook, false, stream_context_create($options));
|
2021-01-20 23:29:57 +00:00
|
|
|
}
|
2023-09-04 23:09:01 +00:00
|
|
|
}
|