-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebhook.h
57 lines (48 loc) · 1.11 KB
/
webhook.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#pragma once
#include "options.h"
#include <dpp/dpp.h>
#include <string>
#include <vector>
namespace webhook
{
inline dpp::cluster &get_bot()
{
static dpp::cluster bot("");
return bot;
}
inline dpp::webhook &get_webhook()
{
static dpp::webhook webhook(global_options.webhook_url);
return webhook;
}
struct webhook_options
{
std::string author;
std::string title;
std::vector<std::pair<std::string, std::string>> fields;
std::string description;
std::string footer;
};
inline void send(webhook_options options)
{
if (global_options.webhook_url.empty())
return;
try
{
dpp::embed embed;
embed.set_title(options.title);
for (const auto &[key, value] : options.fields)
embed.add_field(key, value);
embed.set_description(options.description);
embed.set_footer(dpp::embed_footer { .text = options.footer });
embed.set_author(dpp::embed_author { .name = options.author });
embed.set_thumbnail("https://gopong.dev/chaos/chaos.png");
dpp::message msg;
msg.add_embed(embed);
get_bot().execute_webhook(get_webhook(), msg);
}
catch (dpp::exception)
{
}
}
}