2024-06-27 15:58:40 +00:00
|
|
|
module shared_utils.discord;
|
|
|
|
|
2024-08-03 18:15:41 +00:00
|
|
|
void sendDiscordMessage(string webhookUrl, string msg) {
|
2024-06-27 15:58:40 +00:00
|
|
|
import requests;
|
|
|
|
import std.string : strip;
|
|
|
|
import std.stdio;
|
|
|
|
import std.format;
|
|
|
|
string payload = "{\"content\": \"" ~ strip(msg) ~ "\"}";
|
|
|
|
try {
|
|
|
|
Request rq = Request();
|
2024-08-03 18:15:41 +00:00
|
|
|
Response resp = rq.post(webhookUrl, payload, "application/json");
|
2024-06-27 15:58:40 +00:00
|
|
|
if (resp.code >= 300) {
|
|
|
|
writeln(resp.code);
|
|
|
|
writeln(resp.responseBody);
|
|
|
|
throw new Exception(format!"Discord message failed with code %d: %s"(resp.code, resp.responseBody));
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
stderr.writefln("Failed to send discord webhook message: ", e);
|
|
|
|
}
|
|
|
|
}
|