Discord.C++ 0.13.0
Loading...
Searching...
No Matches
static.h
Go to the documentation of this file.
1#pragma once
2#define VERSION "0.13.0"
3
4#define GATEWAY_URL "wss://gateway.discord.gg?v=10&encoding=json&compress=zlib-stream"
5#define API_PREFIX "/api/v10"
6#define DISCORD_HOST "discord.com"
7
8#ifdef _WIN32
9#define DLL_EXPORT __declspec(dllexport)
10#else
11#define DLL_EXPORT
12#endif
13
14#include <boost/asio/ssl/context.hpp>
15#include <nlohmann/json.hpp>
16#include <optional>
17
18using json = nlohmann::json;
19
20DLL_EXPORT void hexchar(unsigned char c, unsigned char& hex1, unsigned char& hex2);
21DLL_EXPORT std::string urlencode(std::string s);
22
23DLL_EXPORT void load_ssl_certificates(boost::asio::ssl::context& ssl_context);
24
25DLL_EXPORT inline bool has_value(const json& j, const std::string& key) {
26 return j.count(key) > 0 && !j.at(key).is_null();
27}
28
29template <class T>
30DLL_EXPORT T get_or_else(const json& j, const std::string& key, const T& _default) {
31 if (j.count(key) == 0 || j.at(key).is_null())
32 return _default;
33 else
34 return j.at(key).get<T>();
35}
36
37template <class T>
38DLL_EXPORT std::optional<T> get_optional(const json& j, const std::string& key) {
39 if (j.count(key) == 0 || j.at(key).is_null())
40 return {};
41 else
42 return std::make_optional<T>(j.at(key).get<T>());
43}
#define DLL_EXPORT
Definition static.h:11
bool has_value(const json &j, const std::string &key)
Definition static.h:25
void load_ssl_certificates(boost::asio::ssl::context &ssl_context)
Definition static.cpp:41
std::string urlencode(std::string s)
Definition static.cpp:16
std::optional< T > get_optional(const json &j, const std::string &key)
Definition static.h:38
nlohmann::json json
Definition static.h:18
void hexchar(unsigned char c, unsigned char &hex1, unsigned char &hex2)
Definition static.cpp:9
T get_or_else(const json &j, const std::string &key, const T &_default)
Definition static.h:30